blob: c82ff81150ecd60e47348015352de896acf78b3c [file] [log] [blame]
Yegappan Lakshmanan810785c2024-12-30 10:29:44 +01001*builtin.txt* For Vim version 9.1. Last change: 2024 Dec 30
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
Yegappan Lakshmanan810785c2024-12-30 10:29:44 +010070base64_decode({string}) Blob base-64 decode {string} characters
71base64_encode({blob}) String base-64 encode the bytes in {blob}
Christ van Willegence0ef912024-06-20 23:41:59 +020072bindtextdomain({package}, {path})
Christ van Willegen8252ef12024-07-11 21:36:21 +020073 Bool bind text domain to specified path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000074blob2list({blob}) List convert {blob} into a list of numbers
75browse({save}, {title}, {initdir}, {default})
76 String put up a file requester
77browsedir({title}, {initdir}) String put up a directory requester
78bufadd({name}) Number add a buffer to the buffer list
79bufexists({buf}) Number |TRUE| if buffer {buf} exists
80buflisted({buf}) Number |TRUE| if buffer {buf} is listed
81bufload({buf}) Number load buffer {buf} if not loaded yet
82bufloaded({buf}) Number |TRUE| if buffer {buf} is loaded
83bufname([{buf}]) String Name of the buffer {buf}
84bufnr([{buf} [, {create}]]) Number Number of the buffer {buf}
85bufwinid({buf}) Number window ID of buffer {buf}
86bufwinnr({buf}) Number window number of buffer {buf}
87byte2line({byte}) Number line number at byte count {byte}
Christian Brabandt67672ef2023-04-24 21:09:54 +010088byteidx({expr}, {nr} [, {utf16}])
89 Number byte index of {nr}'th char in {expr}
90byteidxcomp({expr}, {nr} [, {utf16}])
91 Number byte index of {nr}'th char in {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000092call({func}, {arglist} [, {dict}])
93 any call {func} with arguments {arglist}
94ceil({expr}) Float round {expr} up
95ch_canread({handle}) Number check if there is something to read
96ch_close({handle}) none close {handle}
97ch_close_in({handle}) none close in part of {handle}
98ch_evalexpr({handle}, {expr} [, {options}])
99 any evaluate {expr} on JSON {handle}
100ch_evalraw({handle}, {string} [, {options}])
101 any evaluate {string} on raw {handle}
102ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
103ch_getjob({channel}) Job get the Job of {channel}
104ch_info({handle}) String info about channel {handle}
105ch_log({msg} [, {handle}]) none write {msg} in the channel log file
106ch_logfile({fname} [, {mode}]) none start logging channel activity
107ch_open({address} [, {options}])
108 Channel open a channel to {address}
109ch_read({handle} [, {options}]) String read from {handle}
110ch_readblob({handle} [, {options}])
111 Blob read Blob from {handle}
112ch_readraw({handle} [, {options}])
113 String read raw from {handle}
114ch_sendexpr({handle}, {expr} [, {options}])
115 any send {expr} over JSON {handle}
116ch_sendraw({handle}, {expr} [, {options}])
117 any send {expr} over raw {handle}
118ch_setoptions({handle}, {options})
119 none set options for {handle}
120ch_status({handle} [, {options}])
121 String status of channel {handle}
122changenr() Number current change number
123char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr}
124charclass({string}) Number character class of {string}
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000125charcol({expr} [, {winid}]) Number column number of cursor or mark
Christian Brabandt67672ef2023-04-24 21:09:54 +0100126charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000127 Number char index of byte {idx} in {string}
128chdir({dir}) String change current working directory
129cindent({lnum}) Number C indent for line {lnum}
130clearmatches([{win}]) none clear all matches
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000131col({expr} [, {winid}]) Number column byte index of cursor or mark
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000132complete({startcol}, {matches}) none set Insert mode completion
133complete_add({expr}) Number add completion match
134complete_check() Number check for key typed during completion
135complete_info([{what}]) Dict get current completion information
136confirm({msg} [, {choices} [, {default} [, {type}]]])
137 Number number of choice picked by user
138copy({expr}) any make a shallow copy of {expr}
139cos({expr}) Float cosine of {expr}
140cosh({expr}) Float hyperbolic cosine of {expr}
141count({comp}, {expr} [, {ic} [, {start}]])
142 Number count how many {expr} are in {comp}
143cscope_connection([{num}, {dbpath} [, {prepend}]])
144 Number checks existence of cscope connection
145cursor({lnum}, {col} [, {off}])
146 Number move cursor to {lnum}, {col}, {off}
147cursor({list}) Number move cursor to position in {list}
148debugbreak({pid}) Number interrupt process being debugged
149deepcopy({expr} [, {noref}]) any make a full copy of {expr}
150delete({fname} [, {flags}]) Number delete the file or directory {fname}
151deletebufline({buf}, {first} [, {last}])
152 Number delete lines from buffer {buf}
153did_filetype() Number |TRUE| if FileType autocmd event used
Yegappan Lakshmananfa378352024-02-01 22:05:27 +0100154diff({fromlist}, {tolist} [, {options}])
155 List diff two Lists of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000156diff_filler({lnum}) Number diff filler lines about {lnum}
157diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
158digraph_get({chars}) String get the |digraph| of {chars}
159digraph_getlist([{listall}]) List get all |digraph|s
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200160digraph_set({chars}, {digraph}) Bool register |digraph|
161digraph_setlist({digraphlist}) Bool register multiple |digraph|s
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000162echoraw({expr}) none output {expr} as-is
163empty({expr}) Number |TRUE| if {expr} is empty
164environ() Dict return environment variables
Sean Dewarb0efa492023-07-08 10:35:19 +0100165err_teapot([{expr}]) none give E418, or E503 if {expr} is |TRUE|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000166escape({string}, {chars}) String escape {chars} in {string} with '\'
167eval({string}) any evaluate {string} into its value
168eventhandler() Number |TRUE| if inside an event handler
169executable({expr}) Number 1 if executable {expr} exists
170execute({command}) String execute {command} and get the output
171exepath({expr}) String full path of the command {expr}
172exists({expr}) Number |TRUE| if {expr} exists
173exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
174exp({expr}) Float exponential of {expr}
175expand({expr} [, {nosuf} [, {list}]])
176 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100177expandcmd({string} [, {options}])
178 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000179extend({expr1}, {expr2} [, {expr3}])
180 List/Dict insert items of {expr2} into {expr1}
181extendnew({expr1}, {expr2} [, {expr3}])
182 List/Dict like |extend()| but creates a new
183 List or Dictionary
184feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
Shougo Matsushita60c87432024-06-03 22:59:27 +0200185filecopy({from}, {to}) Number |TRUE| if copying file {from} to {to}
186 worked
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000187filereadable({file}) Number |TRUE| if {file} is a readable file
188filewritable({file}) Number |TRUE| if {file} is a writable file
189filter({expr1}, {expr2}) List/Dict/Blob/String
190 remove items from {expr1} where
191 {expr2} is 0
192finddir({name} [, {path} [, {count}]])
193 String find directory {name} in {path}
194findfile({name} [, {path} [, {count}]])
195 String find file {name} in {path}
196flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
197flattennew({list} [, {maxdepth}])
198 List flatten a copy of {list}
199float2nr({expr}) Number convert Float {expr} to a Number
200floor({expr}) Float round {expr} down
201fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
202fnameescape({fname}) String escape special characters in {fname}
203fnamemodify({fname}, {mods}) String modify file name
204foldclosed({lnum}) Number first line of fold at {lnum} if closed
205foldclosedend({lnum}) Number last line of fold at {lnum} if closed
206foldlevel({lnum}) Number fold level at {lnum}
207foldtext() String line displayed for closed fold
208foldtextresult({lnum}) String text for closed fold at {lnum}
Ernie Raele79e2072024-01-13 11:47:33 +0100209foreach({expr1}, {expr2}) List/Dict/Blob/String
210 for each item in {expr1} call {expr2}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000211foreground() Number bring the Vim window to the foreground
Bram Moolenaaraa534142022-09-15 21:46:02 +0100212fullcommand({name} [, {vim9}]) String get full command from {name}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000213funcref({name} [, {arglist}] [, {dict}])
214 Funcref reference to function {name}
215function({name} [, {arglist}] [, {dict}])
216 Funcref named reference to function {name}
217garbagecollect([{atexit}]) none free memory, breaking cyclic references
218get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
219get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
220get({func}, {what}) any get property of funcref/partial {func}
221getbufinfo([{buf}]) List information about buffers
222getbufline({buf}, {lnum} [, {end}])
223 List lines {lnum} to {end} of buffer {buf}
Bram Moolenaarce30ccc2022-11-21 19:57:04 +0000224getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000225getbufvar({buf}, {varname} [, {def}])
226 any variable {varname} in buffer {buf}
mikoto20001083cae2024-11-11 21:24:14 +0100227getcellpixels() List get character cell pixel size
Kota Kato66bb9ae2023-01-17 18:31:56 +0000228getcellwidths() List get character cell width overrides
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000229getchangelist([{buf}]) List list of change list items
Doug Kearns9cd9e752024-04-07 17:42:17 +0200230getchar([{expr}]) Number or String
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000231 get one character from the user
232getcharmod() Number modifiers for the last typed character
233getcharpos({expr}) List position of cursor, mark, etc.
234getcharsearch() Dict last character search
Doug Kearns9cd9e752024-04-07 17:42:17 +0200235getcharstr([{expr}]) String get one character from the user
Ruslan Russkikh0407d622024-10-08 22:21:05 +0200236getcmdcomplpat() String return the completion pattern of the
237 current command-line completion
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100238getcmdcompltype() String return the type of the current
239 command-line completion
Shougo Matsushita69084282024-09-23 20:34:47 +0200240getcmdline() String return the current command-line input
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000241getcmdpos() Number return cursor position in command-line
Shougo Matsushita69084282024-09-23 20:34:47 +0200242getcmdprompt() String return the current command-line prompt
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100243getcmdscreenpos() Number return cursor screen position in
244 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000245getcmdtype() String return current command-line type
246getcmdwintype() String return current command-line window type
247getcompletion({pat}, {type} [, {filtered}])
248 List list of cmdline completion matches
249getcurpos([{winnr}]) List position of the cursor
250getcursorcharpos([{winnr}]) List character position of the cursor
251getcwd([{winnr} [, {tabnr}]]) String get the current working directory
252getenv({name}) String return environment variable
253getfontname([{name}]) String name of font being used
254getfperm({fname}) String file permissions of file {fname}
255getfsize({fname}) Number size in bytes of file {fname}
256getftime({fname}) Number last modification time of file
257getftype({fname}) String description of type of file {fname}
258getimstatus() Number |TRUE| if the IME status is active
259getjumplist([{winnr} [, {tabnr}]])
260 List list of jump list items
261getline({lnum}) String line {lnum} of current buffer
262getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
263getloclist({nr}) List list of location list items
264getloclist({nr}, {what}) Dict get specific location list properties
265getmarklist([{buf}]) List list of global/local marks
266getmatches([{win}]) List list of current matches
267getmousepos() Dict last known mouse position
Bram Moolenaar24dc19c2022-11-14 19:49:15 +0000268getmouseshape() String current mouse shape name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000269getpid() Number process ID of Vim
270getpos({expr}) List position of cursor, mark, etc.
271getqflist() List list of quickfix items
272getqflist({what}) Dict get specific quickfix list properties
273getreg([{regname} [, 1 [, {list}]]])
274 String or List contents of a register
275getreginfo([{regname}]) Dict information about a register
Shougo Matsushita19b71882024-02-28 22:48:12 +0100276getregion({pos1}, {pos2} [, {opts}])
Shougo Matsushita3f905ab2024-02-21 00:02:45 +0100277 List get the text from {pos1} to {pos2}
Shougo Matsushitab4757e62024-05-07 20:49:24 +0200278getregionpos({pos1}, {pos2} [, {opts}])
279 List get a list of positions for a region
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000280getregtype([{regname}]) String type of a register
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +0100281getscriptinfo([{opts}]) List list of sourced scripts
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000282gettabinfo([{expr}]) List list of tab pages
283gettabvar({nr}, {varname} [, {def}])
284 any variable {varname} in tab {nr} or {def}
285gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
286 any {name} in {winnr} in tab page {tabnr}
287gettagstack([{nr}]) Dict get the tag stack of window {nr}
h-east52e7cc22024-07-28 17:03:29 +0200288gettext({text} [, {package}]) String lookup translation of {text}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000289getwininfo([{winid}]) List list of info about each window
Bram Moolenaar938ae282023-02-20 20:44:55 +0000290getwinpos([{timeout}]) List X and Y coord in pixels of Vim window
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000291getwinposx() Number X coord in pixels of the Vim window
292getwinposy() Number Y coord in pixels of the Vim window
293getwinvar({nr}, {varname} [, {def}])
294 any variable {varname} in window {nr}
295glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
296 any expand file wildcards in {expr}
297glob2regpat({expr}) String convert a glob pat into a search pat
298globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
299 String do glob({expr}) for all dirs in {path}
300has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
301has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
302haslocaldir([{winnr} [, {tabnr}]])
303 Number |TRUE| if the window executed |:lcd|
304 or |:tcd|
305hasmapto({what} [, {mode} [, {abbr}]])
306 Number |TRUE| if mapping to {what} exists
307histadd({history}, {item}) Number add an item to a history
308histdel({history} [, {item}]) Number remove an item from a history
309histget({history} [, {index}]) String get the item {index} from a history
310histnr({history}) Number highest index of a history
311hlID({name}) Number syntax ID of highlight group {name}
312hlexists({name}) Number |TRUE| if highlight group {name} exists
313hlget([{name} [, {resolve}]]) List get highlight group attributes
314hlset({list}) Number set highlight group attributes
315hostname() String name of the machine Vim is running on
316iconv({expr}, {from}, {to}) String convert encoding of {expr}
Ernie Rael05124252024-07-11 22:10:45 +0200317id({item}) String get unique identity string of item
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000318indent({lnum}) Number indent of line {lnum}
319index({object}, {expr} [, {start} [, {ic}]])
320 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100321indexof({object}, {expr} [, {opts}]])
322 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000323input({prompt} [, {text} [, {completion}]])
324 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100325inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000326 String like input() but in a GUI dialog
327inputlist({textlist}) Number let the user pick from a choice list
328inputrestore() Number restore typeahead
329inputsave() Number save and clear typeahead
330inputsecret({prompt} [, {text}]) String like input() but hiding the text
331insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
LemonBoyafe04662023-08-23 21:08:11 +0200332instanceof({object}, {class}) Number |TRUE| if {object} is an instance of {class}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000333interrupt() none interrupt script execution
334invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100335isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000336isdirectory({directory}) Number |TRUE| if {directory} is a directory
337isinf({expr}) Number determine if {expr} is infinity value
338 (positive or negative)
339islocked({expr}) Number |TRUE| if {expr} is locked
340isnan({expr}) Number |TRUE| if {expr} is NaN
341items({dict}) List key-value pairs in {dict}
342job_getchannel({job}) Channel get the channel handle for {job}
343job_info([{job}]) Dict get information about {job}
344job_setoptions({job}, {options}) none set options for {job}
345job_start({command} [, {options}])
346 Job start a job
347job_status({job}) String get the status of {job}
348job_stop({job} [, {how}]) Number stop {job}
349join({list} [, {sep}]) String join {list} items into one String
350js_decode({string}) any decode JS style JSON
351js_encode({expr}) String encode JS style JSON
352json_decode({string}) any decode JSON
353json_encode({expr}) String encode JSON
354keys({dict}) List keys in {dict}
zeertzjqcdc83932022-09-12 13:38:41 +0100355keytrans({string}) String translate internal keycodes to a form
356 that can be used by |:map|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000357len({expr}) Number the length of {expr}
358libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
359libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
360line({expr} [, {winid}]) Number line nr of cursor, last line or mark
361line2byte({lnum}) Number byte count of line {lnum}
362lispindent({lnum}) Number Lisp indent for line {lnum}
363list2blob({list}) Blob turn {list} of numbers into a Blob
364list2str({list} [, {utf8}]) String turn {list} of numbers into a String
365listener_add({callback} [, {buf}])
366 Number add a callback to listen to changes
367listener_flush([{buf}]) none invoke listener callbacks
368listener_remove({id}) none remove a listener callback
369localtime() Number current time
370log({expr}) Float natural logarithm (base e) of {expr}
371log10({expr}) Float logarithm of Float {expr} to base 10
372luaeval({expr} [, {expr}]) any evaluate |Lua| expression
373map({expr1}, {expr2}) List/Dict/Blob/String
374 change each item in {expr1} to {expr2}
375maparg({name} [, {mode} [, {abbr} [, {dict}]]])
376 String or Dict
377 rhs of mapping {name} in mode {mode}
378mapcheck({name} [, {mode} [, {abbr}]])
379 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100380maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000381mapnew({expr1}, {expr2}) List/Dict/Blob/String
382 like |map()| but creates a new List or
383 Dictionary
384mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
385match({expr}, {pat} [, {start} [, {count}]])
386 Number position where {pat} matches in {expr}
387matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
388 Number highlight {pattern} with {group}
389matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
390 Number highlight positions with {group}
391matcharg({nr}) List arguments of |:match|
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100392matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict})
393 List all the {pat} matches in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000394matchdelete({id} [, {win}]) Number delete match identified by {id}
395matchend({expr}, {pat} [, {start} [, {count}]])
396 Number position where {pat} ends in {expr}
397matchfuzzy({list}, {str} [, {dict}])
398 List fuzzy match {str} in {list}
399matchfuzzypos({list}, {str} [, {dict}])
400 List fuzzy match {str} in {list}
401matchlist({expr}, {pat} [, {start} [, {count}]])
402 List match and submatches of {pat} in {expr}
403matchstr({expr}, {pat} [, {start} [, {count}]])
404 String {count}'th match of {pat} in {expr}
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100405matchstrlist({list}, {pat} [, {dict})
406 List all the {pat} matches in {list}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000407matchstrpos({expr}, {pat} [, {start} [, {count}]])
408 List {count}'th match of {pat} in {expr}
409max({expr}) Number maximum value of items in {expr}
410menu_info({name} [, {mode}]) Dict get menu item information
411min({expr}) Number minimum value of items in {expr}
Bram Moolenaar938ae282023-02-20 20:44:55 +0000412mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000413 Number create directory {name}
Doug Kearns9cd9e752024-04-07 17:42:17 +0200414mode([{expr}]) String current editing mode
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000415mzeval({expr}) any evaluate |MzScheme| expression
416nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
417nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
418or({expr}, {expr}) Number bitwise OR
419pathshorten({expr} [, {len}]) String shorten directory names in a path
420perleval({expr}) any evaluate |Perl| expression
421popup_atcursor({what}, {options}) Number create popup window near the cursor
422popup_beval({what}, {options}) Number create popup window for 'ballooneval'
423popup_clear() none close all popup windows
424popup_close({id} [, {result}]) none close popup window {id}
425popup_create({what}, {options}) Number create a popup window
426popup_dialog({what}, {options}) Number create a popup window used as a dialog
427popup_filter_menu({id}, {key}) Number filter for a menu popup window
428popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100429popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000430popup_findinfo() Number get window ID of info popup window
431popup_findpreview() Number get window ID of preview popup window
432popup_getoptions({id}) Dict get options of popup window {id}
433popup_getpos({id}) Dict get position of popup window {id}
434popup_hide({id}) none hide popup menu {id}
435popup_list() List get a list of window IDs of all popups
436popup_locate({row}, {col}) Number get window ID of popup at position
437popup_menu({what}, {options}) Number create a popup window used as a menu
438popup_move({id}, {options}) none set position of popup window {id}
439popup_notification({what}, {options})
440 Number create a notification popup window
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200441popup_setbuf({id}, {buf}) Bool set the buffer for the popup window {id}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000442popup_setoptions({id}, {options})
443 none set options for popup window {id}
444popup_settext({id}, {text}) none set the text of popup window {id}
445popup_show({id}) none unhide popup window {id}
446pow({x}, {y}) Float {x} to the power of {y}
447prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
448printf({fmt}, {expr1}...) String format text
449prompt_getprompt({buf}) String get prompt text
450prompt_setcallback({buf}, {expr}) none set prompt callback function
451prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
452prompt_setprompt({buf}, {text}) none set prompt text
453prop_add({lnum}, {col}, {props}) none add one text property
454prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
455 none add multiple text properties
456prop_clear({lnum} [, {lnum-end} [, {props}]])
457 none remove all text properties
458prop_find({props} [, {direction}])
459 Dict search for a text property
460prop_list({lnum} [, {props}]) List text properties in {lnum}
461prop_remove({props} [, {lnum} [, {lnum-end}]])
462 Number remove a text property
463prop_type_add({name}, {props}) none define a new property type
464prop_type_change({name}, {props})
465 none change an existing property type
466prop_type_delete({name} [, {props}])
467 none delete a property type
468prop_type_get({name} [, {props}])
469 Dict get property type values
470prop_type_list([{props}]) List get list of property types
471pum_getpos() Dict position and size of pum if visible
472pumvisible() Number whether popup menu is visible
zeertzjq7c515282024-11-10 20:26:12 +0100473py3eval({expr} [, {locals}]) any evaluate |python3| expression
474pyeval({expr} [, {locals}]) any evaluate |Python| expression
475pyxeval({expr} [, {locals}]) any evaluate |python_x| expression
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000476rand([{expr}]) Number get pseudo-random number
477range({expr} [, {max} [, {stride}]])
478 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100479readblob({fname} [, {offset} [, {size}]])
480 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000481readdir({dir} [, {expr} [, {dict}]])
482 List file names in {dir} selected by {expr}
483readdirex({dir} [, {expr} [, {dict}]])
484 List file info in {dir} selected by {expr}
485readfile({fname} [, {type} [, {max}]])
486 List get list of lines from file {fname}
487reduce({object}, {func} [, {initial}])
488 any reduce {object} using {func}
489reg_executing() String get the executing register name
490reg_recording() String get the recording register name
491reltime([{start} [, {end}]]) List get time value
492reltimefloat({time}) Float turn the time value into a Float
493reltimestr({time}) String turn time value into a String
494remote_expr({server}, {string} [, {idvar} [, {timeout}]])
495 String send expression
496remote_foreground({server}) Number bring Vim server to the foreground
497remote_peek({serverid} [, {retvar}])
498 Number check for reply string
499remote_read({serverid} [, {timeout}])
500 String read reply string
501remote_send({server}, {string} [, {idvar}])
502 String send key sequence
503remote_startserver({name}) none become server {name}
504remove({list}, {idx} [, {end}]) any/List
505 remove items {idx}-{end} from {list}
506remove({blob}, {idx} [, {end}]) Number/Blob
507 remove bytes {idx}-{end} from {blob}
508remove({dict}, {key}) any remove entry {key} from {dict}
509rename({from}, {to}) Number rename (move) file from {from} to {to}
Bakudankun375141e2022-09-09 18:46:47 +0100510repeat({expr}, {count}) List/Blob/String
511 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000512resolve({filename}) String get filename a shortcut points to
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +0100513reverse({obj}) List/Blob/String
514 reverse {obj}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000515round({expr}) Float round off {expr}
516rubyeval({expr}) any evaluate |Ruby| expression
517screenattr({row}, {col}) Number attribute at screen position
518screenchar({row}, {col}) Number character at screen position
519screenchars({row}, {col}) List List of characters at screen position
520screencol() Number current cursor column
521screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
522screenrow() Number current cursor row
523screenstring({row}, {col}) String characters at screen position
524search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
525 Number search for {pattern}
526searchcount([{options}]) Dict get or update search stats
527searchdecl({name} [, {global} [, {thisblock}]])
528 Number search for variable declaration
529searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
530 Number search for other end of start/end pair
531searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
532 List search for other end of start/end pair
533searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
534 List search for {pattern}
535server2client({clientid}, {string})
536 Number send reply string
537serverlist() String get a list of available servers
erraelf0837ba2024-06-24 12:27:01 -0700538setbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000539 Number set line {lnum} to {text} in buffer
erraelf0837ba2024-06-24 12:27:01 -0700540 {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000541setbufvar({buf}, {varname}, {val})
542 none set {varname} in buffer {buf} to {val}
543setcellwidths({list}) none set character cell width overrides
544setcharpos({expr}, {list}) Number set the {expr} position to {list}
545setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100546setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000547setcmdpos({pos}) Number set cursor position in command-line
548setcursorcharpos({list}) Number move cursor to position in {list}
549setenv({name}, {val}) none set environment variable
550setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
551setline({lnum}, {line}) Number set line {lnum} to {line}
552setloclist({nr}, {list} [, {action}])
553 Number modify location list using {list}
554setloclist({nr}, {list}, {action}, {what})
555 Number modify specific location list props
556setmatches({list} [, {win}]) Number restore a list of matches
557setpos({expr}, {list}) Number set the {expr} position to {list}
558setqflist({list} [, {action}]) Number modify quickfix list using {list}
559setqflist({list}, {action}, {what})
560 Number modify specific quickfix list props
561setreg({n}, {v} [, {opt}]) Number set register to value and type
562settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
563settabwinvar({tabnr}, {winnr}, {varname}, {val})
564 none set {varname} in window {winnr} in tab
565 page {tabnr} to {val}
566settagstack({nr}, {dict} [, {action}])
567 Number modify tag stack using {dict}
568setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
569sha256({string}) String SHA256 checksum of {string}
570shellescape({string} [, {special}])
571 String escape {string} for use as shell
572 command argument
573shiftwidth([{col}]) Number effective value of 'shiftwidth'
574sign_define({name} [, {dict}]) Number define or update a sign
575sign_define({list}) List define or update a list of signs
576sign_getdefined([{name}]) List get a list of defined signs
577sign_getplaced([{buf} [, {dict}]])
578 List get a list of placed signs
579sign_jump({id}, {group}, {buf})
580 Number jump to a sign
581sign_place({id}, {group}, {name}, {buf} [, {dict}])
582 Number place a sign
583sign_placelist({list}) List place a list of signs
584sign_undefine([{name}]) Number undefine a sign
585sign_undefine({list}) List undefine a list of signs
586sign_unplace({group} [, {dict}])
587 Number unplace a sign
588sign_unplacelist({list}) List unplace a list of signs
589simplify({filename}) String simplify filename as much as possible
590sin({expr}) Float sine of {expr}
591sinh({expr}) Float hyperbolic sine of {expr}
592slice({expr}, {start} [, {end}]) String, List or Blob
593 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000594sort({list} [, {how} [, {dict}]])
595 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000596sound_clear() none stop playing all sounds
597sound_playevent({name} [, {callback}])
598 Number play an event sound
599sound_playfile({path} [, {callback}])
600 Number play sound file {path}
601sound_stop({id}) none stop playing sound {id}
602soundfold({word}) String sound-fold {word}
603spellbadword() String badly spelled word at cursor
604spellsuggest({word} [, {max} [, {capital}]])
605 List spelling suggestions
606split({expr} [, {pat} [, {keepempty}]])
607 List make |List| from {pat} separated {expr}
608sqrt({expr}) Float square root of {expr}
609srand([{expr}]) List get seed for |rand()|
610state([{what}]) String current state of Vim
611str2float({expr} [, {quoted}]) Float convert String to Float
612str2list({expr} [, {utf8}]) List convert each character of {expr} to
613 ASCII/UTF-8 value
614str2nr({expr} [, {base} [, {quoted}]])
615 Number convert String to Number
616strcharlen({expr}) Number character length of the String {expr}
617strcharpart({str}, {start} [, {len} [, {skipcc}]])
618 String {len} characters of {str} at
619 character {start}
620strchars({expr} [, {skipcc}]) Number character count of the String {expr}
621strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
622strftime({format} [, {time}]) String format time with a specified format
623strgetchar({str}, {index}) Number get char {index} from {str}
624stridx({haystack}, {needle} [, {start}])
625 Number index of {needle} in {haystack}
626string({expr}) String String representation of {expr} value
627strlen({expr}) Number length of the String {expr}
628strpart({str}, {start} [, {len} [, {chars}]])
629 String {len} bytes/chars of {str} at
630 byte {start}
631strptime({format}, {timestring})
632 Number Convert {timestring} to unix timestamp
633strridx({haystack}, {needle} [, {start}])
634 Number last index of {needle} in {haystack}
635strtrans({expr}) String translate string to make it printable
Christian Brabandt67672ef2023-04-24 21:09:54 +0100636strutf16len({string} [, {countcc}])
637 Number number of UTF-16 code units in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000638strwidth({expr}) Number display cell length of the String {expr}
639submatch({nr} [, {list}]) String or List
640 specific match in ":s" or substitute()
641substitute({expr}, {pat}, {sub}, {flags})
642 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000643swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000644swapinfo({fname}) Dict information about swap file {fname}
645swapname({buf}) String swap file of buffer {buf}
646synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
647synIDattr({synID}, {what} [, {mode}])
648 String attribute {what} of syntax ID {synID}
649synIDtrans({synID}) Number translated syntax ID of {synID}
650synconcealed({lnum}, {col}) List info about concealing
651synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
652system({expr} [, {input}]) String output of shell command/filter {expr}
653systemlist({expr} [, {input}]) List output of shell command/filter {expr}
654tabpagebuflist([{arg}]) List list of buffer numbers in tab page
655tabpagenr([{arg}]) Number number of current or last tab page
656tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
657tagfiles() List tags files used
658taglist({expr} [, {filename}]) List list of tags matching {expr}
659tan({expr}) Float tangent of {expr}
660tanh({expr}) Float hyperbolic tangent of {expr}
661tempname() String name for a temporary file
662term_dumpdiff({filename}, {filename} [, {options}])
663 Number display difference between two dumps
664term_dumpload({filename} [, {options}])
665 Number displaying a screen dump
666term_dumpwrite({buf}, {filename} [, {options}])
667 none dump terminal window contents
668term_getaltscreen({buf}) Number get the alternate screen flag
669term_getansicolors({buf}) List get ANSI palette in GUI color mode
670term_getattr({attr}, {what}) Number get the value of attribute {what}
671term_getcursor({buf}) List get the cursor position of a terminal
672term_getjob({buf}) Job get the job associated with a terminal
673term_getline({buf}, {row}) String get a line of text from a terminal
674term_getscrolled({buf}) Number get the scroll count of a terminal
675term_getsize({buf}) List get the size of a terminal
676term_getstatus({buf}) String get the status of a terminal
677term_gettitle({buf}) String get the title of a terminal
678term_gettty({buf}, [{input}]) String get the tty name of a terminal
679term_list() List get the list of terminal buffers
680term_scrape({buf}, {row}) List get row of a terminal screen
681term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
682term_setansicolors({buf}, {colors})
683 none set ANSI palette in GUI color mode
684term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
685term_setkill({buf}, {how}) none set signal to stop job in terminal
686term_setrestore({buf}, {command}) none set command to restore terminal
687term_setsize({buf}, {rows}, {cols})
688 none set the size of a terminal
689term_start({cmd} [, {options}]) Number open a terminal window and run a job
690term_wait({buf} [, {time}]) Number wait for screen to be updated
691terminalprops() Dict properties of the terminal
692test_alloc_fail({id}, {countdown}, {repeat})
693 none make memory allocation fail
694test_autochdir() none enable 'autochdir' during startup
695test_feedinput({string}) none add key sequence to input buffer
696test_garbagecollect_now() none free memory right now for testing
697test_garbagecollect_soon() none free memory soon for testing
698test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000699test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000700test_ignore_error({expr}) none ignore a specific error
Christopher Plewright20b795e2022-12-20 20:01:58 +0000701test_mswin_event({event}, {args})
702 bool generate MS-Windows event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000703test_null_blob() Blob null value for testing
704test_null_channel() Channel null value for testing
705test_null_dict() Dict null value for testing
706test_null_function() Funcref null value for testing
707test_null_job() Job null value for testing
708test_null_list() List null value for testing
709test_null_partial() Funcref null value for testing
710test_null_string() String null value for testing
711test_option_not_set({name}) none reset flag indicating option was set
712test_override({expr}, {val}) none test with Vim internal overrides
713test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000714test_setmouse({row}, {col}) none set the mouse position for testing
715test_settime({expr}) none set current time for testing
Doug Kearns9cd9e752024-04-07 17:42:17 +0200716test_srand_seed([{seed}]) none set seed for testing srand()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000717test_unknown() any unknown value for testing
718test_void() any void value for testing
719timer_info([{id}]) List information about timers
720timer_pause({id}, {pause}) none pause or unpause a timer
721timer_start({time}, {callback} [, {options}])
722 Number create a timer
723timer_stop({timer}) none stop a timer
724timer_stopall() none stop all timers
725tolower({expr}) String the String {expr} switched to lowercase
726toupper({expr}) String the String {expr} switched to uppercase
727tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
728 to chars in {tostr}
729trim({text} [, {mask} [, {dir}]])
730 String trim characters in {mask} from {text}
731trunc({expr}) Float truncate Float {expr}
732type({expr}) Number type of value {expr}
733typename({expr}) String representation of the type of {expr}
734undofile({name}) String undo file name for {name}
Devin J. Pohly5fee1112023-04-23 20:26:59 -0500735undotree([{buf}]) List undo file tree for buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000736uniq({list} [, {func} [, {dict}]])
737 List remove adjacent duplicates from a list
Christian Brabandt67672ef2023-04-24 21:09:54 +0100738utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
739 Number UTF-16 index of byte {idx} in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000740values({dict}) List values in {dict}
zeertzjq825cf812023-08-17 22:55:25 +0200741virtcol({expr} [, {list} [, {winid}])
742 Number or List
LemonBoy0f7a3e12022-05-26 12:10:37 +0100743 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100744virtcol2col({winid}, {lnum}, {col})
745 Number byte index of a character on screen
Doug Kearns9cd9e752024-04-07 17:42:17 +0200746visualmode([{expr}]) String last visual mode used
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000747wildmenumode() Number whether 'wildmenu' mode is active
748win_execute({id}, {command} [, {silent}])
749 String execute {command} in window {id}
750win_findbuf({bufnr}) List find windows containing {bufnr}
751win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
752win_gettype([{nr}]) String type of window {nr}
753win_gotoid({expr}) Number go to window with ID {expr}
754win_id2tabwin({expr}) List get tab and window nr from window ID
755win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000756win_move_separator({nr}) Number move window vertical separator
757win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000758win_screenpos({nr}) List get screen position of window {nr}
759win_splitmove({nr}, {target} [, {options}])
760 Number move window {nr} to split of {target}
761winbufnr({nr}) Number buffer number of window {nr}
762wincol() Number window column of the cursor
763windowsversion() String MS-Windows OS version
764winheight({nr}) Number height of window {nr}
765winlayout([{tabnr}]) List layout of windows in tab {tabnr}
766winline() Number window line of the cursor
767winnr([{expr}]) Number number of current window
768winrestcmd() String returns command to restore window sizes
769winrestview({dict}) none restore view of current window
770winsaveview() Dict save view of current window
771winwidth({nr}) Number width of window {nr}
772wordcount() Dict get byte/char/word statistics
773writefile({object}, {fname} [, {flags}])
774 Number write |Blob| or |List| of lines to file
775xor({expr}, {expr}) Number bitwise XOR
776
777==============================================================================
7782. Details *builtin-function-details*
779
780Not all functions are here, some have been moved to a help file covering the
781specific functionality.
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200782Return type specifies the type for |Vim9-script|, see |vim9-types|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000783
784abs({expr}) *abs()*
785 Return the absolute value of {expr}. When {expr} evaluates to
786 a |Float| abs() returns a |Float|. When {expr} can be
787 converted to a |Number| abs() returns a |Number|. Otherwise
788 abs() gives an error message and returns -1.
789 Examples: >
790 echo abs(1.456)
791< 1.456 >
792 echo abs(-5.456)
793< 5.456 >
794 echo abs(-4)
795< 4
796
797 Can also be used as a |method|: >
798 Compute()->abs()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200799<
800 Return type: |Number| or |Float| depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000801
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000802
803acos({expr}) *acos()*
804 Return the arc cosine of {expr} measured in radians, as a
805 |Float| in the range of [0, pi].
806 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100807 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000808 Examples: >
809 :echo acos(0)
810< 1.570796 >
811 :echo acos(-0.5)
812< 2.094395
813
814 Can also be used as a |method|: >
815 Compute()->acos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200816<
817 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000818
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000819
820add({object}, {expr}) *add()*
821 Append the item {expr} to |List| or |Blob| {object}. Returns
822 the resulting |List| or |Blob|. Examples: >
823 :let alist = add([1, 2, 3], item)
824 :call add(mylist, "woodstock")
825< Note that when {expr} is a |List| it is appended as a single
826 item. Use |extend()| to concatenate |Lists|.
827 When {object} is a |Blob| then {expr} must be a number.
828 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100829 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000830
831 Can also be used as a |method|: >
832 mylist->add(val1)->add(val2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200833<
834 Return type: list<{type}> (depending on the given |List|) or
835 |Blob|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000836
837
838and({expr}, {expr}) *and()*
839 Bitwise AND on the two arguments. The arguments are converted
840 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100841 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000842 Example: >
843 :let flag = and(bits, 0x80)
844< Can also be used as a |method|: >
845 :let flag = bits->and(0x80)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200846<
847 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000848
849
850append({lnum}, {text}) *append()*
851 When {text} is a |List|: Append each item of the |List| as a
852 text line below line {lnum} in the current buffer.
853 Otherwise append {text} as one text line below line {lnum} in
854 the current buffer.
855 Any type of item is accepted and converted to a String.
856 {lnum} can be zero to insert a line before the first one.
857 {lnum} is used like with |getline()|.
858 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000859 0 for success. When {text} is an empty list zero is returned,
860 no matter the value of {lnum}.
861 In |Vim9| script an invalid argument or negative number
862 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000863 :let failed = append(line('$'), "# THE END")
864 :let failed = append(0, ["Chapter 1", "the beginning"])
865
866< Can also be used as a |method| after a List, the base is
867 passed as the second argument: >
868 mylist->append(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200869<
870 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000871
872
873appendbufline({buf}, {lnum}, {text}) *appendbufline()*
874 Like |append()| but append the text in buffer {buf}.
875
876 This function works only for loaded buffers. First call
877 |bufload()| if needed.
878
879 For the use of {buf}, see |bufname()|.
880
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000881 {lnum} is the line number to append below. Note that using
882 |line()| would use the current buffer, not the one appending
883 to. Use "$" to append at the end of the buffer. Other string
884 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000885
886 On success 0 is returned, on failure 1 is returned.
887 In |Vim9| script an error is given for an invalid {lnum}.
888
889 If {buf} is not a valid buffer or {lnum} is not valid, an
890 error message is given. Example: >
891 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000892< However, when {text} is an empty list then no error is given
893 for an invalid {lnum}, since {lnum} isn't actually used.
894
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000895 Can also be used as a |method| after a List, the base is
896 passed as the second argument: >
897 mylist->appendbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200898<
899 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000900
901
902argc([{winid}]) *argc()*
903 The result is the number of files in the argument list. See
904 |arglist|.
905 If {winid} is not supplied, the argument list of the current
906 window is used.
907 If {winid} is -1, the global argument list is used.
908 Otherwise {winid} specifies the window of which the argument
909 list is used: either the window number or the window ID.
910 Returns -1 if the {winid} argument is invalid.
911
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200912 Return type: |Number|
913
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000914 *argidx()*
915argidx() The result is the current index in the argument list. 0 is
916 the first file. argc() - 1 is the last one. See |arglist|.
917
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200918 Return type: |Number|
919
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000920 *arglistid()*
921arglistid([{winnr} [, {tabnr}]])
922 Return the argument list ID. This is a number which
923 identifies the argument list being used. Zero is used for the
924 global argument list. See |arglist|.
925 Returns -1 if the arguments are invalid.
926
927 Without arguments use the current window.
928 With {winnr} only use this window in the current tab page.
929 With {winnr} and {tabnr} use the window in the specified tab
930 page.
931 {winnr} can be the window number or the |window-ID|.
932
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200933 Return type: |Number|
934
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000935 *argv()*
936argv([{nr} [, {winid}]])
937 The result is the {nr}th file in the argument list. See
938 |arglist|. "argv(0)" is the first one. Example: >
939 :let i = 0
940 :while i < argc()
941 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000942 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000943 : let i = i + 1
944 :endwhile
945< Without the {nr} argument, or when {nr} is -1, a |List| with
946 the whole |arglist| is returned.
947
948 The {winid} argument specifies the window ID, see |argc()|.
949 For the Vim command line arguments see |v:argv|.
950
Bram Moolenaar016188f2022-06-06 20:52:59 +0100951 Returns an empty string if {nr}th argument is not present in
952 the argument list. Returns an empty List if the {winid}
953 argument is invalid.
954
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200955 Return type: |String|
956
957
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000958asin({expr}) *asin()*
959 Return the arc sine of {expr} measured in radians, as a |Float|
960 in the range of [-pi/2, pi/2].
961 {expr} must evaluate to a |Float| or a |Number| in the range
962 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100963 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
964 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000965 Examples: >
966 :echo asin(0.8)
967< 0.927295 >
968 :echo asin(-0.5)
969< -0.523599
970
971 Can also be used as a |method|: >
972 Compute()->asin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200973<
974 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000975
976assert_ functions are documented here: |assert-functions-details|
977
978
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000979atan({expr}) *atan()*
980 Return the principal value of the arc tangent of {expr}, in
981 the range [-pi/2, +pi/2] radians, as a |Float|.
982 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100983 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000984 Examples: >
985 :echo atan(100)
986< 1.560797 >
987 :echo atan(-4.01)
988< -1.326405
989
990 Can also be used as a |method|: >
991 Compute()->atan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200992<
993 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000994
995
996atan2({expr1}, {expr2}) *atan2()*
997 Return the arc tangent of {expr1} / {expr2}, measured in
998 radians, as a |Float| in the range [-pi, pi].
999 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001000 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
1001 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001002 Examples: >
1003 :echo atan2(-1, 1)
1004< -0.785398 >
1005 :echo atan2(1, -1)
1006< 2.356194
1007
1008 Can also be used as a |method|: >
1009 Compute()->atan2(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001010<
1011 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001012
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001013
1014autocmd_add({acmds}) *autocmd_add()*
1015 Adds a List of autocmds and autocmd groups.
1016
1017 The {acmds} argument is a List where each item is a Dict with
1018 the following optional items:
1019 bufnr buffer number to add a buffer-local autocmd.
1020 If this item is specified, then the "pattern"
1021 item is ignored.
1022 cmd Ex command to execute for this autocmd event
1023 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001024 This can be either a String with a single
1025 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001026 group autocmd group name. Refer to |autocmd-groups|.
1027 If this group doesn't exist then it is
1028 created. If not specified or empty, then the
1029 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001030 nested boolean flag, set to v:true to add a nested
1031 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +01001032 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001033 which executes only once. Refer to
1034 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001035 pattern autocmd pattern string. Refer to
1036 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001037 present, then this item is ignored. This can
1038 be a String with a single pattern or a List of
1039 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001040 replace boolean flag, set to v:true to remove all the
1041 commands associated with the specified autocmd
1042 event and group and add the {cmd}. This is
1043 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +01001044 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001045
1046 Returns v:true on success and v:false on failure.
1047 Examples: >
1048 " Create a buffer-local autocmd for buffer 5
1049 let acmd = {}
1050 let acmd.group = 'MyGroup'
1051 let acmd.event = 'BufEnter'
1052 let acmd.bufnr = 5
1053 let acmd.cmd = 'call BufEnterFunc()'
1054 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00001055<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001056 Can also be used as a |method|: >
1057 GetAutocmdList()->autocmd_add()
1058<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001059 Return type: |vim9-boolean|
1060
1061
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001062autocmd_delete({acmds}) *autocmd_delete()*
1063 Deletes a List of autocmds and autocmd groups.
1064
1065 The {acmds} argument is a List where each item is a Dict with
1066 the following optional items:
1067 bufnr buffer number to delete a buffer-local autocmd.
1068 If this item is specified, then the "pattern"
1069 item is ignored.
1070 cmd Ex command for this autocmd event
1071 event autocmd event name. Refer to |autocmd-events|.
1072 If '*' then all the autocmd events in this
1073 group are deleted.
1074 group autocmd group name. Refer to |autocmd-groups|.
1075 If not specified or empty, then the default
1076 group is used.
1077 nested set to v:true for a nested autocmd.
1078 Refer to |autocmd-nested|.
1079 once set to v:true for an autocmd which executes
1080 only once. Refer to |autocmd-once|.
1081 pattern autocmd pattern string. Refer to
1082 |autocmd-patterns|. If "bufnr" item is
1083 present, then this item is ignored.
1084
1085 If only {group} is specified in a {acmds} entry and {event},
1086 {pattern} and {cmd} are not specified, then that autocmd group
1087 is deleted.
1088
Bram Moolenaar016188f2022-06-06 20:52:59 +01001089 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001090 Examples: >
1091 " :autocmd! BufLeave *.vim
1092 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1093 call autocmd_delete([acmd]})
1094 " :autocmd! MyGroup1 BufLeave
1095 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1096 call autocmd_delete([acmd])
1097 " :autocmd! MyGroup2 BufEnter *.c
1098 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1099 \ pattern: '*.c'}
1100 " :autocmd! MyGroup2 * *.c
1101 let acmd = #{group: 'MyGroup2', event: '*',
1102 \ pattern: '*.c'}
1103 call autocmd_delete([acmd])
1104 " :autocmd! MyGroup3
1105 let acmd = #{group: 'MyGroup3'}
1106 call autocmd_delete([acmd])
1107<
1108 Can also be used as a |method|: >
1109 GetAutocmdList()->autocmd_delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001110<
1111 Return type: |vim9-boolean|
1112
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001113
1114autocmd_get([{opts}]) *autocmd_get()*
1115 Returns a |List| of autocmds. If {opts} is not supplied, then
1116 returns the autocmds for all the events in all the groups.
1117
1118 The optional {opts} Dict argument supports the following
1119 items:
1120 group Autocmd group name. If specified, returns only
1121 the autocmds defined in this group. If the
1122 specified group doesn't exist, results in an
1123 error message. If set to an empty string,
1124 then the default autocmd group is used.
1125 event Autocmd event name. If specified, returns only
1126 the autocmds defined for this event. If set
1127 to "*", then returns autocmds for all the
1128 events. If the specified event doesn't exist,
1129 results in an error message.
1130 pattern Autocmd pattern. If specified, returns only
1131 the autocmds defined for this pattern.
1132 A combination of the above three times can be supplied in
1133 {opts}.
1134
1135 Each Dict in the returned List contains the following items:
1136 bufnr For buffer-local autocmds, buffer number where
1137 the autocmd is defined.
1138 cmd Command executed for this autocmd.
1139 event Autocmd event name.
1140 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001141 nested Boolean flag, set to v:true for a nested
1142 autocmd. See |autocmd-nested|.
1143 once Boolean flag, set to v:true, if the autocmd
1144 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001145 pattern Autocmd pattern. For a buffer-local
1146 autocmd, this will be of the form "<buffer=n>".
1147 If there are multiple commands for an autocmd event in a
1148 group, then separate items are returned for each command.
1149
Bram Moolenaar016188f2022-06-06 20:52:59 +01001150 Returns an empty List if an autocmd with the specified group
1151 or event or pattern is not found.
1152
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001153 Examples: >
1154 " :autocmd MyGroup
1155 echo autocmd_get(#{group: 'Mygroup'})
1156 " :autocmd G BufUnload
1157 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1158 " :autocmd G * *.ts
1159 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1160 echo autocmd_get(acmd)
1161 " :autocmd Syntax
1162 echo autocmd_get(#{event: 'Syntax'})
1163 " :autocmd G BufEnter *.ts
1164 let acmd = #{group: 'G', event: 'BufEnter',
1165 \ pattern: '*.ts'}
1166 echo autocmd_get(acmd)
1167<
1168 Can also be used as a |method|: >
1169 Getopts()->autocmd_get()
1170<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001171 Return type: list<dict<any>>
1172
1173
Yegappan Lakshmanan810785c2024-12-30 10:29:44 +01001174base64_decode({string}) *base64_decode()*
1175 Return a Blob containing the bytes decoded from the base64
1176 characters in {string}.
1177
1178 The {string} argument should contain only base64-encoded
1179 characters and should have a length that is a multiple of 4.
1180
1181 Returns an empty blob on error.
1182
1183 Examples: >
1184 " Write the decoded contents to a binary file
1185 call writefile(base64_decode(s), 'tools.bmp')
1186 " Decode a base64-encoded string
1187 echo list2str(blob2list(base64_decode(encodedstr)))
1188<
1189 Can also be used as a |method|: >
1190 GetEncodedString()->base64_decode()
1191<
1192 Return type: |Blob|
1193
1194
1195base64_encode({blob}) *base64_encode()*
1196 Return a base64-encoded String representing the bytes in
1197 {blob}. The base64 alphabet defined in RFC 4648 is used.
1198
1199 Examples: >
1200 " Encode the contents of a binary file
1201 echo base64_encode(readblob('somefile.bin'))
1202 " Encode a string
1203 echo base64_encode(list2blob(str2list(somestr)))
1204<
1205 Can also be used as a |method|: >
1206 GetBinaryData()->base64_encode()
1207<
1208 Return type: |String|
1209
1210
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001211balloon_gettext() *balloon_gettext()*
1212 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001213 not used for the List. Returns an empty string if balloon
1214 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001215
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001216 Return type: |String|
1217
1218
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001219balloon_show({expr}) *balloon_show()*
1220 Show {expr} inside the balloon. For the GUI {expr} is used as
1221 a string. For a terminal {expr} can be a list, which contains
1222 the lines of the balloon. If {expr} is not a list it will be
1223 split with |balloon_split()|.
1224 If {expr} is an empty string any existing balloon is removed.
1225
1226 Example: >
1227 func GetBalloonContent()
1228 " ... initiate getting the content
1229 return ''
1230 endfunc
1231 set balloonexpr=GetBalloonContent()
1232
1233 func BalloonCallback(result)
1234 call balloon_show(a:result)
1235 endfunc
1236< Can also be used as a |method|: >
1237 GetText()->balloon_show()
1238<
1239 The intended use is that fetching the content of the balloon
1240 is initiated from 'balloonexpr'. It will invoke an
1241 asynchronous method, in which a callback invokes
1242 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001243 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001244
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001245 When showing a balloon is not possible then nothing happens,
1246 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001247 {only available when compiled with the |+balloon_eval| or
1248 |+balloon_eval_term| feature}
1249
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001250 Return type: |Number|
1251
1252
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001253balloon_split({msg}) *balloon_split()*
1254 Split String {msg} into lines to be displayed in a balloon.
1255 The splits are made for the current window size and optimize
1256 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001257 Returns a |List| with the split lines. Returns an empty List
1258 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001259 Can also be used as a |method|: >
1260 GetText()->balloon_split()->balloon_show()
1261
1262< {only available when compiled with the |+balloon_eval_term|
1263 feature}
1264
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001265 Return type: list<any> or list<string>
1266
Christ van Willegence0ef912024-06-20 23:41:59 +02001267bindtextdomain({package}, {path}) *bindtextdomain()*
1268 Bind a specific {package} to a {path} so that the
1269 |gettext()| function can be used to get language-specific
1270 translations for a package. {path} is the directory name
h-east52e7cc22024-07-28 17:03:29 +02001271 for the translations. See |package-translation|.
Christ van Willegence0ef912024-06-20 23:41:59 +02001272
Christ van Willegen8252ef12024-07-11 21:36:21 +02001273 Returns v:true on success and v:false on failure (out of
1274 memory).
1275
1276 Return type: |vim9-boolean|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001277
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001278blob2list({blob}) *blob2list()*
1279 Return a List containing the number value of each byte in Blob
1280 {blob}. Examples: >
1281 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1282 blob2list(0z) returns []
1283< Returns an empty List on error. |list2blob()| does the
1284 opposite.
1285
1286 Can also be used as a |method|: >
1287 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001288<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001289 Return type: list<any> or list<number>
1290
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001291 *browse()*
1292browse({save}, {title}, {initdir}, {default})
1293 Put up a file requester. This only works when "has("browse")"
1294 returns |TRUE| (only in some GUI versions).
1295 The input fields are:
1296 {save} when |TRUE|, select file to write
1297 {title} title for the requester
1298 {initdir} directory to start browsing in
1299 {default} default file name
1300 An empty string is returned when the "Cancel" button is hit,
1301 something went wrong, or browsing is not possible.
1302
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001303 Return type: |String|
1304
1305
1306browsedir({title}, {initdir}) *browsedir()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001307 Put up a directory requester. This only works when
1308 "has("browse")" returns |TRUE| (only in some GUI versions).
1309 On systems where a directory browser is not supported a file
1310 browser is used. In that case: select a file in the directory
1311 to be used.
1312 The input fields are:
1313 {title} title for the requester
1314 {initdir} directory to start browsing in
1315 When the "Cancel" button is hit, something went wrong, or
1316 browsing is not possible, an empty string is returned.
1317
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001318 Return type: |String|
1319
1320
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001321bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001322 Add a buffer to the buffer list with name {name} (must be a
1323 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001324 If a buffer for file {name} already exists, return that buffer
1325 number. Otherwise return the buffer number of the newly
1326 created buffer. When {name} is an empty string then a new
1327 buffer is always created.
1328 The buffer will not have 'buflisted' set and not be loaded
1329 yet. To add some text to the buffer use this: >
1330 let bufnr = bufadd('someName')
1331 call bufload(bufnr)
1332 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001333< Returns 0 on error.
1334 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001335 let bufnr = 'somename'->bufadd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001336<
1337 Return type: |Number|
1338
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001339
1340bufexists({buf}) *bufexists()*
1341 The result is a Number, which is |TRUE| if a buffer called
1342 {buf} exists.
1343 If the {buf} argument is a number, buffer numbers are used.
1344 Number zero is the alternate buffer for the current window.
1345
1346 If the {buf} argument is a string it must match a buffer name
1347 exactly. The name can be:
1348 - Relative to the current directory.
1349 - A full path.
1350 - The name of a buffer with 'buftype' set to "nofile".
1351 - A URL name.
1352 Unlisted buffers will be found.
1353 Note that help files are listed by their short name in the
1354 output of |:buffers|, but bufexists() requires using their
1355 long name to be able to find them.
1356 bufexists() may report a buffer exists, but to use the name
1357 with a |:buffer| command you may need to use |expand()|. Esp
1358 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1359 Use "bufexists(0)" to test for the existence of an alternate
1360 file name.
1361
1362 Can also be used as a |method|: >
1363 let exists = 'somename'->bufexists()
1364<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001365 Return type: |Number|
1366
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001367 Obsolete name: buffer_exists(). *buffer_exists()*
1368
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001369
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001370buflisted({buf}) *buflisted()*
1371 The result is a Number, which is |TRUE| if a buffer called
1372 {buf} exists and is listed (has the 'buflisted' option set).
1373 The {buf} argument is used like with |bufexists()|.
1374
1375 Can also be used as a |method|: >
1376 let listed = 'somename'->buflisted()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001377<
1378 Return type: |Number|
1379
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001380
1381bufload({buf}) *bufload()*
1382 Ensure the buffer {buf} is loaded. When the buffer name
1383 refers to an existing file then the file is read. Otherwise
1384 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001385 then there is no change. If the buffer is not related to a
Daniel Steinbergc2bd2052023-08-09 12:10:59 -04001386 file then no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001387 If there is an existing swap file for the file of the buffer,
1388 there will be no dialog, the buffer will be loaded anyway.
1389 The {buf} argument is used like with |bufexists()|.
1390
1391 Can also be used as a |method|: >
1392 eval 'somename'->bufload()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001393<
1394 Return type: |Number|
1395
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001396
1397bufloaded({buf}) *bufloaded()*
1398 The result is a Number, which is |TRUE| if a buffer called
1399 {buf} exists and is loaded (shown in a window or hidden).
1400 The {buf} argument is used like with |bufexists()|.
1401
1402 Can also be used as a |method|: >
1403 let loaded = 'somename'->bufloaded()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001404<
1405 Return type: |Number|
1406
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001407
1408bufname([{buf}]) *bufname()*
1409 The result is the name of a buffer. Mostly as it is displayed
1410 by the `:ls` command, but not using special names such as
1411 "[No Name]".
1412 If {buf} is omitted the current buffer is used.
1413 If {buf} is a Number, that buffer number's name is given.
1414 Number zero is the alternate buffer for the current window.
1415 If {buf} is a String, it is used as a |file-pattern| to match
1416 with the buffer names. This is always done like 'magic' is
1417 set and 'cpoptions' is empty. When there is more than one
1418 match an empty string is returned.
1419 "" or "%" can be used for the current buffer, "#" for the
1420 alternate buffer.
1421 A full match is preferred, otherwise a match at the start, end
1422 or middle of the buffer name is accepted. If you only want a
1423 full match then put "^" at the start and "$" at the end of the
1424 pattern.
1425 Listed buffers are found first. If there is a single match
1426 with a listed buffer, that one is returned. Next unlisted
1427 buffers are searched for.
1428 If the {buf} is a String, but you want to use it as a buffer
1429 number, force it to be a Number by adding zero to it: >
1430 :echo bufname("3" + 0)
1431< Can also be used as a |method|: >
1432 echo bufnr->bufname()
1433
1434< If the buffer doesn't exist, or doesn't have a name, an empty
1435 string is returned. >
1436 bufname("#") alternate buffer name
1437 bufname(3) name of buffer 3
1438 bufname("%") name of current buffer
1439 bufname("file2") name of buffer where "file2" matches.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001440<
1441 Return type: |String|
1442 *buffer_name()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001443 Obsolete name: buffer_name().
1444
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001445
1446bufnr([{buf} [, {create}]]) *bufnr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001447 The result is the number of a buffer, as it is displayed by
1448 the `:ls` command. For the use of {buf}, see |bufname()|
1449 above.
1450
1451 If the buffer doesn't exist, -1 is returned. Or, if the
1452 {create} argument is present and TRUE, a new, unlisted,
1453 buffer is created and its number is returned. Example: >
1454 let newbuf = bufnr('Scratch001', 1)
1455< Using an empty name uses the current buffer. To create a new
1456 buffer with an empty name use |bufadd()|.
1457
1458 bufnr("$") is the last buffer: >
1459 :let last_buffer = bufnr("$")
1460< The result is a Number, which is the highest buffer number
1461 of existing buffers. Note that not all buffers with a smaller
1462 number necessarily exist, because ":bwipeout" may have removed
1463 them. Use bufexists() to test for the existence of a buffer.
1464
1465 Can also be used as a |method|: >
1466 echo bufref->bufnr()
1467<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001468 Return type: |Number|
1469
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001470 Obsolete name: buffer_number(). *buffer_number()*
1471 *last_buffer_nr()*
1472 Obsolete name for bufnr("$"): last_buffer_nr().
1473
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001474
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001475bufwinid({buf}) *bufwinid()*
1476 The result is a Number, which is the |window-ID| of the first
1477 window associated with buffer {buf}. For the use of {buf},
1478 see |bufname()| above. If buffer {buf} doesn't exist or
1479 there is no such window, -1 is returned. Example: >
1480
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001481 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001482<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001483 Only deals with the current tab page. See |win_findbuf()| for
1484 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001485
1486 Can also be used as a |method|: >
1487 FindBuffer()->bufwinid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001488<
1489 Return type: |Number|
1490
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001491
1492bufwinnr({buf}) *bufwinnr()*
1493 Like |bufwinid()| but return the window number instead of the
1494 |window-ID|.
1495 If buffer {buf} doesn't exist or there is no such window, -1
1496 is returned. Example: >
1497
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001498 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001499
1500< The number can be used with |CTRL-W_w| and ":wincmd w"
1501 |:wincmd|.
1502
1503 Can also be used as a |method|: >
1504 FindBuffer()->bufwinnr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001505<
1506 Return type: |Number|
1507
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001508
1509byte2line({byte}) *byte2line()*
1510 Return the line number that contains the character at byte
1511 count {byte} in the current buffer. This includes the
1512 end-of-line character, depending on the 'fileformat' option
1513 for the current buffer. The first character has byte count
1514 one.
1515 Also see |line2byte()|, |go| and |:goto|.
1516
Bram Moolenaar016188f2022-06-06 20:52:59 +01001517 Returns -1 if the {byte} value is invalid.
1518
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001519 Can also be used as a |method|: >
1520 GetOffset()->byte2line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001521<
1522 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001523
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001524 {not available when compiled without the |+byte_offset|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001525 feature}
1526
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001527
Christian Brabandt67672ef2023-04-24 21:09:54 +01001528byteidx({expr}, {nr} [, {utf16}]) *byteidx()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001529 Return byte index of the {nr}'th character in the String
1530 {expr}. Use zero for the first character, it then returns
1531 zero.
1532 If there are no multibyte characters the returned value is
1533 equal to {nr}.
1534 Composing characters are not counted separately, their byte
1535 length is added to the preceding base character. See
1536 |byteidxcomp()| below for counting composing characters
1537 separately.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001538 When {utf16} is present and TRUE, {nr} is used as the UTF-16
1539 index in the String {expr} instead of as the character index.
1540 The UTF-16 index is the index in the string when it is encoded
1541 with 16-bit words. If the specified UTF-16 index is in the
1542 middle of a character (e.g. in a 4-byte character), then the
1543 byte index of the first byte in the character is returned.
1544 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001545 Example : >
1546 echo matchstr(str, ".", byteidx(str, 3))
1547< will display the fourth character. Another way to do the
1548 same: >
1549 let s = strpart(str, byteidx(str, 3))
1550 echo strpart(s, 0, byteidx(s, 1))
1551< Also see |strgetchar()| and |strcharpart()|.
1552
1553 If there are less than {nr} characters -1 is returned.
1554 If there are exactly {nr} characters the length of the string
1555 in bytes is returned.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001556 See |charidx()| and |utf16idx()| for getting the character and
1557 UTF-16 index respectively from the byte index.
1558 Examples: >
1559 echo byteidx('a😊😊', 2) returns 5
1560 echo byteidx('a😊😊', 2, 1) returns 1
1561 echo byteidx('a😊😊', 3, 1) returns 5
1562<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001563 Can also be used as a |method|: >
1564 GetName()->byteidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001565<
1566 Return type: |Number|
1567
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001568
Christian Brabandt67672ef2023-04-24 21:09:54 +01001569byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001570 Like byteidx(), except that a composing character is counted
1571 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001572 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001573 echo byteidx(s, 1)
1574 echo byteidxcomp(s, 1)
1575 echo byteidxcomp(s, 2)
1576< The first and third echo result in 3 ('e' plus composing
1577 character is 3 bytes), the second echo results in 1 ('e' is
1578 one byte).
1579 Only works differently from byteidx() when 'encoding' is set
1580 to a Unicode encoding.
1581
1582 Can also be used as a |method|: >
1583 GetName()->byteidxcomp(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001584<
1585 Return type: |Number|
1586
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001587
1588call({func}, {arglist} [, {dict}]) *call()* *E699*
1589 Call function {func} with the items in |List| {arglist} as
1590 arguments.
1591 {func} can either be a |Funcref| or the name of a function.
1592 a:firstline and a:lastline are set to the cursor line.
1593 Returns the return value of the called function.
1594 {dict} is for functions with the "dict" attribute. It will be
1595 used to set the local variable "self". |Dictionary-function|
1596
1597 Can also be used as a |method|: >
1598 GetFunc()->call([arg, arg], dict)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001599<
1600 Return type: any, depending on {func}
1601
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001602
1603ceil({expr}) *ceil()*
1604 Return the smallest integral value greater than or equal to
1605 {expr} as a |Float| (round up).
1606 {expr} must evaluate to a |Float| or a |Number|.
1607 Examples: >
1608 echo ceil(1.456)
1609< 2.0 >
1610 echo ceil(-5.456)
1611< -5.0 >
1612 echo ceil(4.0)
1613< 4.0
1614
Bram Moolenaar016188f2022-06-06 20:52:59 +01001615 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1616
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001617 Can also be used as a |method|: >
1618 Compute()->ceil()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001619<
1620 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001621
1622
1623ch_ functions are documented here: |channel-functions-details|
1624
1625
1626changenr() *changenr()*
1627 Return the number of the most recent change. This is the same
1628 number as what is displayed with |:undolist| and can be used
1629 with the |:undo| command.
1630 When a change was made it is the number of that change. After
1631 redo it is the number of the redone change. After undo it is
1632 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001633 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001634
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001635 Return type: |Number|
1636
1637
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001638char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001639 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001640 Examples: >
1641 char2nr(" ") returns 32
1642 char2nr("ABC") returns 65
1643< When {utf8} is omitted or zero, the current 'encoding' is used.
1644 Example for "utf-8": >
1645 char2nr("á") returns 225
1646 char2nr("á"[0]) returns 195
1647< When {utf8} is TRUE, always treat as UTF-8 characters.
1648 A combining character is a separate character.
1649 |nr2char()| does the opposite.
1650 To turn a string into a list of character numbers: >
1651 let str = "ABC"
1652 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1653< Result: [65, 66, 67]
1654
Bram Moolenaar016188f2022-06-06 20:52:59 +01001655 Returns 0 if {string} is not a |String|.
1656
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001657 Can also be used as a |method|: >
1658 GetChar()->char2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001659<
1660 Return type: |Number|
1661
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001662
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001663charclass({string}) *charclass()*
1664 Return the character class of the first character in {string}.
1665 The character class is one of:
1666 0 blank
1667 1 punctuation
Christian Brabandtb5e7da12024-11-01 09:33:00 +01001668 2 word character (depends on 'iskeyword')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001669 3 emoji
1670 other specific Unicode class
1671 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001672 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001673
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001674 Return type: |Number|
1675
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001676
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001677charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001678 Same as |col()| but returns the character index of the column
1679 position given with {expr} instead of the byte position.
1680
1681 Example:
1682 With the cursor on '세' in line 5 with text "여보세요": >
1683 charcol('.') returns 3
1684 col('.') returns 7
1685
1686< Can also be used as a |method|: >
1687 GetPos()->col()
1688<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001689 Return type: |Number|
1690
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001691 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001692charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001693 Return the character index of the byte at {idx} in {string}.
1694 The index of the first character is zero.
1695 If there are no multibyte characters the returned value is
1696 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001697
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001698 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001699 are not counted separately, their byte length is added to the
1700 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001701 When {countcc} is |TRUE|, then composing characters are
1702 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001703
1704 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1705 index in the String {expr} instead of as the byte index.
1706
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001707 Returns -1 if the arguments are invalid or if there are less
1708 than {idx} bytes. If there are exactly {idx} bytes the length
1709 of the string in characters is returned.
1710
1711 An error is given and -1 is returned if the first argument is
1712 not a string, the second argument is not a number or when the
1713 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001714
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001715 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001716 from the character index and |utf16idx()| for getting the
1717 UTF-16 index from the character index.
1718 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001719 Examples: >
1720 echo charidx('áb́ć', 3) returns 1
1721 echo charidx('áb́ć', 6, 1) returns 4
1722 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001723 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001724<
1725 Can also be used as a |method|: >
1726 GetName()->charidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001727<
1728 Return type: |Number|
1729
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001730
1731chdir({dir}) *chdir()*
1732 Change the current working directory to {dir}. The scope of
1733 the directory change depends on the directory of the current
1734 window:
1735 - If the current window has a window-local directory
1736 (|:lcd|), then changes the window local directory.
1737 - Otherwise, if the current tabpage has a local
1738 directory (|:tcd|) then changes the tabpage local
1739 directory.
1740 - Otherwise, changes the global directory.
1741 {dir} must be a String.
1742 If successful, returns the previous working directory. Pass
1743 this to another chdir() to restore the directory.
1744 On failure, returns an empty string.
1745
1746 Example: >
1747 let save_dir = chdir(newdir)
1748 if save_dir != ""
1749 " ... do some work
1750 call chdir(save_dir)
1751 endif
1752
1753< Can also be used as a |method|: >
1754 GetDir()->chdir()
1755<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001756 Return type: |String|
1757
1758
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001759cindent({lnum}) *cindent()*
1760 Get the amount of indent for line {lnum} according the C
1761 indenting rules, as with 'cindent'.
1762 The indent is counted in spaces, the value of 'tabstop' is
1763 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001764 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001765 See |C-indenting|.
1766
1767 Can also be used as a |method|: >
1768 GetLnum()->cindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001769<
1770 Return type: |Number|
1771
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001772
1773clearmatches([{win}]) *clearmatches()*
1774 Clears all matches previously defined for the current window
1775 by |matchadd()| and the |:match| commands.
1776 If {win} is specified, use the window with this number or
1777 window ID instead of the current window.
1778
1779 Can also be used as a |method|: >
1780 GetWin()->clearmatches()
1781<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001782 Return type: |Number|
1783
1784
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001785col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001786 The result is a Number, which is the byte index of the column
zeertzjq02f3eba2024-06-12 20:45:24 +02001787 position given with {expr}.
1788 For accepted positions see |getpos()|.
zeertzjqd353d272024-06-13 23:00:25 +08001789 When {expr} is "$", it means the end of the cursor line, so
1790 the result is the number of bytes in the cursor line plus one.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001791 Additionally {expr} can be [lnum, col]: a |List| with the line
1792 and column number. Most useful when the column is "$", to get
1793 the last column of a specific line. When "lnum" or "col" is
1794 out of range then col() returns zero.
zeertzjq02f3eba2024-06-12 20:45:24 +02001795
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001796 With the optional {winid} argument the values are obtained for
1797 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02001798
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001799 To get the line number use |line()|. To get both use
1800 |getpos()|.
1801 For the screen column position use |virtcol()|. For the
1802 character position use |charcol()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02001803
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001804 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +02001805
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001806 Examples: >
1807 col(".") column of cursor
1808 col("$") length of cursor line plus one
1809 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001810 col("'" .. markname) column of mark markname
zeertzjq02f3eba2024-06-12 20:45:24 +02001811<
1812 The first column is 1. Returns 0 if {expr} is invalid or when
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001813 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001814 For an uppercase mark the column may actually be in another
1815 buffer.
1816 For the cursor position, when 'virtualedit' is active, the
1817 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001818 line. Also, when using a <Cmd> mapping the cursor isn't
1819 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001820 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001821
1822< Can also be used as a |method|: >
1823 GetPos()->col()
1824<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001825 Return type: |Number|
1826
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001827
1828complete({startcol}, {matches}) *complete()* *E785*
1829 Set the matches for Insert mode completion.
1830 Can only be used in Insert mode. You need to use a mapping
1831 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1832 or with an expression mapping.
1833 {startcol} is the byte offset in the line where the completed
1834 text start. The text up to the cursor is the original text
1835 that will be replaced by the matches. Use col('.') for an
1836 empty string. "col('.') - 1" will replace one character by a
1837 match.
1838 {matches} must be a |List|. Each |List| item is one match.
1839 See |complete-items| for the kind of items that are possible.
1840 "longest" in 'completeopt' is ignored.
1841 Note that the after calling this function you need to avoid
1842 inserting anything that would cause completion to stop.
1843 The match can be selected with CTRL-N and CTRL-P as usual with
1844 Insert mode completion. The popup menu will appear if
1845 specified, see |ins-completion-menu|.
1846 Example: >
1847 inoremap <F5> <C-R>=ListMonths()<CR>
1848
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001849 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001850 call complete(col('.'), ['January', 'February', 'March',
1851 \ 'April', 'May', 'June', 'July', 'August', 'September',
1852 \ 'October', 'November', 'December'])
1853 return ''
1854 endfunc
1855< This isn't very useful, but it shows how it works. Note that
1856 an empty string is returned to avoid a zero being inserted.
1857
1858 Can also be used as a |method|, the base is passed as the
1859 second argument: >
1860 GetMatches()->complete(col('.'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001861<
1862 Return type: |Number|
1863
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001864
1865complete_add({expr}) *complete_add()*
1866 Add {expr} to the list of matches. Only to be used by the
1867 function specified with the 'completefunc' option.
1868 Returns 0 for failure (empty string or out of memory),
1869 1 when the match was added, 2 when the match was already in
1870 the list.
1871 See |complete-functions| for an explanation of {expr}. It is
1872 the same as one item in the list that 'omnifunc' would return.
1873
1874 Can also be used as a |method|: >
1875 GetMoreMatches()->complete_add()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001876<
1877 Return type: |Number|
1878
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001879
1880complete_check() *complete_check()*
1881 Check for a key typed while looking for completion matches.
1882 This is to be used when looking for matches takes some time.
1883 Returns |TRUE| when searching for matches is to be aborted,
1884 zero otherwise.
1885 Only to be used by the function specified with the
1886 'completefunc' option.
1887
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001888 Return type: |Number|
1889
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001890
1891complete_info([{what}]) *complete_info()*
1892 Returns a |Dictionary| with information about Insert mode
1893 completion. See |ins-completion|.
1894 The items are:
1895 mode Current completion mode name string.
1896 See |complete_info_mode| for the values.
1897 pum_visible |TRUE| if popup menu is visible.
1898 See |pumvisible()|.
1899 items List of completion matches. Each item is a
1900 dictionary containing the entries "word",
1901 "abbr", "menu", "kind", "info" and "user_data".
1902 See |complete-items|.
1903 selected Selected item index. First index is zero.
1904 Index is -1 if no item is selected (showing
1905 typed text only, or the last completion after
1906 no item is selected when using the <Up> or
1907 <Down> keys)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01001908 inserted Inserted string. [NOT IMPLEMENTED YET]
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001909
1910 *complete_info_mode*
1911 mode values are:
1912 "" Not in completion mode
1913 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1914 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1915 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1916 |i_CTRL-X_CTRL-Y|
1917 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1918 "files" File names |i_CTRL-X_CTRL-F|
1919 "tags" Tags |i_CTRL-X_CTRL-]|
1920 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1921 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1922 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1923 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1924 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1925 "function" User defined completion |i_CTRL-X_CTRL-U|
1926 "omni" Omni completion |i_CTRL-X_CTRL-O|
1927 "spell" Spelling suggestions |i_CTRL-X_s|
1928 "eval" |complete()| completion
1929 "unknown" Other internal modes
1930
1931 If the optional {what} list argument is supplied, then only
1932 the items listed in {what} are returned. Unsupported items in
1933 {what} are silently ignored.
1934
1935 To get the position and size of the popup menu, see
1936 |pum_getpos()|. It's also available in |v:event| during the
1937 |CompleteChanged| event.
1938
Bram Moolenaar016188f2022-06-06 20:52:59 +01001939 Returns an empty |Dictionary| on error.
1940
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001941 Examples: >
1942 " Get all items
1943 call complete_info()
1944 " Get only 'mode'
1945 call complete_info(['mode'])
1946 " Get only 'mode' and 'pum_visible'
1947 call complete_info(['mode', 'pum_visible'])
1948
1949< Can also be used as a |method|: >
1950 GetItems()->complete_info()
1951<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001952 Return type: dict<any>
1953
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001954 *confirm()*
1955confirm({msg} [, {choices} [, {default} [, {type}]]])
1956 confirm() offers the user a dialog, from which a choice can be
1957 made. It returns the number of the choice. For the first
1958 choice this is 1.
1959 Note: confirm() is only supported when compiled with dialog
glepnirdf461152024-04-04 22:23:29 +02001960 support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001961
1962 {msg} is displayed in a |dialog| with {choices} as the
1963 alternatives. When {choices} is missing or empty, "&OK" is
1964 used (and translated).
1965 {msg} is a String, use '\n' to include a newline. Only on
1966 some systems the string is wrapped when it doesn't fit.
1967
1968 {choices} is a String, with the individual choices separated
1969 by '\n', e.g. >
1970 confirm("Save changes?", "&Yes\n&No\n&Cancel")
1971< The letter after the '&' is the shortcut key for that choice.
1972 Thus you can type 'c' to select "Cancel". The shortcut does
1973 not need to be the first letter: >
1974 confirm("file has been modified", "&Save\nSave &All")
1975< For the console, the first letter of each choice is used as
1976 the default shortcut key. Case is ignored.
1977
1978 The optional {default} argument is the number of the choice
1979 that is made if the user hits <CR>. Use 1 to make the first
1980 choice the default one. Use 0 to not set a default. If
1981 {default} is omitted, 1 is used.
1982
1983 The optional {type} String argument gives the type of dialog.
1984 This is only used for the icon of the GTK, Mac, Motif and
1985 Win32 GUI. It can be one of these values: "Error",
1986 "Question", "Info", "Warning" or "Generic". Only the first
1987 character is relevant. When {type} is omitted, "Generic" is
1988 used.
1989
1990 If the user aborts the dialog by pressing <Esc>, CTRL-C,
1991 or another valid interrupt key, confirm() returns 0.
1992
1993 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01001994 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001995 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01001996 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001997 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001998 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001999 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002000 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002001 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01002002 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002003< In a GUI dialog, buttons are used. The layout of the buttons
2004 depends on the 'v' flag in 'guioptions'. If it is included,
2005 the buttons are always put vertically. Otherwise, confirm()
2006 tries to put the buttons in one horizontal line. If they
2007 don't fit, a vertical layout is used anyway. For some systems
2008 the horizontal layout is always used.
2009
2010 Can also be used as a |method|in: >
2011 BuildMessage()->confirm("&Yes\n&No")
2012<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002013 Return type: |Number|
2014
2015
2016copy({expr}) *copy()*
2017 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002018 different from using {expr} directly.
2019 When {expr} is a |List| a shallow copy is created. This means
2020 that the original |List| can be changed without changing the
2021 copy, and vice versa. But the items are identical, thus
2022 changing an item changes the contents of both |Lists|.
2023 A |Dictionary| is copied in a similar way as a |List|.
2024 Also see |deepcopy()|.
2025 Can also be used as a |method|: >
2026 mylist->copy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002027<
2028 Return type: any, depending on {expr}
2029
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002030
2031cos({expr}) *cos()*
2032 Return the cosine of {expr}, measured in radians, as a |Float|.
2033 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002034 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002035 Examples: >
2036 :echo cos(100)
2037< 0.862319 >
2038 :echo cos(-4.01)
2039< -0.646043
2040
2041 Can also be used as a |method|: >
2042 Compute()->cos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002043<
2044 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002045
2046
2047cosh({expr}) *cosh()*
2048 Return the hyperbolic cosine of {expr} as a |Float| in the range
2049 [1, inf].
2050 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002051 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002052 Examples: >
2053 :echo cosh(0.5)
2054< 1.127626 >
2055 :echo cosh(-0.5)
2056< -1.127626
2057
2058 Can also be used as a |method|: >
2059 Compute()->cosh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002060<
2061 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002062
2063
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07002064count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002065 Return the number of times an item with value {expr} appears
2066 in |String|, |List| or |Dictionary| {comp}.
2067
2068 If {start} is given then start with the item with this index.
2069 {start} can only be used with a |List|.
2070
2071 When {ic} is given and it's |TRUE| then case is ignored.
2072
2073 When {comp} is a string then the number of not overlapping
2074 occurrences of {expr} is returned. Zero is returned when
2075 {expr} is an empty string.
2076
2077 Can also be used as a |method|: >
2078 mylist->count(val)
2079<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002080 Return type: |Number|
2081
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002082 *cscope_connection()*
2083cscope_connection([{num} , {dbpath} [, {prepend}]])
2084 Checks for the existence of a |cscope| connection. If no
2085 parameters are specified, then the function returns:
2086 0, if cscope was not available (not compiled in), or
2087 if there are no cscope connections;
2088 1, if there is at least one cscope connection.
2089
2090 If parameters are specified, then the value of {num}
2091 determines how existence of a cscope connection is checked:
2092
2093 {num} Description of existence check
2094 ----- ------------------------------
2095 0 Same as no parameters (e.g., "cscope_connection()").
2096 1 Ignore {prepend}, and use partial string matches for
2097 {dbpath}.
2098 2 Ignore {prepend}, and use exact string matches for
2099 {dbpath}.
2100 3 Use {prepend}, use partial string matches for both
2101 {dbpath} and {prepend}.
2102 4 Use {prepend}, use exact string matches for both
2103 {dbpath} and {prepend}.
2104
2105 Note: All string comparisons are case sensitive!
2106
2107 Examples. Suppose we had the following (from ":cs show"): >
2108
2109 # pid database name prepend path
2110 0 27664 cscope.out /usr/local
2111<
2112 Invocation Return Val ~
2113 ---------- ---------- >
2114 cscope_connection() 1
2115 cscope_connection(1, "out") 1
2116 cscope_connection(2, "out") 0
2117 cscope_connection(3, "out") 0
2118 cscope_connection(3, "out", "local") 1
2119 cscope_connection(4, "out") 0
2120 cscope_connection(4, "out", "local") 0
2121 cscope_connection(4, "cscope.out", "/usr/local") 1
2122<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002123 Return type: |Number|
2124
2125
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002126cursor({lnum}, {col} [, {off}]) *cursor()*
2127cursor({list})
2128 Positions the cursor at the column (byte count) {col} in the
2129 line {lnum}. The first column is one.
2130
2131 When there is one argument {list} this is used as a |List|
2132 with two, three or four item:
2133 [{lnum}, {col}]
2134 [{lnum}, {col}, {off}]
2135 [{lnum}, {col}, {off}, {curswant}]
2136 This is like the return value of |getpos()| or |getcurpos()|,
2137 but without the first item.
2138
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01002139 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002140 |setcursorcharpos()|.
2141
2142 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01002143 {lnum} is used like with |getline()|, except that if {lnum} is
2144 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002145 If {lnum} is greater than the number of lines in the buffer,
2146 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002147 If {col} is greater than the number of bytes in the line,
2148 the cursor will be positioned at the last character in the
2149 line.
2150 If {col} is zero, the cursor will stay in the current column.
2151 If {curswant} is given it is used to set the preferred column
2152 for vertical movement. Otherwise {col} is used.
2153
2154 When 'virtualedit' is used {off} specifies the offset in
2155 screen columns from the start of the character. E.g., a
2156 position within a <Tab> or after the last character.
2157 Returns 0 when the position could be set, -1 otherwise.
2158
2159 Can also be used as a |method|: >
2160 GetCursorPos()->cursor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002161<
2162 Return type: |Number|
2163
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002164
2165debugbreak({pid}) *debugbreak()*
2166 Specifically used to interrupt a program being debugged. It
2167 will cause process {pid} to get a SIGTRAP. Behavior for other
2168 processes is undefined. See |terminal-debugger|.
2169 {only available on MS-Windows}
2170
Bram Moolenaar016188f2022-06-06 20:52:59 +01002171 Returns |TRUE| if successfully interrupted the program.
2172 Otherwise returns |FALSE|.
2173
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002174 Can also be used as a |method|: >
2175 GetPid()->debugbreak()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002176<
2177 Return type: |Number|
2178
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002179
2180deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
2181 Make a copy of {expr}. For Numbers and Strings this isn't
2182 different from using {expr} directly.
2183 When {expr} is a |List| a full copy is created. This means
2184 that the original |List| can be changed without changing the
2185 copy, and vice versa. When an item is a |List| or
2186 |Dictionary|, a copy for it is made, recursively. Thus
2187 changing an item in the copy does not change the contents of
2188 the original |List|.
2189 A |Dictionary| is copied in a similar way as a |List|.
2190
2191 When {noref} is omitted or zero a contained |List| or
2192 |Dictionary| is only copied once. All references point to
2193 this single copy. With {noref} set to 1 every occurrence of a
2194 |List| or |Dictionary| results in a new copy. This also means
2195 that a cyclic reference causes deepcopy() to fail.
2196 *E724*
2197 Nesting is possible up to 100 levels. When there is an item
2198 that refers back to a higher level making a deep copy with
2199 {noref} set to 1 will fail.
2200 Also see |copy()|.
2201
2202 Can also be used as a |method|: >
2203 GetObject()->deepcopy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002204<
2205 Return type: any, depending on {expr}
2206
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002207
2208delete({fname} [, {flags}]) *delete()*
2209 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002210 name {fname}.
2211
2212 This also works when {fname} is a symbolic link. The symbolic
2213 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002214
2215 When {flags} is "d": Deletes the directory by the name
2216 {fname}. This fails when directory {fname} is not empty.
2217
2218 When {flags} is "rf": Deletes the directory by the name
2219 {fname} and everything in it, recursively. BE CAREFUL!
2220 Note: on MS-Windows it is not possible to delete a directory
2221 that is being used.
2222
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002223 The result is a Number, which is 0/false if the delete
2224 operation was successful and -1/true when the deletion failed
2225 or partly failed.
2226
2227 Use |remove()| to delete an item from a |List|.
2228 To delete a line from the buffer use |:delete| or
2229 |deletebufline()|.
2230
2231 Can also be used as a |method|: >
2232 GetName()->delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002233<
2234 Return type: |Number|
2235
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002236
2237deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2238 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2239 If {last} is omitted then delete line {first} only.
2240 On success 0 is returned, on failure 1 is returned.
2241
2242 This function works only for loaded buffers. First call
2243 |bufload()| if needed.
2244
2245 For the use of {buf}, see |bufname()| above.
2246
2247 {first} and {last} are used like with |getline()|. Note that
2248 when using |line()| this refers to the current buffer. Use "$"
2249 to refer to the last line in buffer {buf}.
2250
2251 Can also be used as a |method|: >
2252 GetBuffer()->deletebufline(1)
2253<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002254 Return type: |Number|
2255
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002256 *did_filetype()*
2257did_filetype() Returns |TRUE| when autocommands are being executed and the
2258 FileType event has been triggered at least once. Can be used
2259 to avoid triggering the FileType event again in the scripts
2260 that detect the file type. |FileType|
2261 Returns |FALSE| when `:setf FALLBACK` was used.
2262 When editing another file, the counter is reset, thus this
2263 really checks if the FileType event has been triggered for the
2264 current buffer. This allows an autocommand that starts
2265 editing another buffer to set 'filetype' and load a syntax
2266 file.
2267
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002268 Return type: |Number|
2269
2270
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002271diff({fromlist}, {tolist} [, {options}]) *diff()*
2272 Returns a String or a List containing the diff between the
2273 strings in {fromlist} and {tolist}. Uses the Vim internal
2274 diff library to compute the diff.
2275
2276 *E106*
2277 The optional "output" item in {options} specifies the returned
2278 diff format. The following values are supported:
2279 indices Return a List of the starting and ending
2280 indices and a count of the strings in each
2281 diff hunk.
2282 unified Return the unified diff output as a String.
2283 This is the default.
2284
2285 If the "output" item in {options} is "indices", then a List is
2286 returned. Each List item contains a Dict with the following
2287 items for each diff hunk:
2288 from_idx start index in {fromlist} for this diff hunk.
2289 from_count number of strings in {fromlist} that are
2290 added/removed/modified in this diff hunk.
2291 to_idx start index in {tolist} for this diff hunk.
2292 to_count number of strings in {tolist} that are
2293 added/removed/modified in this diff hunk.
2294
2295 The {options} Dict argument also specifies diff options
2296 (similar to 'diffopt') and supports the following items:
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002297 algorithm Dict specifying the diff algorithm to
2298 use. Supported boolean items are
2299 "myers", "minimal", "patience" and
2300 "histogram".
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002301 context diff context length. Default is 0.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002302 iblank ignore changes where lines are all
2303 blank.
2304 icase ignore changes in case of text.
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002305 indent-heuristic use the indent heuristic for the
2306 internal diff library.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002307 iwhite ignore changes in amount of white
2308 space.
2309 iwhiteall ignore all white space changes.
2310 iwhiteeol ignore white space changes at end of
2311 line.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002312 For more information about these options, refer to 'diffopt'.
2313
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002314 To compute the unified diff, all the items in {fromlist} are
2315 concatenated into a string using a newline separator and the
2316 same for {tolist}. The unified diff output uses line numbers.
2317
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002318 Returns an empty List or String if {fromlist} and {tolist} are
2319 identical.
2320
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002321 Examples: >
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002322 :echo diff(['abc'], ['xxx'])
2323 @@ -1 +1 @@
2324 -abc
2325 +xxx
2326
2327 :echo diff(['abc'], ['xxx'], {'output': 'indices'})
2328 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}]
2329 :echo diff(readfile('oldfile'), readfile('newfile'))
2330 :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$'))
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002331<
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002332 For more examples, refer to |diff-func-examples|
2333
2334 Can also be used as a |method|: >
2335 GetFromList->diff(to_list)
2336<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002337 Return type: |String| or list<dict<number>> or list<any>
2338 depending on {options}
2339
2340
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002341diff_filler({lnum}) *diff_filler()*
2342 Returns the number of filler lines above line {lnum}.
2343 These are the lines that were inserted at this point in
2344 another diff'ed window. These filler lines are shown in the
2345 display but don't exist in the buffer.
2346 {lnum} is used like with |getline()|. Thus "." is the current
2347 line, "'m" mark m, etc.
2348 Returns 0 if the current window is not in diff mode.
2349
2350 Can also be used as a |method|: >
2351 GetLnum()->diff_filler()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002352<
2353 Return type: |Number|
2354
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002355
2356diff_hlID({lnum}, {col}) *diff_hlID()*
2357 Returns the highlight ID for diff mode at line {lnum} column
2358 {col} (byte index). When the current line does not have a
2359 diff change zero is returned.
2360 {lnum} is used like with |getline()|. Thus "." is the current
2361 line, "'m" mark m, etc.
2362 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2363 line.
2364 The highlight ID can be used with |synIDattr()| to obtain
2365 syntax information about the highlighting.
2366
2367 Can also be used as a |method|: >
2368 GetLnum()->diff_hlID(col)
2369<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002370 Return type: |Number|
2371
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002372
2373digraph_get({chars}) *digraph_get()* *E1214*
2374 Return the digraph of {chars}. This should be a string with
2375 exactly two characters. If {chars} are not just two
2376 characters, or the digraph of {chars} does not exist, an error
2377 is given and an empty string is returned.
2378
2379 The character will be converted from Unicode to 'encoding'
2380 when needed. This does require the conversion to be
2381 available, it might fail.
2382
2383 Also see |digraph_getlist()|.
2384
2385 Examples: >
2386 " Get a built-in digraph
2387 :echo digraph_get('00') " Returns '∞'
2388
2389 " Get a user-defined digraph
2390 :call digraph_set('aa', 'あ')
2391 :echo digraph_get('aa') " Returns 'あ'
2392<
2393 Can also be used as a |method|: >
2394 GetChars()->digraph_get()
2395<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002396 Return type: |String|
2397
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002398 This function works only when compiled with the |+digraphs|
2399 feature. If this feature is disabled, this function will
2400 display an error message.
2401
2402
2403digraph_getlist([{listall}]) *digraph_getlist()*
2404 Return a list of digraphs. If the {listall} argument is given
2405 and it is TRUE, return all digraphs, including the default
2406 digraphs. Otherwise, return only user-defined digraphs.
2407
2408 The characters will be converted from Unicode to 'encoding'
2409 when needed. This does require the conservation to be
2410 available, it might fail.
2411
2412 Also see |digraph_get()|.
2413
2414 Examples: >
2415 " Get user-defined digraphs
2416 :echo digraph_getlist()
2417
2418 " Get all the digraphs, including default digraphs
2419 :echo digraph_getlist(1)
2420<
2421 Can also be used as a |method|: >
2422 GetNumber()->digraph_getlist()
2423<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002424 Return type: list<list<string>>
2425
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002426 This function works only when compiled with the |+digraphs|
2427 feature. If this feature is disabled, this function will
2428 display an error message.
2429
2430
Bram Moolenaara2baa732022-02-04 16:09:54 +00002431digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002432 Add digraph {chars} to the list. {chars} must be a string
2433 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002434 encoded character. *E1215*
2435 Be careful, composing characters are NOT ignored. This
2436 function is similar to |:digraphs| command, but useful to add
2437 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002438
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002439 The function returns v:true if |digraph| is registered. If
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002440 this fails an error message is given and v:false is returned.
2441
2442 If you want to define multiple digraphs at once, you can use
2443 |digraph_setlist()|.
2444
2445 Example: >
2446 call digraph_set(' ', 'あ')
2447<
2448 Can be used as a |method|: >
2449 GetString()->digraph_set('あ')
2450<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002451 Return type: |vim9-boolean|
2452
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002453 This function works only when compiled with the |+digraphs|
2454 feature. If this feature is disabled, this function will
2455 display an error message.
2456
2457
2458digraph_setlist({digraphlist}) *digraph_setlist()*
2459 Similar to |digraph_set()| but this function can add multiple
2460 digraphs at once. {digraphlist} is a list composed of lists,
2461 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002462 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002463 Example: >
2464 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2465<
2466 It is similar to the following: >
2467 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2468 call digraph_set(chars, digraph)
2469 endfor
2470< Except that the function returns after the first error,
2471 following digraphs will not be added.
2472
2473 Can be used as a |method|: >
2474 GetList()->digraph_setlist()
2475<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002476 Return type: |vim9-boolean|
2477
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002478 This function works only when compiled with the |+digraphs|
2479 feature. If this feature is disabled, this function will
2480 display an error message.
2481
2482
2483echoraw({string}) *echoraw()*
2484 Output {string} as-is, including unprintable characters.
2485 This can be used to output a terminal code. For example, to
2486 disable modifyOtherKeys: >
2487 call echoraw(&t_TE)
2488< and to enable it again: >
2489 call echoraw(&t_TI)
2490< Use with care, you can mess up the terminal this way.
2491
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002492 Return type: |Number|
2493
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002494
2495empty({expr}) *empty()*
2496 Return the Number 1 if {expr} is empty, zero otherwise.
2497 - A |List| or |Dictionary| is empty when it does not have any
2498 items.
2499 - A |String| is empty when its length is zero.
2500 - A |Number| and |Float| are empty when their value is zero.
2501 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2502 - A |Job| is empty when it failed to start.
2503 - A |Channel| is empty when it is closed.
2504 - A |Blob| is empty when its length is zero.
mityu7f0bba22024-03-29 10:14:41 +01002505 - An |Object| is empty, when the empty() method in the object
2506 (if present) returns true. |object-empty()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002507
2508 For a long |List| this is much faster than comparing the
2509 length with zero.
2510
2511 Can also be used as a |method|: >
2512 mylist->empty()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002513<
2514 Return type: |Number|
2515
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002516
2517environ() *environ()*
2518 Return all of environment variables as dictionary. You can
2519 check if an environment variable exists like this: >
2520 :echo has_key(environ(), 'HOME')
2521< Note that the variable name may be CamelCase; to ignore case
2522 use this: >
2523 :echo index(keys(environ()), 'HOME', 0, 1) != -1
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002524<
2525 Return type: dict<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002526
Bram Moolenaar416bd912023-07-07 23:19:18 +01002527
2528err_teapot([{expr}]) *err_teapot()*
2529 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002530 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002531 If {expr} is present and it is TRUE error 503 is given,
2532 indicating that coffee is temporarily not available.
2533 If {expr} is present it must be a String.
2534
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002535 Return type: |Number|
2536
Bram Moolenaar416bd912023-07-07 23:19:18 +01002537
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002538escape({string}, {chars}) *escape()*
2539 Escape the characters in {chars} that occur in {string} with a
2540 backslash. Example: >
2541 :echo escape('c:\program files\vim', ' \')
2542< results in: >
2543 c:\\program\ files\\vim
2544< Also see |shellescape()| and |fnameescape()|.
2545
2546 Can also be used as a |method|: >
2547 GetText()->escape(' \')
2548<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002549 Return type: |String|
2550
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002551 *eval()*
2552eval({string}) Evaluate {string} and return the result. Especially useful to
2553 turn the result of |string()| back into the original value.
2554 This works for Numbers, Floats, Strings, Blobs and composites
2555 of them. Also works for |Funcref|s that refer to existing
Aliaksei Budavei95740222024-04-04 23:05:33 +03002556 functions. In |Vim9| script, it can be used to obtain |enum|
2557 values from their fully qualified names.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002558
2559 Can also be used as a |method|: >
2560 argv->join()->eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002561<
2562 Return type: any, depending on {string}
2563
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002564
2565eventhandler() *eventhandler()*
2566 Returns 1 when inside an event handler. That is that Vim got
2567 interrupted while waiting for the user to type a character,
2568 e.g., when dropping a file on Vim. This means interactive
2569 commands cannot be used. Otherwise zero is returned.
2570
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002571 Return type: |Number|
2572
2573
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002574executable({expr}) *executable()*
2575 This function checks if an executable with the name {expr}
2576 exists. {expr} must be the name of the program without any
2577 arguments.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002578
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002579 executable() uses the value of $PATH and/or the normal
zeertzjq0cc5dce2024-08-08 21:12:15 +02002580 searchpath for programs.
2581 *PATHEXT*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002582 On MS-Windows the ".exe", ".bat", etc. can optionally be
2583 included. Then the extensions in $PATHEXT are tried. Thus if
2584 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2585 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2586 by itself can be used in $PATHEXT to try using the name
2587 without an extension. When 'shell' looks like a Unix shell,
2588 then the name is also tried without adding an extension.
2589 On MS-Windows it only checks if the file exists and is not a
2590 directory, not if it's really executable.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002591 On MS-Windows an executable in the same directory as the Vim
2592 executable is always found. Since this directory is added to
2593 $PATH it should also work to execute it |win32-PATH|.
2594 *NoDefaultCurrentDirectoryInExePath*
2595 On MS-Windows an executable in Vim's current working directory
2596 is also normally found, but this can be disabled by setting
2597 the $NoDefaultCurrentDirectoryInExePath environment variable.
2598
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002599 The result is a Number:
2600 1 exists
2601 0 does not exist
2602 -1 not implemented on this system
2603 |exepath()| can be used to get the full path of an executable.
2604
2605 Can also be used as a |method|: >
2606 GetCommand()->executable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002607<
2608 Return type: |Number|
2609
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002610
2611execute({command} [, {silent}]) *execute()*
2612 Execute an Ex command or commands and return the output as a
2613 string.
2614 {command} can be a string or a List. In case of a List the
2615 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002616 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002617 redir => var
2618 {command}
2619 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002620< Except that line continuation in {command} is not recognized.
2621
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002622 The optional {silent} argument can have these values:
2623 "" no `:silent` used
2624 "silent" `:silent` used
2625 "silent!" `:silent!` used
2626 The default is "silent". Note that with "silent!", unlike
2627 `:redir`, error messages are dropped. When using an external
2628 command the screen may be messed up, use `system()` instead.
2629 *E930*
2630 It is not possible to use `:redir` anywhere in {command}.
2631
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002632 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002633 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002634
2635< To execute a command in another window than the current one
2636 use `win_execute()`.
2637
2638 When used recursively the output of the recursive call is not
2639 included in the output of the higher level call.
2640
2641 Can also be used as a |method|: >
2642 GetCommand()->execute()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002643<
Marius Gedminasc98bfb92024-06-19 19:59:23 +02002644 Return type: |String|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002645
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002646
2647exepath({expr}) *exepath()*
2648 If {expr} is an executable and is either an absolute path, a
2649 relative path or found in $PATH, return the full path.
2650 Note that the current directory is used when {expr} starts
2651 with "./", which may be a problem for Vim: >
2652 echo exepath(v:progpath)
2653< If {expr} cannot be found in $PATH or is not executable then
2654 an empty string is returned.
2655
2656 Can also be used as a |method|: >
2657 GetCommand()->exepath()
2658<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002659 Return type: |String|
2660
2661
2662exists({expr}) *exists()*
2663 The result is a Number, which is |TRUE| if {expr} is defined,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002664 zero otherwise.
2665
2666 Note: In a compiled |:def| function the evaluation is done at
2667 runtime. Use `exists_compiled()` to evaluate the expression
2668 at compile time.
2669
2670 For checking for a supported feature use |has()|.
2671 For checking if a file exists use |filereadable()|.
2672
2673 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002674 varname internal variable (see
2675 dict.key |internal-variables|). Also works
2676 list[i] for |curly-braces-names|, |Dictionary|
Yegappan Lakshmanana2ebb6e2024-02-25 08:40:10 +01002677 import.Func entries, |List| items, class and
2678 class.Func object methods, imported items, etc.
2679 object.Func Does not work for local variables in a
2680 class.varname compiled `:def` function.
2681 object.varname Also works for a function in |Vim9|
Bram Moolenaar944697a2022-02-20 19:48:20 +00002682 script, since it can be used as a
2683 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002684 Beware that evaluating an index may
2685 cause an error message for an invalid
2686 expression. E.g.: >
2687 :let l = [1, 2, 3]
2688 :echo exists("l[5]")
2689< 0 >
2690 :echo exists("l[xx]")
2691< E121: Undefined variable: xx
2692 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002693 &option-name Vim option (only checks if it exists,
2694 not if it really works)
2695 +option-name Vim option that works.
2696 $ENVNAME environment variable (could also be
2697 done by comparing with an empty
2698 string)
2699 *funcname built-in function (see |functions|)
2700 or user defined function (see
2701 |user-functions|) that is implemented.
2702 Also works for a variable that is a
2703 Funcref.
2704 ?funcname built-in function that could be
2705 implemented; to be used to check if
2706 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002707 :cmdname Ex command: built-in command, user
2708 command or command modifier |:command|.
2709 Returns:
2710 1 for match with start of a command
2711 2 full match with a command
2712 3 matches several user commands
2713 To check for a supported command
2714 always check the return value to be 2.
2715 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002716 :3match The |:3match| command (but you
2717 probably should not use it, it is
2718 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002719 #event autocommand defined for this event
2720 #event#pattern autocommand defined for this event and
2721 pattern (the pattern is taken
2722 literally and compared to the
2723 autocommand patterns character by
2724 character)
2725 #group autocommand group exists
2726 #group#event autocommand defined for this group and
2727 event.
2728 #group#event#pattern
2729 autocommand defined for this group,
2730 event and pattern.
2731 ##event autocommand for this event is
2732 supported.
2733
2734 Examples: >
2735 exists("&shortname")
2736 exists("$HOSTNAME")
2737 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002738 exists("*s:MyFunc") " only for legacy script
2739 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002740 exists("bufcount")
2741 exists(":Make")
2742 exists("#CursorHold")
2743 exists("#BufReadPre#*.gz")
2744 exists("#filetypeindent")
2745 exists("#filetypeindent#FileType")
2746 exists("#filetypeindent#FileType#*")
2747 exists("##ColorScheme")
2748< There must be no space between the symbol (&/$/*/#) and the
2749 name.
2750 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002751 a few cases this is ignored. That may become stricter in the
2752 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002753 Working example: >
2754 exists(":make")
2755< NOT working example: >
2756 exists(":make install")
2757
2758< Note that the argument must be a string, not the name of the
2759 variable itself. For example: >
2760 exists(bufcount)
2761< This doesn't check for existence of the "bufcount" variable,
2762 but gets the value of "bufcount", and checks if that exists.
2763
2764 Can also be used as a |method|: >
2765 Varname()->exists()
2766<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002767 Return type: |String|
2768
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002769
2770exists_compiled({expr}) *exists_compiled()*
2771 Like `exists()` but evaluated at compile time. This is useful
2772 to skip a block where a function is used that would otherwise
2773 give an error: >
2774 if exists_compiled('*ThatFunction')
2775 ThatFunction('works')
2776 endif
2777< If `exists()` were used then a compilation error would be
2778 given if ThatFunction() is not defined.
2779
2780 {expr} must be a literal string. *E1232*
2781 Can only be used in a |:def| function. *E1233*
2782 This does not work to check for arguments or local variables.
2783
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002784 Return type: |String|
2785
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002786
2787exp({expr}) *exp()*
2788 Return the exponential of {expr} as a |Float| in the range
2789 [0, inf].
2790 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002791 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002792 Examples: >
2793 :echo exp(2)
2794< 7.389056 >
2795 :echo exp(-1)
2796< 0.367879
2797
2798 Can also be used as a |method|: >
2799 Compute()->exp()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002800<
2801 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002802
2803
2804expand({string} [, {nosuf} [, {list}]]) *expand()*
2805 Expand wildcards and the following special keywords in
2806 {string}. 'wildignorecase' applies.
2807
2808 If {list} is given and it is |TRUE|, a List will be returned.
2809 Otherwise the result is a String and when there are several
2810 matches, they are separated by <NL> characters. [Note: in
2811 version 5.0 a space was used, which caused problems when a
2812 file name contains a space]
2813
2814 If the expansion fails, the result is an empty string. A name
2815 for a non-existing file is not included, unless {string} does
2816 not start with '%', '#' or '<', see below.
2817
Christian Brabandtec9c3262024-02-21 20:40:05 +01002818 For a |:terminal| window '%' expands to a '!' followed by
h-east53753f62024-05-05 18:42:31 +02002819 the command or shell that is run. |terminal-bufname|
Christian Brabandtec9c3262024-02-21 20:40:05 +01002820
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002821 When {string} starts with '%', '#' or '<', the expansion is
2822 done like for the |cmdline-special| variables with their
2823 associated modifiers. Here is a short overview:
2824
2825 % current file name
2826 # alternate file name
2827 #n alternate file name n
2828 <cfile> file name under the cursor
2829 <afile> autocmd file name
2830 <abuf> autocmd buffer number (as a String!)
2831 <amatch> autocmd matched name
2832 <cexpr> C expression under the cursor
2833 <sfile> sourced script file or function name
2834 <slnum> sourced script line number or function
2835 line number
2836 <sflnum> script file line number, also when in
2837 a function
2838 <SID> "<SNR>123_" where "123" is the
2839 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002840 <script> sourced script file, or script file
2841 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002842 <stack> call stack
2843 <cword> word under the cursor
2844 <cWORD> WORD under the cursor
2845 <client> the {clientid} of the last received
2846 message |server2client()|
2847 Modifiers:
2848 :p expand to full path
2849 :h head (last path component removed)
2850 :t tail (last path component only)
2851 :r root (one extension removed)
2852 :e extension only
2853
2854 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002855 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002856< Note that when expanding a string that starts with '%', '#' or
2857 '<', any following text is ignored. This does NOT work: >
2858 :let doesntwork = expand("%:h.bak")
2859< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002860 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002861< Also note that expanding "<cfile>" and others only returns the
2862 referenced file name without further expansion. If "<cfile>"
2863 is "~/.cshrc", you need to do another expand() to have the
2864 "~/" expanded into the path of the home directory: >
2865 :echo expand(expand("<cfile>"))
2866<
2867 There cannot be white space between the variables and the
2868 following modifier. The |fnamemodify()| function can be used
2869 to modify normal file names.
2870
2871 When using '%' or '#', and the current or alternate file name
2872 is not defined, an empty string is used. Using "%:p" in a
2873 buffer with no name, results in the current directory, with a
2874 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002875 When 'verbose' is set then expanding '%', '#' and <> items
2876 will result in an error message if the argument cannot be
2877 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002878
2879 When {string} does not start with '%', '#' or '<', it is
2880 expanded like a file name is expanded on the command line.
2881 'suffixes' and 'wildignore' are used, unless the optional
2882 {nosuf} argument is given and it is |TRUE|.
2883 Names for non-existing files are included. The "**" item can
2884 be used to search in a directory tree. For example, to find
2885 all "README" files in the current directory and below: >
2886 :echo expand("**/README")
2887<
2888 expand() can also be used to expand variables and environment
2889 variables that are only known in a shell. But this can be
2890 slow, because a shell may be used to do the expansion. See
2891 |expr-env-expand|.
2892 The expanded variable is still handled like a list of file
2893 names. When an environment variable cannot be expanded, it is
2894 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2895 "$FOOBAR".
2896
2897 See |glob()| for finding existing files. See |system()| for
2898 getting the raw output of an external command.
2899
2900 Can also be used as a |method|: >
2901 Getpattern()->expand()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002902<
2903 Return type: |String| or list<string> depending on {list}
2904
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002905
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002906expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002907 Expand special items in String {string} like what is done for
2908 an Ex command such as `:edit`. This expands special keywords,
2909 like with |expand()|, and environment variables, anywhere in
2910 {string}. "~user" and "~/path" are only expanded at the
2911 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002912
2913 The following items are supported in the {options} Dict
2914 argument:
2915 errmsg If set to TRUE, error messages are displayed
2916 if an error is encountered during expansion.
2917 By default, error messages are not displayed.
2918
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002919 Returns the expanded string. If an error is encountered
2920 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002921
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002922 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002923 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002924 make /path/runtime/doc/builtin.o
2925 :echo expandcmd('make %<.o', {'errmsg': v:true})
2926<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002927 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002928 GetCommand()->expandcmd()
2929<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002930 Return type: |String| or list<string> depending on {list}
2931
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002932extend({expr1}, {expr2} [, {expr3}]) *extend()*
2933 {expr1} and {expr2} must be both |Lists| or both
2934 |Dictionaries|.
2935
2936 If they are |Lists|: Append {expr2} to {expr1}.
2937 If {expr3} is given insert the items of {expr2} before the
2938 item with index {expr3} in {expr1}. When {expr3} is zero
2939 insert before the first item. When {expr3} is equal to
2940 len({expr1}) then {expr2} is appended.
2941 Examples: >
2942 :echo sort(extend(mylist, [7, 5]))
2943 :call extend(mylist, [2, 3], 1)
2944< When {expr1} is the same List as {expr2} then the number of
2945 items copied is equal to the original length of the List.
2946 E.g., when {expr3} is 1 you get N new copies of the first item
2947 (where N is the original length of the List).
2948 Use |add()| to concatenate one item to a list. To concatenate
2949 two lists into a new list use the + operator: >
2950 :let newlist = [1, 2, 3] + [4, 5]
2951<
2952 If they are |Dictionaries|:
2953 Add all entries from {expr2} to {expr1}.
2954 If a key exists in both {expr1} and {expr2} then {expr3} is
2955 used to decide what to do:
2956 {expr3} = "keep": keep the value of {expr1}
2957 {expr3} = "force": use the value of {expr2}
2958 {expr3} = "error": give an error message *E737*
2959 When {expr3} is omitted then "force" is assumed.
2960
2961 {expr1} is changed when {expr2} is not empty. If necessary
2962 make a copy of {expr1} first.
2963 {expr2} remains unchanged.
2964 When {expr1} is locked and {expr2} is not empty the operation
2965 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002966 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002967
2968 Can also be used as a |method|: >
2969 mylist->extend(otherlist)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002970<
2971 Return type: list<{type}> or dict<{type}> depending on {expr1}
2972 and {expr2}, in case of error: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002973
2974
2975extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
2976 Like |extend()| but instead of adding items to {expr1} a new
2977 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00002978 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002979
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002980 Return type: list<{type}> or dict<{type}> depending on {expr1}
2981 and {expr2}, in case of error: |Number|
2982
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002983
2984feedkeys({string} [, {mode}]) *feedkeys()*
2985 Characters in {string} are queued for processing as if they
2986 come from a mapping or were typed by the user.
2987
2988 By default the string is added to the end of the typeahead
2989 buffer, thus if a mapping is still being executed the
2990 characters come after them. Use the 'i' flag to insert before
2991 other characters, they will be executed next, before any
2992 characters from a mapping.
2993
2994 The function does not wait for processing of keys contained in
2995 {string}.
2996
2997 To include special keys into {string}, use double-quotes
2998 and "\..." notation |expr-quote|. For example,
2999 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
3000 feedkeys('\<CR>') pushes 5 characters.
3001 A special code that might be useful is <Ignore>, it exits the
3002 wait for a character without doing anything. *<Ignore>*
3003
3004 {mode} is a String, which can contain these character flags:
3005 'm' Remap keys. This is default. If {mode} is absent,
3006 keys are remapped.
3007 'n' Do not remap keys.
3008 't' Handle keys as if typed; otherwise they are handled as
3009 if coming from a mapping. This matters for undo,
3010 opening folds, etc.
3011 'L' Lowlevel input. Only works for Unix or when using the
3012 GUI. Keys are used as if they were coming from the
3013 terminal. Other flags are not used. *E980*
3014 When a CTRL-C interrupts and 't' is included it sets
3015 the internal "got_int" flag.
3016 'i' Insert the string instead of appending (see above).
3017 'x' Execute commands until typeahead is empty. This is
3018 similar to using ":normal!". You can call feedkeys()
3019 several times without 'x' and then one time with 'x'
3020 (possibly with an empty {string}) to execute all the
3021 typeahead. Note that when Vim ends in Insert mode it
3022 will behave as if <Esc> is typed, to avoid getting
3023 stuck, waiting for a character to be typed before the
3024 script continues.
3025 Note that if you manage to call feedkeys() while
3026 executing commands, thus calling it recursively, then
3027 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00003028 'c' Remove any script context when executing, so that
3029 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01003030 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01003031 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003032 '!' When used with 'x' will not end Insert mode. Can be
3033 used in a test when a timer is set to exit Insert mode
3034 a little later. Useful for testing CursorHoldI.
3035
3036 Return value is always 0.
3037
3038 Can also be used as a |method|: >
3039 GetInput()->feedkeys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003040<
3041 Return type: |String| or list<string> depending on {list}
3042
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003043
Shougo Matsushita60c87432024-06-03 22:59:27 +02003044filecopy({from}, {to}) *filecopy()*
3045 Copy the file pointed to by the name {from} to {to}. The
3046 result is a Number, which is |TRUE| if the file was copied
3047 successfully, and |FALSE| when it failed.
3048 If a file with name {to} already exists, it will fail.
3049 Note that it does not handle directories (yet).
3050
3051 This function is not available in the |sandbox|.
3052
3053 Can also be used as a |method|: >
3054 GetOldName()->filecopy(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003055<
3056 Return type: |Number|
3057
Shougo Matsushita60c87432024-06-03 22:59:27 +02003058
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003059filereadable({file}) *filereadable()*
3060 The result is a Number, which is |TRUE| when a file with the
3061 name {file} exists, and can be read. If {file} doesn't exist,
3062 or is a directory, the result is |FALSE|. {file} is any
3063 expression, which is used as a String.
3064 If you don't care about the file being readable you can use
3065 |glob()|.
3066 {file} is used as-is, you may want to expand wildcards first: >
3067 echo filereadable('~/.vimrc')
3068 0
3069 echo filereadable(expand('~/.vimrc'))
3070 1
3071
3072< Can also be used as a |method|: >
3073 GetName()->filereadable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003074<
3075 Return type: |Number|
3076
3077 *file_readable()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003078 Obsolete name: file_readable().
3079
3080
3081filewritable({file}) *filewritable()*
3082 The result is a Number, which is 1 when a file with the
3083 name {file} exists, and can be written. If {file} doesn't
3084 exist, or is not writable, the result is 0. If {file} is a
3085 directory, and we can write to it, the result is 2.
3086
3087 Can also be used as a |method|: >
3088 GetName()->filewritable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003089<
3090 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003091
3092
3093filter({expr1}, {expr2}) *filter()*
3094 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3095 For each item in {expr1} evaluate {expr2} and when the result
3096 is zero or false remove the item from the |List| or
3097 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003098 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003099
3100 {expr2} must be a |string| or |Funcref|.
3101
3102 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3103 of the current item. For a |Dictionary| |v:key| has the key
3104 of the current item and for a |List| |v:key| has the index of
3105 the current item. For a |Blob| |v:key| has the index of the
3106 current byte. For a |String| |v:key| has the index of the
3107 current character.
3108 Examples: >
3109 call filter(mylist, 'v:val !~ "OLD"')
3110< Removes the items where "OLD" appears. >
3111 call filter(mydict, 'v:key >= 8')
3112< Removes the items with a key below 8. >
3113 call filter(var, 0)
3114< Removes all the items, thus clears the |List| or |Dictionary|.
3115
3116 Note that {expr2} is the result of expression and is then
3117 used as an expression again. Often it is good to use a
3118 |literal-string| to avoid having to double backslashes.
3119
3120 If {expr2} is a |Funcref| it must take two arguments:
3121 1. the key or the index of the current item.
3122 2. the value of the current item.
3123 The function must return |TRUE| if the item should be kept.
3124 Example that keeps the odd items of a list: >
3125 func Odd(idx, val)
3126 return a:idx % 2 == 1
3127 endfunc
3128 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003129< It is shorter when using a |lambda|. In |Vim9| syntax: >
3130 call filter(myList, (idx, val) => idx * val <= 42)
3131< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003132 call filter(myList, {idx, val -> idx * val <= 42})
3133< If you do not use "val" you can leave it out: >
3134 call filter(myList, {idx -> idx % 2 == 1})
3135<
3136 In |Vim9| script the result must be true, false, zero or one.
3137 Other values will result in a type error.
3138
3139 For a |List| and a |Dictionary| the operation is done
3140 in-place. If you want it to remain unmodified make a copy
3141 first: >
3142 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
3143
3144< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00003145 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003146 When an error is encountered while evaluating {expr2} no
3147 further items in {expr1} are processed.
3148 When {expr2} is a Funcref errors inside a function are ignored,
3149 unless it was defined with the "abort" flag.
3150
3151 Can also be used as a |method|: >
3152 mylist->filter(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003153<
3154 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
3155 depending on {expr1}
3156
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003157
3158finddir({name} [, {path} [, {count}]]) *finddir()*
3159 Find directory {name} in {path}. Supports both downwards and
3160 upwards recursive directory searches. See |file-searching|
3161 for the syntax of {path}.
3162
3163 Returns the path of the first found match. When the found
3164 directory is below the current directory a relative path is
3165 returned. Otherwise a full path is returned.
3166 If {path} is omitted or empty then 'path' is used.
3167
3168 If the optional {count} is given, find {count}'s occurrence of
3169 {name} in {path} instead of the first one.
3170 When {count} is negative return all the matches in a |List|.
3171
Bram Moolenaar016188f2022-06-06 20:52:59 +01003172 Returns an empty string if the directory is not found.
3173
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003174 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003175
3176 Can also be used as a |method|: >
3177 GetName()->finddir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003178<
3179 Return type: |String|
3180
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003181
3182findfile({name} [, {path} [, {count}]]) *findfile()*
3183 Just like |finddir()|, but find a file instead of a directory.
3184 Uses 'suffixesadd'.
3185 Example: >
3186 :echo findfile("tags.vim", ".;")
3187< Searches from the directory of the current file upwards until
3188 it finds the file "tags.vim".
3189
3190 Can also be used as a |method|: >
3191 GetName()->findfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003192<
3193 Return type: |String|
3194
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003195
3196flatten({list} [, {maxdepth}]) *flatten()*
3197 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
3198 the result is a |List| without nesting, as if {maxdepth} is
3199 a very large number.
3200 The {list} is changed in place, use |flattennew()| if you do
3201 not want that.
3202 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00003203 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003204 *E900*
3205 {maxdepth} means how deep in nested lists changes are made.
3206 {list} is not modified when {maxdepth} is 0.
3207 {maxdepth} must be positive number.
3208
3209 If there is an error the number zero is returned.
3210
3211 Example: >
3212 :echo flatten([1, [2, [3, 4]], 5])
3213< [1, 2, 3, 4, 5] >
3214 :echo flatten([1, [2, [3, 4]], 5], 1)
3215< [1, 2, [3, 4], 5]
3216
3217 Can also be used as a |method|: >
3218 mylist->flatten()
3219<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003220 Return type: list<{type}>
3221
3222
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003223flattennew({list} [, {maxdepth}]) *flattennew()*
3224 Like |flatten()| but first make a copy of {list}.
3225
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003226 Return type: list<{type}>
3227
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003228
3229float2nr({expr}) *float2nr()*
3230 Convert {expr} to a Number by omitting the part after the
3231 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00003232 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003233 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003234 When the value of {expr} is out of range for a |Number| the
3235 result is truncated to 0x7fffffff or -0x7fffffff (or when
3236 64-bit Number support is enabled, 0x7fffffffffffffff or
3237 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
3238 64-bit Number support is enabled, -0x8000000000000000).
3239 Examples: >
3240 echo float2nr(3.95)
3241< 3 >
3242 echo float2nr(-23.45)
3243< -23 >
3244 echo float2nr(1.0e100)
3245< 2147483647 (or 9223372036854775807) >
3246 echo float2nr(-1.0e150)
3247< -2147483647 (or -9223372036854775807) >
3248 echo float2nr(1.0e-100)
3249< 0
3250
3251 Can also be used as a |method|: >
3252 Compute()->float2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003253<
3254 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003255
3256
3257floor({expr}) *floor()*
3258 Return the largest integral value less than or equal to
3259 {expr} as a |Float| (round down).
3260 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003261 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003262 Examples: >
3263 echo floor(1.856)
3264< 1.0 >
3265 echo floor(-5.456)
3266< -6.0 >
3267 echo floor(4.0)
3268< 4.0
3269
3270 Can also be used as a |method|: >
3271 Compute()->floor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003272<
3273 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003274
3275
3276fmod({expr1}, {expr2}) *fmod()*
3277 Return the remainder of {expr1} / {expr2}, even if the
3278 division is not representable. Returns {expr1} - i * {expr2}
3279 for some integer i such that if {expr2} is non-zero, the
3280 result has the same sign as {expr1} and magnitude less than
3281 the magnitude of {expr2}. If {expr2} is zero, the value
3282 returned is zero. The value returned is a |Float|.
3283 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003284 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
3285 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003286 Examples: >
3287 :echo fmod(12.33, 1.22)
3288< 0.13 >
3289 :echo fmod(-12.33, 1.22)
3290< -0.13
3291
3292 Can also be used as a |method|: >
3293 Compute()->fmod(1.22)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003294<
3295 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003296
3297
3298fnameescape({string}) *fnameescape()*
3299 Escape {string} for use as file name command argument. All
3300 characters that have a special meaning, such as '%' and '|'
3301 are escaped with a backslash.
3302 For most systems the characters escaped are
3303 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3304 appears in a filename, it depends on the value of 'isfname'.
3305 A leading '+' and '>' is also escaped (special after |:edit|
3306 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01003307 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003308 Example: >
3309 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003310 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003311< results in executing: >
3312 edit \+some\ str\%nge\|name
3313<
3314 Can also be used as a |method|: >
3315 GetName()->fnameescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003316<
3317 Return type: |String|
3318
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003319
3320fnamemodify({fname}, {mods}) *fnamemodify()*
3321 Modify file name {fname} according to {mods}. {mods} is a
3322 string of characters like it is used for file names on the
3323 command line. See |filename-modifiers|.
3324 Example: >
3325 :echo fnamemodify("main.c", ":p:h")
3326< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01003327 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01003328< If {mods} is empty or an unsupported modifier is used then
3329 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01003330 When {fname} is empty then with {mods} ":h" returns ".", so
3331 that `:cd` can be used with it. This is different from
3332 expand('%:h') without a buffer name, which returns an empty
3333 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003334 Note: Environment variables don't work in {fname}, use
3335 |expand()| first then.
3336
3337 Can also be used as a |method|: >
3338 GetName()->fnamemodify(':p:h')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003339<
3340 Return type: |String|
3341
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003342
3343foldclosed({lnum}) *foldclosed()*
3344 The result is a Number. If the line {lnum} is in a closed
3345 fold, the result is the number of the first line in that fold.
3346 If the line {lnum} is not in a closed fold, -1 is returned.
3347 {lnum} is used like with |getline()|. Thus "." is the current
3348 line, "'m" mark m, etc.
3349
3350 Can also be used as a |method|: >
3351 GetLnum()->foldclosed()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003352<
3353 Return type: |Number|
3354
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003355
3356foldclosedend({lnum}) *foldclosedend()*
3357 The result is a Number. If the line {lnum} is in a closed
3358 fold, the result is the number of the last line in that fold.
3359 If the line {lnum} is not in a closed fold, -1 is returned.
3360 {lnum} is used like with |getline()|. Thus "." is the current
3361 line, "'m" mark m, etc.
3362
3363 Can also be used as a |method|: >
3364 GetLnum()->foldclosedend()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003365<
3366 Return type: |Number|
3367
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003368
3369foldlevel({lnum}) *foldlevel()*
3370 The result is a Number, which is the foldlevel of line {lnum}
3371 in the current buffer. For nested folds the deepest level is
3372 returned. If there is no fold at line {lnum}, zero is
3373 returned. It doesn't matter if the folds are open or closed.
3374 When used while updating folds (from 'foldexpr') -1 is
3375 returned for lines where folds are still to be updated and the
3376 foldlevel is unknown. As a special case the level of the
3377 previous line is usually available.
3378 {lnum} is used like with |getline()|. Thus "." is the current
3379 line, "'m" mark m, etc.
3380
3381 Can also be used as a |method|: >
3382 GetLnum()->foldlevel()
3383<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003384 Return type: |Number|
3385
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003386 *foldtext()*
3387foldtext() Returns a String, to be displayed for a closed fold. This is
3388 the default function used for the 'foldtext' option and should
3389 only be called from evaluating 'foldtext'. It uses the
3390 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3391 The returned string looks like this: >
3392 +-- 45 lines: abcdef
3393< The number of leading dashes depends on the foldlevel. The
3394 "45" is the number of lines in the fold. "abcdef" is the text
3395 in the first non-blank line of the fold. Leading white space,
3396 "//" or "/*" and the text from the 'foldmarker' and
3397 'commentstring' options is removed.
3398 When used to draw the actual foldtext, the rest of the line
3399 will be filled with the fold char from the 'fillchars'
3400 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003401 Returns an empty string when there is no fold.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003402
3403 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003404 {not available when compiled without the |+folding| feature}
3405
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003406
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003407foldtextresult({lnum}) *foldtextresult()*
3408 Returns the text that is displayed for the closed fold at line
3409 {lnum}. Evaluates 'foldtext' in the appropriate context.
3410 When there is no closed fold at {lnum} an empty string is
3411 returned.
3412 {lnum} is used like with |getline()|. Thus "." is the current
3413 line, "'m" mark m, etc.
3414 Useful when exporting folded text, e.g., to HTML.
3415 {not available when compiled without the |+folding| feature}
3416
3417
3418 Can also be used as a |method|: >
3419 GetLnum()->foldtextresult()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003420<
3421 Return type: |String|
3422
Ernie Raele79e2072024-01-13 11:47:33 +01003423
3424foreach({expr1}, {expr2}) *foreach()*
3425 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3426 For each item in {expr1} execute {expr2}. {expr1} is not
erraelc92b8be2024-01-14 10:11:07 -08003427 modified; its values may be, as with |:lockvar| 1. |E741|
Ernie Raele79e2072024-01-13 11:47:33 +01003428 See |map()| and |filter()| to modify {expr1}.
3429
3430 {expr2} must be a |string| or |Funcref|.
3431
3432 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3433 of the current item. For a |Dictionary| |v:key| has the key
3434 of the current item and for a |List| |v:key| has the index of
3435 the current item. For a |Blob| |v:key| has the index of the
3436 current byte. For a |String| |v:key| has the index of the
3437 current character.
3438 Examples: >
3439 call foreach(mylist, 'used[v:val] = true')
3440< This records the items that are in the {expr1} list.
3441
3442 Note that {expr2} is the result of expression and is then used
3443 as a command. Often it is good to use a |literal-string| to
3444 avoid having to double backslashes.
3445
3446 If {expr2} is a |Funcref| it must take two arguments:
3447 1. the key or the index of the current item.
3448 2. the value of the current item.
3449 With a legacy script lambda you don't get an error if it only
3450 accepts one argument, but with a Vim9 lambda you get "E1106:
3451 One argument too many", the number of arguments must match.
3452 If the function returns a value, it is ignored.
3453
3454 Returns {expr1} in all cases.
3455 When an error is encountered while executing {expr2} no
3456 further items in {expr1} are processed.
3457 When {expr2} is a Funcref errors inside a function are ignored,
3458 unless it was defined with the "abort" flag.
3459
3460 Can also be used as a |method|: >
3461 mylist->foreach(expr2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003462<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003463 Return type: |String|, |Blob| list<{type}> or dict<{type}>
3464 depending on {expr1}
3465
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003466 *foreground()*
3467foreground() Move the Vim window to the foreground. Useful when sent from
3468 a client to a Vim server. |remote_send()|
3469 On Win32 systems this might not work, the OS does not always
3470 allow a window to bring itself to the foreground. Use
3471 |remote_foreground()| instead.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003472
3473 Return type: |Number|
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003474 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003475 Win32 console version}
3476
Bram Moolenaaraa534142022-09-15 21:46:02 +01003477fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003478 Get the full command name from a short abbreviated command
3479 name; see |20.2| for details on command abbreviations.
3480
3481 The string argument {name} may start with a `:` and can
3482 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003483 Returns an empty string if a command doesn't exist, if it's
3484 ambiguous (for user-defined commands) or cannot be shortened
3485 this way. |vim9-no-shorten|
3486
3487 Without the {vim9} argument uses the current script version.
3488 If {vim9} is present and FALSE then legacy script rules are
3489 used. When {vim9} is present and TRUE then Vim9 rules are
3490 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003491
3492 For example `fullcommand('s')`, `fullcommand('sub')`,
3493 `fullcommand(':%substitute')` all return "substitute".
3494
3495 Can also be used as a |method|: >
3496 GetName()->fullcommand()
3497<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003498 Return type: |String|
3499
3500
3501funcref({name} [, {arglist}] [, {dict}]) *funcref()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003502 Just like |function()|, but the returned Funcref will lookup
3503 the function by reference, not by name. This matters when the
3504 function {name} is redefined later.
3505
3506 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003507 It only works for an autoloaded function if it has already
3508 been loaded (to avoid mistakenly loading the autoload script
3509 when only intending to use the function name, use |function()|
3510 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003511 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003512
3513 Can also be used as a |method|: >
3514 GetFuncname()->funcref([arg])
3515<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003516 Return type: func(...): any or |Number| on error
3517
Dominique Pellee764d1b2023-03-12 21:20:59 +00003518 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003519function({name} [, {arglist}] [, {dict}])
3520 Return a |Funcref| variable that refers to function {name}.
3521 {name} can be the name of a user defined function or an
3522 internal function.
3523
3524 {name} can also be a Funcref or a partial. When it is a
3525 partial the dict stored in it will be used and the {dict}
3526 argument is not allowed. E.g.: >
3527 let FuncWithArg = function(dict.Func, [arg])
3528 let Broken = function(dict.Func, [arg], dict)
3529<
3530 When using the Funcref the function will be found by {name},
3531 also when it was redefined later. Use |funcref()| to keep the
3532 same function.
3533
3534 When {arglist} or {dict} is present this creates a partial.
3535 That means the argument list and/or the dictionary is stored in
3536 the Funcref and will be used when the Funcref is called.
3537
3538 The arguments are passed to the function in front of other
3539 arguments, but after any argument from |method|. Example: >
3540 func Callback(arg1, arg2, name)
3541 ...
3542 let Partial = function('Callback', ['one', 'two'])
3543 ...
3544 call Partial('name')
3545< Invokes the function as with: >
3546 call Callback('one', 'two', 'name')
3547
3548< With a |method|: >
3549 func Callback(one, two, three)
3550 ...
3551 let Partial = function('Callback', ['two'])
3552 ...
3553 eval 'one'->Partial('three')
3554< Invokes the function as with: >
3555 call Callback('one', 'two', 'three')
3556
3557< The function() call can be nested to add more arguments to the
3558 Funcref. The extra arguments are appended to the list of
3559 arguments. Example: >
3560 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003561 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003562 let Func = function('Callback', ['one'])
3563 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003564 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003565 call Func2('name')
3566< Invokes the function as with: >
3567 call Callback('one', 'two', 'name')
3568
3569< The Dictionary is only useful when calling a "dict" function.
3570 In that case the {dict} is passed in as "self". Example: >
3571 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003572 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003573 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003574 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003575 let context = {"name": "example"}
3576 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003577 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003578 call Func() " will echo: called for example
3579< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003580 arguments, these two are equivalent, if Callback() is defined
3581 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003582 let Func = function('Callback', context)
3583 let Func = context.Callback
3584
3585< The argument list and the Dictionary can be combined: >
3586 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003587 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003588 let context = {"name": "example"}
3589 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003590 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003591 call Func(500)
3592< Invokes the function as with: >
3593 call context.Callback('one', 500)
3594<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003595 Returns 0 on error.
3596
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003597 Can also be used as a |method|: >
3598 GetFuncname()->function([arg])
3599
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003600<
3601 Return type: func(...): any or |Number| on error
3602
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003603
3604garbagecollect([{atexit}]) *garbagecollect()*
3605 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3606 that have circular references.
3607
3608 There is hardly ever a need to invoke this function, as it is
3609 automatically done when Vim runs out of memory or is waiting
3610 for the user to press a key after 'updatetime'. Items without
3611 circular references are always freed when they become unused.
3612 This is useful if you have deleted a very big |List| and/or
3613 |Dictionary| with circular references in a script that runs
3614 for a long time.
3615
3616 When the optional {atexit} argument is one, garbage
3617 collection will also be done when exiting Vim, if it wasn't
3618 done before. This is useful when checking for memory leaks.
3619
3620 The garbage collection is not done immediately but only when
3621 it's safe to perform. This is when waiting for the user to
3622 type a character. To force garbage collection immediately use
3623 |test_garbagecollect_now()|.
3624
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003625 Return type: |String|
3626
3627
LemonBoy48b7d052024-07-09 18:24:59 +02003628get({list}, {idx} [, {default}]) *get()* *get()-list*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003629 Get item {idx} from |List| {list}. When this item is not
3630 available return {default}. Return zero when {default} is
3631 omitted.
3632 Preferably used as a |method|: >
3633 mylist->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003634<
3635 Return type: any, depending on {list}
3636
LemonBoy48b7d052024-07-09 18:24:59 +02003637get({blob}, {idx} [, {default}]) *get()-blob*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003638 Get byte {idx} from |Blob| {blob}. When this byte is not
3639 available return {default}. Return -1 when {default} is
3640 omitted.
3641 Preferably used as a |method|: >
3642 myblob->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003643<
3644 Return type: |Number|
3645
LemonBoy48b7d052024-07-09 18:24:59 +02003646get({dict}, {key} [, {default}]) *get()-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003647 Get item with key {key} from |Dictionary| {dict}. When this
3648 item is not available return {default}. Return zero when
3649 {default} is omitted. Useful example: >
3650 let val = get(g:, 'var_name', 'default')
3651< This gets the value of g:var_name if it exists, and uses
3652 'default' when it does not exist.
3653 Preferably used as a |method|: >
3654 mydict->get(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003655<
h-east84ac2122024-06-17 18:12:30 +02003656 Return type: any, depending on {dict}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003657
LemonBoy48b7d052024-07-09 18:24:59 +02003658get({func}, {what}) *get()-func*
3659 Get item {what} from |Funcref| {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003660 {what} are:
LemonBoy48b7d052024-07-09 18:24:59 +02003661 "name" The function name
3662 "func" The function
3663 "dict" The dictionary
3664 "args" The list with arguments
3665 "arity" A dictionary with information about the number of
3666 arguments accepted by the function (minus the
3667 {arglist}) with the following fields:
3668 required the number of positional arguments
3669 optional the number of optional arguments,
3670 in addition to the required ones
3671 varargs |TRUE| if the function accepts a
3672 variable number of arguments |...|
3673
3674 Note: There is no error, if the {arglist} of
3675 the Funcref contains more arguments than the
3676 Funcref expects, it's not validated.
3677
Bram Moolenaar016188f2022-06-06 20:52:59 +01003678 Returns zero on error.
LemonBoy48b7d052024-07-09 18:24:59 +02003679
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003680 Preferably used as a |method|: >
3681 myfunc->get(what)
3682<
LemonBoy48b7d052024-07-09 18:24:59 +02003683 Return type: any, depending on {func} and {what}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003684
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003685 *getbufinfo()*
3686getbufinfo([{buf}])
3687getbufinfo([{dict}])
3688 Get information about buffers as a List of Dictionaries.
3689
3690 Without an argument information about all the buffers is
3691 returned.
3692
3693 When the argument is a |Dictionary| only the buffers matching
3694 the specified criteria are returned. The following keys can
3695 be specified in {dict}:
3696 buflisted include only listed buffers.
3697 bufloaded include only loaded buffers.
3698 bufmodified include only modified buffers.
3699
3700 Otherwise, {buf} specifies a particular buffer to return
3701 information for. For the use of {buf}, see |bufname()|
3702 above. If the buffer is found the returned List has one item.
3703 Otherwise the result is an empty list.
3704
3705 Each returned List item is a dictionary with the following
3706 entries:
3707 bufnr Buffer number.
3708 changed TRUE if the buffer is modified.
3709 changedtick Number of changes made to the buffer.
Sean Dewar1fb41032023-08-16 17:15:05 +01003710 command TRUE if the buffer belongs to the
3711 command-line window |cmdwin|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003712 hidden TRUE if the buffer is hidden.
3713 lastused Timestamp in seconds, like
3714 |localtime()|, when the buffer was
3715 last used.
3716 {only with the |+viminfo| feature}
3717 listed TRUE if the buffer is listed.
3718 lnum Line number used for the buffer when
3719 opened in the current window.
3720 Only valid if the buffer has been
3721 displayed in the window in the past.
3722 If you want the line number of the
3723 last known cursor position in a given
3724 window, use |line()|: >
3725 :echo line('.', {winid})
3726<
3727 linecount Number of lines in the buffer (only
3728 valid when loaded)
3729 loaded TRUE if the buffer is loaded.
3730 name Full path to the file in the buffer.
3731 signs List of signs placed in the buffer.
3732 Each list item is a dictionary with
3733 the following fields:
3734 id sign identifier
3735 lnum line number
3736 name sign name
3737 variables A reference to the dictionary with
3738 buffer-local variables.
3739 windows List of |window-ID|s that display this
3740 buffer
3741 popups List of popup |window-ID|s that
3742 display this buffer
3743
3744 Examples: >
3745 for buf in getbufinfo()
3746 echo buf.name
3747 endfor
3748 for buf in getbufinfo({'buflisted':1})
3749 if buf.changed
3750 ....
3751 endif
3752 endfor
3753<
3754 To get buffer-local options use: >
3755 getbufvar({bufnr}, '&option_name')
3756<
3757 Can also be used as a |method|: >
3758 GetBufnr()->getbufinfo()
3759<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003760 Return type: list<dict<any>>
3761
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003762
3763 *getbufline()*
3764getbufline({buf}, {lnum} [, {end}])
3765 Return a |List| with the lines starting from {lnum} to {end}
3766 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003767 |List| with only the line {lnum} is returned. See
3768 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003769
3770 For the use of {buf}, see |bufname()| above.
3771
3772 For {lnum} and {end} "$" can be used for the last line of the
3773 buffer. Otherwise a number must be used.
3774
3775 When {lnum} is smaller than 1 or bigger than the number of
3776 lines in the buffer, an empty |List| is returned.
3777
3778 When {end} is greater than the number of lines in the buffer,
3779 it is treated as {end} is set to the number of lines in the
3780 buffer. When {end} is before {lnum} an empty |List| is
3781 returned.
3782
3783 This function works only for loaded buffers. For unloaded and
3784 non-existing buffers, an empty |List| is returned.
3785
3786 Example: >
3787 :let lines = getbufline(bufnr("myfile"), 1, "$")
3788
3789< Can also be used as a |method|: >
3790 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003791<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003792 Return type: list<string>
3793
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003794 *getbufoneline()*
3795getbufoneline({buf}, {lnum})
3796 Just like `getbufline()` but only get one line and return it
3797 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003798
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003799 Return type: |String|
3800
3801
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003802getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3803 The result is the value of option or local buffer variable
3804 {varname} in buffer {buf}. Note that the name without "b:"
3805 must be used.
3806 The {varname} argument is a string.
3807 When {varname} is empty returns a |Dictionary| with all the
3808 buffer-local variables.
3809 When {varname} is equal to "&" returns a |Dictionary| with all
3810 the buffer-local options.
3811 Otherwise, when {varname} starts with "&" returns the value of
3812 a buffer-local option.
3813 This also works for a global or buffer-local option, but it
3814 doesn't work for a global variable, window-local variable or
3815 window-local option.
3816 For the use of {buf}, see |bufname()| above.
3817 When the buffer or variable doesn't exist {def} or an empty
3818 string is returned, there is no error message.
3819 Examples: >
3820 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003821 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003822
3823< Can also be used as a |method|: >
3824 GetBufnr()->getbufvar(varname)
3825<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003826 Return type: any, depending on {varname}
3827
3828
mikoto20001083cae2024-11-11 21:24:14 +01003829getcellpixels() *getcellpixels()*
3830 Returns a |List| of terminal cell pixel size.
h-eastb534e802024-12-03 20:37:52 +01003831 List format is [xpixel, ypixel].
mikoto2000a73dfc22024-11-18 21:12:21 +01003832
3833 Only works on Unix (terminal and gVim) and Windows (gVim only).
3834 Returns [] on other systems or on failure.
3835 Note that there could be variations across different terminals.
3836 On macOS, system Terminal.app returns sizes in points (before
3837 Retina scaling), whereas third-party terminals return raw pixel
3838 sizes (post Retina scaling).
mikoto20001083cae2024-11-11 21:24:14 +01003839
mikoto2000de094dc2024-11-14 22:13:48 +01003840 Return type: list<any>
mikoto20001083cae2024-11-11 21:24:14 +01003841
3842
Kota Kato66bb9ae2023-01-17 18:31:56 +00003843getcellwidths() *getcellwidths()*
3844 Returns a |List| of cell widths of character ranges overridden
3845 by |setcellwidths()|. The format is equal to the argument of
3846 |setcellwidths()|. If no character ranges have their cell
3847 widths overridden, an empty List is returned.
h-east84ac2122024-06-17 18:12:30 +02003848
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003849 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003850
3851
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003852getchangelist([{buf}]) *getchangelist()*
3853 Returns the |changelist| for the buffer {buf}. For the use
3854 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3855 exist, an empty list is returned.
3856
3857 The returned list contains two entries: a list with the change
3858 locations and the current position in the list. Each
3859 entry in the change list is a dictionary with the following
3860 entries:
3861 col column number
3862 coladd column offset for 'virtualedit'
3863 lnum line number
3864 If buffer {buf} is the current buffer, then the current
3865 position refers to the position in the list. For other
3866 buffers, it is set to the length of the list.
3867
3868 Can also be used as a |method|: >
3869 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003870<
3871 Return type: list<any>
3872
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003873
Doug Kearns9cd9e752024-04-07 17:42:17 +02003874getchar([{expr}]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003875 Get a single character from the user or input stream.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003876 If {expr} is omitted, wait until a character is available.
3877 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003878 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003879 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003880 not consumed. Return zero if no character available.
3881 If you prefer always getting a string use |getcharstr()|.
3882
Doug Kearns9cd9e752024-04-07 17:42:17 +02003883 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003884 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003885 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003886 Otherwise a String is returned with the encoded character.
3887 For a special key it's a String with a sequence of bytes
3888 starting with 0x80 (decimal: 128). This is the same value as
3889 the String "\<Key>", e.g., "\<Left>". The returned value is
3890 also a String when a modifier (shift, control, alt) was used
3891 that is not included in the character.
3892
Doug Kearns9cd9e752024-04-07 17:42:17 +02003893 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003894 while Vim waits to see if this is the start of an escape
3895 sequence.
3896
Doug Kearns9cd9e752024-04-07 17:42:17 +02003897 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003898 one-byte character it is the character itself as a number.
3899 Use nr2char() to convert it to a String.
3900
3901 Use getcharmod() to obtain any additional modifiers.
3902
3903 When the user clicks a mouse button, the mouse event will be
3904 returned. The position can then be found in |v:mouse_col|,
3905 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3906 |getmousepos()| can also be used. Mouse move events will be
3907 ignored.
3908 This example positions the mouse as it would normally happen: >
3909 let c = getchar()
3910 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003911 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003912 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003913 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003914 endif
3915<
3916 When using bracketed paste only the first character is
3917 returned, the rest of the pasted text is dropped.
3918 |xterm-bracketed-paste|.
3919
3920 There is no prompt, you will somehow have to make clear to the
3921 user that a character has to be typed. The screen is not
3922 redrawn, e.g. when resizing the window. When using a popup
3923 window it should work better with a |popup-filter|.
3924
3925 There is no mapping for the character.
3926 Key codes are replaced, thus when the user presses the <Del>
3927 key you get the code for the <Del> key, not the raw character
3928 sequence. Examples: >
3929 getchar() == "\<Del>"
3930 getchar() == "\<S-Left>"
3931< This example redefines "f" to ignore case: >
3932 :nmap f :call FindChar()<CR>
3933 :function FindChar()
3934 : let c = nr2char(getchar())
3935 : while col('.') < col('$') - 1
3936 : normal l
3937 : if getline('.')[col('.') - 1] ==? c
3938 : break
3939 : endif
3940 : endwhile
3941 :endfunction
3942<
3943 You may also receive synthetic characters, such as
3944 |<CursorHold>|. Often you will want to ignore this and get
3945 another character: >
3946 :function GetKey()
3947 : let c = getchar()
3948 : while c == "\<CursorHold>"
3949 : let c = getchar()
3950 : endwhile
3951 : return c
3952 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003953<
3954 Return type: |Number| or |String|
3955
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003956
3957getcharmod() *getcharmod()*
3958 The result is a Number which is the state of the modifiers for
3959 the last obtained character with getchar() or in another way.
3960 These values are added together:
3961 2 shift
3962 4 control
3963 8 alt (meta)
3964 16 meta (when it's different from ALT)
3965 32 mouse double click
3966 64 mouse triple click
3967 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01003968 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003969 Only the modifiers that have not been included in the
3970 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01003971 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003972
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003973 Return type: |Number|
3974
3975
3976getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003977 Get the position for String {expr}. Same as |getpos()| but the
3978 column number in the returned List is a character index
3979 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00003980 If |getpos()| returns a very large column number, equal to
3981 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003982 of the last character.
3983
3984 Example:
3985 With the cursor on '세' in line 5 with text "여보세요": >
3986 getcharpos('.') returns [0, 5, 3, 0]
3987 getpos('.') returns [0, 5, 7, 0]
3988<
3989 Can also be used as a |method|: >
3990 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003991<
3992 Return type: list<number>
3993
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003994
3995getcharsearch() *getcharsearch()*
3996 Return the current character search information as a {dict}
3997 with the following entries:
3998
3999 char character previously used for a character
4000 search (|t|, |f|, |T|, or |F|); empty string
4001 if no character search has been performed
4002 forward direction of character search; 1 for forward,
4003 0 for backward
4004 until type of character search; 1 for a |t| or |T|
4005 character search, 0 for an |f| or |F|
4006 character search
4007
4008 This can be useful to always have |;| and |,| search
4009 forward/backward regardless of the direction of the previous
4010 character search: >
4011 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
4012 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
4013< Also see |setcharsearch()|.
4014
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004015 Return type: dict<any>
4016
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004017
Doug Kearns9cd9e752024-04-07 17:42:17 +02004018getcharstr([{expr}]) *getcharstr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004019 Get a single character from the user or input stream as a
4020 string.
Doug Kearns9cd9e752024-04-07 17:42:17 +02004021 If {expr} is omitted, wait until a character is available.
4022 If {expr} is 0 or false, only get a character when one is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004023 available. Return an empty string otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02004024 If {expr} is 1 or true, only check if a character is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004025 available, it is not consumed. Return an empty string
4026 if no character is available.
4027 Otherwise this works like |getchar()|, except that a number
4028 result is converted to a string.
4029
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004030 Return type: |String|
4031
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004032getcmdcomplpat() *getcmdcomplpat()*
4033 Return completion pattern of the current command-line.
4034 Only works when the command line is being edited, thus
4035 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4036 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4037 |getcmdprompt()|, |getcmdcompltype()| and |setcmdline()|.
4038 Returns an empty string when completion is not defined.
4039
4040 Return type: |String|
4041
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004042
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004043getcmdcompltype() *getcmdcompltype()*
4044 Return the type of the current command-line completion.
4045 Only works when the command line is being edited, thus
4046 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01004047 See |:command-completion| for the return string.
Shougo Matsushita69084282024-09-23 20:34:47 +02004048 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004049 |getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004050 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004051
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004052 Return type: |String|
4053
4054
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004055getcmdline() *getcmdline()*
Shougo Matsushita69084282024-09-23 20:34:47 +02004056 Return the current command-line input. Only works when the
4057 command line is being edited, thus requires use of
4058 |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004059 Example: >
4060 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita69084282024-09-23 20:34:47 +02004061< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()|,
4062 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004063 Returns an empty string when entering a password or using
4064 |inputsecret()|.
4065
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004066 Return type: |String|
4067
4068
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004069getcmdpos() *getcmdpos()*
4070 Return the position of the cursor in the command line as a
4071 byte count. The first column is 1.
4072 Only works when editing the command line, thus requires use of
4073 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4074 Returns 0 otherwise.
Shougo Matsushita69084282024-09-23 20:34:47 +02004075 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4076 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004077
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004078 Return type: |Number|
4079
4080
Shougo Matsushita69084282024-09-23 20:34:47 +02004081getcmdprompt() *getcmdprompt()*
4082 Return the current command-line prompt when using functions
4083 like |input()| or |confirm()|.
4084 Only works when the command line is being edited, thus
4085 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4086 Also see |getcmdtype()|, |getcmdline()|, |getcmdpos()|,
4087 |setcmdpos()| and |setcmdline()|.
4088
4089 Return type: |String|
4090
4091
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004092getcmdscreenpos() *getcmdscreenpos()*
4093 Return the screen position of the cursor in the command line
4094 as a byte count. The first column is 1.
4095 Instead of |getcmdpos()|, it adds the prompt position.
4096 Only works when editing the command line, thus requires use of
4097 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4098 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004099 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
4100 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004101
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004102 Return type: |Number|
4103
4104
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004105getcmdtype() *getcmdtype()*
4106 Return the current command-line type. Possible return values
4107 are:
4108 : normal Ex command
4109 > debug mode command |debug-mode|
4110 / forward search command
4111 ? backward search command
4112 @ |input()| command
4113 - |:insert| or |:append| command
4114 = |i_CTRL-R_=|
4115 Only works when editing the command line, thus requires use of
4116 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4117 Returns an empty string otherwise.
4118 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4119
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004120 Return type: |String|
4121
4122
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004123getcmdwintype() *getcmdwintype()*
4124 Return the current |command-line-window| type. Possible return
4125 values are the same as |getcmdtype()|. Returns an empty string
4126 when not in the command-line window.
4127
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004128 Return type: |String|
4129
4130
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004131getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4132 Return a list of command-line completion matches. The String
4133 {type} argument specifies what for. The following completion
4134 types are supported:
4135
4136 arglist file names in argument list
4137 augroup autocmd groups
4138 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004139 behave |:behave| suboptions
4140 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004141 color color schemes
4142 command Ex command
4143 cmdline |cmdline-completion| result
4144 compiler compilers
4145 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004146 custom,{func} custom completion, defined via {func}
4147 customlist,{func} custom completion, defined via {func}
zeertzjq85f36d62024-10-10 19:14:13 +02004148 diff_buffer |:diffget| and |:diffput| completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004149 dir directory names
LemonBoya20bf692024-07-11 22:35:53 +02004150 dir_in_path directory names in |'cdpath'|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004151 environment environment variable names
4152 event autocommand events
4153 expression Vim expression
4154 file file and directory names
4155 file_in_path file and directory names in |'path'|
4156 filetype filetype names |'filetype'|
4157 function function name
4158 help help subjects
4159 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004160 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004161 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004162 locale locale names (as output of locale -a)
4163 mapclear buffer argument
4164 mapping mapping name
4165 menu menus
4166 messages |:messages| suboptions
4167 option options
4168 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004169 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004170 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004171 shellcmd Shell command
zeertzjq85f36d62024-10-10 19:14:13 +02004172 shellcmdline Shell command line with filename arguments
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004173 sign |:sign| suboptions
4174 syntax syntax file names |'syntax'|
4175 syntime |:syntime| suboptions
4176 tag tags
4177 tag_listfiles tags, file names
4178 user user names
4179 var user variables
4180
4181 If {pat} is an empty string, then all the matches are
4182 returned. Otherwise only items matching {pat} are returned.
4183 See |wildcards| for the use of special characters in {pat}.
4184
4185 If the optional {filtered} flag is set to 1, then 'wildignore'
4186 is applied to filter the results. Otherwise all the matches
4187 are returned. The 'wildignorecase' option always applies.
4188
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004189 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4190 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004191 regular expression matching is used. Thus this function
4192 follows the user preference, what happens on the command line.
4193 If you do not want this you can make 'wildoptions' empty
4194 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004195
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004196 If {type} is "cmdline", then the |cmdline-completion| result is
4197 returned. For example, to complete the possible values after
4198 a ":call" command: >
4199 echo getcompletion('call ', 'cmdline')
4200<
4201 If there are no matches, an empty list is returned. An
4202 invalid value for {type} produces an error.
4203
4204 Can also be used as a |method|: >
4205 GetPattern()->getcompletion('color')
4206<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004207 Return type: list<string>
4208
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004209 *getcurpos()*
4210getcurpos([{winid}])
4211 Get the position of the cursor. This is like getpos('.'), but
4212 includes an extra "curswant" item in the list:
4213 [0, lnum, col, off, curswant] ~
4214 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004215 cursor vertically. After |$| command it will be a very large
4216 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004217 |getpos()|.
4218 The first "bufnum" item is always zero. The byte position of
4219 the cursor is returned in 'col'. To get the character
4220 position, use |getcursorcharpos()|.
4221
4222 The optional {winid} argument can specify the window. It can
4223 be the window number or the |window-ID|. The last known
4224 cursor position is returned, this may be invalid for the
4225 current value of the buffer if it is not the current window.
4226 If {winid} is invalid a list with zeroes is returned.
4227
4228 This can be used to save and restore the cursor position: >
4229 let save_cursor = getcurpos()
4230 MoveTheCursorAround
4231 call setpos('.', save_cursor)
4232< Note that this only works within the window. See
4233 |winrestview()| for restoring more state.
4234
4235 Can also be used as a |method|: >
4236 GetWinid()->getcurpos()
4237<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004238 Return type: list<number>
4239
4240
4241getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004242 Same as |getcurpos()| but the column number in the returned
4243 List is a character index instead of a byte index.
4244
4245 Example:
4246 With the cursor on '보' in line 3 with text "여보세요": >
4247 getcursorcharpos() returns [0, 3, 2, 0, 3]
4248 getcurpos() returns [0, 3, 4, 0, 3]
4249<
4250 Can also be used as a |method|: >
4251 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004252<
4253 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004254
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004255
4256getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004257 The result is a String, which is the name of the current
4258 working directory. 'autochdir' is ignored.
4259
4260 With {winnr} return the local current directory of this window
4261 in the current tab page. {winnr} can be the window number or
4262 the |window-ID|.
4263 If {winnr} is -1 return the name of the global working
4264 directory. See also |haslocaldir()|.
4265
4266 With {winnr} and {tabnr} return the local current directory of
4267 the window in the specified tab page. If {winnr} is -1 return
4268 the working directory of the tabpage.
4269 If {winnr} is zero use the current window, if {tabnr} is zero
4270 use the current tabpage.
4271 Without any arguments, return the actual working directory of
4272 the current window.
4273 Return an empty string if the arguments are invalid.
4274
4275 Examples: >
4276 " Get the working directory of the current window
4277 :echo getcwd()
4278 :echo getcwd(0)
4279 :echo getcwd(0, 0)
4280 " Get the working directory of window 3 in tabpage 2
4281 :echo getcwd(3, 2)
4282 " Get the global working directory
4283 :echo getcwd(-1)
4284 " Get the working directory of tabpage 3
4285 :echo getcwd(-1, 3)
4286 " Get the working directory of current tabpage
4287 :echo getcwd(-1, 0)
4288
4289< Can also be used as a |method|: >
4290 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004291<
4292 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004293
4294getenv({name}) *getenv()*
4295 Return the value of environment variable {name}. The {name}
4296 argument is a string, without a leading '$'. Example: >
4297 myHome = getenv('HOME')
4298
4299< When the variable does not exist |v:null| is returned. That
4300 is different from a variable set to an empty string, although
4301 some systems interpret the empty value as the variable being
4302 deleted. See also |expr-env|.
4303
4304 Can also be used as a |method|: >
4305 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004306<
4307 Return type: |String| or |Number|
4308
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004309
4310getfontname([{name}]) *getfontname()*
4311 Without an argument returns the name of the normal font being
4312 used. Like what is used for the Normal highlight group
4313 |hl-Normal|.
4314 With an argument a check is done whether String {name} is a
4315 valid font name. If not then an empty string is returned.
4316 Otherwise the actual font name is returned, or {name} if the
4317 GUI does not support obtaining the real name.
4318 Only works when the GUI is running, thus not in your vimrc or
4319 gvimrc file. Use the |GUIEnter| autocommand to use this
4320 function just after the GUI has started.
4321 Note that the GTK GUI accepts any font name, thus checking for
4322 a valid name does not work.
4323
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004324 Return type: |String|
4325
4326
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004327getfperm({fname}) *getfperm()*
4328 The result is a String, which is the read, write, and execute
4329 permissions of the given file {fname}.
4330 If {fname} does not exist or its directory cannot be read, an
4331 empty string is returned.
4332 The result is of the form "rwxrwxrwx", where each group of
4333 "rwx" flags represent, in turn, the permissions of the owner
4334 of the file, the group the file belongs to, and other users.
4335 If a user does not have a given permission the flag for this
4336 is replaced with the string "-". Examples: >
4337 :echo getfperm("/etc/passwd")
4338 :echo getfperm(expand("~/.vimrc"))
4339< This will hopefully (from a security point of view) display
4340 the string "rw-r--r--" or even "rw-------".
4341
4342 Can also be used as a |method|: >
4343 GetFilename()->getfperm()
4344<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004345 Return type: |String|
4346
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004347 For setting permissions use |setfperm()|.
4348
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004349
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004350getfsize({fname}) *getfsize()*
4351 The result is a Number, which is the size in bytes of the
4352 given file {fname}.
4353 If {fname} is a directory, 0 is returned.
4354 If the file {fname} can't be found, -1 is returned.
4355 If the size of {fname} is too big to fit in a Number then -2
4356 is returned.
4357
4358 Can also be used as a |method|: >
4359 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004360<
4361 Return type: |Number|
4362
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004363
4364getftime({fname}) *getftime()*
4365 The result is a Number, which is the last modification time of
4366 the given file {fname}. The value is measured as seconds
4367 since 1st Jan 1970, and may be passed to strftime(). See also
4368 |localtime()| and |strftime()|.
4369 If the file {fname} can't be found -1 is returned.
4370
4371 Can also be used as a |method|: >
4372 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004373<
4374 Return type: |Number|
4375
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004376
4377getftype({fname}) *getftype()*
4378 The result is a String, which is a description of the kind of
4379 file of the given file {fname}.
4380 If {fname} does not exist an empty string is returned.
4381 Here is a table over different kinds of files and their
4382 results:
4383 Normal file "file"
4384 Directory "dir"
4385 Symbolic link "link"
4386 Block device "bdev"
4387 Character device "cdev"
4388 Socket "socket"
4389 FIFO "fifo"
4390 All other "other"
4391 Example: >
4392 getftype("/home")
4393< Note that a type such as "link" will only be returned on
4394 systems that support it. On some systems only "dir" and
4395 "file" are returned. On MS-Windows a symbolic link to a
4396 directory returns "dir" instead of "link".
4397
4398 Can also be used as a |method|: >
4399 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004400<
4401 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004402
4403getimstatus() *getimstatus()*
4404 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004405 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004406 See 'imstatusfunc'.
4407
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004408 Return type: |Number|
4409
4410
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004411getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4412 Returns the |jumplist| for the specified window.
4413
4414 Without arguments use the current window.
4415 With {winnr} only use this window in the current tab page.
4416 {winnr} can also be a |window-ID|.
4417 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004418 page. If {winnr} or {tabnr} is invalid, an empty list is
4419 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004420
4421 The returned list contains two entries: a list with the jump
4422 locations and the last used jump position number in the list.
4423 Each entry in the jump location list is a dictionary with
4424 the following entries:
4425 bufnr buffer number
4426 col column number
4427 coladd column offset for 'virtualedit'
4428 filename filename if available
4429 lnum line number
4430
4431 Can also be used as a |method|: >
4432 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004433<
4434 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004435
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004436 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004437getline({lnum} [, {end}])
4438 Without {end} the result is a String, which is line {lnum}
4439 from the current buffer. Example: >
4440 getline(1)
4441< When {lnum} is a String that doesn't start with a
4442 digit, |line()| is called to translate the String into a Number.
4443 To get the line under the cursor: >
4444 getline(".")
4445< When {lnum} is a number smaller than 1 or bigger than the
4446 number of lines in the buffer, an empty string is returned.
4447
4448 When {end} is given the result is a |List| where each item is
4449 a line from the current buffer in the range {lnum} to {end},
4450 including line {end}.
4451 {end} is used in the same way as {lnum}.
4452 Non-existing lines are silently omitted.
4453 When {end} is before {lnum} an empty |List| is returned.
4454 Example: >
4455 :let start = line('.')
4456 :let end = search("^$") - 1
4457 :let lines = getline(start, end)
4458
4459< Can also be used as a |method|: >
4460 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004461<
4462 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004463
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004464 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004465 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004466
4467getloclist({nr} [, {what}]) *getloclist()*
4468 Returns a |List| with all the entries in the location list for
4469 window {nr}. {nr} can be the window number or the |window-ID|.
4470 When {nr} is zero the current window is used.
4471
4472 For a location list window, the displayed location list is
4473 returned. For an invalid window number {nr}, an empty list is
4474 returned. Otherwise, same as |getqflist()|.
4475
4476 If the optional {what} dictionary argument is supplied, then
4477 returns the items listed in {what} as a dictionary. Refer to
4478 |getqflist()| for the supported items in {what}.
4479
4480 In addition to the items supported by |getqflist()| in {what},
4481 the following item is supported by |getloclist()|:
4482
4483 filewinid id of the window used to display files
4484 from the location list. This field is
4485 applicable only when called from a
4486 location list window. See
4487 |location-list-file-window| for more
4488 details.
4489
4490 Returns a |Dictionary| with default values if there is no
4491 location list for the window {nr}.
4492 Returns an empty Dictionary if window {nr} does not exist.
4493
4494 Examples (See also |getqflist-examples|): >
4495 :echo getloclist(3, {'all': 0})
4496 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004497<
4498 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004499
4500
4501getmarklist([{buf}]) *getmarklist()*
4502 Without the {buf} argument returns a |List| with information
4503 about all the global marks. |mark|
4504
4505 If the optional {buf} argument is specified, returns the
4506 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004507 see |bufname()|. If {buf} is invalid, an empty list is
4508 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004509
4510 Each item in the returned List is a |Dict| with the following:
4511 mark name of the mark prefixed by "'"
4512 pos a |List| with the position of the mark:
4513 [bufnum, lnum, col, off]
4514 Refer to |getpos()| for more information.
4515 file file name
4516
4517 Refer to |getpos()| for getting information about a specific
4518 mark.
4519
4520 Can also be used as a |method|: >
4521 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004522<
4523 Return type: list<dict<any>> or list<any>
4524
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004525
4526getmatches([{win}]) *getmatches()*
4527 Returns a |List| with all matches previously defined for the
4528 current window by |matchadd()| and the |:match| commands.
4529 |getmatches()| is useful in combination with |setmatches()|,
4530 as |setmatches()| can restore a list of matches saved by
4531 |getmatches()|.
4532 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004533 window ID instead of the current window. If {win} is invalid,
4534 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004535 Example: >
4536 :echo getmatches()
4537< [{'group': 'MyGroup1', 'pattern': 'TODO',
4538 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4539 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4540 :let m = getmatches()
4541 :call clearmatches()
4542 :echo getmatches()
4543< [] >
4544 :call setmatches(m)
4545 :echo getmatches()
4546< [{'group': 'MyGroup1', 'pattern': 'TODO',
4547 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4548 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4549 :unlet m
4550<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004551 Return type: list<dict<any>> or list<any>
4552
4553
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004554getmousepos() *getmousepos()*
4555 Returns a |Dictionary| with the last known position of the
4556 mouse. This can be used in a mapping for a mouse click or in
4557 a filter of a popup window. The items are:
4558 screenrow screen row
4559 screencol screen column
4560 winid Window ID of the click
4561 winrow row inside "winid"
4562 wincol column inside "winid"
4563 line text line inside "winid"
4564 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004565 coladd offset (in screen columns) from the
4566 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004567 All numbers are 1-based.
4568
4569 If not over a window, e.g. when in the command line, then only
4570 "screenrow" and "screencol" are valid, the others are zero.
4571
4572 When on the status line below a window or the vertical
4573 separator right of a window, the "line" and "column" values
4574 are zero.
4575
4576 When the position is after the text then "column" is the
4577 length of the text in bytes plus one.
4578
4579 If the mouse is over a popup window then that window is used.
4580
4581 When using |getchar()| the Vim variables |v:mouse_lnum|,
4582 |v:mouse_col| and |v:mouse_winid| also provide these values.
4583
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004584 Return type: dict<number>
4585
4586
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004587getmouseshape() *getmouseshape()*
4588 Returns the name of the currently showing mouse pointer.
4589 When the |+mouseshape| feature is not supported or the shape
4590 is unknown an empty string is returned.
4591 This function is mainly intended for testing.
4592
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004593 Return type: |String|
4594
4595
4596getpid() *getpid()*
4597 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004598 On Unix and MS-Windows this is a unique number, until Vim
4599 exits.
4600
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004601 Return type: |Number|
4602
4603
4604getpos({expr}) *getpos()*
zeertzjq02f3eba2024-06-12 20:45:24 +02004605 Get the position for String {expr}.
4606 The accepted values for {expr} are: *E1209*
4607 . The cursor position.
4608 $ The last line in the current buffer.
4609 'x Position of mark x (if the mark is not set, 0 is
zeertzjqd353d272024-06-13 23:00:25 +08004610 returned for all values).
zeertzjq02f3eba2024-06-12 20:45:24 +02004611 w0 First line visible in current window (one if the
4612 display isn't updated, e.g. in silent Ex mode).
4613 w$ Last line visible in current window (this is one
4614 less than "w0" if no lines are visible).
4615 v When not in Visual mode, returns the cursor
4616 position. In Visual mode, returns the other end
4617 of the Visual area. A good way to think about
4618 this is that in Visual mode "v" and "." complement
4619 each other. While "." refers to the cursor
4620 position, "v" refers to where |v_o| would move the
4621 cursor. As a result, you can use "v" and "."
4622 together to work on all of a selection in
4623 characterwise Visual mode. If the cursor is at
4624 the end of a characterwise Visual area, "v" refers
4625 to the start of the same Visual area. And if the
4626 cursor is at the start of a characterwise Visual
4627 area, "v" refers to the end of the same Visual
4628 area. "v" differs from |'<| and |'>| in that it's
4629 updated right away.
4630 Note that a mark in another file can be used. The line number
4631 then applies to another buffer.
4632
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004633 The result is a |List| with four numbers:
4634 [bufnum, lnum, col, off]
4635 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4636 is the buffer number of the mark.
4637 "lnum" and "col" are the position in the buffer. The first
4638 column is 1.
4639 The "off" number is zero, unless 'virtualedit' is used. Then
4640 it is the offset in screen columns from the start of the
4641 character. E.g., a position within a <Tab> or after the last
4642 character.
zeertzjq02f3eba2024-06-12 20:45:24 +02004643
4644 For getting the cursor position see |getcurpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004645 The column number in the returned List is the byte position
4646 within the line. To get the character position in the line,
4647 use |getcharpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02004648
4649 Note that for '< and '> Visual mode matters: when it is "V"
4650 (visual line mode) the column of '< is zero and the column of
4651 '> is a large number equal to |v:maxcol|.
naohiro ono56200ee2022-01-01 14:59:44 +00004652 A very large column number equal to |v:maxcol| can be returned,
4653 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004654 If {expr} is invalid, returns a list with all zeros.
zeertzjq02f3eba2024-06-12 20:45:24 +02004655
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004656 This can be used to save and restore the position of a mark: >
4657 let save_a_mark = getpos("'a")
4658 ...
4659 call setpos("'a", save_a_mark)
zeertzjqd353d272024-06-13 23:00:25 +08004660<
4661 Also see |getcharpos()|, |getcurpos()| and |setpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004662
4663 Can also be used as a |method|: >
4664 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004665<
4666 Return type: list<number>
4667
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004668
4669getqflist([{what}]) *getqflist()*
4670 Returns a |List| with all the current quickfix errors. Each
4671 list item is a dictionary with these entries:
4672 bufnr number of buffer that has the file name, use
4673 bufname() to get the name
4674 module module name
4675 lnum line number in the buffer (first line is 1)
4676 end_lnum
4677 end of line number if the item is multiline
4678 col column number (first column is 1)
4679 end_col end of column number if the item has range
4680 vcol |TRUE|: "col" is visual column
4681 |FALSE|: "col" is byte index
4682 nr error number
h-east84ac2122024-06-17 18:12:30 +02004683 pattern search pattern used to locate the error
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004684 text description of the error
4685 type type of the error, 'E', '1', etc.
4686 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004687 user_data
4688 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004689 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004690
4691 When there is no error list or it's empty, an empty list is
4692 returned. Quickfix list entries with a non-existing buffer
4693 number are returned with "bufnr" set to zero (Note: some
4694 functions accept buffer number zero for the alternate buffer,
4695 you may need to explicitly check for zero).
4696
4697 Useful application: Find pattern matches in multiple files and
4698 do something with them: >
4699 :vimgrep /theword/jg *.c
4700 :for d in getqflist()
4701 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4702 :endfor
4703<
4704 If the optional {what} dictionary argument is supplied, then
4705 returns only the items listed in {what} as a dictionary. The
4706 following string items are supported in {what}:
4707 changedtick get the total number of changes made
4708 to the list |quickfix-changedtick|
4709 context get the |quickfix-context|
4710 efm errorformat to use when parsing "lines". If
4711 not present, then the 'errorformat' option
4712 value is used.
4713 id get information for the quickfix list with
4714 |quickfix-ID|; zero means the id for the
4715 current list or the list specified by "nr"
4716 idx get information for the quickfix entry at this
4717 index in the list specified by 'id' or 'nr'.
4718 If set to zero, then uses the current entry.
4719 See |quickfix-index|
4720 items quickfix list entries
4721 lines parse a list of lines using 'efm' and return
4722 the resulting entries. Only a |List| type is
4723 accepted. The current quickfix list is not
4724 modified. See |quickfix-parse|.
4725 nr get information for this quickfix list; zero
4726 means the current quickfix list and "$" means
4727 the last quickfix list
4728 qfbufnr number of the buffer displayed in the quickfix
4729 window. Returns 0 if the quickfix buffer is
4730 not present. See |quickfix-buffer|.
4731 size number of entries in the quickfix list
4732 title get the list title |quickfix-title|
4733 winid get the quickfix |window-ID|
4734 all all of the above quickfix properties
4735 Non-string items in {what} are ignored. To get the value of a
4736 particular item, set it to zero.
4737 If "nr" is not present then the current quickfix list is used.
4738 If both "nr" and a non-zero "id" are specified, then the list
4739 specified by "id" is used.
4740 To get the number of lists in the quickfix stack, set "nr" to
4741 "$" in {what}. The "nr" value in the returned dictionary
4742 contains the quickfix stack size.
4743 When "lines" is specified, all the other items except "efm"
4744 are ignored. The returned dictionary contains the entry
4745 "items" with the list of entries.
4746
4747 The returned dictionary contains the following entries:
4748 changedtick total number of changes made to the
4749 list |quickfix-changedtick|
4750 context quickfix list context. See |quickfix-context|
4751 If not present, set to "".
4752 id quickfix list ID |quickfix-ID|. If not
4753 present, set to 0.
4754 idx index of the quickfix entry in the list. If not
4755 present, set to 0.
4756 items quickfix list entries. If not present, set to
4757 an empty list.
4758 nr quickfix list number. If not present, set to 0
4759 qfbufnr number of the buffer displayed in the quickfix
4760 window. If not present, set to 0.
4761 size number of entries in the quickfix list. If not
4762 present, set to 0.
4763 title quickfix list title text. If not present, set
4764 to "".
4765 winid quickfix |window-ID|. If not present, set to 0
4766
4767 Examples (See also |getqflist-examples|): >
4768 :echo getqflist({'all': 1})
4769 :echo getqflist({'nr': 2, 'title': 1})
4770 :echo getqflist({'lines' : ["F1:10:L10"]})
4771<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004772 Return type: list<dict<any>> or list<any>
4773
4774
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004775getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4776 The result is a String, which is the contents of register
4777 {regname}. Example: >
4778 :let cliptext = getreg('*')
4779< When register {regname} was not set the result is an empty
4780 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004781 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004782
4783 getreg('=') returns the last evaluated value of the expression
4784 register. (For use in maps.)
4785 getreg('=', 1) returns the expression itself, so that it can
4786 be restored with |setreg()|. For other registers the extra
4787 argument is ignored, thus you can always give it.
4788
4789 If {list} is present and |TRUE|, the result type is changed
4790 to |List|. Each list item is one text line. Use it if you care
4791 about zero bytes possibly present inside register: without
4792 third argument both NLs and zero bytes are represented as NLs
4793 (see |NL-used-for-Nul|).
4794 When the register was not set an empty list is returned.
4795
4796 If {regname} is "", the unnamed register '"' is used.
4797 If {regname} is not specified, |v:register| is used.
4798 In |Vim9-script| {regname} must be one character.
4799
4800 Can also be used as a |method|: >
4801 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004802<
4803 Return type: |String|
4804
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004805
4806getreginfo([{regname}]) *getreginfo()*
4807 Returns detailed information about register {regname} as a
4808 Dictionary with the following entries:
4809 regcontents List of lines contained in register
4810 {regname}, like
4811 |getreg|({regname}, 1, 1).
4812 regtype the type of register {regname}, as in
4813 |getregtype()|.
4814 isunnamed Boolean flag, v:true if this register
4815 is currently pointed to by the unnamed
4816 register.
4817 points_to for the unnamed register, gives the
4818 single letter name of the register
4819 currently pointed to (see |quotequote|).
4820 For example, after deleting a line
4821 with `dd`, this field will be "1",
4822 which is the register that got the
4823 deleted text.
4824
4825 The {regname} argument is a string. If {regname} is invalid
4826 or not set, an empty Dictionary will be returned.
4827 If {regname} is "" or "@", the unnamed register '"' is used.
4828 If {regname} is not specified, |v:register| is used.
4829 The returned Dictionary can be passed to |setreg()|.
4830 In |Vim9-script| {regname} must be one character.
4831
4832 Can also be used as a |method|: >
4833 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004834<
4835 Return type: dict<any>
4836
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004837
Shougo Matsushita19b71882024-02-28 22:48:12 +01004838getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004839 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01004840 buffer.
4841
4842 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004843 See |getpos()| for the format of the list. It's possible
4844 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01004845 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01004846
4847 The optional argument {opts} is a Dict and supports the
4848 following items:
4849
zeertzjqafc22952024-05-24 19:07:12 +02004850 type Specify the region's selection type.
4851 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02004852 except that the width can be omitted
4853 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02004854 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01004855
zeertzjq87410ab2024-03-02 06:00:23 +08004856 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02004857 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08004858 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01004859
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004860 You can get the last selection type by |visualmode()|.
4861 If Visual mode is active, use |mode()| to get the Visual mode
4862 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08004863 This function is useful to get text starting and ending in
4864 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004865
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004866 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004867 Note that:
4868 - Order of {pos1} and {pos2} doesn't matter, it will always
4869 return content from the upper left position to the lower
4870 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08004871 - If 'virtualedit' is enabled and the region is past the end
4872 of the lines, resulting lines are padded with spaces.
4873 - If the region is blockwise and it starts or ends in the
4874 middle of a multi-cell character, it is not included but
4875 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004876 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01004877 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004878 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01004879 - It is evaluated in current window context, which makes a
4880 difference if the buffer is displayed in a window with
4881 different 'virtualedit' or 'list' values.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004882
4883 Examples: >
4884 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01004885 \ <Cmd>echow getregion(
4886 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004887<
4888 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01004889 getpos('.')->getregion(getpos("'a"))
zeertzjqd4d12072024-07-16 20:34:16 +02004890<
4891 Return type: list<string>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004892
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01004893
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004894getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
4895 Same as |getregion()|, but returns a list of positions
4896 describing the buffer text segments bound by {pos1} and
4897 {pos2}.
4898 The segments are a pair of positions for every line: >
4899 [[{start_pos}, {end_pos}], ...]
4900<
4901 The position is a |List| with four numbers:
4902 [bufnum, lnum, col, off]
4903 "bufnum" is the buffer number.
4904 "lnum" and "col" are the position in the buffer. The first
4905 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02004906 If the "off" number of a starting position is non-zero, it is
4907 the offset in screen columns from the start of the character.
4908 E.g., a position within a <Tab> or after the last character.
4909 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02004910 the offset of the character's first cell not included in the
4911 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004912
zeertzjq2b09de92024-05-24 07:48:51 +02004913 Apart from the options supported by |getregion()|, {opts} also
4914 supports the following:
4915
4916 eol If |TRUE|, indicate positions beyond
4917 the end of a line with "col" values
4918 one more than the length of the line.
4919 If |FALSE|, positions are limited
4920 within their lines, and if a line is
4921 empty or the selection is entirely
4922 beyond the end of a line, a "col"
4923 value of 0 is used for both positions.
4924 (default: |FALSE|)
4925
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004926 Can also be used as a |method|: >
4927 getpos('.')->getregionpos(getpos("'a"))
4928<
zeertzjqd4d12072024-07-16 20:34:16 +02004929 Return type: list<list<list<number>>>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004930
4931
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004932getregtype([{regname}]) *getregtype()*
4933 The result is a String, which is type of register {regname}.
4934 The value will be one of:
4935 "v" for |characterwise| text
4936 "V" for |linewise| text
4937 "<CTRL-V>{width}" for |blockwise-visual| text
4938 "" for an empty or unknown register
4939 <CTRL-V> is one character with value 0x16.
4940 The {regname} argument is a string. If {regname} is "", the
4941 unnamed register '"' is used. If {regname} is not specified,
4942 |v:register| is used.
4943 In |Vim9-script| {regname} must be one character.
4944
4945 Can also be used as a |method|: >
4946 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004947<
4948 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004949
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01004950
Bram Moolenaar71badf92023-04-22 22:40:14 +01004951getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004952 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01004953 scripts in the order they were sourced, like what
4954 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004955
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004956 The optional Dict argument {opts} supports the following
4957 optional items:
4958 name Script name match pattern. If specified,
4959 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01004960 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004961 "name" are returned.
4962 sid Script ID |<SID>|. If specified, only
4963 information about the script with ID "sid" is
4964 returned and "name" is ignored.
4965
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004966 Each item in the returned List is a |Dict| with the following
4967 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004968 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01004969 `import autoload` but was not actually sourced
4970 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004971 functions List of script-local function names defined in
4972 the script. Present only when a particular
4973 script is specified using the "sid" item in
4974 {opts}.
4975 name Vim script file name.
4976 sid Script ID |<SID>|.
4977 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01004978 this script name links to, if any, otherwise
4979 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004980 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00004981 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004982 specified using the "sid" item in {opts}.
4983 Note that this is a copy, the value of
4984 script-local variables cannot be changed using
4985 this dictionary.
h_east59858792023-10-25 22:47:05 +09004986 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01004987
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004988 Examples: >
4989 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08004990 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004991<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004992 Return type: list<dict<any>>
4993
4994
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004995gettabinfo([{tabnr}]) *gettabinfo()*
4996 If {tabnr} is not specified, then information about all the
4997 tab pages is returned as a |List|. Each List item is a
4998 |Dictionary|. Otherwise, {tabnr} specifies the tab page
4999 number and information about that one is returned. If the tab
5000 page does not exist an empty List is returned.
5001
5002 Each List item is a |Dictionary| with the following entries:
5003 tabnr tab page number.
5004 variables a reference to the dictionary with
5005 tabpage-local variables
5006 windows List of |window-ID|s in the tab page.
5007
5008 Can also be used as a |method|: >
5009 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005010<
5011 Return type: list<dict<any>>
5012
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005013
5014gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
5015 Get the value of a tab-local variable {varname} in tab page
5016 {tabnr}. |t:var|
5017 Tabs are numbered starting with one.
5018 The {varname} argument is a string. When {varname} is empty a
5019 dictionary with all tab-local variables is returned.
5020 Note that the name without "t:" must be used.
5021 When the tab or variable doesn't exist {def} or an empty
5022 string is returned, there is no error message.
5023
5024 Can also be used as a |method|: >
5025 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005026<
5027 Return type: any, depending on {varname}
5028
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005029
5030gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
5031 Get the value of window-local variable {varname} in window
5032 {winnr} in tab page {tabnr}.
5033 The {varname} argument is a string. When {varname} is empty a
5034 dictionary with all window-local variables is returned.
5035 When {varname} is equal to "&" get the values of all
5036 window-local options in a |Dictionary|.
5037 Otherwise, when {varname} starts with "&" get the value of a
5038 window-local option.
5039 Note that {varname} must be the name without "w:".
5040 Tabs are numbered starting with one. For the current tabpage
5041 use |getwinvar()|.
5042 {winnr} can be the window number or the |window-ID|.
5043 When {winnr} is zero the current window is used.
5044 This also works for a global option, buffer-local option and
5045 window-local option, but it doesn't work for a global variable
5046 or buffer-local variable.
5047 When the tab, window or variable doesn't exist {def} or an
5048 empty string is returned, there is no error message.
5049 Examples: >
5050 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005051 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005052<
5053 To obtain all window-local variables use: >
5054 gettabwinvar({tabnr}, {winnr}, '&')
5055
5056< Can also be used as a |method|: >
5057 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005058<
5059 Return type: any, depending on {varname}
5060
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005061
5062gettagstack([{winnr}]) *gettagstack()*
5063 The result is a Dict, which is the tag stack of window {winnr}.
5064 {winnr} can be the window number or the |window-ID|.
5065 When {winnr} is not specified, the current window is used.
5066 When window {winnr} doesn't exist, an empty Dict is returned.
5067
5068 The returned dictionary contains the following entries:
5069 curidx Current index in the stack. When at
5070 top of the stack, set to (length + 1).
5071 Index of bottom of the stack is 1.
5072 items List of items in the stack. Each item
5073 is a dictionary containing the
5074 entries described below.
5075 length Number of entries in the stack.
5076
5077 Each item in the stack is a dictionary with the following
5078 entries:
5079 bufnr buffer number of the current jump
5080 from cursor position before the tag jump.
5081 See |getpos()| for the format of the
5082 returned list.
5083 matchnr current matching tag number. Used when
5084 multiple matching tags are found for a
5085 name.
5086 tagname name of the tag
5087
5088 See |tagstack| for more information about the tag stack.
5089
5090 Can also be used as a |method|: >
5091 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005092<
5093 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005094
5095
Christ van Willegence0ef912024-06-20 23:41:59 +02005096gettext({text} [, {package}]) *gettext()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005097 Translate String {text} if possible.
RestorerZ96509102024-07-11 21:14:15 +02005098 This is intended for use in Vim scripts. When generating
5099 message translations the {text} is extracted by `xgettext`,
5100 the translator can add translated messages into the .po file
5101 and Vim will lookup the translation when gettext() is called.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005102 For {text} double quoted strings are preferred, because
RestorerZ96509102024-07-11 21:14:15 +02005103 `xgettext` does not support single quoted escaped text.
5104
Christ van Willegence0ef912024-06-20 23:41:59 +02005105 When the {package} is specified, the translation is looked up
RestorerZ96509102024-07-11 21:14:15 +02005106 for that specific package. This is mainly required for
5107 third-party Vim scripts. You need to specify a path to the
5108 translations with the |bindtextdomain()| function before
5109 using the gettext() function.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005110
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005111 Return type: |String|
5112
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005113
5114getwininfo([{winid}]) *getwininfo()*
5115 Returns information about windows as a |List| with Dictionaries.
5116
5117 If {winid} is given Information about the window with that ID
5118 is returned, as a |List| with one item. If the window does not
5119 exist the result is an empty list.
5120
5121 Without {winid} information about all the windows in all the
5122 tab pages is returned.
5123
5124 Each List item is a |Dictionary| with the following entries:
5125 botline last complete displayed buffer line
5126 bufnr number of buffer in the window
5127 height window height (excluding winbar)
glepnir0a850672024-11-25 19:39:04 +01005128 leftcol first column displayed; only used when
5129 'wrap' is off
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005130 loclist 1 if showing a location list
5131 {only with the +quickfix feature}
5132 quickfix 1 if quickfix or location list window
5133 {only with the +quickfix feature}
5134 terminal 1 if a terminal window
5135 {only with the +terminal feature}
5136 tabnr tab page number
5137 topline first displayed buffer line
5138 variables a reference to the dictionary with
5139 window-local variables
5140 width window width
5141 winbar 1 if the window has a toolbar, 0
5142 otherwise
5143 wincol leftmost screen column of the window;
5144 "col" from |win_screenpos()|
5145 textoff number of columns occupied by any
5146 'foldcolumn', 'signcolumn' and line
5147 number in front of the text
5148 winid |window-ID|
5149 winnr window number
5150 winrow topmost screen line of the window;
5151 "row" from |win_screenpos()|
5152
5153 Can also be used as a |method|: >
5154 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005155<
5156 Return type: list<dict<any>>
5157
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005158
5159getwinpos([{timeout}]) *getwinpos()*
5160 The result is a |List| with two numbers, the result of
5161 |getwinposx()| and |getwinposy()| combined:
5162 [x-pos, y-pos]
5163 {timeout} can be used to specify how long to wait in msec for
5164 a response from the terminal. When omitted 100 msec is used.
5165 Use a longer time for a remote terminal.
5166 When using a value less than 10 and no response is received
5167 within that time, a previously reported position is returned,
5168 if available. This can be used to poll for the position and
5169 do some work in the meantime: >
5170 while 1
5171 let res = getwinpos(1)
5172 if res[0] >= 0
5173 break
5174 endif
5175 " Do some work here
5176 endwhile
5177<
5178
5179 Can also be used as a |method|: >
5180 GetTimeout()->getwinpos()
5181<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005182 Return type: list<number>
5183
5184
5185getwinposx() *getwinposx()*
5186 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005187 the left hand side of the GUI Vim window. Also works for an
5188 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005189 The result will be -1 if the information is not available
5190 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005191 The value can be used with `:winpos`.
5192
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005193 Return type: |Number|
5194
5195
5196getwinposy() *getwinposy()*
5197 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005198 the top of the GUI Vim window. Also works for an xterm (uses
5199 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005200 The result will be -1 if the information is not available
5201 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005202 The value can be used with `:winpos`.
5203
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005204 Return type: |Number|
5205
5206
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005207getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5208 Like |gettabwinvar()| for the current tabpage.
5209 Examples: >
5210 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005211 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005212
5213< Can also be used as a |method|: >
5214 GetWinnr()->getwinvar(varname)
5215<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005216 Return type: any, depending on {varname}
5217
5218
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005219glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5220 Expand the file wildcards in {expr}. See |wildcards| for the
5221 use of special characters.
5222
5223 Unless the optional {nosuf} argument is given and is |TRUE|,
5224 the 'suffixes' and 'wildignore' options apply: Names matching
5225 one of the patterns in 'wildignore' will be skipped and
5226 'suffixes' affect the ordering of matches.
5227 'wildignorecase' always applies.
5228
5229 When {list} is present and it is |TRUE| the result is a |List|
5230 with all matching files. The advantage of using a List is,
5231 you also get filenames containing newlines correctly.
5232 Otherwise the result is a String and when there are several
5233 matches, they are separated by <NL> characters.
5234
5235 If the expansion fails, the result is an empty String or List.
5236
5237 You can also use |readdir()| if you need to do complicated
5238 things, such as limiting the number of matches.
5239
5240 A name for a non-existing file is not included. A symbolic
5241 link is only included if it points to an existing file.
5242 However, when the {alllinks} argument is present and it is
5243 |TRUE| then all symbolic links are included.
5244
5245 For most systems backticks can be used to get files names from
5246 any external command. Example: >
5247 :let tagfiles = glob("`find . -name tags -print`")
5248 :let &tags = substitute(tagfiles, "\n", ",", "g")
5249< The result of the program inside the backticks should be one
5250 item per line. Spaces inside an item are allowed.
5251
5252 See |expand()| for expanding special Vim variables. See
5253 |system()| for getting the raw output of an external command.
5254
5255 Can also be used as a |method|: >
5256 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005257<
5258 Return type: |String| or list<string> or list<any> depending
5259 on {list}
5260
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005261
h-east624bb832024-11-09 18:37:32 +01005262glob2regpat({string}) *glob2regpat()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005263 Convert a file pattern, as used by glob(), into a search
5264 pattern. The result can be used to match with a string that
5265 is a file name. E.g. >
5266 if filename =~ glob2regpat('Make*.mak')
5267< This is equivalent to: >
5268 if filename =~ '^Make.*\.mak$'
5269< When {string} is an empty string the result is "^$", match an
5270 empty string.
5271 Note that the result depends on the system. On MS-Windows
5272 a backslash usually means a path separator.
5273
5274 Can also be used as a |method|: >
5275 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005276<
5277 Return type: |String|
5278
5279 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005280globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5281 Perform glob() for String {expr} on all directories in {path}
5282 and concatenate the results. Example: >
5283 :echo globpath(&rtp, "syntax/c.vim")
5284<
5285 {path} is a comma-separated list of directory names. Each
5286 directory name is prepended to {expr} and expanded like with
5287 |glob()|. A path separator is inserted when needed.
5288 To add a comma inside a directory name escape it with a
5289 backslash. Note that on MS-Windows a directory may have a
5290 trailing backslash, remove it if you put a comma after it.
5291 If the expansion fails for one of the directories, there is no
5292 error message.
5293
5294 Unless the optional {nosuf} argument is given and is |TRUE|,
5295 the 'suffixes' and 'wildignore' options apply: Names matching
5296 one of the patterns in 'wildignore' will be skipped and
5297 'suffixes' affect the ordering of matches.
5298
5299 When {list} is present and it is |TRUE| the result is a |List|
5300 with all matching files. The advantage of using a List is, you
5301 also get filenames containing newlines correctly. Otherwise
5302 the result is a String and when there are several matches,
5303 they are separated by <NL> characters. Example: >
5304 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5305<
5306 {alllinks} is used as with |glob()|.
5307
5308 The "**" item can be used to search in a directory tree.
5309 For example, to find all "README.txt" files in the directories
5310 in 'runtimepath' and below: >
5311 :echo globpath(&rtp, "**/README.txt")
5312< Upwards search and limiting the depth of "**" is not
5313 supported, thus using 'path' will not always work properly.
5314
5315 Can also be used as a |method|, the base is passed as the
5316 second argument: >
5317 GetExpr()->globpath(&rtp)
5318<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005319 Return type: |String| or list<string> or list<any> depending
5320 on {list}
5321
5322
5323has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005324 When {check} is omitted or is zero: The result is a Number,
5325 which is 1 if the feature {feature} is supported, zero
5326 otherwise. The {feature} argument is a string, case is
5327 ignored. See |feature-list| below.
5328
5329 When {check} is present and not zero: The result is a Number,
5330 which is 1 if the feature {feature} could ever be supported,
5331 zero otherwise. This is useful to check for a typo in
5332 {feature} and to detect dead code. Keep in mind that an older
5333 Vim version will not know about a feature added later and
5334 features that have been abandoned will not be known by the
5335 current Vim version.
5336
5337 Also see |exists()| and |exists_compiled()|.
5338
5339 Note that to skip code that has a syntax error when the
5340 feature is not available, Vim may skip the rest of the line
5341 and miss a following `endif`. Therefore put the `endif` on a
5342 separate line: >
5343 if has('feature')
5344 let x = this->breaks->without->the->feature
5345 endif
5346< If the `endif` would be moved to the second line as "| endif" it
5347 would not be found.
5348
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005349 Return type: |Number|
5350
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005351
5352has_key({dict}, {key}) *has_key()*
5353 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005354 has an entry with key {key}. FALSE otherwise.
5355 The {key} argument is a string. In |Vim9| script a number is
5356 also accepted (and converted to a string) but no other types.
5357 In legacy script the usual automatic conversion to string is
5358 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005359
5360 Can also be used as a |method|: >
5361 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005362<
5363 Return type: |Number|
5364
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005365
5366haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5367 The result is a Number:
5368 1 when the window has set a local directory via |:lcd|
5369 2 when the tab-page has set a local directory via |:tcd|
5370 0 otherwise.
5371
5372 Without arguments use the current window.
5373 With {winnr} use this window in the current tab page.
5374 With {winnr} and {tabnr} use the window in the specified tab
5375 page.
5376 {winnr} can be the window number or the |window-ID|.
5377 If {winnr} is -1 it is ignored and only the tabpage is used.
5378 Return 0 if the arguments are invalid.
5379 Examples: >
5380 if haslocaldir() == 1
5381 " window local directory case
5382 elseif haslocaldir() == 2
5383 " tab-local directory case
5384 else
5385 " global directory case
5386 endif
5387
5388 " current window
5389 :echo haslocaldir()
5390 :echo haslocaldir(0)
5391 :echo haslocaldir(0, 0)
5392 " window n in current tab page
5393 :echo haslocaldir(n)
5394 :echo haslocaldir(n, 0)
5395 " window n in tab page m
5396 :echo haslocaldir(n, m)
5397 " tab page m
5398 :echo haslocaldir(-1, m)
5399<
5400 Can also be used as a |method|: >
5401 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005402<
5403 Return type: |Number|
5404
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005405
5406hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5407 The result is a Number, which is TRUE if there is a mapping
5408 that contains {what} in somewhere in the rhs (what it is
5409 mapped to) and this mapping exists in one of the modes
5410 indicated by {mode}.
5411 The arguments {what} and {mode} are strings.
5412 When {abbr} is there and it is |TRUE| use abbreviations
5413 instead of mappings. Don't forget to specify Insert and/or
5414 Command-line mode.
5415 Both the global mappings and the mappings local to the current
5416 buffer are checked for a match.
5417 If no matching mapping is found FALSE is returned.
5418 The following characters are recognized in {mode}:
5419 n Normal mode
5420 v Visual and Select mode
5421 x Visual mode
5422 s Select mode
5423 o Operator-pending mode
5424 i Insert mode
5425 l Language-Argument ("r", "f", "t", etc.)
5426 c Command-line mode
5427 When {mode} is omitted, "nvo" is used.
5428
5429 This function is useful to check if a mapping already exists
5430 to a function in a Vim script. Example: >
5431 :if !hasmapto('\ABCdoit')
5432 : map <Leader>d \ABCdoit
5433 :endif
5434< This installs the mapping to "\ABCdoit" only if there isn't
5435 already a mapping to "\ABCdoit".
5436
5437 Can also be used as a |method|: >
5438 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005439<
5440 Return type: |Number|
5441
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005442
5443histadd({history}, {item}) *histadd()*
5444 Add the String {item} to the history {history} which can be
5445 one of: *hist-names*
5446 "cmd" or ":" command line history
5447 "search" or "/" search pattern history
5448 "expr" or "=" typed expression history
5449 "input" or "@" input line history
5450 "debug" or ">" debug command history
5451 empty the current or last used history
5452 The {history} string does not need to be the whole name, one
5453 character is sufficient.
5454 If {item} does already exist in the history, it will be
5455 shifted to become the newest entry.
5456 The result is a Number: TRUE if the operation was successful,
5457 otherwise FALSE is returned.
5458
5459 Example: >
5460 :call histadd("input", strftime("%Y %b %d"))
5461 :let date=input("Enter date: ")
5462< This function is not available in the |sandbox|.
5463
5464 Can also be used as a |method|, the base is passed as the
5465 second argument: >
5466 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005467<
5468 Return type: |Number|
5469
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005470
5471histdel({history} [, {item}]) *histdel()*
5472 Clear {history}, i.e. delete all its entries. See |hist-names|
5473 for the possible values of {history}.
5474
5475 If the parameter {item} evaluates to a String, it is used as a
5476 regular expression. All entries matching that expression will
5477 be removed from the history (if there are any).
5478 Upper/lowercase must match, unless "\c" is used |/\c|.
5479 If {item} evaluates to a Number, it will be interpreted as
5480 an index, see |:history-indexing|. The respective entry will
5481 be removed if it exists.
5482
5483 The result is TRUE for a successful operation, otherwise FALSE
5484 is returned.
5485
5486 Examples:
5487 Clear expression register history: >
5488 :call histdel("expr")
5489<
5490 Remove all entries starting with "*" from the search history: >
5491 :call histdel("/", '^\*')
5492<
5493 The following three are equivalent: >
5494 :call histdel("search", histnr("search"))
5495 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005496 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005497<
5498 To delete the last search pattern and use the last-but-one for
5499 the "n" command and 'hlsearch': >
5500 :call histdel("search", -1)
5501 :let @/ = histget("search", -1)
5502<
5503 Can also be used as a |method|: >
5504 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005505<
5506 Return type: |Number|
5507
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005508
5509histget({history} [, {index}]) *histget()*
5510 The result is a String, the entry with Number {index} from
5511 {history}. See |hist-names| for the possible values of
5512 {history}, and |:history-indexing| for {index}. If there is
5513 no such entry, an empty String is returned. When {index} is
5514 omitted, the most recent item from the history is used.
5515
5516 Examples:
5517 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005518 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005519
5520< Define an Ex command ":H {num}" that supports re-execution of
5521 the {num}th entry from the output of |:history|. >
5522 :command -nargs=1 H execute histget("cmd", 0+<args>)
5523<
5524 Can also be used as a |method|: >
5525 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005526<
5527 Return type: |String|
5528
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005529
5530histnr({history}) *histnr()*
5531 The result is the Number of the current entry in {history}.
5532 See |hist-names| for the possible values of {history}.
5533 If an error occurred, -1 is returned.
5534
5535 Example: >
5536 :let inp_index = histnr("expr")
5537
5538< Can also be used as a |method|: >
5539 GetHistory()->histnr()
5540<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005541 Return type: |Number|
5542
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005543hlexists({name}) *hlexists()*
5544 The result is a Number, which is TRUE if a highlight group
5545 called {name} exists. This is when the group has been
5546 defined in some way. Not necessarily when highlighting has
5547 been defined for it, it may also have been used for a syntax
5548 item.
5549 *highlight_exists()*
5550 Obsolete name: highlight_exists().
5551
5552 Can also be used as a |method|: >
5553 GetName()->hlexists()
5554<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005555 Return type: |Number|
5556
5557
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005558hlget([{name} [, {resolve}]]) *hlget()*
5559 Returns a List of all the highlight group attributes. If the
5560 optional {name} is specified, then returns a List with only
5561 the attributes of the specified highlight group. Returns an
5562 empty List if the highlight group {name} is not present.
5563
5564 If the optional {resolve} argument is set to v:true and the
5565 highlight group {name} is linked to another group, then the
5566 link is resolved recursively and the attributes of the
5567 resolved highlight group are returned.
5568
5569 Each entry in the returned List is a Dictionary with the
5570 following items:
5571 cleared boolean flag, set to v:true if the highlight
5572 group attributes are cleared or not yet
5573 specified. See |highlight-clear|.
5574 cterm cterm attributes. See |highlight-cterm|.
5575 ctermbg cterm background color.
5576 See |highlight-ctermbg|.
5577 ctermfg cterm foreground color.
5578 See |highlight-ctermfg|.
5579 ctermul cterm underline color. See |highlight-ctermul|.
5580 default boolean flag, set to v:true if the highlight
5581 group link is a default link. See
5582 |highlight-default|.
5583 font highlight group font. See |highlight-font|.
5584 gui gui attributes. See |highlight-gui|.
5585 guibg gui background color. See |highlight-guibg|.
5586 guifg gui foreground color. See |highlight-guifg|.
5587 guisp gui special color. See |highlight-guisp|.
5588 id highlight group ID.
5589 linksto linked highlight group name.
5590 See |:highlight-link|.
5591 name highlight group name. See |group-name|.
5592 start start terminal keycode. See |highlight-start|.
5593 stop stop terminal keycode. See |highlight-stop|.
5594 term term attributes. See |highlight-term|.
5595
5596 The 'term', 'cterm' and 'gui' items in the above Dictionary
5597 have a dictionary value with the following optional boolean
5598 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5599 'reverse', 'inverse' and 'strikethrough'.
5600
5601 Example(s): >
5602 :echo hlget()
5603 :echo hlget('ModeMsg')
5604 :echo hlget('Number', v:true)
5605<
5606 Can also be used as a |method|: >
5607 GetName()->hlget()
5608<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005609 Return type: list<dict<any>>
5610
5611
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005612hlset({list}) *hlset()*
5613 Creates or modifies the attributes of a List of highlight
5614 groups. Each item in {list} is a dictionary containing the
5615 attributes of a highlight group. See |hlget()| for the list of
5616 supported items in this dictionary.
5617
5618 In addition to the items described in |hlget()|, the following
5619 additional items are supported in the dictionary:
5620
5621 force boolean flag to force the creation of
5622 a link for an existing highlight group
5623 with attributes.
5624
5625 The highlight group is identified using the 'name' item and
5626 the 'id' item (if supplied) is ignored. If a highlight group
5627 with a specified name doesn't exist, then it is created.
5628 Otherwise the attributes of an existing highlight group are
5629 modified.
5630
5631 If an empty dictionary value is used for the 'term' or 'cterm'
5632 or 'gui' entries, then the corresponding attributes are
5633 cleared. If the 'cleared' item is set to v:true, then all the
5634 attributes of the highlight group are cleared.
5635
5636 The 'linksto' item can be used to link a highlight group to
5637 another highlight group. See |:highlight-link|.
5638
5639 Returns zero for success, -1 for failure.
5640
5641 Example(s): >
5642 " add bold attribute to the Visual highlight group
5643 :call hlset([#{name: 'Visual',
5644 \ term: #{reverse: 1 , bold: 1}}])
5645 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5646 :let l = hlget()
5647 :call hlset(l)
5648 " clear the Search highlight group
5649 :call hlset([#{name: 'Search', cleared: v:true}])
5650 " clear the 'term' attributes for a highlight group
5651 :call hlset([#{name: 'Title', term: {}}])
5652 " create the MyHlg group linking it to DiffAdd
5653 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5654 " remove the MyHlg group link
5655 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5656 " clear the attributes and a link
5657 :call hlset([#{name: 'MyHlg', cleared: v:true,
5658 \ linksto: 'NONE'}])
5659<
5660 Can also be used as a |method|: >
5661 GetAttrList()->hlset()
5662<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005663 Return type: |Number|
5664
5665hlID({name}) *hlID()*
5666 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005667 with name {name}. When the highlight group doesn't exist,
5668 zero is returned.
5669 This can be used to retrieve information about the highlight
5670 group. For example, to get the background color of the
5671 "Comment" group: >
5672 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5673< *highlightID()*
5674 Obsolete name: highlightID().
5675
5676 Can also be used as a |method|: >
5677 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005678<
5679 Return type: |Number|
5680
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005681
5682hostname() *hostname()*
5683 The result is a String, which is the name of the machine on
5684 which Vim is currently running. Machine names greater than
5685 256 characters long are truncated.
5686
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005687 Return type: |String|
5688
5689
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005690iconv({string}, {from}, {to}) *iconv()*
5691 The result is a String, which is the text {string} converted
5692 from encoding {from} to encoding {to}.
5693 When the conversion completely fails an empty string is
5694 returned. When some characters could not be converted they
5695 are replaced with "?".
5696 The encoding names are whatever the iconv() library function
5697 can accept, see ":!man 3 iconv".
5698 Most conversions require Vim to be compiled with the |+iconv|
5699 feature. Otherwise only UTF-8 to latin1 conversion and back
5700 can be done.
5701 This can be used to display messages with special characters,
5702 no matter what 'encoding' is set to. Write the message in
5703 UTF-8 and use: >
5704 echo iconv(utf8_str, "utf-8", &enc)
5705< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5706 from/to UCS-2 is automatically changed to use UTF-8. You
5707 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5708
5709 Can also be used as a |method|: >
5710 GetText()->iconv('latin1', 'utf-8')
5711<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005712 Return type: |String|
5713
5714
h-east624bb832024-11-09 18:37:32 +01005715id({item}) *id()*
Ernie Raelc8e158b2024-07-09 18:39:52 +02005716 The result is a unique String associated with the {item} and
5717 not with the {item}'s contents. It is only valid while the
5718 {item} exists and is referenced. It is valid only in the
5719 instance of vim that produces the result. The whole idea is
5720 that `id({item})` does not change if the contents of {item}
5721 changes. This is useful as a `key` for creating an identity
5722 dictionary, rather than one based on equals.
5723
5724 This operation does not reference {item} and there is no
5725 function to convert the `id` to the {item}. It may be useful to
5726 have a map of `id` to {item}. The following >
5727 var referenceMap: dict<any>
5728 var id = item->id()
5729 referenceMap[id] = item
5730< prevents {item} from being garbage collected and provides a
5731 way to get the {item} from the `id`.
5732
5733 {item} may be a List, Dictionary, Object, Job, Channel or
5734 Blob. If the item is not a permitted type, or it is a null
5735 value, then an empty String is returned.
5736
5737 Can also be used as a |method|: >
5738 GetItem()->id()
5739<
5740 Return type: |String|
5741
5742
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005743indent({lnum}) *indent()*
5744 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005745 current buffer. The indent is counted in spaces, the value
5746 of 'tabstop' is relevant. {lnum} is used just like in
5747 |getline()|.
5748 When {lnum} is invalid -1 is returned. In |Vim9| script an
5749 error is given.
5750
5751 Can also be used as a |method|: >
5752 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005753<
5754 Return type: |Number|
5755
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005756
5757index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005758 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005759 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005760
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005761 If {object} is a |List| return the lowest index where the item
5762 has a value equal to {expr}. There is no automatic
5763 conversion, so the String "4" is different from the Number 4.
5764 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005765 of 'ignorecase' is not used here, case matters as indicated by
5766 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005767
5768 If {object} is |Blob| return the lowest index where the byte
5769 value is equal to {expr}.
5770
5771 If {start} is given then start looking at the item with index
5772 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005773
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005774 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5775 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005776
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005777 -1 is returned when {expr} is not found in {object}.
5778 Example: >
5779 :let idx = index(words, "the")
5780 :if index(numbers, 123) >= 0
5781
5782< Can also be used as a |method|: >
5783 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005784<
5785 Return type: |Number|
5786
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005787
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005788indexof({object}, {expr} [, {opts}]) *indexof()*
5789 Returns the index of an item in {object} where {expr} is
5790 v:true. {object} must be a |List| or a |Blob|.
5791
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005792 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005793 List until the expression is v:true and return the index of
5794 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005795
5796 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005797 Blob until the expression is v:true and return the index of
5798 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005799
5800 {expr} must be a |string| or |Funcref|.
5801
5802 If {expr} is a |string|: If {object} is a |List|, inside
5803 {expr} |v:key| has the index of the current List item and
5804 |v:val| has the value of the item. If {object} is a |Blob|,
5805 inside {expr} |v:key| has the index of the current byte and
5806 |v:val| has the byte value.
5807
5808 If {expr} is a |Funcref| it must take two arguments:
5809 1. the key or the index of the current item.
5810 2. the value of the current item.
5811 The function must return |TRUE| if the item is found and the
5812 search should stop.
5813
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005814 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005815 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005816 startidx start evaluating {expr} at the item with this
5817 index; may be negative for an item relative to
5818 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005819 Returns -1 when {expr} evaluates to v:false for all the items.
5820 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005821 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
5822 :echo indexof(l, "v:val.n == 20")
5823 :echo indexof(l, {i, v -> v.n == 30})
5824 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005825
5826< Can also be used as a |method|: >
5827 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005828<
5829 Return type: |Number|
5830
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005831
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005832input({prompt} [, {text} [, {completion}]]) *input()*
5833 The result is a String, which is whatever the user typed on
5834 the command-line. The {prompt} argument is either a prompt
5835 string, or a blank string (for no prompt). A '\n' can be used
5836 in the prompt to start a new line.
5837 The highlighting set with |:echohl| is used for the prompt.
5838 The input is entered just like a command-line, with the same
5839 editing commands and mappings. There is a separate history
5840 for lines typed for input().
5841 Example: >
5842 :if input("Coffee or beer? ") == "beer"
5843 : echo "Cheers!"
5844 :endif
5845<
5846 If the optional {text} argument is present and not empty, this
5847 is used for the default reply, as if the user typed this.
5848 Example: >
5849 :let color = input("Color? ", "white")
5850
5851< The optional {completion} argument specifies the type of
5852 completion supported for the input. Without it completion is
5853 not performed. The supported completion types are the same as
5854 that can be supplied to a user-defined command using the
5855 "-complete=" argument. Refer to |:command-completion| for
5856 more information. Example: >
5857 let fname = input("File: ", "", "file")
5858<
5859 NOTE: This function must not be used in a startup file, for
5860 the versions that only run in GUI mode (e.g., the Win32 GUI).
5861 Note: When input() is called from within a mapping it will
5862 consume remaining characters from that mapping, because a
5863 mapping is handled like the characters were typed.
5864 Use |inputsave()| before input() and |inputrestore()|
5865 after input() to avoid that. Another solution is to avoid
5866 that further characters follow in the mapping, e.g., by using
5867 |:execute| or |:normal|.
5868
5869 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005870 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005871 :function GetFoo()
5872 : call inputsave()
5873 : let g:Foo = input("enter search pattern: ")
5874 : call inputrestore()
5875 :endfunction
5876
5877< Can also be used as a |method|: >
5878 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005879<
5880 Return type: |String|
5881
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005882
5883inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
5884 Like |input()|, but when the GUI is running and text dialogs
5885 are supported, a dialog window pops up to input the text.
5886 Example: >
5887 :let n = inputdialog("value for shiftwidth", shiftwidth())
5888 :if n != ""
5889 : let &sw = n
5890 :endif
5891< When the dialog is cancelled {cancelreturn} is returned. When
5892 omitted an empty string is returned.
5893 Hitting <Enter> works like pressing the OK button. Hitting
5894 <Esc> works like pressing the Cancel button.
5895 NOTE: Command-line completion is not supported.
5896
5897 Can also be used as a |method|: >
5898 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005899<
5900 Return type: |String|
5901
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005902
5903inputlist({textlist}) *inputlist()*
5904 {textlist} must be a |List| of strings. This |List| is
5905 displayed, one string per line. The user will be prompted to
5906 enter a number, which is returned.
5907 The user can also select an item by clicking on it with the
5908 mouse, if the mouse is enabled in the command line ('mouse' is
5909 "a" or includes "c"). For the first string 0 is returned.
5910 When clicking above the first item a negative number is
5911 returned. When clicking on the prompt one more than the
5912 length of {textlist} is returned.
5913 Make sure {textlist} has less than 'lines' entries, otherwise
5914 it won't work. It's a good idea to put the entry number at
5915 the start of the string. And put a prompt in the first item.
5916 Example: >
5917 let color = inputlist(['Select color:', '1. red',
5918 \ '2. green', '3. blue'])
5919
5920< Can also be used as a |method|: >
5921 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005922<
5923 Return type: |Number|
5924
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005925
5926inputrestore() *inputrestore()*
5927 Restore typeahead that was saved with a previous |inputsave()|.
5928 Should be called the same number of times inputsave() is
5929 called. Calling it more often is harmless though.
5930 Returns TRUE when there is nothing to restore, FALSE otherwise.
5931
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005932 Return type: |Number|
5933
5934
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005935inputsave() *inputsave()*
5936 Preserve typeahead (also from mappings) and clear it, so that
5937 a following prompt gets input from the user. Should be
5938 followed by a matching inputrestore() after the prompt. Can
5939 be used several times, in which case there must be just as
5940 many inputrestore() calls.
5941 Returns TRUE when out of memory, FALSE otherwise.
5942
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005943 Return type: |Number|
5944
5945
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005946inputsecret({prompt} [, {text}]) *inputsecret()*
5947 This function acts much like the |input()| function with but
5948 two exceptions:
5949 a) the user's response will be displayed as a sequence of
5950 asterisks ("*") thereby keeping the entry secret, and
5951 b) the user's response will not be recorded on the input
5952 |history| stack.
5953 The result is a String, which is whatever the user actually
5954 typed on the command-line in response to the issued prompt.
5955 NOTE: Command-line completion is not supported.
5956
5957 Can also be used as a |method|: >
5958 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005959<
5960 Return type: |String|
5961
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005962
5963insert({object}, {item} [, {idx}]) *insert()*
5964 When {object} is a |List| or a |Blob| insert {item} at the start
5965 of it.
5966
5967 If {idx} is specified insert {item} before the item with index
5968 {idx}. If {idx} is zero it goes before the first item, just
5969 like omitting {idx}. A negative {idx} is also possible, see
5970 |list-index|. -1 inserts just before the last item.
5971
5972 Returns the resulting |List| or |Blob|. Examples: >
5973 :let mylist = insert([2, 3, 5], 1)
5974 :call insert(mylist, 4, -1)
5975 :call insert(mylist, 6, len(mylist))
5976< The last example can be done simpler with |add()|.
5977 Note that when {item} is a |List| it is inserted as a single
5978 item. Use |extend()| to concatenate |Lists|.
5979
5980 Can also be used as a |method|: >
5981 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005982<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005983 Return type: |Number|
5984
5985
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005986 *instanceof()* *E614* *E616* *E693*
5987instanceof({object}, {class})
5988 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01005989 argument is a direct or indirect instance of a |Class|,
5990 |Interface|, or class |:type| alias specified by {class}.
5991 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005992 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02005993 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01005994 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02005995
5996< Can also be used as a |method|: >
5997 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005998<
5999 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02006000
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006001interrupt() *interrupt()*
6002 Interrupt script execution. It works more or less like the
6003 user typing CTRL-C, most commands won't execute and control
6004 returns to the user. This is useful to abort execution
6005 from lower down, e.g. in an autocommand. Example: >
6006 :function s:check_typoname(file)
6007 : if fnamemodify(a:file, ':t') == '['
6008 : echomsg 'Maybe typo'
6009 : call interrupt()
6010 : endif
6011 :endfunction
6012 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006013<
6014 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006015
6016invert({expr}) *invert()*
6017 Bitwise invert. The argument is converted to a number. A
6018 List, Dict or Float argument causes an error. Example: >
6019 :let bits = invert(bits)
6020< Can also be used as a |method|: >
6021 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006022<
6023 Return type: |Number|
6024
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006025
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006026isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01006027 The result is a Number, which is |TRUE| when {path} is an
6028 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006029 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01006030 On MS-Windows, it is considered absolute when it starts with an
6031 optional drive prefix and is followed by a '\' or '/'. UNC paths
6032 are always absolute.
6033 Example: >
6034 echo isabsolutepath('/usr/share/') " 1
6035 echo isabsolutepath('./foobar') " 0
6036 echo isabsolutepath('C:\Windows') " 1
6037 echo isabsolutepath('foobar') " 0
6038 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006039<
LemonBoydca1d402022-04-28 15:26:33 +01006040 Can also be used as a |method|: >
6041 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006042<
6043 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01006044
6045
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006046isdirectory({directory}) *isdirectory()*
6047 The result is a Number, which is |TRUE| when a directory
6048 with the name {directory} exists. If {directory} doesn't
6049 exist, or isn't a directory, the result is |FALSE|. {directory}
6050 is any expression, which is used as a String.
6051
6052 Can also be used as a |method|: >
6053 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006054<
6055 Return type: |Number|
6056
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006057
6058isinf({expr}) *isinf()*
6059 Return 1 if {expr} is a positive infinity, or -1 a negative
6060 infinity, otherwise 0. >
6061 :echo isinf(1.0 / 0.0)
6062< 1 >
6063 :echo isinf(-1.0 / 0.0)
6064< -1
6065
6066 Can also be used as a |method|: >
6067 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006068<
6069 Return type: |Number|
6070
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006071
6072islocked({expr}) *islocked()* *E786*
6073 The result is a Number, which is |TRUE| when {expr} is the
6074 name of a locked variable.
6075 The string argument {expr} must be the name of a variable,
6076 |List| item or |Dictionary| entry, not the variable itself!
6077 Example: >
6078 :let alist = [0, ['a', 'b'], 2, 3]
6079 :lockvar 1 alist
6080 :echo islocked('alist') " 1
6081 :echo islocked('alist[1]') " 0
6082
Bram Moolenaar9da17d72022-02-09 21:50:44 +00006083< When {expr} is a variable that does not exist -1 is returned.
6084 If {expr} uses a range, list or dict index that is out of
6085 range or does not exist you get an error message. Use
6086 |exists()| to check for existence.
6087 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006088
6089 Can also be used as a |method|: >
6090 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006091<
6092 Return type: |Number|
6093
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006094
6095isnan({expr}) *isnan()*
6096 Return |TRUE| if {expr} is a float with value NaN. >
6097 echo isnan(0.0 / 0.0)
6098< 1
6099
6100 Can also be used as a |method|: >
6101 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006102<
6103 Return type: |Number|
6104
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006105
6106items({dict}) *items()*
6107 Return a |List| with all the key-value pairs of {dict}. Each
6108 |List| item is a list with two items: the key of a {dict}
6109 entry and the value of this entry. The |List| is in arbitrary
6110 order. Also see |keys()| and |values()|.
6111 Example: >
6112 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006113 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006114 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006115<
6116 A List or a String argument is also supported. In these
6117 cases, items() returns a List with the index and the value at
6118 the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006119
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006120 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006121 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006122<
6123 Return type: list<list<any>> or list<any>
6124
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006125
6126job_ functions are documented here: |job-functions-details|
6127
6128
6129join({list} [, {sep}]) *join()*
6130 Join the items in {list} together into one String.
6131 When {sep} is specified it is put in between the items. If
6132 {sep} is omitted a single space is used.
6133 Note that {sep} is not added at the end. You might want to
6134 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006135 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006136< String items are used as-is. |Lists| and |Dictionaries| are
6137 converted into a string like with |string()|.
6138 The opposite function is |split()|.
6139
6140 Can also be used as a |method|: >
6141 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006142<
6143 Return type: |String|
6144
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006145
6146js_decode({string}) *js_decode()*
6147 This is similar to |json_decode()| with these differences:
6148 - Object key names do not have to be in quotes.
6149 - Strings can be in single quotes.
6150 - Empty items in an array (between two commas) are allowed and
6151 result in v:none items.
6152
6153 Can also be used as a |method|: >
6154 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006155<
6156 Return type: any, depending on {varname}
6157
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006158
6159js_encode({expr}) *js_encode()*
6160 This is similar to |json_encode()| with these differences:
6161 - Object key names are not in quotes.
6162 - v:none items in an array result in an empty item between
6163 commas.
6164 For example, the Vim object:
6165 [1,v:none,{"one":1},v:none] ~
6166 Will be encoded as:
6167 [1,,{one:1},,] ~
6168 While json_encode() would produce:
6169 [1,null,{"one":1},null] ~
6170 This encoding is valid for JavaScript. It is more efficient
6171 than JSON, especially when using an array with optional items.
6172
6173 Can also be used as a |method|: >
6174 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006175<
6176 Return type: |String|
6177
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006178
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006179json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006180 This parses a JSON formatted string and returns the equivalent
6181 in Vim values. See |json_encode()| for the relation between
6182 JSON and Vim values.
6183 The decoding is permissive:
6184 - A trailing comma in an array and object is ignored, e.g.
6185 "[1, 2, ]" is the same as "[1, 2]".
6186 - Integer keys are accepted in objects, e.g. {1:2} is the
6187 same as {"1":2}.
6188 - More floating point numbers are recognized, e.g. "1." for
6189 "1.0", or "001.2" for "1.2". Special floating point values
6190 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6191 are accepted.
6192 - Leading zeroes in integer numbers are ignored, e.g. "012"
6193 for "12" or "-012" for "-12".
6194 - Capitalization is ignored in literal names null, true or
6195 false, e.g. "NULL" for "null", "True" for "true".
6196 - Control characters U+0000 through U+001F which are not
6197 escaped in strings are accepted, e.g. " " (tab
6198 character in string) for "\t".
6199 - An empty JSON expression or made of only spaces is accepted
6200 and results in v:none.
6201 - Backslash in an invalid 2-character sequence escape is
6202 ignored, e.g. "\a" is decoded as "a".
6203 - A correct surrogate pair in JSON strings should normally be
6204 a 12 character sequence such as "\uD834\uDD1E", but
6205 json_decode() silently accepts truncated surrogate pairs
6206 such as "\uD834" or "\uD834\u"
6207 *E938*
6208 A duplicate key in an object, valid in rfc7159, is not
6209 accepted by json_decode() as the result must be a valid Vim
6210 type, e.g. this fails: {"a":"b", "a":"c"}
6211
6212 Can also be used as a |method|: >
6213 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006214<
6215 Return type: any, depending on {varname}
6216
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006217
6218json_encode({expr}) *json_encode()*
6219 Encode {expr} as JSON and return this as a string.
6220 The encoding is specified in:
6221 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006222 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006223 |Number| decimal number
6224 |Float| floating point number
6225 Float nan "NaN"
6226 Float inf "Infinity"
6227 Float -inf "-Infinity"
6228 |String| in double quotes (possibly null)
6229 |Funcref| not possible, error
6230 |List| as an array (possibly null); when
6231 used recursively: []
6232 |Dict| as an object (possibly null); when
6233 used recursively: {}
6234 |Blob| as an array of the individual bytes
6235 v:false "false"
6236 v:true "true"
6237 v:none "null"
6238 v:null "null"
6239 Note that NaN and Infinity are passed on as values. This is
6240 missing in the JSON standard, but several implementations do
6241 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006242 If a string contains an illegal character then the replacement
6243 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006244
6245 Can also be used as a |method|: >
6246 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006247<
6248 Return type: |String|
6249
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006250
6251keys({dict}) *keys()*
6252 Return a |List| with all the keys of {dict}. The |List| is in
6253 arbitrary order. Also see |items()| and |values()|.
6254
6255 Can also be used as a |method|: >
6256 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006257<
6258 Return type: list<string>
6259
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006260
zeertzjqcdc83932022-09-12 13:38:41 +01006261keytrans({string}) *keytrans()*
6262 Turn the internal byte representation of keys into a form that
6263 can be used for |:map|. E.g. >
6264 :let xx = "\<C-Home>"
6265 :echo keytrans(xx)
6266< <C-Home>
6267
6268 Can also be used as a |method|: >
6269 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006270<
6271 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006272
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006273
6274len({expr}) *len()* *E701*
6275 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006276 When {expr} is a String or a Number the length in bytes is
6277 used, as with |strlen()|.
6278 When {expr} is a |List| the number of items in the |List| is
6279 returned.
6280 When {expr} is a |Blob| the number of bytes is returned.
6281 When {expr} is a |Dictionary| the number of entries in the
6282 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006283 When {expr} is an |Object|, invokes the len() method in the
6284 object (if present) to get the length (|object-len()|).
6285 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006286
6287 Can also be used as a |method|: >
6288 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006289<
6290 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006291
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006292
6293 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006294libcall({libname}, {funcname}, {argument})
6295 Call function {funcname} in the run-time library {libname}
6296 with single argument {argument}.
6297 This is useful to call functions in a library that you
6298 especially made to be used with Vim. Since only one argument
6299 is possible, calling standard library functions is rather
6300 limited.
6301 The result is the String returned by the function. If the
6302 function returns NULL, this will appear as an empty string ""
6303 to Vim.
6304 If the function returns a number, use libcallnr()!
6305 If {argument} is a number, it is passed to the function as an
6306 int; if {argument} is a string, it is passed as a
6307 null-terminated string.
6308 This function will fail in |restricted-mode|.
6309
6310 libcall() allows you to write your own 'plug-in' extensions to
6311 Vim without having to recompile the program. It is NOT a
6312 means to call system functions! If you try to do so Vim will
6313 very probably crash.
6314
6315 For Win32, the functions you write must be placed in a DLL
6316 and use the normal C calling convention (NOT Pascal which is
6317 used in Windows System DLLs). The function must take exactly
6318 one parameter, either a character pointer or a long integer,
6319 and must return a character pointer or NULL. The character
6320 pointer returned must point to memory that will remain valid
6321 after the function has returned (e.g. in static data in the
6322 DLL). If it points to allocated memory, that memory will
6323 leak away. Using a static buffer in the function should work,
6324 it's then freed when the DLL is unloaded.
6325
6326 WARNING: If the function returns a non-valid pointer, Vim may
6327 crash! This also happens if the function returns a number,
6328 because Vim thinks it's a pointer.
6329 For Win32 systems, {libname} should be the filename of the DLL
6330 without the ".DLL" suffix. A full path is only required if
6331 the DLL is not in the usual places.
6332 For Unix: When compiling your own plugins, remember that the
6333 object code must be compiled as position-independent ('PIC').
6334 {only in Win32 and some Unix versions, when the |+libcall|
6335 feature is present}
6336 Examples: >
6337 :echo libcall("libc.so", "getenv", "HOME")
6338
6339< Can also be used as a |method|, the base is passed as the
6340 third argument: >
6341 GetValue()->libcall("libc.so", "getenv")
6342<
6343 *libcallnr()*
6344libcallnr({libname}, {funcname}, {argument})
6345 Just like |libcall()|, but used for a function that returns an
6346 int instead of a string.
6347 {only in Win32 on some Unix versions, when the |+libcall|
6348 feature is present}
6349 Examples: >
6350 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6351 :call libcallnr("libc.so", "printf", "Hello World!\n")
6352 :call libcallnr("libc.so", "sleep", 10)
6353<
6354 Can also be used as a |method|, the base is passed as the
6355 third argument: >
6356 GetValue()->libcallnr("libc.so", "printf")
6357<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006358 Return type: |String|
6359
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006360
6361line({expr} [, {winid}]) *line()*
6362 The result is a Number, which is the line number of the file
6363 position given with {expr}. The {expr} argument is a string.
zeertzjq02f3eba2024-06-12 20:45:24 +02006364 See |getpos()| for accepted positions.
6365
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006366 To get the column number use |col()|. To get both use
6367 |getpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02006368
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006369 With the optional {winid} argument the values are obtained for
6370 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02006371
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006372 Returns 0 for invalid values of {expr} and {winid}.
zeertzjq02f3eba2024-06-12 20:45:24 +02006373
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006374 Examples: >
6375 line(".") line number of the cursor
6376 line(".", winid) idem, in window "winid"
6377 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006378 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006379<
6380 To jump to the last known position when opening a file see
6381 |last-position-jump|.
6382
6383 Can also be used as a |method|: >
6384 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006385<
6386 Return type: |Number|
6387
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006388
6389line2byte({lnum}) *line2byte()*
6390 Return the byte count from the start of the buffer for line
6391 {lnum}. This includes the end-of-line character, depending on
6392 the 'fileformat' option for the current buffer. The first
6393 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6394 This can also be used to get the byte count for the line just
6395 below the last line: >
6396 line2byte(line("$") + 1)
6397< This is the buffer size plus one. If 'fileencoding' is empty
6398 it is the file size plus one. {lnum} is used like with
6399 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6400 feature has been disabled at compile time, -1 is returned.
6401 Also see |byte2line()|, |go| and |:goto|.
6402
6403 Can also be used as a |method|: >
6404 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006405<
6406 Return type: |Number|
6407
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006408
6409lispindent({lnum}) *lispindent()*
6410 Get the amount of indent for line {lnum} according the lisp
6411 indenting rules, as with 'lisp'.
6412 The indent is counted in spaces, the value of 'tabstop' is
6413 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006414 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006415 error is given.
6416
6417 Can also be used as a |method|: >
6418 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006419<
6420 Return type: |Number|
6421
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006422
6423list2blob({list}) *list2blob()*
6424 Return a Blob concatenating all the number values in {list}.
6425 Examples: >
6426 list2blob([1, 2, 3, 4]) returns 0z01020304
6427 list2blob([]) returns 0z
6428< Returns an empty Blob on error. If one of the numbers is
6429 negative or more than 255 error *E1239* is given.
6430
6431 |blob2list()| does the opposite.
6432
6433 Can also be used as a |method|: >
6434 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006435<
6436 Return type: |Blob|
6437
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006438
6439list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006440 Convert each number in {list} to a character string and
6441 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006442 list2str([32]) returns " "
6443 list2str([65, 66, 67]) returns "ABC"
6444< The same can be done (slowly) with: >
6445 join(map(list, {nr, val -> nr2char(val)}), '')
6446< |str2list()| does the opposite.
6447
6448 When {utf8} is omitted or zero, the current 'encoding' is used.
6449 When {utf8} is TRUE, always return UTF-8 characters.
6450 With UTF-8 composing characters work as expected: >
6451 list2str([97, 769]) returns "á"
6452<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006453 Returns an empty string on error.
6454
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006455 Can also be used as a |method|: >
6456 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006457<
6458 Return type: |String|
6459
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006460
6461listener_add({callback} [, {buf}]) *listener_add()*
6462 Add a callback function that will be invoked when changes have
6463 been made to buffer {buf}.
6464 {buf} refers to a buffer name or number. For the accepted
6465 values, see |bufname()|. When {buf} is omitted the current
6466 buffer is used.
6467 Returns a unique ID that can be passed to |listener_remove()|.
6468
6469 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006470 bufnr the buffer that was changed
6471 start first changed line number
6472 end first line number below the change
6473 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006474 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006475 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006476
6477 Example: >
6478 func Listener(bufnr, start, end, added, changes)
6479 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6480 endfunc
6481 call listener_add('Listener', bufnr)
6482
Bram Moolenaar944697a2022-02-20 19:48:20 +00006483< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006484 dictionary with these entries:
6485 lnum the first line number of the change
6486 end the first line below the change
6487 added number of lines added; negative if lines were
6488 deleted
6489 col first column in "lnum" that was affected by
6490 the change; one if unknown or the whole line
6491 was affected; this is a byte index, first
6492 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006493 When lines are inserted (not when a line is split, e.g. by
6494 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006495 lnum line above which the new line is added
6496 end equal to "lnum"
6497 added number of lines inserted
6498 col 1
6499 When lines are deleted the values are:
6500 lnum the first deleted line
6501 end the line below the first deleted line, before
6502 the deletion was done
6503 added negative, number of lines deleted
6504 col 1
6505 When lines are changed:
6506 lnum the first changed line
6507 end the line below the last changed line
6508 added 0
6509 col first column with a change or 1
6510
6511 The entries are in the order the changes were made, thus the
6512 most recent change is at the end. The line numbers are valid
6513 when the callback is invoked, but later changes may make them
6514 invalid, thus keeping a copy for later might not work.
6515
6516 The {callback} is invoked just before the screen is updated,
6517 when |listener_flush()| is called or when a change is being
6518 made that changes the line count in a way it causes a line
6519 number in the list of changes to become invalid.
6520
6521 The {callback} is invoked with the text locked, see
6522 |textlock|. If you do need to make changes to the buffer, use
6523 a timer to do this later |timer_start()|.
6524
6525 The {callback} is not invoked when the buffer is first loaded.
6526 Use the |BufReadPost| autocmd event to handle the initial text
6527 of a buffer.
6528 The {callback} is also not invoked when the buffer is
6529 unloaded, use the |BufUnload| autocmd event for that.
6530
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006531 Returns zero if {callback} or {buf} is invalid.
6532
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006533 Can also be used as a |method|, the base is passed as the
6534 second argument: >
6535 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006536<
6537 Return type: |Number|
6538
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006539
6540listener_flush([{buf}]) *listener_flush()*
6541 Invoke listener callbacks for buffer {buf}. If there are no
6542 pending changes then no callbacks are invoked.
6543
6544 {buf} refers to a buffer name or number. For the accepted
6545 values, see |bufname()|. When {buf} is omitted the current
6546 buffer is used.
6547
6548 Can also be used as a |method|: >
6549 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006550<
6551 Return type: |Number|
6552
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006553
6554listener_remove({id}) *listener_remove()*
6555 Remove a listener previously added with listener_add().
6556 Returns FALSE when {id} could not be found, TRUE when {id} was
6557 removed.
6558
6559 Can also be used as a |method|: >
6560 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006561<
6562 Return type: |Number|
6563
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006564
6565localtime() *localtime()*
6566 Return the current time, measured as seconds since 1st Jan
6567 1970. See also |strftime()|, |strptime()| and |getftime()|.
6568
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006569 Return type: |Number|
6570
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006571
6572log({expr}) *log()*
6573 Return the natural logarithm (base e) of {expr} as a |Float|.
6574 {expr} must evaluate to a |Float| or a |Number| in the range
6575 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006576 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006577 Examples: >
6578 :echo log(10)
6579< 2.302585 >
6580 :echo log(exp(5))
6581< 5.0
6582
6583 Can also be used as a |method|: >
6584 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006585<
6586 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006587
6588
6589log10({expr}) *log10()*
6590 Return the logarithm of Float {expr} to base 10 as a |Float|.
6591 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006592 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006593 Examples: >
6594 :echo log10(1000)
6595< 3.0 >
6596 :echo log10(0.01)
6597< -2.0
6598
6599 Can also be used as a |method|: >
6600 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006601<
6602 Return type: |Float|
6603
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006604
6605luaeval({expr} [, {expr}]) *luaeval()*
6606 Evaluate Lua expression {expr} and return its result converted
6607 to Vim data structures. Second {expr} may hold additional
6608 argument accessible as _A inside first {expr}.
6609 Strings are returned as they are.
6610 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006611 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006612 Dictionaries and lists obtained by vim.eval() are returned
6613 as-is.
6614 Other objects are returned as zero without any errors.
6615 See |lua-luaeval| for more details.
6616 Note that in a `:def` function local variables are not visible
6617 to {expr}.
6618
6619 Can also be used as a |method|: >
6620 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006621<
6622 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006623
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006624 {only available when compiled with the |+lua| feature}
6625
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006626
6627map({expr1}, {expr2}) *map()*
6628 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006629 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006630 item in {expr1} with the result of evaluating {expr2}.
6631 For a |Blob| each byte is replaced.
6632 For a |String|, each character, including composing
6633 characters, is replaced.
6634 If the item type changes you may want to use |mapnew()| to
6635 create a new List or Dictionary. This is required when using
6636 Vim9 script.
6637
6638 {expr2} must be a |String| or |Funcref|.
6639
6640 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6641 of the current item. For a |Dictionary| |v:key| has the key
6642 of the current item and for a |List| |v:key| has the index of
6643 the current item. For a |Blob| |v:key| has the index of the
6644 current byte. For a |String| |v:key| has the index of the
6645 current character.
6646 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006647 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006648< This puts "> " before and " <" after each item in "mylist".
6649
6650 Note that {expr2} is the result of an expression and is then
6651 used as an expression again. Often it is good to use a
6652 |literal-string| to avoid having to double backslashes. You
6653 still have to double ' quotes
6654
6655 If {expr2} is a |Funcref| it is called with two arguments:
6656 1. The key or the index of the current item.
6657 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006658 With a legacy script lambda you don't get an error if it only
6659 accepts one argument, but with a Vim9 lambda you get "E1106:
6660 One argument too many", the number of arguments must match.
6661
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006662 The function must return the new value of the item. Example
6663 that changes each value by "key-value": >
6664 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006665 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006666 endfunc
6667 call map(myDict, function('KeyValue'))
6668< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006669 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006670< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006671 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006672< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006673 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006674<
6675 The operation is done in-place for a |List| and |Dictionary|.
6676 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006677 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006678
6679< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6680 or a new |Blob| or |String|.
6681 When an error is encountered while evaluating {expr2} no
6682 further items in {expr1} are processed.
6683 When {expr2} is a Funcref errors inside a function are ignored,
6684 unless it was defined with the "abort" flag.
6685
6686 Can also be used as a |method|: >
6687 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006688<
6689 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6690 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006691
6692
6693maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6694 When {dict} is omitted or zero: Return the rhs of mapping
6695 {name} in mode {mode}. The returned String has special
6696 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006697 listing. When {dict} is TRUE a dictionary is returned, see
6698 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006699
6700 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006701 returned if {dict} is FALSE, otherwise returns an empty Dict.
6702 When the mapping for {name} is empty, then "<Nop>" is
6703 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006704
6705 The {name} can have special key names, like in the ":map"
6706 command.
6707
6708 {mode} can be one of these strings:
6709 "n" Normal
6710 "v" Visual (including Select)
6711 "o" Operator-pending
6712 "i" Insert
6713 "c" Cmd-line
6714 "s" Select
6715 "x" Visual
6716 "l" langmap |language-mapping|
6717 "t" Terminal-Job
6718 "" Normal, Visual and Operator-pending
6719 When {mode} is omitted, the modes for "" are used.
6720
6721 When {abbr} is there and it is |TRUE| use abbreviations
6722 instead of mappings.
6723
6724 When {dict} is there and it is |TRUE| return a dictionary
6725 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006726 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006727 "lhs" The {lhs} of the mapping as it would be typed
6728 "lhsraw" The {lhs} of the mapping as raw bytes
6729 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6730 form, only present when it differs from "lhsraw"
6731 "rhs" The {rhs} of the mapping as typed.
6732 "silent" 1 for a |:map-silent| mapping, else 0.
6733 "noremap" 1 if the {rhs} of the mapping is not remappable.
6734 "script" 1 if mapping was defined with <script>.
6735 "expr" 1 for an expression mapping (|:map-<expr>|).
6736 "buffer" 1 for a buffer local mapping (|:map-local|).
6737 "mode" Modes for which the mapping is defined. In
6738 addition to the modes mentioned above, these
6739 characters will be used:
6740 " " Normal, Visual and Operator-pending
6741 "!" Insert and Commandline mode
6742 (|mapmode-ic|)
6743 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006744 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006745 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006746 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006747 "lnum" The line number in "sid", zero if unknown.
6748 "nowait" Do not wait for other, longer mappings.
6749 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006750 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006751 "mode_bits" Vim's internal binary representation of "mode".
6752 |mapset()| ignores this; only "mode" is used.
6753 See |maplist()| for usage examples. The values
6754 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006755
6756 The dictionary can be used to restore a mapping with
6757 |mapset()|.
6758
6759 The mappings local to the current buffer are checked first,
6760 then the global mappings.
6761 This function can be used to map a key even when it's already
6762 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006763 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006764
6765< Can also be used as a |method|: >
6766 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006767<
6768 Return type: |String| or dict<any> depending on {dict}
6769
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006770
6771mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6772 Check if there is a mapping that matches with {name} in mode
6773 {mode}. See |maparg()| for {mode} and special names in
6774 {name}.
6775 When {abbr} is there and it is |TRUE| use abbreviations
6776 instead of mappings.
6777 A match happens with a mapping that starts with {name} and
6778 with a mapping which is equal to the start of {name}.
6779
6780 matches mapping "a" "ab" "abc" ~
6781 mapcheck("a") yes yes yes
6782 mapcheck("abc") yes yes yes
6783 mapcheck("ax") yes no no
6784 mapcheck("b") no no no
6785
6786 The difference with maparg() is that mapcheck() finds a
6787 mapping that matches with {name}, while maparg() only finds a
6788 mapping for {name} exactly.
6789 When there is no mapping that starts with {name}, an empty
6790 String is returned. If there is one, the RHS of that mapping
6791 is returned. If there are several mappings that start with
6792 {name}, the RHS of one of them is returned. This will be
6793 "<Nop>" if the RHS is empty.
6794 The mappings local to the current buffer are checked first,
6795 then the global mappings.
6796 This function can be used to check if a mapping can be added
6797 without being ambiguous. Example: >
6798 :if mapcheck("_vv") == ""
6799 : map _vv :set guifont=7x13<CR>
6800 :endif
6801< This avoids adding the "_vv" mapping when there already is a
6802 mapping for "_v" or for "_vvv".
6803
6804 Can also be used as a |method|: >
6805 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006806<
6807 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006808
6809
Ernie Rael09661202022-04-25 14:40:44 +01006810maplist([{abbr}]) *maplist()*
6811 Returns a |List| of all mappings. Each List item is a |Dict|,
6812 the same as what is returned by |maparg()|, see
6813 |mapping-dict|. When {abbr} is there and it is |TRUE| use
6814 abbreviations instead of mappings.
6815
6816 Example to show all mappings with 'MultiMatch' in rhs: >
6817 vim9script
6818 echo maplist()->filter(
6819 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01006820< It can be tricky to find mappings for particular |:map-modes|.
6821 |mapping-dict|'s "mode_bits" can simplify this. For example,
6822 the mode_bits for Normal, Insert or Command-line modes are
6823 0x19. To find all the mappings available in those modes you
6824 can do: >
6825 vim9script
6826 var saved_maps = []
6827 for m in maplist()
6828 if and(m.mode_bits, 0x19) != 0
6829 saved_maps->add(m)
6830 endif
6831 endfor
6832 echo saved_maps->mapnew((_, m) => m.lhs)
6833< The values of the mode_bits are defined in Vim's src/vim.h
6834 file and they can be discovered at runtime using
6835 |:map-commands| and "maplist()". Example: >
6836 vim9script
6837 omap xyzzy <Nop>
6838 var op_bit = maplist()->filter(
6839 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
6840 ounmap xyzzy
6841 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006842<
6843 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01006844
6845
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006846mapnew({expr1}, {expr2}) *mapnew()*
6847 Like |map()| but instead of replacing items in {expr1} a new
6848 List or Dictionary is created and returned. {expr1} remains
6849 unchanged. Items can still be changed by {expr2}, if you
6850 don't want that use |deepcopy()| first.
6851
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006852 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6853 depending on {expr1}
6854
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006855
6856mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01006857mapset({dict})
6858 Restore a mapping from a dictionary, possibly returned by
6859 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
6860 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006861 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01006862 feature allows copying mappings from one buffer to another.
6863 The dict.mode value may restore a single mapping that covers
6864 more than one mode, like with mode values of '!', ' ', 'nox',
6865 or 'v'. *E1276*
6866
6867 In the first form, {mode} and {abbr} should be the same as
6868 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006869 {mode} is used to define the mode in which the mapping is set,
6870 not the "mode" entry in {dict}.
6871 Example for saving and restoring a mapping: >
6872 let save_map = maparg('K', 'n', 0, 1)
6873 nnoremap K somethingelse
6874 ...
6875 call mapset('n', 0, save_map)
6876< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01006877 e.g. with `:map!`, you need to save/restore the mapping for
6878 all of them, when they might differ.
6879
6880 In the second form, with {dict} as the only argument, mode
6881 and abbr are taken from the dict.
6882 Example: >
6883 vim9script
6884 var save_maps = maplist()->filter(
6885 (_, m) => m.lhs == 'K')
6886 nnoremap K somethingelse
6887 cnoremap K somethingelse2
6888 # ...
6889 unmap K
6890 for d in save_maps
6891 mapset(d)
6892 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006893<
6894 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006895
6896
6897match({expr}, {pat} [, {start} [, {count}]]) *match()*
6898 When {expr} is a |List| then this returns the index of the
6899 first item where {pat} matches. Each item is used as a
6900 String, |Lists| and |Dictionaries| are used as echoed.
6901
6902 Otherwise, {expr} is used as a String. The result is a
6903 Number, which gives the index (byte offset) in {expr} where
6904 {pat} matches.
6905
6906 A match at the first character or |List| item returns zero.
6907 If there is no match -1 is returned.
6908
6909 For getting submatches see |matchlist()|.
6910 Example: >
6911 :echo match("testing", "ing") " results in 4
6912 :echo match([1, 'x'], '\a') " results in 1
6913< See |string-match| for how {pat} is used.
6914 *strpbrk()*
6915 Vim doesn't have a strpbrk() function. But you can do: >
6916 :let sepidx = match(line, '[.,;: \t]')
6917< *strcasestr()*
6918 Vim doesn't have a strcasestr() function. But you can add
6919 "\c" to the pattern to ignore case: >
6920 :let idx = match(haystack, '\cneedle')
6921<
6922 If {start} is given, the search starts from byte index
6923 {start} in a String or item {start} in a |List|.
6924 The result, however, is still the index counted from the
6925 first character/item. Example: >
6926 :echo match("testing", "ing", 2)
6927< result is again "4". >
6928 :echo match("testing", "ing", 4)
6929< result is again "4". >
6930 :echo match("testing", "t", 2)
6931< result is "3".
6932 For a String, if {start} > 0 then it is like the string starts
6933 {start} bytes later, thus "^" will match at {start}. Except
6934 when {count} is given, then it's like matches before the
6935 {start} byte are ignored (this is a bit complicated to keep it
6936 backwards compatible).
6937 For a String, if {start} < 0, it will be set to 0. For a list
6938 the index is counted from the end.
6939 If {start} is out of range ({start} > strlen({expr}) for a
6940 String or {start} > len({expr}) for a |List|) -1 is returned.
6941
6942 When {count} is given use the {count}'th match. When a match
6943 is found in a String the search for the next one starts one
6944 character further. Thus this example results in 1: >
6945 echo match("testing", "..", 0, 2)
6946< In a |List| the search continues in the next item.
6947 Note that when {count} is added the way {start} works changes,
6948 see above.
6949
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01006950 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006951 See |pattern| for the patterns that are accepted.
6952 The 'ignorecase' option is used to set the ignore-caseness of
6953 the pattern. 'smartcase' is NOT used. The matching is always
6954 done like 'magic' is set and 'cpoptions' is empty.
6955 Note that a match at the start is preferred, thus when the
6956 pattern is using "*" (any number of matches) it tends to find
6957 zero matches at the start instead of a number of matches
6958 further down in the text.
6959
6960 Can also be used as a |method|: >
6961 GetText()->match('word')
6962 GetList()->match('word')
6963<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006964 Return type: |Number|
6965
6966
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006967 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006968matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
6969 Defines a pattern to be highlighted in the current window (a
6970 "match"). It will be highlighted with {group}. Returns an
6971 identification number (ID), which can be used to delete the
6972 match using |matchdelete()|. The ID is bound to the window.
6973 Matching is case sensitive and magic, unless case sensitivity
6974 or magicness are explicitly overridden in {pattern}. The
6975 'magic', 'smartcase' and 'ignorecase' options are not used.
6976 The "Conceal" value is special, it causes the match to be
6977 concealed.
6978
6979 The optional {priority} argument assigns a priority to the
6980 match. A match with a high priority will have its
6981 highlighting overrule that of a match with a lower priority.
6982 A priority is specified as an integer (negative numbers are no
6983 exception). If the {priority} argument is not specified, the
6984 default priority is 10. The priority of 'hlsearch' is zero,
6985 hence all matches with a priority greater than zero will
6986 overrule it. Syntax highlighting (see 'syntax') is a separate
6987 mechanism, and regardless of the chosen priority a match will
6988 always overrule syntax highlighting.
6989
6990 The optional {id} argument allows the request for a specific
6991 match ID. If a specified ID is already taken, an error
6992 message will appear and the match will not be added. An ID
6993 is specified as a positive integer (zero excluded). IDs 1, 2
6994 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01006995 respectively. 3 is reserved for use by the |matchparen|
6996 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01006997 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01006998 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006999
7000 The optional {dict} argument allows for further custom
7001 values. Currently this is used to specify a match specific
7002 conceal character that will be shown for |hl-Conceal|
7003 highlighted matches. The dict can have the following members:
7004
7005 conceal Special character to show instead of the
7006 match (only for |hl-Conceal| highlighted
7007 matches, see |:syn-cchar|)
7008 window Instead of the current window use the
7009 window with this number or window ID.
7010
7011 The number of matches is not limited, as it is the case with
7012 the |:match| commands.
7013
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007014 Returns -1 on error.
7015
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007016 Example: >
7017 :highlight MyGroup ctermbg=green guibg=green
7018 :let m = matchadd("MyGroup", "TODO")
7019< Deletion of the pattern: >
7020 :call matchdelete(m)
7021
7022< A list of matches defined by |matchadd()| and |:match| are
7023 available from |getmatches()|. All matches can be deleted in
7024 one operation by |clearmatches()|.
7025
7026 Can also be used as a |method|: >
7027 GetGroup()->matchadd('TODO')
7028<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007029 Return type: |Number|
7030
7031
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007032 *matchaddpos()*
7033matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
7034 Same as |matchadd()|, but requires a list of positions {pos}
7035 instead of a pattern. This command is faster than |matchadd()|
Shane Harperc1b39842024-07-17 19:40:40 +02007036 because it does not handle regular expressions and it sets
7037 buffer line boundaries to redraw screen. It is supposed to be
7038 used when fast match additions and deletions are required, for
7039 example to highlight matching parentheses.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007040
7041 {pos} is a list of positions. Each position can be one of
7042 these:
7043 - A number. This whole line will be highlighted. The first
7044 line has number 1.
7045 - A list with one number, e.g., [23]. The whole line with this
7046 number will be highlighted.
7047 - A list with two numbers, e.g., [23, 11]. The first number is
7048 the line number, the second one is the column number (first
7049 column is 1, the value must correspond to the byte index as
7050 |col()| would return). The character at this position will
7051 be highlighted.
7052 - A list with three numbers, e.g., [23, 11, 3]. As above, but
7053 the third number gives the length of the highlight in bytes.
7054
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007055 Returns -1 on error.
7056
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007057 Example: >
7058 :highlight MyGroup ctermbg=green guibg=green
7059 :let m = matchaddpos("MyGroup", [[23, 24], 34])
7060< Deletion of the pattern: >
7061 :call matchdelete(m)
7062
7063< Matches added by |matchaddpos()| are returned by
7064 |getmatches()|.
7065
7066 Can also be used as a |method|: >
7067 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007068<
7069 Return type: |Number|
7070
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007071
7072matcharg({nr}) *matcharg()*
7073 Selects the {nr} match item, as set with a |:match|,
7074 |:2match| or |:3match| command.
7075 Return a |List| with two elements:
7076 The name of the highlight group used
7077 The pattern used.
7078 When {nr} is not 1, 2 or 3 returns an empty |List|.
7079 When there is no match item set returns ['', ''].
7080 This is useful to save and restore a |:match|.
7081 Highlighting matches using the |:match| commands are limited
7082 to three matches. |matchadd()| does not have this limitation.
7083
7084 Can also be used as a |method|: >
7085 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007086<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007087 Return type: list<string>
7088
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007089 *matchbufline()*
7090matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
7091 Returns the |List| of matches in lines from {lnum} to {end} in
7092 buffer {buf} where {pat} matches.
7093
7094 {lnum} and {end} can either be a line number or the string "$"
7095 to refer to the last line in {buf}.
7096
7097 The {dict} argument supports following items:
7098 submatches include submatch information (|/\(|)
7099
7100 For each match, a |Dict| with the following items is returned:
7101 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007102 lnum line number where there is a match
7103 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007104 Note that there can be multiple matches in a single line.
7105
7106 This function works only for loaded buffers. First call
7107 |bufload()| if needed.
7108
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007109 See |match-pattern| for information about the effect of some
7110 option settings on the pattern.
7111
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007112 When {buf} is not a valid buffer, the buffer is not loaded or
7113 {lnum} or {end} is not valid then an error is given and an
7114 empty |List| is returned.
7115
7116 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007117 " Assuming line 3 in buffer 5 contains "a"
7118 :echo matchbufline(5, '\<\k\+\>', 3, 3)
7119 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
7120 " Assuming line 4 in buffer 10 contains "tik tok"
7121 :echo matchbufline(10, '\<\k\+\>', 1, 4)
7122 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007123<
7124 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007125 "\1", "\2", etc. are also returned. Example: >
7126 " Assuming line 2 in buffer 2 contains "acd"
7127 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007128 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007129 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007130< The "submatches" List always contains 9 items. If a submatch
7131 is not found, then an empty string is returned for that
7132 submatch.
7133
7134 Can also be used as a |method|: >
7135 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007136<
7137 Return type: list<dict<any>> or list<any>
7138
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007139
h-east624bb832024-11-09 18:37:32 +01007140matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007141 Deletes a match with ID {id} previously defined by |matchadd()|
7142 or one of the |:match| commands. Returns 0 if successful,
7143 otherwise -1. See example for |matchadd()|. All matches can
7144 be deleted in one operation by |clearmatches()|.
7145 If {win} is specified, use the window with this number or
7146 window ID instead of the current window.
7147
7148 Can also be used as a |method|: >
7149 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007150<
7151 Return type: |Number|
7152
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007153
7154matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
7155 Same as |match()|, but return the index of first character
7156 after the match. Example: >
7157 :echo matchend("testing", "ing")
7158< results in "7".
7159 *strspn()* *strcspn()*
7160 Vim doesn't have a strspn() or strcspn() function, but you can
7161 do it with matchend(): >
7162 :let span = matchend(line, '[a-zA-Z]')
7163 :let span = matchend(line, '[^a-zA-Z]')
7164< Except that -1 is returned when there are no matches.
7165
7166 The {start}, if given, has the same meaning as for |match()|. >
7167 :echo matchend("testing", "ing", 2)
7168< results in "7". >
7169 :echo matchend("testing", "ing", 5)
7170< result is "-1".
7171 When {expr} is a |List| the result is equal to |match()|.
7172
7173 Can also be used as a |method|: >
7174 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007175<
7176 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007177
7178
7179matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7180 If {list} is a list of strings, then returns a |List| with all
7181 the strings in {list} that fuzzy match {str}. The strings in
7182 the returned list are sorted based on the matching score.
7183
7184 The optional {dict} argument always supports the following
7185 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007186 matchseq When this item is present return only matches
7187 that contain the characters in {str} in the
7188 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007189 limit Maximum number of matches in {list} to be
7190 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007191
7192 If {list} is a list of dictionaries, then the optional {dict}
7193 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007194 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007195 {str}. The value of this item should be a
7196 string.
7197 text_cb |Funcref| that will be called for every item
7198 in {list} to get the text for fuzzy matching.
7199 This should accept a dictionary item as the
7200 argument and return the text for that item to
7201 use for fuzzy matching.
7202
7203 {str} is treated as a literal string and regular expression
7204 matching is NOT supported. The maximum supported {str} length
7205 is 256.
7206
7207 When {str} has multiple words each separated by white space,
7208 then the list of strings that have all the words is returned.
7209
7210 If there are no matching strings or there is an error, then an
7211 empty list is returned. If length of {str} is greater than
7212 256, then returns an empty list.
7213
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007214 When {limit} is given, matchfuzzy() will find up to this
7215 number of matches in {list} and return them in sorted order.
7216
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007217 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007218 matching strings.
7219
7220 Example: >
7221 :echo matchfuzzy(["clay", "crow"], "cay")
7222< results in ["clay"]. >
7223 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7224< results in a list of buffer names fuzzy matching "ndl". >
7225 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7226< results in a list of buffer information dicts with buffer
7227 names fuzzy matching "ndl". >
7228 :echo getbufinfo()->matchfuzzy("spl",
7229 \ {'text_cb' : {v -> v.name}})
7230< results in a list of buffer information dicts with buffer
7231 names fuzzy matching "spl". >
7232 :echo v:oldfiles->matchfuzzy("test")
7233< results in a list of file names fuzzy matching "test". >
7234 :let l = readfile("buffer.c")->matchfuzzy("str")
7235< results in a list of lines in "buffer.c" fuzzy matching "str". >
7236 :echo ['one two', 'two one']->matchfuzzy('two one')
7237< results in ['two one', 'one two']. >
7238 :echo ['one two', 'two one']->matchfuzzy('two one',
7239 \ {'matchseq': 1})
7240< results in ['two one'].
7241
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007242 Return type: list<string> or list<any>
7243
7244
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007245matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7246 Same as |matchfuzzy()|, but returns the list of matched
7247 strings, the list of character positions where characters
7248 in {str} matches and a list of matching scores. You can
7249 use |byteidx()| to convert a character position to a byte
7250 position.
7251
7252 If {str} matches multiple times in a string, then only the
7253 positions for the best match is returned.
7254
7255 If there are no matching strings or there is an error, then a
7256 list with three empty list items is returned.
7257
7258 Example: >
7259 :echo matchfuzzypos(['testing'], 'tsg')
7260< results in [['testing'], [[0, 2, 6]], [99]] >
7261 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7262< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7263 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7264< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7265
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007266 Return type: list<list<any>>
7267
7268
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007269matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7270 Same as |match()|, but return a |List|. The first item in the
7271 list is the matched string, same as what matchstr() would
7272 return. Following items are submatches, like "\1", "\2", etc.
7273 in |:substitute|. When an optional submatch didn't match an
7274 empty string is used. Example: >
7275 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7276< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7277 When there is no match an empty list is returned.
7278
7279 You can pass in a List, but that is not very useful.
7280
7281 Can also be used as a |method|: >
7282 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007283<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007284 Return type: list<string> or list<any>
7285
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007286 *matchstrlist()*
7287matchstrlist({list}, {pat} [, {dict}])
7288 Returns the |List| of matches in {list} where {pat} matches.
7289 {list} is a |List| of strings. {pat} is matched against each
7290 string in {list}.
7291
7292 The {dict} argument supports following items:
7293 submatches include submatch information (|/\(|)
7294
7295 For each match, a |Dict| with the following items is returned:
7296 byteidx starting byte index of the match.
7297 idx index in {list} of the match.
7298 text matched string
7299 submatches a List of submatches. Present only if
7300 "submatches" is set to v:true in {dict}.
7301
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007302 See |match-pattern| for information about the effect of some
7303 option settings on the pattern.
7304
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007305 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007306 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7307 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7308 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7309 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007310<
7311 If "submatches" is present and is v:true, then submatches like
7312 "\1", "\2", etc. are also returned. Example: >
7313 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7314 \ #{submatches: v:true})
7315 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7316< The "submatches" List always contains 9 items. If a submatch
7317 is not found, then an empty string is returned for that
7318 submatch.
7319
7320 Can also be used as a |method|: >
7321 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007322<
7323 Return type: list<dict<any>> or list<any>
7324
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007325
7326matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7327 Same as |match()|, but return the matched string. Example: >
7328 :echo matchstr("testing", "ing")
7329< results in "ing".
7330 When there is no match "" is returned.
7331 The {start}, if given, has the same meaning as for |match()|. >
7332 :echo matchstr("testing", "ing", 2)
7333< results in "ing". >
7334 :echo matchstr("testing", "ing", 5)
7335< result is "".
7336 When {expr} is a |List| then the matching item is returned.
7337 The type isn't changed, it's not necessarily a String.
7338
7339 Can also be used as a |method|: >
7340 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007341<
7342 Return type: |String|
7343
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007344
7345matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7346 Same as |matchstr()|, but return the matched string, the start
7347 position and the end position of the match. Example: >
7348 :echo matchstrpos("testing", "ing")
7349< results in ["ing", 4, 7].
7350 When there is no match ["", -1, -1] is returned.
7351 The {start}, if given, has the same meaning as for |match()|. >
7352 :echo matchstrpos("testing", "ing", 2)
7353< results in ["ing", 4, 7]. >
7354 :echo matchstrpos("testing", "ing", 5)
7355< result is ["", -1, -1].
7356 When {expr} is a |List| then the matching item, the index
7357 of first item where {pat} matches, the start position and the
7358 end position of the match are returned. >
7359 :echo matchstrpos([1, '__x'], '\a')
7360< result is ["x", 1, 2, 3].
7361 The type isn't changed, it's not necessarily a String.
7362
7363 Can also be used as a |method|: >
7364 GetText()->matchstrpos('word')
7365<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007366 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007367
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007368
7369max({expr}) *max()*
7370 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007371 echo max([apples, pears, oranges])
7372
7373< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7374 it returns the maximum of all values in the Dictionary.
7375 If {expr} is neither a List nor a Dictionary, or one of the
7376 items in {expr} cannot be used as a Number this results in
7377 an error. An empty |List| or |Dictionary| results in zero.
7378
7379 Can also be used as a |method|: >
7380 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007381<
7382 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007383
7384
7385menu_info({name} [, {mode}]) *menu_info()*
7386 Return information about the specified menu {name} in
7387 mode {mode}. The menu name should be specified without the
7388 shortcut character ('&'). If {name} is "", then the top-level
7389 menu names are returned.
7390
7391 {mode} can be one of these strings:
7392 "n" Normal
7393 "v" Visual (including Select)
7394 "o" Operator-pending
7395 "i" Insert
7396 "c" Cmd-line
7397 "s" Select
7398 "x" Visual
7399 "t" Terminal-Job
7400 "" Normal, Visual and Operator-pending
7401 "!" Insert and Cmd-line
7402 When {mode} is omitted, the modes for "" are used.
7403
7404 Returns a |Dictionary| containing the following items:
7405 accel menu item accelerator text |menu-text|
7406 display display name (name without '&')
7407 enabled v:true if this menu item is enabled
7408 Refer to |:menu-enable|
7409 icon name of the icon file (for toolbar)
7410 |toolbar-icon|
7411 iconidx index of a built-in icon
7412 modes modes for which the menu is defined. In
7413 addition to the modes mentioned above, these
7414 characters will be used:
7415 " " Normal, Visual and Operator-pending
7416 name menu item name.
7417 noremenu v:true if the {rhs} of the menu item is not
7418 remappable else v:false.
7419 priority menu order priority |menu-priority|
7420 rhs right-hand-side of the menu item. The returned
7421 string has special characters translated like
7422 in the output of the ":menu" command listing.
7423 When the {rhs} of a menu item is empty, then
7424 "<Nop>" is returned.
7425 script v:true if script-local remapping of {rhs} is
7426 allowed else v:false. See |:menu-script|.
7427 shortcut shortcut key (character after '&' in
7428 the menu name) |menu-shortcut|
7429 silent v:true if the menu item is created
7430 with <silent> argument |:menu-silent|
7431 submenus |List| containing the names of
7432 all the submenus. Present only if the menu
7433 item has submenus.
7434
7435 Returns an empty dictionary if the menu item is not found.
7436
7437 Examples: >
7438 :echo menu_info('Edit.Cut')
7439 :echo menu_info('File.Save', 'n')
7440
7441 " Display the entire menu hierarchy in a buffer
7442 func ShowMenu(name, pfx)
7443 let m = menu_info(a:name)
7444 call append(line('$'), a:pfx .. m.display)
7445 for child in m->get('submenus', [])
7446 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7447 \ a:pfx .. ' ')
7448 endfor
7449 endfunc
7450 new
7451 for topmenu in menu_info('').submenus
7452 call ShowMenu(topmenu, '')
7453 endfor
7454<
7455 Can also be used as a |method|: >
7456 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007457<
7458 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007459
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007460min({expr}) *min()*
7461 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007462 echo min([apples, pears, oranges])
7463
7464< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7465 it returns the minimum of all values in the Dictionary.
7466 If {expr} is neither a List nor a Dictionary, or one of the
7467 items in {expr} cannot be used as a Number this results in
7468 an error. An empty |List| or |Dictionary| results in zero.
7469
7470 Can also be used as a |method|: >
7471 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007472<
7473 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007474
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007475
7476mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007477 Create directory {name}.
7478
Bram Moolenaar938ae282023-02-20 20:44:55 +00007479 When {flags} is present it must be a string. An empty string
7480 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007481
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007482 {flags} can contain these character flags:
7483 "p" intermediate directories will be created as necessary
7484 "D" {name} will be deleted at the end of the current
Christian Brabandtc509c002024-06-14 20:22:05 +02007485 function, but not recursively |:defer|
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007486 "R" {name} will be deleted recursively at the end of the
Christian Brabandtc509c002024-06-14 20:22:05 +02007487 current function |:defer|
Bram Moolenaar938ae282023-02-20 20:44:55 +00007488
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007489 Note that when {name} has more than one part and "p" is used
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007490 some directories may already exist. Only the first one that
7491 is created and what it contains is scheduled to be deleted.
7492 E.g. when using: >
7493 call mkdir('subdir/tmp/autoload', 'pR')
7494< and "subdir" already exists then "subdir/tmp" will be
7495 scheduled for deletion, like with: >
7496 defer delete('subdir/tmp', 'rf')
7497< Note that if scheduling the defer fails the directory is not
7498 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007499
7500 If {prot} is given it is used to set the protection bits of
7501 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7502 the user, readable for others). Use 0o700 to make it
7503 unreadable for others. This is only used for the last part of
7504 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
7505 created with 0o755.
7506 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007507 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007508
7509< This function is not available in the |sandbox|.
7510
7511 There is no error if the directory already exists and the "p"
7512 flag is passed (since patch 8.0.1708). However, without the
7513 "p" option the call will fail.
7514
7515 The function result is a Number, which is TRUE if the call was
7516 successful or FALSE if the directory creation failed or partly
7517 failed.
7518
7519 Not available on all systems. To check use: >
7520 :if exists("*mkdir")
7521
7522< Can also be used as a |method|: >
7523 GetName()->mkdir()
7524<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007525 Return type: |Number|
7526
7527
7528mode([{expr}]) *mode()*
7529 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007530 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007531 a non-empty String (|non-zero-arg|), then the full mode is
7532 returned, otherwise only the first letter is returned.
7533 Also see |state()|.
7534
7535 n Normal
7536 no Operator-pending
7537 nov Operator-pending (forced characterwise |o_v|)
7538 noV Operator-pending (forced linewise |o_V|)
7539 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7540 CTRL-V is one character
7541 niI Normal using |i_CTRL-O| in |Insert-mode|
7542 niR Normal using |i_CTRL-O| in |Replace-mode|
7543 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7544 nt Terminal-Normal (insert goes to Terminal-Job mode)
7545 v Visual by character
7546 vs Visual by character using |v_CTRL-O| in Select mode
7547 V Visual by line
7548 Vs Visual by line using |v_CTRL-O| in Select mode
7549 CTRL-V Visual blockwise
7550 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7551 s Select by character
7552 S Select by line
7553 CTRL-S Select blockwise
7554 i Insert
7555 ic Insert mode completion |compl-generic|
7556 ix Insert mode |i_CTRL-X| completion
7557 R Replace |R|
7558 Rc Replace mode completion |compl-generic|
7559 Rx Replace mode |i_CTRL-X| completion
7560 Rv Virtual Replace |gR|
7561 Rvc Virtual Replace mode completion |compl-generic|
7562 Rvx Virtual Replace mode |i_CTRL-X| completion
7563 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007564 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007565 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007566 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007567 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007568 ce Normal Ex mode |Q|
7569 r Hit-enter prompt
7570 rm The -- more -- prompt
7571 r? A |:confirm| query of some sort
7572 ! Shell or external command is executing
7573 t Terminal-Job mode: keys go to the job
7574
7575 This is useful in the 'statusline' option or when used
7576 with |remote_expr()| In most other places it always returns
7577 "c" or "n".
7578 Note that in the future more modes and more specific modes may
7579 be added. It's better not to compare the whole string but only
7580 the leading character(s).
7581 Also see |visualmode()|.
7582
7583 Can also be used as a |method|: >
7584 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007585<
7586 Return type: |String|
7587
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007588
7589mzeval({expr}) *mzeval()*
7590 Evaluate MzScheme expression {expr} and return its result
7591 converted to Vim data structures.
7592 Numbers and strings are returned as they are.
7593 Pairs (including lists and improper lists) and vectors are
7594 returned as Vim |Lists|.
7595 Hash tables are represented as Vim |Dictionary| type with keys
7596 converted to strings.
7597 All other types are converted to string with display function.
7598 Examples: >
7599 :mz (define l (list 1 2 3))
7600 :mz (define h (make-hash)) (hash-set! h "list" l)
7601 :echo mzeval("l")
7602 :echo mzeval("h")
7603<
7604 Note that in a `:def` function local variables are not visible
7605 to {expr}.
7606
7607 Can also be used as a |method|: >
7608 GetExpr()->mzeval()
7609<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007610 Return type: any, depending on {expr}
7611
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007612 {only available when compiled with the |+mzscheme| feature}
7613
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007614
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007615nextnonblank({lnum}) *nextnonblank()*
7616 Return the line number of the first line at or below {lnum}
7617 that is not blank. Example: >
7618 if getline(nextnonblank(1)) =~ "Java"
7619< When {lnum} is invalid or there is no non-blank line at or
7620 below it, zero is returned.
7621 {lnum} is used like with |getline()|.
7622 See also |prevnonblank()|.
7623
7624 Can also be used as a |method|: >
7625 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007626<
7627 Return type: |Number|
7628
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007629
7630nr2char({expr} [, {utf8}]) *nr2char()*
7631 Return a string with a single character, which has the number
7632 value {expr}. Examples: >
7633 nr2char(64) returns "@"
7634 nr2char(32) returns " "
7635< When {utf8} is omitted or zero, the current 'encoding' is used.
7636 Example for "utf-8": >
7637 nr2char(300) returns I with bow character
7638< When {utf8} is TRUE, always return UTF-8 characters.
7639 Note that a NUL character in the file is specified with
7640 nr2char(10), because NULs are represented with newline
7641 characters. nr2char(0) is a real NUL and terminates the
7642 string, thus results in an empty string.
7643 To turn a list of character numbers into a string: >
7644 let list = [65, 66, 67]
7645 let str = join(map(list, {_, val -> nr2char(val)}), '')
7646< Result: "ABC"
7647
7648 Can also be used as a |method|: >
7649 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007650<
7651 Return type: |String|
7652
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007653
7654or({expr}, {expr}) *or()*
7655 Bitwise OR on the two arguments. The arguments are converted
7656 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007657 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007658 Example: >
7659 :let bits = or(bits, 0x80)
7660< Can also be used as a |method|: >
7661 :let bits = bits->or(0x80)
7662
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007663< Rationale: The reason this is a function and not using the "|"
7664 character like many languages, is that Vi has always used "|"
7665 to separate commands. In many places it would not be clear if
7666 "|" is an operator or a command separator.
7667
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007668 Return type: |Number|
7669
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007670
7671pathshorten({path} [, {len}]) *pathshorten()*
7672 Shorten directory names in the path {path} and return the
7673 result. The tail, the file name, is kept as-is. The other
7674 components in the path are reduced to {len} letters in length.
7675 If {len} is omitted or smaller than 1 then 1 is used (single
7676 letters). Leading '~' and '.' characters are kept. Examples: >
7677 :echo pathshorten('~/.vim/autoload/myfile.vim')
7678< ~/.v/a/myfile.vim ~
7679>
7680 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7681< ~/.vi/au/myfile.vim ~
7682 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007683 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007684
7685 Can also be used as a |method|: >
7686 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007687<
7688 Return type: |String|
7689
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007690
7691perleval({expr}) *perleval()*
7692 Evaluate Perl expression {expr} in scalar context and return
7693 its result converted to Vim data structures. If value can't be
7694 converted, it is returned as a string Perl representation.
7695 Note: If you want an array or hash, {expr} must return a
7696 reference to it.
7697 Example: >
7698 :echo perleval('[1 .. 4]')
7699< [1, 2, 3, 4]
7700
7701 Note that in a `:def` function local variables are not visible
7702 to {expr}.
7703
7704 Can also be used as a |method|: >
7705 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007706<
7707 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007708
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007709 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007710
7711
7712popup_ functions are documented here: |popup-functions|
7713
7714
7715pow({x}, {y}) *pow()*
7716 Return the power of {x} to the exponent {y} as a |Float|.
7717 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007718 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007719 Examples: >
7720 :echo pow(3, 3)
7721< 27.0 >
7722 :echo pow(2, 16)
7723< 65536.0 >
7724 :echo pow(32, 0.20)
7725< 2.0
7726
7727 Can also be used as a |method|: >
7728 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007729<
7730 Return type: |Number|
7731
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007732
7733prevnonblank({lnum}) *prevnonblank()*
7734 Return the line number of the first line at or above {lnum}
7735 that is not blank. Example: >
7736 let ind = indent(prevnonblank(v:lnum - 1))
7737< When {lnum} is invalid or there is no non-blank line at or
7738 above it, zero is returned.
7739 {lnum} is used like with |getline()|.
7740 Also see |nextnonblank()|.
7741
7742 Can also be used as a |method|: >
7743 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007744<
7745 Return type: |Number|
7746
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007747
7748printf({fmt}, {expr1} ...) *printf()*
7749 Return a String with {fmt}, where "%" items are replaced by
7750 the formatted form of their respective arguments. Example: >
7751 printf("%4d: E%d %.30s", lnum, errno, msg)
7752< May result in:
7753 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7754
7755 When used as a |method| the base is passed as the second
7756 argument: >
7757 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007758<
7759 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007760
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007761 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007762 %s string
7763 %6S string right-aligned in 6 display cells
7764 %6s string right-aligned in 6 bytes
7765 %.9s string truncated to 9 bytes
7766 %c single byte
7767 %d decimal number
7768 %5d decimal number padded with spaces to 5 characters
7769 %x hex number
7770 %04x hex number padded with zeros to at least 4 characters
7771 %X hex number using upper case letters
7772 %o octal number
7773 %08b binary number padded with zeros to at least 8 chars
7774 %f floating point number as 12.23, inf, -inf or nan
7775 %F floating point number as 12.23, INF, -INF or NAN
7776 %e floating point number as 1.23e3, inf, -inf or nan
7777 %E floating point number as 1.23E3, INF, -INF or NAN
7778 %g floating point number, as %f or %e depending on value
7779 %G floating point number, as %F or %E depending on value
7780 %% the % character itself
7781
7782 Conversion specifications start with '%' and end with the
7783 conversion type. All other characters are copied unchanged to
7784 the result.
7785
7786 The "%" starts a conversion specification. The following
7787 arguments appear in sequence:
7788
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007789 % [pos-argument] [flags] [field-width] [.precision] type
7790
7791 pos-argument
7792 At most one positional argument specifier. These
7793 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007794
7795 flags
7796 Zero or more of the following flags:
7797
7798 # The value should be converted to an "alternate
7799 form". For c, d, and s conversions, this option
7800 has no effect. For o conversions, the precision
7801 of the number is increased to force the first
7802 character of the output string to a zero (except
7803 if a zero value is printed with an explicit
7804 precision of zero).
7805 For b and B conversions, a non-zero result has
7806 the string "0b" (or "0B" for B conversions)
7807 prepended to it.
7808 For x and X conversions, a non-zero result has
7809 the string "0x" (or "0X" for X conversions)
7810 prepended to it.
7811
7812 0 (zero) Zero padding. For all conversions the converted
7813 value is padded on the left with zeros rather
7814 than blanks. If a precision is given with a
7815 numeric conversion (d, b, B, o, x, and X), the 0
7816 flag is ignored.
7817
7818 - A negative field width flag; the converted value
7819 is to be left adjusted on the field boundary.
7820 The converted value is padded on the right with
7821 blanks, rather than on the left with blanks or
7822 zeros. A - overrides a 0 if both are given.
7823
7824 ' ' (space) A blank should be left before a positive
7825 number produced by a signed conversion (d).
7826
7827 + A sign must always be placed before a number
7828 produced by a signed conversion. A + overrides
7829 a space if both are used.
7830
7831 field-width
7832 An optional decimal digit string specifying a minimum
7833 field width. If the converted value has fewer bytes
7834 than the field width, it will be padded with spaces on
7835 the left (or right, if the left-adjustment flag has
7836 been given) to fill out the field width. For the S
7837 conversion the count is in cells.
7838
7839 .precision
7840 An optional precision, in the form of a period '.'
7841 followed by an optional digit string. If the digit
7842 string is omitted, the precision is taken as zero.
7843 This gives the minimum number of digits to appear for
7844 d, o, x, and X conversions, the maximum number of
7845 bytes to be printed from a string for s conversions,
7846 or the maximum number of cells to be printed from a
7847 string for S conversions.
7848 For floating point it is the number of digits after
7849 the decimal point.
7850
7851 type
7852 A character that specifies the type of conversion to
7853 be applied, see below.
7854
7855 A field width or precision, or both, may be indicated by an
7856 asterisk '*' instead of a digit string. In this case, a
7857 Number argument supplies the field width or precision. A
7858 negative field width is treated as a left adjustment flag
7859 followed by a positive field width; a negative precision is
7860 treated as though it were missing. Example: >
7861 :echo printf("%d: %.*s", nr, width, line)
7862< This limits the length of the text used from "line" to
7863 "width" bytes.
7864
Dominique Pellé17dca3c2023-12-14 20:36:32 +01007865 If the argument to be formatted is specified using a
7866 positional argument specifier, and a '*' is used to indicate
7867 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007868 precision, the argument(s) to be used must also be specified
7869 using a {n$} positional argument specifier. See |printf-$|.
7870
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007871 The conversion specifiers and their meanings are:
7872
7873 *printf-d* *printf-b* *printf-B* *printf-o*
7874 *printf-x* *printf-X*
7875 dbBoxX The Number argument is converted to signed decimal
7876 (d), unsigned binary (b and B), unsigned octal (o), or
7877 unsigned hexadecimal (x and X) notation. The letters
7878 "abcdef" are used for x conversions; the letters
7879 "ABCDEF" are used for X conversions.
7880 The precision, if any, gives the minimum number of
7881 digits that must appear; if the converted value
7882 requires fewer digits, it is padded on the left with
7883 zeros.
7884 In no case does a non-existent or small field width
7885 cause truncation of a numeric field; if the result of
7886 a conversion is wider than the field width, the field
7887 is expanded to contain the conversion result.
7888 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02007889 The 'l' modifier indicates the argument is a long
7890 integer. The size will be 32 bits or 64 bits
7891 depending on your platform.
7892 The "ll" modifier indicates the argument is 64 bits.
7893 The b and B conversion specifiers never take a width
7894 modifier and always assume their argument is a 64 bit
7895 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007896 Generally, these modifiers are not useful. They are
7897 ignored when type is known from the argument.
7898
7899 i alias for d
7900 D alias for ld
7901 U alias for lu
7902 O alias for lo
7903
7904 *printf-c*
7905 c The Number argument is converted to a byte, and the
7906 resulting character is written.
7907
7908 *printf-s*
7909 s The text of the String argument is used. If a
7910 precision is specified, no more bytes than the number
7911 specified are used.
7912 If the argument is not a String type, it is
7913 automatically converted to text with the same format
7914 as ":echo".
7915 *printf-S*
7916 S The text of the String argument is used. If a
7917 precision is specified, no more display cells than the
7918 number specified are used.
7919
7920 *printf-f* *E807*
7921 f F The Float argument is converted into a string of the
7922 form 123.456. The precision specifies the number of
7923 digits after the decimal point. When the precision is
7924 zero the decimal point is omitted. When the precision
7925 is not specified 6 is used. A really big number
7926 (out of range or dividing by zero) results in "inf"
7927 or "-inf" with %f (INF or -INF with %F).
7928 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
7929 Example: >
7930 echo printf("%.2f", 12.115)
7931< 12.12
7932 Note that roundoff depends on the system libraries.
7933 Use |round()| when in doubt.
7934
7935 *printf-e* *printf-E*
7936 e E The Float argument is converted into a string of the
7937 form 1.234e+03 or 1.234E+03 when using 'E'. The
7938 precision specifies the number of digits after the
7939 decimal point, like with 'f'.
7940
7941 *printf-g* *printf-G*
7942 g G The Float argument is converted like with 'f' if the
7943 value is between 0.001 (inclusive) and 10000000.0
7944 (exclusive). Otherwise 'e' is used for 'g' and 'E'
7945 for 'G'. When no precision is specified superfluous
7946 zeroes and '+' signs are removed, except for the zero
7947 immediately after the decimal point. Thus 10000000.0
7948 results in 1.0e7.
7949
7950 *printf-%*
7951 % A '%' is written. No argument is converted. The
7952 complete conversion specification is "%%".
7953
7954 When a Number argument is expected a String argument is also
7955 accepted and automatically converted.
7956 When a Float or String argument is expected a Number argument
7957 is also accepted and automatically converted.
7958 Any other argument type results in an error message.
7959
7960 *E766* *E767*
7961 The number of {exprN} arguments must exactly match the number
7962 of "%" items. If there are not sufficient or too many
7963 arguments an error is given. Up to 18 arguments can be used.
7964
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007965 *printf-$*
7966 In certain languages, error and informative messages are
7967 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02007968 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007969 having a different word order, positional arguments may be
7970 used to indicate this. For instance: >
7971
h_east596a9f22023-11-21 21:24:23 +09007972 #, c-format
7973 msgid "%s returning %s"
7974 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007975<
h_east596a9f22023-11-21 21:24:23 +09007976 In this example, the sentence has its 2 string arguments
7977 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007978
h_east596a9f22023-11-21 21:24:23 +09007979 echo printf(
7980 "In The Netherlands, vim's creator's name is: %1$s %2$s",
7981 "Bram", "Moolenaar")
7982< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007983
h_east596a9f22023-11-21 21:24:23 +09007984 echo printf(
7985 "In Belgium, vim's creator's name is: %2$s %1$s",
7986 "Bram", "Moolenaar")
7987< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007988
7989 Width (and precision) can be specified using the '*' specifier.
7990 In this case, you must specify the field width position in the
7991 argument list. >
7992
h_east596a9f22023-11-21 21:24:23 +09007993 echo printf("%1$*2$.*3$d", 1, 2, 3)
7994< 001 >
7995 echo printf("%2$*3$.*1$d", 1, 2, 3)
7996< 2 >
7997 echo printf("%3$*1$.*2$d", 1, 2, 3)
7998< 03 >
7999 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
8000< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008001
8002 You can mix specifying the width and/or precision directly
8003 and via positional arguments: >
8004
h_east596a9f22023-11-21 21:24:23 +09008005 echo printf("%1$4.*2$f", 1.4142135, 6)
8006< 1.414214 >
8007 echo printf("%1$*2$.4f", 1.4142135, 6)
8008< 1.4142 >
8009 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
8010< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008011
Christ van Willegenc35fc032024-03-14 18:30:41 +01008012 You will get an overflow error |E1510|, when the field-width
8013 or precision will result in a string longer than 6400 chars.
8014
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008015 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008016 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09008017 echo printf("%s%1$s", "One", "Two")
8018< E1500: Cannot mix positional and non-positional arguments:
8019 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008020
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008021 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008022 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09008023 echo printf("%3$s%1$s", "One", "Two", "Three")
8024< E1501: format argument 2 unused in $-style format:
8025 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008026
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008027 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008028 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09008029 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
8030< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008031
8032 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09008033 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
8034< E1502: Positional argument 2 used as field width reused as
8035 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008036
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008037 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008038 When a positional argument is used, but not the correct number
8039 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09008040 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
8041< E1503: Positional argument 3 out of bounds: %1$d at width
8042 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008043
8044 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09008045 echo printf("%01$*2$.*3$d %4$d", 1, 2)
8046< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
8047 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008048
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008049 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008050 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09008051 echo printf("%1$s %2$s %1$s", "One", "Two")
8052< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008053
8054 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09008055 echo printf("%1$s %2$s %1$d", "One", "Two")
8056< E1504: Positional argument 1 type used inconsistently:
8057 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008058
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008059 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008060 Various other errors that lead to a format string being
8061 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09008062 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
8063< E1505: Invalid format specifier: %1$d at width %2$d is:
8064 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008065
Christ van Willegenea746f92023-10-05 20:48:36 +02008066 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08008067 This internal error indicates that the logic to parse a
8068 positional format argument ran into a problem that couldn't be
8069 otherwise reported. Please file a bug against Vim if you run
8070 into this, copying the exact format string and parameters that
8071 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02008072
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008073 Return type: |String|
8074
Christ van Willegenea746f92023-10-05 20:48:36 +02008075
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008076prompt_getprompt({buf}) *prompt_getprompt()*
8077 Returns the effective prompt text for buffer {buf}. {buf} can
8078 be a buffer name or number. See |prompt-buffer|.
8079
8080 If the buffer doesn't exist or isn't a prompt buffer, an empty
8081 string is returned.
8082
8083 Can also be used as a |method|: >
8084 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008085<
8086 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008087
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008088 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008089
8090
8091prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
8092 Set prompt callback for buffer {buf} to {expr}. When {expr}
8093 is an empty string the callback is removed. This has only
8094 effect if {buf} has 'buftype' set to "prompt".
8095
8096 The callback is invoked when pressing Enter. The current
8097 buffer will always be the prompt buffer. A new line for a
8098 prompt is added before invoking the callback, thus the prompt
8099 for which the callback was invoked will be in the last but one
8100 line.
8101 If the callback wants to add text to the buffer, it must
8102 insert it above the last line, since that is where the current
8103 prompt is. This can also be done asynchronously.
8104 The callback is invoked with one argument, which is the text
8105 that was entered at the prompt. This can be an empty string
8106 if the user only typed Enter.
8107 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008108 func s:TextEntered(text)
8109 if a:text == 'exit' || a:text == 'quit'
8110 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008111 " Reset 'modified' to allow the buffer to be closed.
8112 " We assume there is nothing useful to be saved.
8113 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008114 close
8115 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008116 " Do something useful with "a:text". In this example
8117 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008118 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008119 endif
8120 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008121 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008122
8123< Can also be used as a |method|: >
8124 GetBuffer()->prompt_setcallback(callback)
8125
8126< {only available when compiled with the |+channel| feature}
8127
8128prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
8129 Set a callback for buffer {buf} to {expr}. When {expr} is an
8130 empty string the callback is removed. This has only effect if
8131 {buf} has 'buftype' set to "prompt".
8132
8133 This callback will be invoked when pressing CTRL-C in Insert
8134 mode. Without setting a callback Vim will exit Insert mode,
8135 as in any buffer.
8136
8137 Can also be used as a |method|: >
8138 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008139<
8140 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008141
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008142 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008143
8144prompt_setprompt({buf}, {text}) *prompt_setprompt()*
8145 Set prompt for buffer {buf} to {text}. You most likely want
8146 {text} to end in a space.
8147 The result is only visible if {buf} has 'buftype' set to
8148 "prompt". Example: >
8149 call prompt_setprompt(bufnr(), 'command: ')
8150<
8151 Can also be used as a |method|: >
8152 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008153<
8154 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008155
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008156 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008157
8158prop_ functions are documented here: |text-prop-functions|
8159
8160pum_getpos() *pum_getpos()*
8161 If the popup menu (see |ins-completion-menu|) is not visible,
8162 returns an empty |Dictionary|, otherwise, returns a
8163 |Dictionary| with the following keys:
8164 height nr of items visible
8165 width screen cells
8166 row top screen row (0 first row)
8167 col leftmost screen column (0 first col)
8168 size total nr of items
8169 scrollbar |TRUE| if scrollbar is visible
8170
8171 The values are the same as in |v:event| during
8172 |CompleteChanged|.
8173
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008174 Return type: dict<any>
8175
8176
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008177pumvisible() *pumvisible()*
8178 Returns non-zero when the popup menu is visible, zero
8179 otherwise. See |ins-completion-menu|.
8180 This can be used to avoid some things that would remove the
8181 popup menu.
8182
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008183 Return type: |Number|
8184
8185
zeertzjq7c515282024-11-10 20:26:12 +01008186py3eval({expr} [, {locals}]) *py3eval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008187 Evaluate Python expression {expr} and return its result
8188 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008189 If a {locals} |Dictionary| is given, it defines set of local
8190 variables available in the expression. The keys are variable
8191 names and the values are the variable values. |Dictionary| and
8192 |List| values are referenced, and may be updated by the
8193 expression (as if |python-bindeval| was used).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008194 Numbers and strings are returned as they are (strings are
8195 copied though, Unicode strings are additionally converted to
8196 'encoding').
8197 Lists are represented as Vim |List| type.
8198 Dictionaries are represented as Vim |Dictionary| type with
8199 keys converted to strings.
8200 Note that in a `:def` function local variables are not visible
8201 to {expr}.
8202
8203 Can also be used as a |method|: >
8204 GetExpr()->py3eval()
Ben Jacksonea19e782024-11-06 21:50:05 +01008205 'b",".join(l)'->py3eval({'l': ['a', 'b', 'c']})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008206<
8207 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008208
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008209 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008210
8211 *E858* *E859*
zeertzjq7c515282024-11-10 20:26:12 +01008212pyeval({expr} [, {locals}]) *pyeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008213 Evaluate Python expression {expr} and return its result
8214 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008215 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008216 Numbers and strings are returned as they are (strings are
8217 copied though).
8218 Lists are represented as Vim |List| type.
8219 Dictionaries are represented as Vim |Dictionary| type,
8220 non-string keys result in error.
8221 Note that in a `:def` function local variables are not visible
8222 to {expr}.
8223
8224 Can also be used as a |method|: >
8225 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008226<
8227 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008228
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008229 {only available when compiled with the |+python| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008230
zeertzjq7c515282024-11-10 20:26:12 +01008231pyxeval({expr} [, {locals}]) *pyxeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008232 Evaluate Python expression {expr} and return its result
8233 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008234 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008235 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8236 See also: |pyeval()|, |py3eval()|
8237
8238 Can also be used as a |method|: >
h-east52e7cc22024-07-28 17:03:29 +02008239 GetExpr()->pyxeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008240<
8241 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008242
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008243 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008244 |+python3| feature}
8245
8246rand([{expr}]) *rand()* *random*
8247 Return a pseudo-random Number generated with an xoshiro128**
8248 algorithm using seed {expr}. The returned number is 32 bits,
8249 also on 64 bits systems, for consistency.
8250 {expr} can be initialized by |srand()| and will be updated by
8251 rand(). If {expr} is omitted, an internal seed value is used
8252 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008253 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008254
8255 Examples: >
8256 :echo rand()
8257 :let seed = srand()
8258 :echo rand(seed)
8259 :echo rand(seed) % 16 " random number 0 - 15
8260<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008261 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008262
8263 *E726* *E727*
8264range({expr} [, {max} [, {stride}]]) *range()*
8265 Returns a |List| with Numbers:
8266 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8267 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8268 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8269 {max}] (increasing {expr} with {stride} each time, not
8270 producing a value past {max}).
8271 When the maximum is one before the start the result is an
8272 empty list. When the maximum is more than one before the
8273 start this is an error.
8274 Examples: >
8275 range(4) " [0, 1, 2, 3]
8276 range(2, 4) " [2, 3, 4]
8277 range(2, 9, 3) " [2, 5, 8]
8278 range(2, -2, -1) " [2, 1, 0, -1, -2]
8279 range(0) " []
8280 range(2, 0) " error!
8281<
8282 Can also be used as a |method|: >
8283 GetExpr()->range()
8284<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008285 Return type: list<number>
8286
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008287
K.Takata11df3ae2022-10-19 14:02:40 +01008288readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008289 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008290 If {offset} is specified, read the file from the specified
8291 offset. If it is a negative value, it is used as an offset
8292 from the end of the file. E.g., to read the last 12 bytes: >
8293 readblob('file.bin', -12)
8294< If {size} is specified, only the specified size will be read.
8295 E.g. to read the first 100 bytes of a file: >
8296 readblob('file.bin', 0, 100)
8297< If {size} is -1 or omitted, the whole data starting from
8298 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008299 This can be also used to read the data from a character device
8300 on Unix when {size} is explicitly set. Only if the device
8301 supports seeking {offset} can be used. Otherwise it should be
8302 zero. E.g. to read 10 bytes from a serial console: >
8303 readblob('/dev/ttyS0', 0, 10)
8304< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008305 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008306 When the offset is beyond the end of the file the result is an
8307 empty blob.
8308 When trying to read more bytes than are available the result
8309 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008310 Also see |readfile()| and |writefile()|.
8311
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008312 Return type: |Blob|
8313
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008314
8315readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8316 Return a list with file and directory names in {directory}.
8317 You can also use |glob()| if you don't need to do complicated
8318 things, such as limiting the number of matches.
8319 The list will be sorted (case sensitive), see the {dict}
8320 argument below for changing the sort order.
8321
8322 When {expr} is omitted all entries are included.
8323 When {expr} is given, it is evaluated to check what to do:
8324 If {expr} results in -1 then no further entries will
8325 be handled.
8326 If {expr} results in 0 then this entry will not be
8327 added to the list.
8328 If {expr} results in 1 then this entry will be added
8329 to the list.
8330 The entries "." and ".." are always excluded.
8331 Each time {expr} is evaluated |v:val| is set to the entry name.
8332 When {expr} is a function the name is passed as the argument.
8333 For example, to get a list of files ending in ".txt": >
8334 readdir(dirname, {n -> n =~ '.txt$'})
8335< To skip hidden and backup files: >
8336 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008337< *E857*
8338 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008339 values. Currently this is used to specify if and how sorting
8340 should be performed. The dict can have the following members:
8341
8342 sort How to sort the result returned from the system.
8343 Valid values are:
8344 "none" do not sort (fastest method)
8345 "case" sort case sensitive (byte value of
8346 each character, technically, using
8347 strcmp()) (default)
8348 "icase" sort case insensitive (technically
8349 using strcasecmp())
8350 "collate" sort using the collation order
8351 of the "POSIX" or "C" |locale|
8352 (technically using strcoll())
8353 Other values are silently ignored.
8354
8355 For example, to get a list of all files in the current
8356 directory without sorting the individual entries: >
8357 readdir('.', '1', #{sort: 'none'})
8358< If you want to get a directory tree: >
8359 function! s:tree(dir)
8360 return {a:dir : map(readdir(a:dir),
8361 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008362 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008363 endfunction
8364 echo s:tree(".")
8365<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008366 Returns an empty List on error.
8367
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008368 Can also be used as a |method|: >
8369 GetDirName()->readdir()
8370<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008371 Return type: list<string> or list<any>
8372
8373
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008374readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8375 Extended version of |readdir()|.
8376 Return a list of Dictionaries with file and directory
8377 information in {directory}.
8378 This is useful if you want to get the attributes of file and
8379 directory at the same time as getting a list of a directory.
8380 This is much faster than calling |readdir()| then calling
8381 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8382 each file and directory especially on MS-Windows.
8383 The list will by default be sorted by name (case sensitive),
8384 the sorting can be changed by using the optional {dict}
8385 argument, see |readdir()|.
8386
8387 The Dictionary for file and directory information has the
8388 following items:
8389 group Group name of the entry. (Only on Unix)
8390 name Name of the entry.
8391 perm Permissions of the entry. See |getfperm()|.
8392 size Size of the entry. See |getfsize()|.
8393 time Timestamp of the entry. See |getftime()|.
8394 type Type of the entry.
8395 On Unix, almost same as |getftype()| except:
8396 Symlink to a dir "linkd"
8397 Other symlink "link"
8398 On MS-Windows:
8399 Normal file "file"
8400 Directory "dir"
8401 Junction "junction"
8402 Symlink to a dir "linkd"
8403 Other symlink "link"
8404 Other reparse point "reparse"
8405 user User name of the entry's owner. (Only on Unix)
8406 On Unix, if the entry is a symlink, the Dictionary includes
8407 the information of the target (except the "type" item).
8408 On MS-Windows, it includes the information of the symlink
8409 itself because of performance reasons.
8410
8411 When {expr} is omitted all entries are included.
8412 When {expr} is given, it is evaluated to check what to do:
8413 If {expr} results in -1 then no further entries will
8414 be handled.
8415 If {expr} results in 0 then this entry will not be
8416 added to the list.
8417 If {expr} results in 1 then this entry will be added
8418 to the list.
8419 The entries "." and ".." are always excluded.
8420 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8421 of the entry.
8422 When {expr} is a function the entry is passed as the argument.
8423 For example, to get a list of files ending in ".txt": >
8424 readdirex(dirname, {e -> e.name =~ '.txt$'})
8425<
8426 For example, to get a list of all files in the current
8427 directory without sorting the individual entries: >
8428 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008429<
8430 Can also be used as a |method|: >
8431 GetDirName()->readdirex()
8432<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008433 Return type: list<dict<any>> or list<any>
8434
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008435
8436 *readfile()*
8437readfile({fname} [, {type} [, {max}]])
8438 Read file {fname} and return a |List|, each line of the file
8439 as an item. Lines are broken at NL characters. Macintosh
8440 files separated with CR will result in a single long line
8441 (unless a NL appears somewhere).
8442 All NUL characters are replaced with a NL character.
8443 When {type} contains "b" binary mode is used:
8444 - When the last line ends in a NL an extra empty list item is
8445 added.
8446 - No CR characters are removed.
8447 Otherwise:
8448 - CR characters that appear before a NL are removed.
8449 - Whether the last line ends in a NL or not does not matter.
8450 - When 'encoding' is Unicode any UTF-8 byte order mark is
8451 removed from the text.
8452 When {max} is given this specifies the maximum number of lines
8453 to be read. Useful if you only want to check the first ten
8454 lines of a file: >
8455 :for line in readfile(fname, '', 10)
8456 : if line =~ 'Date' | echo line | endif
8457 :endfor
8458< When {max} is negative -{max} lines from the end of the file
8459 are returned, or as many as there are.
8460 When {max} is zero the result is an empty list.
8461 Note that without {max} the whole file is read into memory.
8462 Also note that there is no recognition of encoding. Read a
8463 file into a buffer if you need to.
8464 Deprecated (use |readblob()| instead): When {type} contains
8465 "B" a |Blob| is returned with the binary data of the file
8466 unmodified.
8467 When the file can't be opened an error message is given and
8468 the result is an empty list.
8469 Also see |writefile()|.
8470
8471 Can also be used as a |method|: >
8472 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008473<
8474 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008475
8476reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8477 {func} is called for every item in {object}, which can be a
8478 |String|, |List| or a |Blob|. {func} is called with two
8479 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008480 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008481
8482 {initial} is the initial result. When omitted, the first item
8483 in {object} is used and {func} is first called for the second
8484 item. If {initial} is not given and {object} is empty no
8485 result can be computed, an E998 error is given.
8486
8487 Examples: >
8488 echo reduce([1, 3, 5], { acc, val -> acc + val })
8489 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8490 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8491 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8492<
8493 Can also be used as a |method|: >
8494 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008495<
8496 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8497 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008498
8499
8500reg_executing() *reg_executing()*
8501 Returns the single letter name of the register being executed.
8502 Returns an empty string when no register is being executed.
8503 See |@|.
8504
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008505 Return type: |String|
8506
8507
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008508reg_recording() *reg_recording()*
8509 Returns the single letter name of the register being recorded.
8510 Returns an empty string when not recording. See |q|.
8511
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008512 Return type: |String|
8513
8514
8515reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008516reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008517reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008518 Return an item that represents a time value. The item is a
8519 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008520 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008521 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008522 string or |reltimefloat()| to convert to a Float. For
8523 example, to see the time spent in function Work(): >
8524 var startTime = reltime()
8525 Work()
8526 echo startTime->reltime()->reltimestr()
8527<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008528 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008529 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008530 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008531 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008532 specified in the argument.
8533 With two arguments it returns the time passed between {start}
8534 and {end}.
8535
8536 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008537 reltime(). If there is an error an empty List is returned in
8538 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008539
8540 Can also be used as a |method|: >
8541 GetStart()->reltime()
8542<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008543 Return type: list<number>
8544
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008545 {only available when compiled with the |+reltime| feature}
8546
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008547
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008548reltimefloat({time}) *reltimefloat()*
8549 Return a Float that represents the time value of {time}.
8550 Example: >
8551 let start = reltime()
8552 call MyFunction()
8553 let seconds = reltimefloat(reltime(start))
8554< See the note of reltimestr() about overhead.
8555 Also see |profiling|.
8556 If there is an error 0.0 is returned in legacy script, in Vim9
8557 script an error is given.
8558
8559 Can also be used as a |method|: >
8560 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008561<
8562 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008563
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008564 {only available when compiled with the |+reltime| feature}
8565
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008566
8567reltimestr({time}) *reltimestr()*
8568 Return a String that represents the time value of {time}.
8569 This is the number of seconds, a dot and the number of
8570 microseconds. Example: >
8571 let start = reltime()
8572 call MyFunction()
8573 echo reltimestr(reltime(start))
8574< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008575 The accuracy depends on the system. Use reltimefloat() for the
8576 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008577 Leading spaces are used to make the string align nicely. You
8578 can use split() to remove it. >
8579 echo split(reltimestr(reltime(start)))[0]
8580< Also see |profiling|.
8581 If there is an error an empty string is returned in legacy
8582 script, in Vim9 script an error is given.
8583
8584 Can also be used as a |method|: >
8585 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008586<
8587 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008588
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008589 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008590
8591 *remote_expr()* *E449*
8592remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008593 Send the {string} to {server}. The {server} argument is a
8594 string, also see |{server}|.
8595
8596 The string is sent as an expression and the result is returned
Christian Brabandt1961caf2024-10-12 11:57:12 +02008597 after evaluation. The result must be a String or a |List|
8598 other types will be converted to String. A |List| is turned
8599 into a String by joining the items with a line break in
8600 between (not at the end), like with join(expr, "\n").
Bram Moolenaar944697a2022-02-20 19:48:20 +00008601
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008602 If {idvar} is present and not empty, it is taken as the name
8603 of a variable and a {serverid} for later use with
8604 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008605
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008606 If {timeout} is given the read times out after this many
8607 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008608
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008609 See also |clientserver| |RemoteReply|.
8610 This function is not available in the |sandbox|.
8611 {only available when compiled with the |+clientserver| feature}
8612 Note: Any errors will cause a local error message to be issued
8613 and the result will be the empty string.
8614
8615 Variables will be evaluated in the global namespace,
8616 independent of a function currently being active. Except
8617 when in debug mode, then local function variables and
8618 arguments can be evaluated.
8619
8620 Examples: >
8621 :echo remote_expr("gvim", "2+2")
8622 :echo remote_expr("gvim1", "b:current_syntax")
8623<
8624 Can also be used as a |method|: >
8625 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008626<
8627 Return type: |String| or list<{type}>
8628
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008629
8630remote_foreground({server}) *remote_foreground()*
8631 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008632 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008633 This works like: >
8634 remote_expr({server}, "foreground()")
8635< Except that on Win32 systems the client does the work, to work
8636 around the problem that the OS doesn't always allow the server
8637 to bring itself to the foreground.
8638 Note: This does not restore the window if it was minimized,
8639 like foreground() does.
8640 This function is not available in the |sandbox|.
8641
8642 Can also be used as a |method|: >
8643 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008644<
8645 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008646
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008647 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008648 Win32 console version}
8649
8650
8651remote_peek({serverid} [, {retvar}]) *remote_peek()*
8652 Returns a positive number if there are available strings
8653 from {serverid}. Copies any reply string into the variable
8654 {retvar} if specified. {retvar} must be a string with the
8655 name of a variable.
8656 Returns zero if none are available.
8657 Returns -1 if something is wrong.
8658 See also |clientserver|.
8659 This function is not available in the |sandbox|.
8660 {only available when compiled with the |+clientserver| feature}
8661 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008662 :let repl = ""
8663 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008664
8665< Can also be used as a |method|: >
8666 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008667<
8668 Return type: |Number|
8669
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008670
8671remote_read({serverid}, [{timeout}]) *remote_read()*
8672 Return the oldest available reply from {serverid} and consume
8673 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008674 reply is available. Returns an empty string, if a reply is
8675 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008676 See also |clientserver|.
8677 This function is not available in the |sandbox|.
8678 {only available when compiled with the |+clientserver| feature}
8679 Example: >
8680 :echo remote_read(id)
8681
8682< Can also be used as a |method|: >
8683 ServerId()->remote_read()
8684<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008685 Return type: |String|
8686
8687
8688remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008689 Send the {string} to {server}. The {server} argument is a
8690 string, also see |{server}|.
8691
8692 The string is sent as input keys and the function returns
8693 immediately. At the Vim server the keys are not mapped
8694 |:map|.
8695
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008696 If {idvar} is present, it is taken as the name of a variable
8697 and a {serverid} for later use with remote_read() is stored
8698 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008699
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008700 See also |clientserver| |RemoteReply|.
8701 This function is not available in the |sandbox|.
8702 {only available when compiled with the |+clientserver| feature}
8703
8704 Note: Any errors will be reported in the server and may mess
8705 up the display.
8706 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008707 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008708 \ remote_read(serverid)
8709
8710 :autocmd NONE RemoteReply *
8711 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008712 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008713 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8714<
8715 Can also be used as a |method|: >
8716 ServerName()->remote_send(keys)
8717<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008718 Return type: |String|
8719
8720
8721remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008722 Become the server {name}. {name} must be a non-empty string.
8723 This fails if already running as a server, when |v:servername|
8724 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008725
8726 Can also be used as a |method|: >
8727 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008728<
8729 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008730
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008731 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008732
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008733
8734remove({list}, {idx}) *remove()*
8735remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008736 Without {end}: Remove the item at {idx} from |List| {list} and
8737 return the item.
8738 With {end}: Remove items from {idx} to {end} (inclusive) and
8739 return a |List| with these items. When {idx} points to the same
8740 item as {end} a list with one item is returned. When {end}
8741 points to an item before {idx} this is an error.
8742 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008743 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008744 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008745 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008746 :call remove(mylist, 0, 9)
8747<
8748 Use |delete()| to remove a file.
8749
8750 Can also be used as a |method|: >
8751 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008752<
8753 Return type: any, depending on {list}
8754
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008755
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008756remove({blob}, {idx})
8757remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008758 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8759 return the byte.
8760 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8761 return a |Blob| with these bytes. When {idx} points to the same
8762 byte as {end} a |Blob| with one byte is returned. When {end}
8763 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008764 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008765 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008766 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008767 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008768<
8769 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008770
8771remove({dict}, {key})
8772 Remove the entry from {dict} with key {key} and return it.
8773 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008774 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008775< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008776 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008777
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008778 Return type: any, depending on {dict}
8779
8780
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008781rename({from}, {to}) *rename()*
8782 Rename the file by the name {from} to the name {to}. This
8783 should also work to move files across file systems. The
8784 result is a Number, which is 0 if the file was renamed
8785 successfully, and non-zero when the renaming failed.
8786 NOTE: If {to} exists it is overwritten without warning.
8787 This function is not available in the |sandbox|.
8788
8789 Can also be used as a |method|: >
8790 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008791<
8792 Return type: |Number|
8793
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008794
8795repeat({expr}, {count}) *repeat()*
8796 Repeat {expr} {count} times and return the concatenated
8797 result. Example: >
8798 :let separator = repeat('-', 80)
8799< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01008800 When {expr} is a |List| or a |Blob| the result is {expr}
8801 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008802 :let longlist = repeat(['a', 'b'], 3)
8803< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
8804
8805 Can also be used as a |method|: >
8806 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008807<
8808 Return type: |String|, |Blob| or list<{type}> depending on
8809 {expr}
8810
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008811
8812resolve({filename}) *resolve()* *E655*
8813 On MS-Windows, when {filename} is a shortcut (a .lnk file),
8814 returns the path the shortcut points to in a simplified form.
8815 When {filename} is a symbolic link or junction point, return
8816 the full path to the target. If the target of junction is
8817 removed, return {filename}.
8818 On Unix, repeat resolving symbolic links in all path
8819 components of {filename} and return the simplified result.
8820 To cope with link cycles, resolving of symbolic links is
8821 stopped after 100 iterations.
8822 On other systems, return the simplified {filename}.
8823 The simplification step is done as by |simplify()|.
8824 resolve() keeps a leading path component specifying the
8825 current directory (provided the result is still a relative
8826 path name) and also keeps a trailing path separator.
8827
8828 Can also be used as a |method|: >
8829 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008830<
8831 Return type: |String|
8832
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008833
8834reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01008835 Reverse the order of items in {object}. {object} can be a
8836 |List|, a |Blob| or a |String|. For a List and a Blob the
8837 items are reversed in-place and {object} is returned.
8838 For a String a new String is returned.
8839 Returns zero if {object} is not a List, Blob or a String.
8840 If you want a List or Blob to remain unmodified make a copy
8841 first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008842 :let revlist = reverse(copy(mylist))
8843< Can also be used as a |method|: >
8844 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008845<
8846 Return type: |String|, |Blob| or list<{type}> depending on
8847 {object}
8848
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008849
8850round({expr}) *round()*
8851 Round off {expr} to the nearest integral value and return it
8852 as a |Float|. If {expr} lies halfway between two integral
8853 values, then use the larger one (away from zero).
8854 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008855 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008856 Examples: >
8857 echo round(0.456)
8858< 0.0 >
8859 echo round(4.5)
8860< 5.0 >
8861 echo round(-4.5)
8862< -5.0
8863
8864 Can also be used as a |method|: >
8865 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008866<
8867 Return type: |Float|
8868
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008869
8870rubyeval({expr}) *rubyeval()*
8871 Evaluate Ruby expression {expr} and return its result
8872 converted to Vim data structures.
8873 Numbers, floats and strings are returned as they are (strings
8874 are copied though).
8875 Arrays are represented as Vim |List| type.
8876 Hashes are represented as Vim |Dictionary| type.
8877 Other objects are represented as strings resulted from their
8878 "Object#to_s" method.
8879 Note that in a `:def` function local variables are not visible
8880 to {expr}.
8881
8882 Can also be used as a |method|: >
8883 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008884<
8885 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008886
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008887 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008888
8889screenattr({row}, {col}) *screenattr()*
8890 Like |screenchar()|, but return the attribute. This is a rather
8891 arbitrary number that can only be used to compare to the
8892 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008893 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008894
8895 Can also be used as a |method|: >
8896 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008897<
8898 Return type: |Number|
8899
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008900
8901screenchar({row}, {col}) *screenchar()*
8902 The result is a Number, which is the character at position
8903 [row, col] on the screen. This works for every possible
8904 screen position, also status lines, window separators and the
8905 command line. The top left position is row one, column one
8906 The character excludes composing characters. For double-byte
8907 encodings it may only be the first byte.
8908 This is mainly to be used for testing.
8909 Returns -1 when row or col is out of range.
8910
8911 Can also be used as a |method|: >
8912 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008913<
8914 Return type: |Number|
8915
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008916
8917screenchars({row}, {col}) *screenchars()*
8918 The result is a |List| of Numbers. The first number is the same
8919 as what |screenchar()| returns. Further numbers are
8920 composing characters on top of the base character.
8921 This is mainly to be used for testing.
8922 Returns an empty List when row or col is out of range.
8923
8924 Can also be used as a |method|: >
8925 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008926<
8927 Return type: list<number> or list<any>
8928
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008929
8930screencol() *screencol()*
8931 The result is a Number, which is the current screen column of
8932 the cursor. The leftmost column has number 1.
8933 This function is mainly used for testing.
8934
8935 Note: Always returns the current screen column, thus if used
8936 in a command (e.g. ":echo screencol()") it will return the
8937 column inside the command line, which is 1 when the command is
8938 executed. To get the cursor position in the file use one of
8939 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008940 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008941 nnoremap <silent> GG :echom screencol()<CR>
8942 nnoremap GG <Cmd>echom screencol()<CR>
8943<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008944 Return type: |Number|
8945
8946
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008947screenpos({winid}, {lnum}, {col}) *screenpos()*
8948 The result is a Dict with the screen position of the text
8949 character in window {winid} at buffer line {lnum} and column
8950 {col}. {col} is a one-based byte index.
8951 The Dict has these members:
8952 row screen row
8953 col first screen column
8954 endcol last screen column
8955 curscol cursor screen column
8956 If the specified position is not visible, all values are zero.
8957 The "endcol" value differs from "col" when the character
8958 occupies more than one screen cell. E.g. for a Tab "col" can
8959 be 1 and "endcol" can be 8.
8960 The "curscol" value is where the cursor would be placed. For
8961 a Tab it would be the same as "endcol", while for a double
8962 width character it would be the same as "col".
8963 The |conceal| feature is ignored here, the column numbers are
8964 as if 'conceallevel' is zero. You can set the cursor to the
8965 right position and use |screencol()| to get the value with
8966 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008967 If the position is in a closed fold the screen position of the
8968 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008969 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008970
8971 Can also be used as a |method|: >
8972 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008973<
8974 Return type: dict<number> or dict<any>
8975
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008976
8977screenrow() *screenrow()*
8978 The result is a Number, which is the current screen row of the
8979 cursor. The top line has number one.
8980 This function is mainly used for testing.
8981 Alternatively you can use |winline()|.
8982
8983 Note: Same restrictions as with |screencol()|.
8984
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008985 Return type: |Number|
8986
8987
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008988screenstring({row}, {col}) *screenstring()*
8989 The result is a String that contains the base character and
8990 any composing characters at position [row, col] on the screen.
8991 This is like |screenchars()| but returning a String with the
8992 characters.
8993 This is mainly to be used for testing.
8994 Returns an empty String when row or col is out of range.
8995
8996 Can also be used as a |method|: >
8997 GetRow()->screenstring(col)
8998<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008999 Return type: |String|
9000
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009001 *search()*
9002search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9003 Search for regexp pattern {pattern}. The search starts at the
9004 cursor position (you can use |cursor()| to set it).
9005
9006 When a match has been found its line number is returned.
9007 If there is no match a 0 is returned and the cursor doesn't
9008 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01009009 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009010
9011 {flags} is a String, which can contain these character flags:
9012 'b' search Backward instead of forward
9013 'c' accept a match at the Cursor position
9014 'e' move to the End of the match
9015 'n' do Not move the cursor
9016 'p' return number of matching sub-Pattern (see below)
9017 's' Set the ' mark at the previous location of the cursor
9018 'w' Wrap around the end of the file
9019 'W' don't Wrap around the end of the file
9020 'z' start searching at the cursor column instead of zero
9021 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
9022
9023 If the 's' flag is supplied, the ' mark is set, only if the
9024 cursor is moved. The 's' flag cannot be combined with the 'n'
9025 flag.
9026
9027 'ignorecase', 'smartcase' and 'magic' are used.
9028
9029 When the 'z' flag is not given, forward searching always
9030 starts in column zero and then matches before the cursor are
9031 skipped. When the 'c' flag is present in 'cpo' the next
9032 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01009033 search starts one column after the start of the match. This
9034 matters for overlapping matches. See |cpo-c|. You can also
9035 insert "\ze" to change where the match ends, see |/\ze|.
9036
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009037 When searching backwards and the 'z' flag is given then the
9038 search starts in column zero, thus no match in the current
9039 line will be found (unless wrapping around the end of the
9040 file).
9041
9042 When the {stopline} argument is given then the search stops
9043 after searching this line. This is useful to restrict the
9044 search to a range of lines. Examples: >
9045 let match = search('(', 'b', line("w0"))
9046 let end = search('END', '', line("w$"))
9047< When {stopline} is used and it is not zero this also implies
9048 that the search does not wrap around the end of the file.
9049 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01009050 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009051 When the {timeout} argument is given the search stops when
9052 more than this many milliseconds have passed. Thus when
9053 {timeout} is 500 the search stops after half a second.
9054 The value must not be negative. A zero value is like not
9055 giving the argument.
Christian Brabandtd657d3d2024-09-10 21:55:49 +02009056
9057 Note: the timeout is only considered when searching, not
9058 while evaluating the {skip} expression.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009059 {only available when compiled with the |+reltime| feature}
9060
9061 If the {skip} expression is given it is evaluated with the
9062 cursor positioned on the start of a match. If it evaluates to
9063 non-zero this match is skipped. This can be used, for
9064 example, to skip a match in a comment or a string.
9065 {skip} can be a string, which is evaluated as an expression, a
9066 function reference or a lambda.
9067 When {skip} is omitted or empty, every match is accepted.
9068 When evaluating {skip} causes an error the search is aborted
9069 and -1 returned.
9070 *search()-sub-match*
9071 With the 'p' flag the returned value is one more than the
9072 first sub-match in \(\). One if none of them matched but the
9073 whole pattern did match.
9074 To get the column number too use |searchpos()|.
9075
9076 The cursor will be positioned at the match, unless the 'n'
9077 flag is used.
9078
9079 Example (goes over all files in the argument list): >
9080 :let n = 1
9081 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009082 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009083 : " start at the last char in the file and wrap for the
9084 : " first search to find match at start of file
9085 : normal G$
9086 : let flags = "w"
9087 : while search("foo", flags) > 0
9088 : s/foo/bar/g
9089 : let flags = "W"
9090 : endwhile
9091 : update " write the file if modified
9092 : let n = n + 1
9093 :endwhile
9094<
9095 Example for using some flags: >
9096 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
9097< This will search for the keywords "if", "else", and "endif"
9098 under or after the cursor. Because of the 'p' flag, it
9099 returns 1, 2, or 3 depending on which keyword is found, or 0
9100 if the search fails. With the cursor on the first word of the
9101 line:
9102 if (foo == 0) | let foo = foo + 1 | endif ~
9103 the function returns 1. Without the 'c' flag, the function
9104 finds the "endif" and returns 3. The same thing happens
9105 without the 'e' flag if the cursor is on the "f" of "if".
9106 The 'n' flag tells the function not to move the cursor.
9107
9108 Can also be used as a |method|: >
9109 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009110<
9111 Return type: |Number|
9112
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009113
9114searchcount([{options}]) *searchcount()*
9115 Get or update the last search count, like what is displayed
9116 without the "S" flag in 'shortmess'. This works even if
9117 'shortmess' does contain the "S" flag.
9118
9119 This returns a |Dictionary|. The dictionary is empty if the
9120 previous pattern was not set and "pattern" was not specified.
9121
9122 key type meaning ~
9123 current |Number| current position of match;
9124 0 if the cursor position is
9125 before the first match
9126 exact_match |Boolean| 1 if "current" is matched on
9127 "pos", otherwise 0
9128 total |Number| total count of matches found
9129 incomplete |Number| 0: search was fully completed
9130 1: recomputing was timed out
9131 2: max count exceeded
9132
9133 For {options} see further down.
9134
9135 To get the last search count when |n| or |N| was pressed, call
9136 this function with `recompute: 0` . This sometimes returns
9137 wrong information because |n| and |N|'s maximum count is 99.
9138 If it exceeded 99 the result must be max count + 1 (100). If
9139 you want to get correct information, specify `recompute: 1`: >
9140
9141 " result == maxcount + 1 (100) when many matches
9142 let result = searchcount(#{recompute: 0})
9143
9144 " Below returns correct result (recompute defaults
9145 " to 1)
9146 let result = searchcount()
9147<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01009148 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009149 function! LastSearchCount() abort
9150 let result = searchcount(#{recompute: 0})
9151 if empty(result)
9152 return ''
9153 endif
9154 if result.incomplete ==# 1 " timed out
9155 return printf(' /%s [?/??]', @/)
9156 elseif result.incomplete ==# 2 " max count exceeded
9157 if result.total > result.maxcount &&
9158 \ result.current > result.maxcount
9159 return printf(' /%s [>%d/>%d]', @/,
9160 \ result.current, result.total)
9161 elseif result.total > result.maxcount
9162 return printf(' /%s [%d/>%d]', @/,
9163 \ result.current, result.total)
9164 endif
9165 endif
9166 return printf(' /%s [%d/%d]', @/,
9167 \ result.current, result.total)
9168 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009169 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009170
9171 " Or if you want to show the count only when
9172 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009173 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009174 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9175<
9176 You can also update the search count, which can be useful in a
9177 |CursorMoved| or |CursorMovedI| autocommand: >
9178
9179 autocmd CursorMoved,CursorMovedI *
9180 \ let s:searchcount_timer = timer_start(
9181 \ 200, function('s:update_searchcount'))
9182 function! s:update_searchcount(timer) abort
9183 if a:timer ==# s:searchcount_timer
9184 call searchcount(#{
9185 \ recompute: 1, maxcount: 0, timeout: 100})
9186 redrawstatus
9187 endif
9188 endfunction
9189<
9190 This can also be used to count matched texts with specified
9191 pattern in the current buffer using "pattern": >
9192
9193 " Count '\<foo\>' in this buffer
9194 " (Note that it also updates search count)
9195 let result = searchcount(#{pattern: '\<foo\>'})
9196
9197 " To restore old search count by old pattern,
9198 " search again
9199 call searchcount()
9200<
9201 {options} must be a |Dictionary|. It can contain:
9202 key type meaning ~
9203 recompute |Boolean| if |TRUE|, recompute the count
9204 like |n| or |N| was executed.
9205 otherwise returns the last
9206 computed result (when |n| or
9207 |N| was used when "S" is not
9208 in 'shortmess', or this
9209 function was called).
9210 (default: |TRUE|)
9211 pattern |String| recompute if this was given
9212 and different with |@/|.
9213 this works as same as the
9214 below command is executed
9215 before calling this function >
9216 let @/ = pattern
9217< (default: |@/|)
9218 timeout |Number| 0 or negative number is no
9219 timeout. timeout milliseconds
9220 for recomputing the result
9221 (default: 0)
9222 maxcount |Number| 0 or negative number is no
9223 limit. max count of matched
9224 text while recomputing the
9225 result. if search exceeded
9226 total count, "total" value
9227 becomes `maxcount + 1`
9228 (default: 99)
9229 pos |List| `[lnum, col, off]` value
9230 when recomputing the result.
9231 this changes "current" result
9232 value. see |cursor()|,
9233 |getpos()|
9234 (default: cursor's position)
9235
9236 Can also be used as a |method|: >
9237 GetSearchOpts()->searchcount()
9238<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009239 Return type: dict<number>
9240
9241
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009242searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9243 Search for the declaration of {name}.
9244
9245 With a non-zero {global} argument it works like |gD|, find
9246 first match in the file. Otherwise it works like |gd|, find
9247 first match in the function.
9248
9249 With a non-zero {thisblock} argument matches in a {} block
9250 that ends before the cursor position are ignored. Avoids
9251 finding variable declarations only valid in another scope.
9252
9253 Moves the cursor to the found match.
9254 Returns zero for success, non-zero for failure.
9255 Example: >
9256 if searchdecl('myvar') == 0
9257 echo getline('.')
9258 endif
9259<
9260 Can also be used as a |method|: >
9261 GetName()->searchdecl()
9262<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009263 Return type: |Number|
9264
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009265 *searchpair()*
9266searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9267 [, {stopline} [, {timeout}]]]])
9268 Search for the match of a nested start-end pair. This can be
9269 used to find the "endif" that matches an "if", while other
9270 if/endif pairs in between are ignored.
9271 The search starts at the cursor. The default is to search
9272 forward, include 'b' in {flags} to search backward.
9273 If a match is found, the cursor is positioned at it and the
9274 line number is returned. If no match is found 0 or -1 is
9275 returned and the cursor doesn't move. No error message is
9276 given.
9277
9278 {start}, {middle} and {end} are patterns, see |pattern|. They
9279 must not contain \( \) pairs. Use of \%( \) is allowed. When
9280 {middle} is not empty, it is found when searching from either
9281 direction, but only when not in a nested start-end pair. A
9282 typical use is: >
9283 searchpair('\<if\>', '\<else\>', '\<endif\>')
9284< By leaving {middle} empty the "else" is skipped.
9285
9286 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9287 |search()|. Additionally:
9288 'r' Repeat until no more matches found; will find the
9289 outer pair. Implies the 'W' flag.
9290 'm' Return number of matches instead of line number with
9291 the match; will be > 1 when 'r' is used.
9292 Note: it's nearly always a good idea to use the 'W' flag, to
9293 avoid wrapping around the end of the file.
9294
9295 When a match for {start}, {middle} or {end} is found, the
9296 {skip} expression is evaluated with the cursor positioned on
9297 the start of the match. It should return non-zero if this
9298 match is to be skipped. E.g., because it is inside a comment
9299 or a string.
9300 When {skip} is omitted or empty, every match is accepted.
9301 When evaluating {skip} causes an error the search is aborted
9302 and -1 returned.
9303 {skip} can be a string, a lambda, a funcref or a partial.
9304 Anything else makes the function fail.
9305 In a `:def` function when the {skip} argument is a string
9306 constant it is compiled into instructions.
9307
9308 For {stopline} and {timeout} see |search()|.
9309
9310 The value of 'ignorecase' is used. 'magic' is ignored, the
9311 patterns are used like it's on.
9312
9313 The search starts exactly at the cursor. A match with
9314 {start}, {middle} or {end} at the next character, in the
9315 direction of searching, is the first one found. Example: >
9316 if 1
9317 if 2
9318 endif 2
9319 endif 1
9320< When starting at the "if 2", with the cursor on the "i", and
9321 searching forwards, the "endif 2" is found. When starting on
9322 the character just before the "if 2", the "endif 1" will be
9323 found. That's because the "if 2" will be found first, and
9324 then this is considered to be a nested if/endif from "if 2" to
9325 "endif 2".
9326 When searching backwards and {end} is more than one character,
9327 it may be useful to put "\zs" at the end of the pattern, so
9328 that when the cursor is inside a match with the end it finds
9329 the matching start.
9330
9331 Example, to find the "endif" command in a Vim script: >
9332
9333 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9334 \ 'getline(".") =~ "^\\s*\""')
9335
9336< The cursor must be at or after the "if" for which a match is
9337 to be found. Note that single-quote strings are used to avoid
9338 having to double the backslashes. The skip expression only
9339 catches comments at the start of a line, not after a command.
9340 Also, a word "en" or "if" halfway a line is considered a
9341 match.
9342 Another example, to search for the matching "{" of a "}": >
9343
9344 :echo searchpair('{', '', '}', 'bW')
9345
9346< This works when the cursor is at or before the "}" for which a
9347 match is to be found. To reject matches that syntax
9348 highlighting recognized as strings: >
9349
9350 :echo searchpair('{', '', '}', 'bW',
9351 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9352<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009353 Return type: |Number|
9354
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009355 *searchpairpos()*
9356searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9357 [, {stopline} [, {timeout}]]]])
9358 Same as |searchpair()|, but returns a |List| with the line and
9359 column position of the match. The first element of the |List|
9360 is the line number and the second element is the byte index of
9361 the column position of the match. If no match is found,
9362 returns [0, 0]. >
9363
9364 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9365<
9366 See |match-parens| for a bigger and more useful example.
9367
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009368 Return type: list<number>
9369
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009370 *searchpos()*
9371searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9372 Same as |search()|, but returns a |List| with the line and
9373 column position of the match. The first element of the |List|
9374 is the line number and the second element is the byte index of
9375 the column position of the match. If no match is found,
9376 returns [0, 0].
9377 Example: >
9378 :let [lnum, col] = searchpos('mypattern', 'n')
9379
9380< When the 'p' flag is given then there is an extra item with
9381 the sub-pattern match number |search()-sub-match|. Example: >
9382 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9383< In this example "submatch" is 2 when a lowercase letter is
9384 found |/\l|, 3 when an uppercase letter is found |/\u|.
9385
9386 Can also be used as a |method|: >
9387 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009388<
9389 Return type: list<number>
9390
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009391
9392server2client({clientid}, {string}) *server2client()*
9393 Send a reply string to {clientid}. The most recent {clientid}
9394 that sent a string can be retrieved with expand("<client>").
9395 {only available when compiled with the |+clientserver| feature}
9396 Returns zero for success, -1 for failure.
9397 Note:
9398 This id has to be stored before the next command can be
9399 received. I.e. before returning from the received command and
9400 before calling any commands that waits for input.
9401 See also |clientserver|.
9402 Example: >
9403 :echo server2client(expand("<client>"), "HELLO")
9404
9405< Can also be used as a |method|: >
9406 GetClientId()->server2client(string)
9407<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009408 Return type: |Number|
9409
9410
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009411serverlist() *serverlist()*
9412 Return a list of available server names, one per line.
9413 When there are no servers or the information is not available
9414 an empty string is returned. See also |clientserver|.
9415 {only available when compiled with the |+clientserver| feature}
9416 Example: >
9417 :echo serverlist()
9418<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009419 Return type: |String|
9420
9421
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009422setbufline({buf}, {lnum}, {text}) *setbufline()*
9423 Set line {lnum} to {text} in buffer {buf}. This works like
9424 |setline()| for the specified buffer.
9425
9426 This function works only for loaded buffers. First call
9427 |bufload()| if needed.
9428
9429 To insert lines use |appendbufline()|.
9430 Any text properties in {lnum} are cleared.
9431
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009432 {text} can be a string to set one line, or a List of strings
9433 to set multiple lines. If the List extends below the last
9434 line then those lines are added. If the List is empty then
9435 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009436
9437 For the use of {buf}, see |bufname()| above.
9438
9439 {lnum} is used like with |setline()|.
9440 Use "$" to refer to the last line in buffer {buf}.
9441 When {lnum} is just below the last line the {text} will be
9442 added below the last line.
9443
9444 When {buf} is not a valid buffer, the buffer is not loaded or
9445 {lnum} is not valid then 1 is returned. In |Vim9| script an
9446 error is given.
9447 On success 0 is returned.
9448
9449 Can also be used as a |method|, the base is passed as the
9450 third argument: >
9451 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009452<
9453 Return type: |Number|
9454
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009455
9456setbufvar({buf}, {varname}, {val}) *setbufvar()*
9457 Set option or local variable {varname} in buffer {buf} to
9458 {val}.
9459 This also works for a global or local window option, but it
9460 doesn't work for a global or local window variable.
9461 For a local window option the global value is unchanged.
9462 For the use of {buf}, see |bufname()| above.
9463 The {varname} argument is a string.
9464 Note that the variable name without "b:" must be used.
9465 Examples: >
9466 :call setbufvar(1, "&mod", 1)
9467 :call setbufvar("todo", "myvar", "foobar")
9468< This function is not available in the |sandbox|.
9469
9470 Can also be used as a |method|, the base is passed as the
9471 third argument: >
9472 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009473<
9474 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009475
9476
9477setcellwidths({list}) *setcellwidths()*
9478 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009479 tells Vim how wide characters are when displayed in the
9480 terminal, counted in screen cells. The values override
9481 'ambiwidth'. Example: >
9482 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009483 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009484 \ [0x2194, 0x2199, 2],
9485 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009486
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009487< The {list} argument is a List of Lists with each three
9488 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9489 {low} and {high} can be the same, in which case this refers to
9490 one character. Otherwise it is the range of characters from
9491 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009492 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009493
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009494 {width} must be either 1 or 2, indicating the character width
9495 in screen cells. *E1112*
9496 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009497 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009498
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009499 If the new value causes 'fillchars' or 'listchars' to become
9500 invalid it is rejected and an error is given.
9501
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009502 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009503 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009504
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009505< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009506 the effect for known emoji characters. Move the cursor
9507 through the text to check if the cell widths of your terminal
9508 match with what Vim knows about each emoji. If it doesn't
9509 look right you need to adjust the {list} argument.
9510
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009511 Return type: |Number|
9512
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009513
9514setcharpos({expr}, {list}) *setcharpos()*
9515 Same as |setpos()| but uses the specified column number as the
9516 character index instead of the byte index in the line.
9517
9518 Example:
9519 With the text "여보세요" in line 8: >
9520 call setcharpos('.', [0, 8, 4, 0])
9521< positions the cursor on the fourth character '요'. >
9522 call setpos('.', [0, 8, 4, 0])
9523< positions the cursor on the second character '보'.
9524
9525 Can also be used as a |method|: >
9526 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009527<
9528 Return type: |Number|
9529
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009530
9531setcharsearch({dict}) *setcharsearch()*
9532 Set the current character search information to {dict},
9533 which contains one or more of the following entries:
9534
9535 char character which will be used for a subsequent
9536 |,| or |;| command; an empty string clears the
9537 character search
9538 forward direction of character search; 1 for forward,
9539 0 for backward
9540 until type of character search; 1 for a |t| or |T|
9541 character search, 0 for an |f| or |F|
9542 character search
9543
9544 This can be useful to save/restore a user's character search
9545 from a script: >
9546 :let prevsearch = getcharsearch()
9547 :" Perform a command which clobbers user's search
9548 :call setcharsearch(prevsearch)
9549< Also see |getcharsearch()|.
9550
9551 Can also be used as a |method|: >
9552 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009553<
9554 Return type: dict<any>
9555
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009556
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009557setcmdline({str} [, {pos}]) *setcmdline()*
9558 Set the command line to {str} and set the cursor position to
9559 {pos}.
9560 If {pos} is omitted, the cursor is positioned after the text.
9561 Returns 0 when successful, 1 when not editing the command
9562 line.
9563
9564 Can also be used as a |method|: >
9565 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009566<
9567 Return type: |Number|
9568
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009569
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009570setcmdpos({pos}) *setcmdpos()*
9571 Set the cursor position in the command line to byte position
9572 {pos}. The first position is 1.
9573 Use |getcmdpos()| to obtain the current position.
9574 Only works while editing the command line, thus you must use
9575 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9576 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9577 set after the command line is set to the expression. For
9578 |c_CTRL-R_=| it is set after evaluating the expression but
9579 before inserting the resulting text.
9580 When the number is too big the cursor is put at the end of the
9581 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009582 Returns 0 when successful, 1 when not editing the command
9583 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009584
9585 Can also be used as a |method|: >
9586 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009587<
9588 Return type: |Number|
9589
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009590
9591setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9592setcursorcharpos({list})
9593 Same as |cursor()| but uses the specified column number as the
9594 character index instead of the byte index in the line.
9595
9596 Example:
9597 With the text "여보세요" in line 4: >
9598 call setcursorcharpos(4, 3)
9599< positions the cursor on the third character '세'. >
9600 call cursor(4, 3)
9601< positions the cursor on the first character '여'.
9602
9603 Can also be used as a |method|: >
9604 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009605<
9606 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009607
9608
9609setenv({name}, {val}) *setenv()*
9610 Set environment variable {name} to {val}. Example: >
9611 call setenv('HOME', '/home/myhome')
9612
9613< When {val} is |v:null| the environment variable is deleted.
9614 See also |expr-env|.
9615
9616 Can also be used as a |method|, the base is passed as the
9617 second argument: >
9618 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009619<
9620 Return type: |Number|
9621
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009622
9623setfperm({fname}, {mode}) *setfperm()* *chmod*
9624 Set the file permissions for {fname} to {mode}.
9625 {mode} must be a string with 9 characters. It is of the form
9626 "rwxrwxrwx", where each group of "rwx" flags represent, in
9627 turn, the permissions of the owner of the file, the group the
9628 file belongs to, and other users. A '-' character means the
9629 permission is off, any other character means on. Multi-byte
9630 characters are not supported.
9631
9632 For example "rw-r-----" means read-write for the user,
9633 readable by the group, not accessible by others. "xx-x-----"
9634 would do the same thing.
9635
9636 Returns non-zero for success, zero for failure.
9637
9638 Can also be used as a |method|: >
9639 GetFilename()->setfperm(mode)
9640<
9641 To read permissions see |getfperm()|.
9642
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009643 Return type: |Number|
9644
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009645
9646setline({lnum}, {text}) *setline()*
9647 Set line {lnum} of the current buffer to {text}. To insert
9648 lines use |append()|. To set lines in another buffer use
Christian Brabandt946f61c2024-06-17 13:17:58 +02009649 |setbufline()|.
h-east52e7cc22024-07-28 17:03:29 +02009650 Any text properties in {lnum} are cleared. See
9651 |text-prop-cleared|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009652
9653 {lnum} is used like with |getline()|.
9654 When {lnum} is just below the last line the {text} will be
9655 added below the last line.
9656 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009657 converted to a String. When {text} is an empty List then
9658 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009659
9660 If this succeeds, FALSE is returned. If this fails (most likely
9661 because {lnum} is invalid) TRUE is returned.
9662 In |Vim9| script an error is given if {lnum} is invalid.
9663
9664 Example: >
9665 :call setline(5, strftime("%c"))
9666
9667< When {text} is a |List| then line {lnum} and following lines
9668 will be set to the items in the list. Example: >
9669 :call setline(5, ['aaa', 'bbb', 'ccc'])
9670< This is equivalent to: >
9671 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9672 : call setline(n, l)
9673 :endfor
9674
9675< Note: The '[ and '] marks are not set.
9676
9677 Can also be used as a |method|, the base is passed as the
9678 second argument: >
9679 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009680<
9681 Return type: |Number|
9682
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009683
9684setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9685 Create or replace or add to the location list for window {nr}.
9686 {nr} can be the window number or the |window-ID|.
9687 When {nr} is zero the current window is used.
9688
9689 For a location list window, the displayed location list is
9690 modified. For an invalid window number {nr}, -1 is returned.
9691 Otherwise, same as |setqflist()|.
9692 Also see |location-list|.
9693
9694 For {action} see |setqflist-action|.
9695
9696 If the optional {what} dictionary argument is supplied, then
9697 only the items listed in {what} are set. Refer to |setqflist()|
9698 for the list of supported keys in {what}.
9699
9700 Can also be used as a |method|, the base is passed as the
9701 second argument: >
9702 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009703<
9704 Return type: |Number|
9705
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009706
9707setmatches({list} [, {win}]) *setmatches()*
9708 Restores a list of matches saved by |getmatches()| for the
9709 current window. Returns 0 if successful, otherwise -1. All
9710 current matches are cleared before the list is restored. See
9711 example for |getmatches()|.
9712 If {win} is specified, use the window with this number or
9713 window ID instead of the current window.
9714
9715 Can also be used as a |method|: >
9716 GetMatches()->setmatches()
9717<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009718 Return type: |Number|
9719
9720
9721setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009722 Set the position for String {expr}. Possible values:
9723 . the cursor
9724 'x mark x
9725
9726 {list} must be a |List| with four or five numbers:
9727 [bufnum, lnum, col, off]
9728 [bufnum, lnum, col, off, curswant]
9729
9730 "bufnum" is the buffer number. Zero can be used for the
9731 current buffer. When setting an uppercase mark "bufnum" is
9732 used for the mark position. For other marks it specifies the
9733 buffer to set the mark in. You can use the |bufnr()| function
9734 to turn a file name into a buffer number.
9735 For setting the cursor and the ' mark "bufnum" is ignored,
9736 since these are associated with a window, not a buffer.
9737 Does not change the jumplist.
9738
9739 "lnum" and "col" are the position in the buffer. The first
9740 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9741 smaller than 1 then 1 is used. To use the character count
9742 instead of the byte count, use |setcharpos()|.
9743
9744 The "off" number is only used when 'virtualedit' is set. Then
9745 it is the offset in screen columns from the start of the
9746 character. E.g., a position within a <Tab> or after the last
9747 character.
9748
9749 The "curswant" number is only used when setting the cursor
9750 position. It sets the preferred column for when moving the
9751 cursor vertically. When the "curswant" number is missing the
9752 preferred column is not set. When it is present and setting a
9753 mark position it is not used.
9754
9755 Note that for '< and '> changing the line number may result in
9756 the marks to be effectively be swapped, so that '< is always
9757 before '>.
9758
9759 Returns 0 when the position could be set, -1 otherwise.
9760 An error message is given if {expr} is invalid.
9761
9762 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9763
9764 This does not restore the preferred column for moving
9765 vertically; if you set the cursor position with this, |j| and
9766 |k| motions will jump to previous columns! Use |cursor()| to
9767 also set the preferred column. Also see the "curswant" key in
9768 |winrestview()|.
9769
9770 Can also be used as a |method|: >
9771 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009772<
9773 Return type: |Number|
9774
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009775
9776setqflist({list} [, {action} [, {what}]]) *setqflist()*
9777 Create or replace or add to the quickfix list.
9778
9779 If the optional {what} dictionary argument is supplied, then
9780 only the items listed in {what} are set. The first {list}
9781 argument is ignored. See below for the supported items in
9782 {what}.
9783 *setqflist-what*
9784 When {what} is not present, the items in {list} are used. Each
9785 item must be a dictionary. Non-dictionary items in {list} are
9786 ignored. Each dictionary item can contain the following
9787 entries:
9788
9789 bufnr buffer number; must be the number of a valid
9790 buffer
9791 filename name of a file; only used when "bufnr" is not
9792 present or it is invalid.
9793 module name of a module; if given it will be used in
9794 quickfix error window instead of the filename.
9795 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00009796 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009797 pattern search pattern used to locate the error
9798 col column number
9799 vcol when non-zero: "col" is visual column
9800 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00009801 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009802 nr error number
9803 text description of the error
9804 type single-character error type, 'E', 'W', etc.
9805 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +02009806 user_data custom data associated with the item, can be
9807 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009808
9809 The "col", "vcol", "nr", "type" and "text" entries are
9810 optional. Either "lnum" or "pattern" entry can be used to
9811 locate a matching error line.
9812 If the "filename" and "bufnr" entries are not present or
9813 neither the "lnum" or "pattern" entries are present, then the
9814 item will not be handled as an error line.
9815 If both "pattern" and "lnum" are present then "pattern" will
9816 be used.
9817 If the "valid" entry is not supplied, then the valid flag is
9818 set when "bufnr" is a valid buffer or "filename" exists.
9819 If you supply an empty {list}, the quickfix list will be
9820 cleared.
9821 Note that the list is not exactly the same as what
9822 |getqflist()| returns.
9823
9824 {action} values: *setqflist-action* *E927*
9825 'a' The items from {list} are added to the existing
9826 quickfix list. If there is no existing list, then a
9827 new list is created.
9828
9829 'r' The items from the current quickfix list are replaced
9830 with the items from {list}. This can also be used to
9831 clear the list: >
9832 :call setqflist([], 'r')
9833<
Jeremy Fleischman27fbf6e2024-10-14 20:46:27 +02009834 'u' Like 'r', but tries to preserve the current selection
9835 in the quickfix list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009836 'f' All the quickfix lists in the quickfix stack are
9837 freed.
9838
9839 If {action} is not present or is set to ' ', then a new list
9840 is created. The new quickfix list is added after the current
9841 quickfix list in the stack and all the following lists are
9842 freed. To add a new quickfix list at the end of the stack,
9843 set "nr" in {what} to "$".
9844
9845 The following items can be specified in dictionary {what}:
9846 context quickfix list context. See |quickfix-context|
9847 efm errorformat to use when parsing text from
9848 "lines". If this is not present, then the
9849 'errorformat' option value is used.
9850 See |quickfix-parse|
9851 id quickfix list identifier |quickfix-ID|
9852 idx index of the current entry in the quickfix
9853 list specified by 'id' or 'nr'. If set to '$',
9854 then the last entry in the list is set as the
9855 current entry. See |quickfix-index|
9856 items list of quickfix entries. Same as the {list}
9857 argument.
9858 lines use 'errorformat' to parse a list of lines and
9859 add the resulting entries to the quickfix list
9860 {nr} or {id}. Only a |List| value is supported.
9861 See |quickfix-parse|
9862 nr list number in the quickfix stack; zero
9863 means the current quickfix list and "$" means
9864 the last quickfix list.
9865 quickfixtextfunc
9866 function to get the text to display in the
9867 quickfix window. The value can be the name of
9868 a function or a funcref or a lambda. Refer to
9869 |quickfix-window-function| for an explanation
9870 of how to write the function and an example.
9871 title quickfix list title text. See |quickfix-title|
9872 Unsupported keys in {what} are ignored.
9873 If the "nr" item is not present, then the current quickfix list
9874 is modified. When creating a new quickfix list, "nr" can be
9875 set to a value one greater than the quickfix stack size.
9876 When modifying a quickfix list, to guarantee that the correct
9877 list is modified, "id" should be used instead of "nr" to
9878 specify the list.
9879
9880 Examples (See also |setqflist-examples|): >
9881 :call setqflist([], 'r', {'title': 'My search'})
9882 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
9883 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
9884<
9885 Returns zero for success, -1 for failure.
9886
9887 This function can be used to create a quickfix list
9888 independent of the 'errorformat' setting. Use a command like
9889 `:cc 1` to jump to the first position.
9890
9891 Can also be used as a |method|, the base is passed as the
9892 second argument: >
9893 GetErrorlist()->setqflist()
9894<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009895 Return type: |Number|
9896
9897
9898setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009899 Set the register {regname} to {value}.
9900 If {regname} is "" or "@", the unnamed register '"' is used.
9901 The {regname} argument is a string. In |Vim9-script|
9902 {regname} must be one character.
9903
9904 {value} may be any value returned by |getreg()| or
9905 |getreginfo()|, including a |List| or |Dict|.
9906 If {options} contains "a" or {regname} is upper case,
9907 then the value is appended.
9908
9909 {options} can also contain a register type specification:
9910 "c" or "v" |characterwise| mode
9911 "l" or "V" |linewise| mode
9912 "b" or "<CTRL-V>" |blockwise-visual| mode
9913 If a number immediately follows "b" or "<CTRL-V>" then this is
9914 used as the width of the selection - if it is not specified
9915 then the width of the block is set to the number of characters
9916 in the longest line (counting a <Tab> as 1 character).
9917
9918 If {options} contains no register settings, then the default
9919 is to use character mode unless {value} ends in a <NL> for
9920 string {value} and linewise mode for list {value}. Blockwise
9921 mode is never selected automatically.
9922 Returns zero for success, non-zero for failure.
9923
9924 *E883*
9925 Note: you may not use |List| containing more than one item to
9926 set search and expression registers. Lists containing no
9927 items act like empty strings.
9928
9929 Examples: >
9930 :call setreg(v:register, @*)
9931 :call setreg('*', @%, 'ac')
9932 :call setreg('a', "1\n2\n3", 'b5')
9933 :call setreg('"', { 'points_to': 'a'})
9934
9935< This example shows using the functions to save and restore a
9936 register: >
9937 :let var_a = getreginfo()
9938 :call setreg('a', var_a)
9939< or: >
9940 :let var_a = getreg('a', 1, 1)
9941 :let var_amode = getregtype('a')
9942 ....
9943 :call setreg('a', var_a, var_amode)
9944< Note: you may not reliably restore register value
9945 without using the third argument to |getreg()| as without it
9946 newlines are represented as newlines AND Nul bytes are
9947 represented as newlines as well, see |NL-used-for-Nul|.
9948
9949 You can also change the type of a register by appending
9950 nothing: >
9951 :call setreg('a', '', 'al')
9952
9953< Can also be used as a |method|, the base is passed as the
9954 second argument: >
9955 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009956<
9957 Return type: |Number|
9958
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009959
9960settabvar({tabnr}, {varname}, {val}) *settabvar()*
9961 Set tab-local variable {varname} to {val} in tab page {tabnr}.
9962 |t:var|
9963 The {varname} argument is a string.
9964 Note that autocommands are blocked, side effects may not be
9965 triggered, e.g. when setting 'filetype'.
9966 Note that the variable name without "t:" must be used.
9967 Tabs are numbered starting with one.
9968 This function is not available in the |sandbox|.
9969
9970 Can also be used as a |method|, the base is passed as the
9971 third argument: >
9972 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009973<
9974 Return type: |Number|
9975
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009976
9977settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
9978 Set option or local variable {varname} in window {winnr} to
9979 {val}.
9980 Tabs are numbered starting with one. For the current tabpage
9981 use |setwinvar()|.
9982 {winnr} can be the window number or the |window-ID|.
9983 When {winnr} is zero the current window is used.
9984 Note that autocommands are blocked, side effects may not be
9985 triggered, e.g. when setting 'filetype' or 'syntax'.
9986 This also works for a global or local buffer option, but it
9987 doesn't work for a global or local buffer variable.
9988 For a local buffer option the global value is unchanged.
9989 Note that the variable name without "w:" must be used.
9990 Examples: >
9991 :call settabwinvar(1, 1, "&list", 0)
9992 :call settabwinvar(3, 2, "myvar", "foobar")
9993< This function is not available in the |sandbox|.
9994
9995 Can also be used as a |method|, the base is passed as the
9996 fourth argument: >
9997 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009998<
9999 Return type: |Number|
10000
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010001
10002settagstack({nr}, {dict} [, {action}]) *settagstack()*
10003 Modify the tag stack of the window {nr} using {dict}.
10004 {nr} can be the window number or the |window-ID|.
10005
10006 For a list of supported items in {dict}, refer to
10007 |gettagstack()|. "curidx" takes effect before changing the tag
10008 stack.
10009 *E962*
10010 How the tag stack is modified depends on the {action}
10011 argument:
10012 - If {action} is not present or is set to 'r', then the tag
10013 stack is replaced.
10014 - If {action} is set to 'a', then new entries from {dict} are
10015 pushed (added) onto the tag stack.
10016 - If {action} is set to 't', then all the entries from the
10017 current entry in the tag stack or "curidx" in {dict} are
10018 removed and then new entries are pushed to the stack.
10019
10020 The current index is set to one after the length of the tag
10021 stack after the modification.
10022
10023 Returns zero for success, -1 for failure.
10024
10025 Examples (for more examples see |tagstack-examples|):
10026 Empty the tag stack of window 3: >
10027 call settagstack(3, {'items' : []})
10028
10029< Save and restore the tag stack: >
10030 let stack = gettagstack(1003)
10031 " do something else
10032 call settagstack(1003, stack)
10033 unlet stack
10034<
10035 Can also be used as a |method|, the base is passed as the
10036 second argument: >
10037 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010038<
10039 Return type: |Number|
10040
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010041
10042setwinvar({winnr}, {varname}, {val}) *setwinvar()*
10043 Like |settabwinvar()| for the current tab page.
10044 Examples: >
10045 :call setwinvar(1, "&list", 0)
10046 :call setwinvar(2, "myvar", "foobar")
10047
10048< Can also be used as a |method|, the base is passed as the
10049 third argument: >
10050 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010051<
10052 Return type: |Number|
10053
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010054
10055sha256({string}) *sha256()*
10056 Returns a String with 64 hex characters, which is the SHA256
10057 checksum of {string}.
10058
10059 Can also be used as a |method|: >
10060 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010061<
10062 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010063
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010064 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010065
10066shellescape({string} [, {special}]) *shellescape()*
10067 Escape {string} for use as a shell command argument.
10068 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +000010069 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010070 in single quotes and will double up all internal single
10071 quotes.
10072 On MS-Windows, when 'shellslash' is not set, it will enclose
10073 {string} in double quotes and double all double quotes within
10074 {string}.
10075 Otherwise it will enclose {string} in single quotes and
10076 replace all "'" with "'\''".
10077
Enno5faeb602024-05-15 21:54:19 +020010078 The {special} argument adds additional escaping of keywords
10079 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +090010080 number or a non-empty String (|non-zero-arg|), then special
10081 items such as "!", "%", "#" and "<cword>" (as listed in
10082 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +020010083 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010084
10085 The "!" character will be escaped (again with a |non-zero-arg|
10086 {special}) when 'shell' contains "csh" in the tail. That is
10087 because for csh and tcsh "!" is used for history replacement
10088 even when inside single quotes.
10089
10090 With a |non-zero-arg| {special} the <NL> character is also
10091 escaped. When 'shell' containing "csh" in the tail it's
10092 escaped a second time.
10093
10094 The "\" character will be escaped when 'shell' contains "fish"
10095 in the tail. That is because for fish "\" is used as an escape
10096 character inside single quotes.
10097
10098 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010099 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010100< This results in a directory listing for the file under the
10101 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010102 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010103< See also |::S|.
10104
10105 Can also be used as a |method|: >
10106 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010107<
10108 Return type: |String|
10109
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010110
10111shiftwidth([{col}]) *shiftwidth()*
10112 Returns the effective value of 'shiftwidth'. This is the
10113 'shiftwidth' value unless it is zero, in which case it is the
10114 'tabstop' value. This function was introduced with patch
10115 7.3.694 in 2012, everybody should have it by now (however it
10116 did not allow for the optional {col} argument until 8.1.542).
10117
10118 When there is one argument {col} this is used as column number
10119 for which to return the 'shiftwidth' value. This matters for the
10120 'vartabstop' feature. If the 'vartabstop' setting is enabled and
10121 no {col} argument is given, column 1 will be assumed.
10122
10123 Can also be used as a |method|: >
10124 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010125<
10126 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010127
10128sign_ functions are documented here: |sign-functions-details|
10129
10130
10131simplify({filename}) *simplify()*
10132 Simplify the file name as much as possible without changing
10133 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
10134 Unix) are not resolved. If the first path component in
10135 {filename} designates the current directory, this will be
10136 valid for the result as well. A trailing path separator is
10137 not removed either. On Unix "//path" is unchanged, but
10138 "///path" is simplified to "/path" (this follows the Posix
10139 standard).
10140 Example: >
10141 simplify("./dir/.././/file/") == "./file/"
10142< Note: The combination "dir/.." is only removed if "dir" is
10143 a searchable directory or does not exist. On Unix, it is also
10144 removed when "dir" is a symbolic link within the same
10145 directory. In order to resolve all the involved symbolic
10146 links before simplifying the path name, use |resolve()|.
10147
10148 Can also be used as a |method|: >
10149 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010150<
10151 Return type: |String|
10152
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010153
10154sin({expr}) *sin()*
10155 Return the sine of {expr}, measured in radians, as a |Float|.
10156 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010157 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010158 Examples: >
10159 :echo sin(100)
10160< -0.506366 >
10161 :echo sin(-4.01)
10162< 0.763301
10163
10164 Can also be used as a |method|: >
10165 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010166<
10167 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010168
10169
10170sinh({expr}) *sinh()*
10171 Return the hyperbolic sine of {expr} as a |Float| in the range
10172 [-inf, inf].
10173 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010174 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010175 Examples: >
10176 :echo sinh(0.5)
10177< 0.521095 >
10178 :echo sinh(-0.9)
10179< -1.026517
10180
10181 Can also be used as a |method|: >
10182 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010183<
10184 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010185
10186
10187slice({expr}, {start} [, {end}]) *slice()*
10188 Similar to using a |slice| "expr[start : end]", but "end" is
10189 used exclusive. And for a string the indexes are used as
10190 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010191 |vim9script|. Also, composing characters are treated as a
10192 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010193 When {end} is omitted the slice continues to the last item.
10194 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010195 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010196
10197 Can also be used as a |method|: >
10198 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010199<
10200 Return type: list<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010201
10202
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010203sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010204 Sort the items in {list} in-place. Returns {list}.
10205
10206 If you want a list to remain unmodified make a copy first: >
10207 :let sortedlist = sort(copy(mylist))
10208
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010209< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010210 string representation of each item to sort on. Numbers sort
10211 after Strings, |Lists| after Numbers. For sorting text in the
10212 current buffer use |:sort|.
10213
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010214 When {how} is given and it is 'i' then case is ignored.
10215 In legacy script, for backwards compatibility, the value one
10216 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010217
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010218 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010219 locale is used for ordering. Implementation details: strcoll()
10220 is used to compare strings. See |:language| check or set the
10221 collation locale. |v:collate| can also be used to check the
10222 current locale. Sorting using the locale typically ignores
10223 case. Example: >
10224 " ö is sorted similarly to o with English locale.
10225 :language collate en_US.UTF8
10226 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10227< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10228>
10229 " ö is sorted after z with Swedish locale.
10230 :language collate sv_SE.UTF8
10231 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10232< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10233 This does not work properly on Mac.
10234
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010235 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010236 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010237 strtod() function to parse numbers. Strings, Lists, Dicts and
10238 Funcrefs will be considered as being 0). Note that this won't
10239 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010240
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010241 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010242 sorted numerical. This is like 'n' but a string containing
10243 digits will be used as the number they represent.
10244
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010245 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010246 sorted numerical. All values must be a Number or a Float.
10247
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010248 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010249 is called to compare items. The function is invoked with two
10250 items as argument and must return zero if they are equal, 1 or
10251 bigger if the first one sorts after the second one, -1 or
10252 smaller if the first one sorts before the second one.
10253
10254 {dict} is for functions with the "dict" attribute. It will be
10255 used to set the local variable "self". |Dictionary-function|
10256
10257 The sort is stable, items which compare equal (as number or as
10258 string) will keep their relative position. E.g., when sorting
10259 on numbers, text strings will sort next to each other, in the
10260 same order as they were originally.
10261
10262 Can also be used as a |method|: >
10263 mylist->sort()
10264
10265< Also see |uniq()|.
10266
10267 Example: >
10268 func MyCompare(i1, i2)
10269 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10270 endfunc
10271 eval mylist->sort("MyCompare")
10272< A shorter compare version for this specific simple case, which
10273 ignores overflow: >
10274 func MyCompare(i1, i2)
10275 return a:i1 - a:i2
10276 endfunc
10277< For a simple expression you can use a lambda: >
10278 eval mylist->sort({i1, i2 -> i1 - i2})
10279<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010280 Return type: list<{type}>
10281
10282
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010283sound_clear() *sound_clear()*
10284 Stop playing all sounds.
10285
10286 On some Linux systems you may need the libcanberra-pulse
10287 package, otherwise sound may not stop.
10288
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010289 Return type: |Number|
10290
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010291 {only available when compiled with the |+sound| feature}
10292
10293 *sound_playevent()*
10294sound_playevent({name} [, {callback}])
10295 Play a sound identified by {name}. Which event names are
10296 supported depends on the system. Often the XDG sound names
10297 are used. On Ubuntu they may be found in
10298 /usr/share/sounds/freedesktop/stereo. Example: >
10299 call sound_playevent('bell')
10300< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10301 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10302 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010303 On macOS, {name} refers to files located in
10304 /System/Library/Sounds (e.g. "Tink"). It will also work for
10305 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010306
10307 When {callback} is specified it is invoked when the sound is
10308 finished. The first argument is the sound ID, the second
10309 argument is the status:
10310 0 sound was played to the end
10311 1 sound was interrupted
10312 2 error occurred after sound started
10313 Example: >
10314 func Callback(id, status)
10315 echomsg "sound " .. a:id .. " finished with " .. a:status
10316 endfunc
10317 call sound_playevent('bell', 'Callback')
10318
10319< MS-Windows: {callback} doesn't work for this function.
10320
10321 Returns the sound ID, which can be passed to `sound_stop()`.
10322 Returns zero if the sound could not be played.
10323
10324 Can also be used as a |method|: >
10325 GetSoundName()->sound_playevent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010326<
10327 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010328
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010329 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010330
10331 *sound_playfile()*
10332sound_playfile({path} [, {callback}])
10333 Like `sound_playevent()` but play sound file {path}. {path}
10334 must be a full path. On Ubuntu you may find files to play
10335 with this command: >
10336 :!find /usr/share/sounds -type f | grep -v index.theme
10337
10338< Can also be used as a |method|: >
10339 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010340<
10341 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010342
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010343 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010344
10345
10346sound_stop({id}) *sound_stop()*
10347 Stop playing sound {id}. {id} must be previously returned by
10348 `sound_playevent()` or `sound_playfile()`.
10349
10350 On some Linux systems you may need the libcanberra-pulse
10351 package, otherwise sound may not stop.
10352
10353 On MS-Windows, this does not work for event sound started by
10354 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10355
10356 Can also be used as a |method|: >
10357 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010358<
10359 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010360
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010361 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010362
10363 *soundfold()*
10364soundfold({word})
10365 Return the sound-folded equivalent of {word}. Uses the first
10366 language in 'spelllang' for the current window that supports
10367 soundfolding. 'spell' must be set. When no sound folding is
10368 possible the {word} is returned unmodified.
10369 This can be used for making spelling suggestions. Note that
10370 the method can be quite slow.
10371
10372 Can also be used as a |method|: >
10373 GetWord()->soundfold()
10374<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010375 Return type: |String|
10376
10377
10378spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010379 Without argument: The result is the badly spelled word under
10380 or after the cursor. The cursor is moved to the start of the
10381 bad word. When no bad word is found in the cursor line the
10382 result is an empty string and the cursor doesn't move.
10383
10384 With argument: The result is the first word in {sentence} that
10385 is badly spelled. If there are no spelling mistakes the
10386 result is an empty string.
10387
10388 The return value is a list with two items:
10389 - The badly spelled word or an empty string.
10390 - The type of the spelling error:
10391 "bad" spelling mistake
10392 "rare" rare word
10393 "local" word only valid in another region
10394 "caps" word should start with Capital
10395 Example: >
10396 echo spellbadword("the quik brown fox")
10397< ['quik', 'bad'] ~
10398
10399 The spelling information for the current window and the value
10400 of 'spelllang' are used.
10401
10402 Can also be used as a |method|: >
10403 GetText()->spellbadword()
10404<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010405 Return type: list<string>
10406
10407
10408spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010409 Return a |List| with spelling suggestions to replace {word}.
10410 When {max} is given up to this number of suggestions are
10411 returned. Otherwise up to 25 suggestions are returned.
10412
10413 When the {capital} argument is given and it's non-zero only
10414 suggestions with a leading capital will be given. Use this
10415 after a match with 'spellcapcheck'.
10416
10417 {word} can be a badly spelled word followed by other text.
10418 This allows for joining two words that were split. The
10419 suggestions also include the following text, thus you can
10420 replace a line.
10421
10422 {word} may also be a good word. Similar words will then be
10423 returned. {word} itself is not included in the suggestions,
10424 although it may appear capitalized.
10425
10426 The spelling information for the current window is used. The
10427 values of 'spelllang' and 'spellsuggest' are used.
10428
10429 Can also be used as a |method|: >
10430 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010431<
10432 Return type: list<string> or list<any>
10433
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010434
10435split({string} [, {pattern} [, {keepempty}]]) *split()*
10436 Make a |List| out of {string}. When {pattern} is omitted or
Shane Harperc1b39842024-07-17 19:40:40 +020010437 empty each white space separated sequence of characters
10438 becomes an item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010439 Otherwise the string is split where {pattern} matches,
10440 removing the matched characters. 'ignorecase' is not used
10441 here, add \c to ignore case. |/\c|
10442 When the first or last item is empty it is omitted, unless the
10443 {keepempty} argument is given and it's non-zero.
10444 Other empty items are kept when {pattern} matches at least one
10445 character or when {keepempty} is non-zero.
10446 Example: >
10447 :let words = split(getline('.'), '\W\+')
10448< To split a string in individual characters: >
10449 :for c in split(mystring, '\zs')
10450< If you want to keep the separator you can also use '\zs' at
10451 the end of the pattern: >
10452 :echo split('abc:def:ghi', ':\zs')
10453< ['abc:', 'def:', 'ghi'] ~
10454 Splitting a table where the first element can be empty: >
10455 :let items = split(line, ':', 1)
10456< The opposite function is |join()|.
10457
10458 Can also be used as a |method|: >
10459 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010460<
10461 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010462
10463sqrt({expr}) *sqrt()*
10464 Return the non-negative square root of Float {expr} as a
10465 |Float|.
10466 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010467 is negative the result is NaN (Not a Number). Returns 0.0 if
10468 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010469 Examples: >
10470 :echo sqrt(100)
10471< 10.0 >
10472 :echo sqrt(-4.01)
10473< nan
10474 "nan" may be different, it depends on system libraries.
10475
10476 Can also be used as a |method|: >
10477 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010478<
10479 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010480
10481
10482srand([{expr}]) *srand()*
10483 Initialize seed used by |rand()|:
10484 - If {expr} is not given, seed values are initialized by
10485 reading from /dev/urandom, if possible, or using time(NULL)
10486 a.k.a. epoch time otherwise; this only has second accuracy.
10487 - If {expr} is given it must be a Number. It is used to
10488 initialize the seed values. This is useful for testing or
10489 when a predictable sequence is intended.
10490
10491 Examples: >
10492 :let seed = srand()
10493 :let seed = srand(userinput)
10494 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010495<
10496 Return type: list<number>
10497
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010498
10499state([{what}]) *state()*
10500 Return a string which contains characters indicating the
10501 current state. Mostly useful in callbacks that want to do
10502 work that may not always be safe. Roughly this works like:
10503 - callback uses state() to check if work is safe to do.
10504 Yes: then do it right away.
10505 No: add to work queue and add a |SafeState| and/or
10506 |SafeStateAgain| autocommand (|SafeState| triggers at
10507 toplevel, |SafeStateAgain| triggers after handling
10508 messages and callbacks).
10509 - When SafeState or SafeStateAgain is triggered and executes
10510 your autocommand, check with `state()` if the work can be
10511 done now, and if yes remove it from the queue and execute.
10512 Remove the autocommand if the queue is now empty.
10513 Also see |mode()|.
10514
10515 When {what} is given only characters in this string will be
10516 added. E.g, this checks if the screen has scrolled: >
10517 if state('s') == ''
10518 " screen has not scrolled
10519<
10520 These characters indicate the state, generally indicating that
10521 something is busy:
10522 m halfway a mapping, :normal command, feedkeys() or
10523 stuffed command
10524 o operator pending, e.g. after |d|
10525 a Insert mode autocomplete active
10526 x executing an autocommand
10527 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10528 ch_readraw() when reading json
10529 S not triggering SafeState or SafeStateAgain, e.g. after
10530 |f| or a count
10531 c callback invoked, including timer (repeats for
10532 recursiveness up to "ccc")
10533 s screen has scrolled for messages
10534
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010535 Return type: |String|
10536
10537
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010538str2float({string} [, {quoted}]) *str2float()*
10539 Convert String {string} to a Float. This mostly works the
10540 same as when using a floating point number in an expression,
10541 see |floating-point-format|. But it's a bit more permissive.
10542 E.g., "1e40" is accepted, while in an expression you need to
10543 write "1.0e40". The hexadecimal form "0x123" is also
10544 accepted, but not others, like binary or octal.
10545 When {quoted} is present and non-zero then embedded single
10546 quotes before the dot are ignored, thus "1'000.0" is a
10547 thousand.
10548 Text after the number is silently ignored.
10549 The decimal point is always '.', no matter what the locale is
10550 set to. A comma ends the number: "12,345.67" is converted to
10551 12.0. You can strip out thousands separators with
10552 |substitute()|: >
10553 let f = str2float(substitute(text, ',', '', 'g'))
10554<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010555 Returns 0.0 if the conversion fails.
10556
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010557 Can also be used as a |method|: >
10558 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010559<
10560 Return type: |Float|
10561
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010562
10563str2list({string} [, {utf8}]) *str2list()*
10564 Return a list containing the number values which represent
10565 each character in String {string}. Examples: >
10566 str2list(" ") returns [32]
10567 str2list("ABC") returns [65, 66, 67]
10568< |list2str()| does the opposite.
10569
10570 When {utf8} is omitted or zero, the current 'encoding' is used.
10571 When {utf8} is TRUE, always treat the String as UTF-8
10572 characters. With UTF-8 composing characters are handled
10573 properly: >
10574 str2list("á") returns [97, 769]
10575
10576< Can also be used as a |method|: >
10577 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010578<
10579 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010580
10581
10582str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10583 Convert string {string} to a number.
10584 {base} is the conversion base, it can be 2, 8, 10 or 16.
10585 When {quoted} is present and non-zero then embedded single
10586 quotes are ignored, thus "1'000'000" is a million.
10587
10588 When {base} is omitted base 10 is used. This also means that
10589 a leading zero doesn't cause octal conversion to be used, as
10590 with the default String to Number conversion. Example: >
10591 let nr = str2nr('0123')
10592<
10593 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10594 different base the result will be zero. Similarly, when
10595 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10596 {base} is 2 a leading "0b" or "0B" is ignored.
10597 Text after the number is silently ignored.
10598
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010599 Returns 0 if {string} is empty or on error.
10600
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010601 Can also be used as a |method|: >
10602 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010603<
10604 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010605
10606
10607strcharlen({string}) *strcharlen()*
10608 The result is a Number, which is the number of characters
10609 in String {string}. Composing characters are ignored.
10610 |strchars()| can count the number of characters, counting
10611 composing characters separately.
10612
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010613 Returns 0 if {string} is empty or on error.
10614
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010615 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10616
10617 Can also be used as a |method|: >
10618 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010619<
10620 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010621
10622
10623strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10624 Like |strpart()| but using character index and length instead
10625 of byte index and length.
10626 When {skipcc} is omitted or zero, composing characters are
10627 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010628 When {skipcc} set to 1, composing characters are treated as a
10629 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010630 When a character index is used where a character does not
10631 exist it is omitted and counted as one character. For
10632 example: >
10633 strcharpart('abc', -1, 2)
10634< results in 'a'.
10635
Bram Moolenaard592deb2022-06-17 15:42:40 +010010636 Returns an empty string on error.
10637
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010638 Can also be used as a |method|: >
10639 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010640<
10641 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010642
10643
10644strchars({string} [, {skipcc}]) *strchars()*
10645 The result is a Number, which is the number of characters
10646 in String {string}.
10647 When {skipcc} is omitted or zero, composing characters are
10648 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010649 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010650 |strcharlen()| always does this.
10651
Bram Moolenaard592deb2022-06-17 15:42:40 +010010652 Returns zero on error.
10653
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010654 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10655
10656 {skipcc} is only available after 7.4.755. For backward
10657 compatibility, you can define a wrapper function: >
10658 if has("patch-7.4.755")
10659 function s:strchars(str, skipcc)
10660 return strchars(a:str, a:skipcc)
10661 endfunction
10662 else
10663 function s:strchars(str, skipcc)
10664 if a:skipcc
10665 return strlen(substitute(a:str, ".", "x", "g"))
10666 else
10667 return strchars(a:str)
10668 endif
10669 endfunction
10670 endif
10671<
10672 Can also be used as a |method|: >
10673 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010674<
10675 Return type: |Number|
10676
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010677
10678strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10679 The result is a Number, which is the number of display cells
10680 String {string} occupies on the screen when it starts at {col}
10681 (first column is zero). When {col} is omitted zero is used.
10682 Otherwise it is the screen column where to start. This
10683 matters for Tab characters.
10684 The option settings of the current window are used. This
10685 matters for anything that's displayed differently, such as
10686 'tabstop' and 'display'.
10687 When {string} contains characters with East Asian Width Class
10688 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010689 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010690 Also see |strlen()|, |strwidth()| and |strchars()|.
10691
10692 Can also be used as a |method|: >
10693 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010694<
10695 Return type: |Number|
10696
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010697
10698strftime({format} [, {time}]) *strftime()*
10699 The result is a String, which is a formatted date and time, as
10700 specified by the {format} string. The given {time} is used,
10701 or the current time if no time is given. The accepted
10702 {format} depends on your system, thus this is not portable!
10703 See the manual page of the C function strftime() for the
10704 format. The maximum length of the result is 80 characters.
10705 See also |localtime()|, |getftime()| and |strptime()|.
10706 The language can be changed with the |:language| command.
10707 Examples: >
10708 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10709 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10710 :echo strftime("%y%m%d %T") 970427 11:53:55
10711 :echo strftime("%H:%M") 11:55
10712 :echo strftime("%c", getftime("file.c"))
10713 Show mod time of file.c.
10714< Not available on all systems. To check use: >
10715 :if exists("*strftime")
10716
10717< Can also be used as a |method|: >
10718 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010719<
10720 Return type: |String|
10721
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010722
10723strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010724 Get a Number corresponding to the character at {index} in
10725 {str}. This uses a zero-based character index, not a byte
10726 index. Composing characters are considered separate
10727 characters here. Use |nr2char()| to convert the Number to a
10728 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010729 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010730 Also see |strcharpart()| and |strchars()|.
10731
10732 Can also be used as a |method|: >
10733 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010734<
10735 Return type: |Number|
10736
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010737
10738stridx({haystack}, {needle} [, {start}]) *stridx()*
10739 The result is a Number, which gives the byte index in
10740 {haystack} of the first occurrence of the String {needle}.
10741 If {start} is specified, the search starts at index {start}.
10742 This can be used to find a second match: >
10743 :let colon1 = stridx(line, ":")
10744 :let colon2 = stridx(line, ":", colon1 + 1)
10745< The search is done case-sensitive.
10746 For pattern searches use |match()|.
10747 -1 is returned if the {needle} does not occur in {haystack}.
10748 See also |strridx()|.
10749 Examples: >
10750 :echo stridx("An Example", "Example") 3
10751 :echo stridx("Starting point", "Start") 0
10752 :echo stridx("Starting point", "start") -1
10753< *strstr()* *strchr()*
10754 stridx() works similar to the C function strstr(). When used
10755 with a single character it works similar to strchr().
10756
10757 Can also be used as a |method|: >
10758 GetHaystack()->stridx(needle)
10759<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010760 Return type: |Number|
10761
10762
10763string({expr}) *string()*
10764 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010765 Float, String, Blob or a composition of them, then the result
10766 can be parsed back with |eval()|.
10767 {expr} type result ~
10768 String 'string' (single quotes are doubled)
10769 Number 123
10770 Float 123.123456 or 1.123456e8
10771 Funcref function('name')
10772 Blob 0z00112233.44556677.8899
10773 List [item, item]
10774 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000010775 Class class SomeName
10776 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010010777 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020010778 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010779
10780 When a |List| or |Dictionary| has a recursive reference it is
10781 replaced by "[...]" or "{...}". Using eval() on the result
10782 will then fail.
10783
mityu7f0bba22024-03-29 10:14:41 +010010784 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010785 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010010786 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010787
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010788 Can also be used as a |method|: >
10789 mylist->string()
10790
10791< Also see |strtrans()|.
10792
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010793 Return type: |String|
10794
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010795
10796strlen({string}) *strlen()*
10797 The result is a Number, which is the length of the String
10798 {string} in bytes.
10799 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010800 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010801 If you want to count the number of multibyte characters use
10802 |strchars()|.
10803 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
10804
10805 Can also be used as a |method|: >
10806 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010807<
10808 Return type: |Number|
10809
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010810
10811strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
10812 The result is a String, which is part of {src}, starting from
10813 byte {start}, with the byte length {len}.
10814 When {chars} is present and TRUE then {len} is the number of
10815 characters positions (composing characters are not counted
10816 separately, thus "1" means one base character and any
10817 following composing characters).
10818 To count {start} as characters instead of bytes use
10819 |strcharpart()|.
10820
10821 When bytes are selected which do not exist, this doesn't
10822 result in an error, the bytes are simply omitted.
10823 If {len} is missing, the copy continues from {start} till the
10824 end of the {src}. >
10825 strpart("abcdefg", 3, 2) == "de"
10826 strpart("abcdefg", -2, 4) == "ab"
10827 strpart("abcdefg", 5, 4) == "fg"
10828 strpart("abcdefg", 3) == "defg"
10829
10830< Note: To get the first character, {start} must be 0. For
10831 example, to get the character under the cursor: >
10832 strpart(getline("."), col(".") - 1, 1, v:true)
10833<
Bram Moolenaard592deb2022-06-17 15:42:40 +010010834 Returns an empty string on error.
10835
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010836 Can also be used as a |method|: >
10837 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010838<
10839 Return type: |String|
10840
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010841
10842strptime({format}, {timestring}) *strptime()*
10843 The result is a Number, which is a unix timestamp representing
10844 the date and time in {timestring}, which is expected to match
10845 the format specified in {format}.
10846
10847 The accepted {format} depends on your system, thus this is not
10848 portable! See the manual page of the C function strptime()
10849 for the format. Especially avoid "%c". The value of $TZ also
10850 matters.
10851
10852 If the {timestring} cannot be parsed with {format} zero is
10853 returned. If you do not know the format of {timestring} you
10854 can try different {format} values until you get a non-zero
10855 result.
10856
10857 See also |strftime()|.
10858 Examples: >
10859 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
10860< 862156163 >
10861 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
10862< Sun Apr 27 11:53:55 1997 >
10863 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
10864< Sun Apr 27 12:53:55 1997
10865
10866 Can also be used as a |method|: >
10867 GetFormat()->strptime(timestring)
10868<
10869 Not available on all systems. To check use: >
10870 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010871<
10872 Return type: |Number|
10873
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010874
10875strridx({haystack}, {needle} [, {start}]) *strridx()*
10876 The result is a Number, which gives the byte index in
10877 {haystack} of the last occurrence of the String {needle}.
10878 When {start} is specified, matches beyond this index are
10879 ignored. This can be used to find a match before a previous
10880 match: >
10881 :let lastcomma = strridx(line, ",")
10882 :let comma2 = strridx(line, ",", lastcomma - 1)
10883< The search is done case-sensitive.
10884 For pattern searches use |match()|.
10885 -1 is returned if the {needle} does not occur in {haystack}.
10886 If the {needle} is empty the length of {haystack} is returned.
10887 See also |stridx()|. Examples: >
10888 :echo strridx("an angry armadillo", "an") 3
10889< *strrchr()*
10890 When used with a single character it works similar to the C
10891 function strrchr().
10892
10893 Can also be used as a |method|: >
10894 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010895<
10896 Return type: |Number|
10897
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010898
10899strtrans({string}) *strtrans()*
10900 The result is a String, which is {string} with all unprintable
10901 characters translated into printable characters |'isprint'|.
10902 Like they are shown in a window. Example: >
10903 echo strtrans(@a)
10904< This displays a newline in register a as "^@" instead of
10905 starting a new line.
10906
Bram Moolenaard592deb2022-06-17 15:42:40 +010010907 Returns an empty string on error.
10908
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010909 Can also be used as a |method|: >
10910 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010911<
10912 Return type: |String|
10913
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010914
Christian Brabandt67672ef2023-04-24 21:09:54 +010010915strutf16len({string} [, {countcc}]) *strutf16len()*
10916 The result is a Number, which is the number of UTF-16 code
10917 units in String {string} (after converting it to UTF-16).
10918
10919 When {countcc} is TRUE, composing characters are counted
10920 separately.
10921 When {countcc} is omitted or FALSE, composing characters are
10922 ignored.
10923
10924 Returns zero on error.
10925
10926 Also see |strlen()| and |strcharlen()|.
10927 Examples: >
10928 echo strutf16len('a') returns 1
10929 echo strutf16len('©') returns 1
10930 echo strutf16len('😊') returns 2
10931 echo strutf16len('ą́') returns 1
10932 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090010933<
Christian Brabandt67672ef2023-04-24 21:09:54 +010010934 Can also be used as a |method|: >
10935 GetText()->strutf16len()
10936<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010937 Return type: |Number|
10938
10939
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010940strwidth({string}) *strwidth()*
10941 The result is a Number, which is the number of display cells
10942 String {string} occupies. A Tab character is counted as one
10943 cell, alternatively use |strdisplaywidth()|.
10944 When {string} contains characters with East Asian Width Class
10945 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010946 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010947 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
10948
10949 Can also be used as a |method|: >
10950 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010951<
10952 Return type: |Number|
10953
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010954
10955submatch({nr} [, {list}]) *submatch()* *E935*
10956 Only for an expression in a |:substitute| command or
10957 substitute() function.
10958 Returns the {nr}'th submatch of the matched text. When {nr}
10959 is 0 the whole matched text is returned.
10960 Note that a NL in the string can stand for a line break of a
10961 multi-line match or a NUL character in the text.
10962 Also see |sub-replace-expression|.
10963
10964 If {list} is present and non-zero then submatch() returns
10965 a list of strings, similar to |getline()| with two arguments.
10966 NL characters in the text represent NUL characters in the
10967 text.
10968 Only returns more than one item for |:substitute|, inside
10969 |substitute()| this list will always contain one or zero
10970 items, since there are no real line breaks.
10971
10972 When substitute() is used recursively only the submatches in
10973 the current (deepest) call can be obtained.
10974
Bram Moolenaard592deb2022-06-17 15:42:40 +010010975 Returns an empty string or list on error.
10976
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010977 Examples: >
10978 :s/\d\+/\=submatch(0) + 1/
10979 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
10980< This finds the first number in the line and adds one to it.
10981 A line break is included as a newline character.
10982
10983 Can also be used as a |method|: >
10984 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010985<
10986 Return type: |String| or list<string> depending on {list}
10987
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010988
10989substitute({string}, {pat}, {sub}, {flags}) *substitute()*
10990 The result is a String, which is a copy of {string}, in which
10991 the first match of {pat} is replaced with {sub}.
10992 When {flags} is "g", all matches of {pat} in {string} are
10993 replaced. Otherwise {flags} should be "".
10994
10995 This works like the ":substitute" command (without any flags).
10996 But the matching with {pat} is always done like the 'magic'
10997 option is set and 'cpoptions' is empty (to make scripts
10998 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
10999 if you want to ignore or match case and ignore 'ignorecase'.
11000 'smartcase' is not used. See |string-match| for how {pat} is
11001 used.
11002
11003 A "~" in {sub} is not replaced with the previous {sub}.
11004 Note that some codes in {sub} have a special meaning
11005 |sub-replace-special|. For example, to replace something with
11006 "\n" (two characters), use "\\\\n" or '\\n'.
11007
11008 When {pat} does not match in {string}, {string} is returned
11009 unmodified.
11010
11011 Example: >
11012 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
11013< This removes the last component of the 'path' option. >
11014 :echo substitute("testing", ".*", "\\U\\0", "")
11015< results in "TESTING".
11016
11017 When {sub} starts with "\=", the remainder is interpreted as
11018 an expression. See |sub-replace-expression|. Example: >
11019 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011020 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011021
11022< When {sub} is a Funcref that function is called, with one
11023 optional argument. Example: >
11024 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
11025< The optional argument is a list which contains the whole
11026 matched string and up to nine submatches, like what
11027 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011028 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011029
Bram Moolenaard592deb2022-06-17 15:42:40 +010011030< Returns an empty string on error.
11031
11032 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011033 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011034<
11035 Return type: |String|
11036
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011037
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011038swapfilelist() *swapfilelist()*
11039 Returns a list of swap file names, like what "vim -r" shows.
11040 See the |-r| command argument. The 'directory' option is used
11041 for the directories to inspect. If you only want to get a
11042 list of swap files in the current directory then temporarily
11043 set 'directory' to a dot: >
11044 let save_dir = &directory
11045 let &directory = '.'
11046 let swapfiles = swapfilelist()
11047 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011048<
11049 Return type: list<string>
11050
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011051
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011052swapinfo({fname}) *swapinfo()*
11053 The result is a dictionary, which holds information about the
11054 swapfile {fname}. The available fields are:
11055 version Vim version
11056 user user name
11057 host host name
11058 fname original file name
11059 pid PID of the Vim process that created the swap
11060 file
11061 mtime last modification time in seconds
11062 inode Optional: INODE number of the file
11063 dirty 1 if file was modified, 0 if not
11064 Note that "user" and "host" are truncated to at most 39 bytes.
11065 In case of failure an "error" item is added with the reason:
11066 Cannot open file: file not found or in accessible
11067 Cannot read file: cannot read first block
11068 Not a swap file: does not contain correct block ID
11069 Magic number mismatch: Info in first block is invalid
11070
11071 Can also be used as a |method|: >
11072 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011073<
11074 Return type: dict<any> or dict<string>
11075
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011076
11077swapname({buf}) *swapname()*
11078 The result is the swap file path of the buffer {expr}.
11079 For the use of {buf}, see |bufname()| above.
11080 If buffer {buf} is the current buffer, the result is equal to
11081 |:swapname| (unless there is no swap file).
11082 If buffer {buf} has no swap file, returns an empty string.
11083
11084 Can also be used as a |method|: >
11085 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011086<
11087 Return type: |String|
11088
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011089
11090synID({lnum}, {col}, {trans}) *synID()*
11091 The result is a Number, which is the syntax ID at the position
11092 {lnum} and {col} in the current window.
11093 The syntax ID can be used with |synIDattr()| and
11094 |synIDtrans()| to obtain syntax information about text.
11095
11096 {col} is 1 for the leftmost column, {lnum} is 1 for the first
11097 line. 'synmaxcol' applies, in a longer line zero is returned.
11098 Note that when the position is after the last character,
11099 that's where the cursor can be in Insert mode, synID() returns
11100 zero. {lnum} is used like with |getline()|.
11101
11102 When {trans} is |TRUE|, transparent items are reduced to the
11103 item that they reveal. This is useful when wanting to know
11104 the effective color. When {trans} is |FALSE|, the transparent
11105 item is returned. This is useful when wanting to know which
11106 syntax item is effective (e.g. inside parens).
11107 Warning: This function can be very slow. Best speed is
11108 obtained by going through the file in forward direction.
11109
Bram Moolenaard592deb2022-06-17 15:42:40 +010011110 Returns zero on error.
11111
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011112 Example (echoes the name of the syntax item under the cursor): >
11113 :echo synIDattr(synID(line("."), col("."), 1), "name")
11114<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011115 Return type: |Number|
11116
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011117
11118synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
11119 The result is a String, which is the {what} attribute of
11120 syntax ID {synID}. This can be used to obtain information
11121 about a syntax item.
11122 {mode} can be "gui", "cterm" or "term", to get the attributes
11123 for that mode. When {mode} is omitted, or an invalid value is
11124 used, the attributes for the currently active highlighting are
11125 used (GUI, cterm or term).
11126 Use synIDtrans() to follow linked highlight groups.
11127 {what} result
11128 "name" the name of the syntax item
11129 "fg" foreground color (GUI: color name used to set
11130 the color, cterm: color number as a string,
11131 term: empty string)
11132 "bg" background color (as with "fg")
11133 "font" font name (only available in the GUI)
11134 |highlight-font|
11135 "sp" special color for the GUI (as with "fg")
11136 |highlight-guisp|
11137 "ul" underline color for cterm: number as a string
11138 "fg#" like "fg", but for the GUI and the GUI is
11139 running the name in "#RRGGBB" form
11140 "bg#" like "fg#" for "bg"
11141 "sp#" like "fg#" for "sp"
11142 "bold" "1" if bold
11143 "italic" "1" if italic
11144 "reverse" "1" if reverse
11145 "inverse" "1" if inverse (= reverse)
11146 "standout" "1" if standout
11147 "underline" "1" if underlined
11148 "undercurl" "1" if undercurled
11149 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010011150 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011151
Bram Moolenaard592deb2022-06-17 15:42:40 +010011152 Returns an empty string on error.
11153
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011154 Example (echoes the color of the syntax item under the
11155 cursor): >
11156 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
11157<
11158 Can also be used as a |method|: >
11159 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011160<
11161 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011162
11163
11164synIDtrans({synID}) *synIDtrans()*
11165 The result is a Number, which is the translated syntax ID of
11166 {synID}. This is the syntax group ID of what is being used to
11167 highlight the character. Highlight links given with
11168 ":highlight link" are followed.
11169
Bram Moolenaard592deb2022-06-17 15:42:40 +010011170 Returns zero on error.
11171
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011172 Can also be used as a |method|: >
11173 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011174<
11175 Return type: |Number|
11176
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011177
11178synconcealed({lnum}, {col}) *synconcealed()*
11179 The result is a |List| with currently three items:
11180 1. The first item in the list is 0 if the character at the
11181 position {lnum} and {col} is not part of a concealable
11182 region, 1 if it is. {lnum} is used like with |getline()|.
11183 2. The second item in the list is a string. If the first item
11184 is 1, the second item contains the text which will be
11185 displayed in place of the concealed text, depending on the
11186 current setting of 'conceallevel' and 'listchars'.
11187 3. The third and final item in the list is a number
11188 representing the specific syntax region matched in the
11189 line. When the character is not concealed the value is
11190 zero. This allows detection of the beginning of a new
11191 concealable region if there are two consecutive regions
11192 with the same replacement character. For an example, if
11193 the text is "123456" and both "23" and "45" are concealed
11194 and replaced by the character "X", then:
11195 call returns ~
11196 synconcealed(lnum, 1) [0, '', 0]
11197 synconcealed(lnum, 2) [1, 'X', 1]
11198 synconcealed(lnum, 3) [1, 'X', 1]
11199 synconcealed(lnum, 4) [1, 'X', 2]
11200 synconcealed(lnum, 5) [1, 'X', 2]
11201 synconcealed(lnum, 6) [0, '', 0]
11202
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011203 Note: Doesn't consider |matchadd()| highlighting items,
11204 since syntax and matching highlighting are two different
11205 mechanisms |syntax-vs-match|.
h-east52e7cc22024-07-28 17:03:29 +020011206
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011207 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011208
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011209
11210synstack({lnum}, {col}) *synstack()*
11211 Return a |List|, which is the stack of syntax items at the
11212 position {lnum} and {col} in the current window. {lnum} is
11213 used like with |getline()|. Each item in the List is an ID
11214 like what |synID()| returns.
11215 The first item in the List is the outer region, following are
11216 items contained in that one. The last one is what |synID()|
11217 returns, unless not the whole item is highlighted or it is a
11218 transparent item.
11219 This function is useful for debugging a syntax file.
11220 Example that shows the syntax stack under the cursor: >
11221 for id in synstack(line("."), col("."))
11222 echo synIDattr(id, "name")
11223 endfor
11224< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011225 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011226 character in a line and the first column in an empty line are
11227 valid positions.
11228
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011229 Return type: list<number> or list<any>
11230
11231
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011232system({expr} [, {input}]) *system()* *E677*
11233 Get the output of the shell command {expr} as a |String|. See
11234 |systemlist()| to get the output as a |List|.
11235
11236 When {input} is given and is a |String| this string is written
11237 to a file and passed as stdin to the command. The string is
11238 written as-is, you need to take care of using the correct line
11239 separators yourself.
11240 If {input} is given and is a |List| it is written to the file
11241 in a way |writefile()| does with {binary} set to "b" (i.e.
11242 with a newline between each list item with newlines inside
11243 list items converted to NULs).
11244 When {input} is given and is a number that is a valid id for
11245 an existing buffer then the content of the buffer is written
11246 to the file line by line, each line terminated by a NL and
11247 NULs characters where the text has a NL.
11248
11249 Pipes are not used, the 'shelltemp' option is not used.
11250
11251 When prepended by |:silent| the terminal will not be set to
11252 cooked mode. This is meant to be used for commands that do
11253 not need the user to type. It avoids stray characters showing
11254 up on the screen which require |CTRL-L| to remove. >
11255 :silent let f = system('ls *.vim')
11256<
11257 Note: Use |shellescape()| or |::S| with |expand()| or
11258 |fnamemodify()| to escape special characters in a command
11259 argument. Newlines in {expr} may cause the command to fail.
11260 The characters in 'shellquote' and 'shellxquote' may also
11261 cause trouble.
11262 This is not to be used for interactive commands.
11263
11264 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011265 :let files = system('ls ' .. shellescape(expand('%:h')))
11266 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011267
11268< To make the result more system-independent, the shell output
11269 is filtered to replace <CR> with <NL> for Macintosh, and
11270 <CR><NL> with <NL> for DOS-like systems.
11271 To avoid the string being truncated at a NUL, all NUL
11272 characters are replaced with SOH (0x01).
11273
11274 The command executed is constructed using several options:
11275 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11276 ({tmp} is an automatically generated file name).
11277 For Unix, braces are put around {expr} to allow for
11278 concatenated commands.
11279
11280 The command will be executed in "cooked" mode, so that a
11281 CTRL-C will interrupt the command (on Unix at least).
11282
11283 The resulting error code can be found in |v:shell_error|.
11284 This function will fail in |restricted-mode|.
11285
11286 Note that any wrong value in the options mentioned above may
11287 make the function fail. It has also been reported to fail
11288 when using a security agent application.
11289 Unlike ":!cmd" there is no automatic check for changed files.
11290 Use |:checktime| to force a check.
11291
11292 Can also be used as a |method|: >
11293 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011294<
11295 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011296
11297
11298systemlist({expr} [, {input}]) *systemlist()*
11299 Same as |system()|, but returns a |List| with lines (parts of
11300 output separated by NL) with NULs transformed into NLs. Output
11301 is the same as |readfile()| will output with {binary} argument
11302 set to "b", except that there is no extra empty item when the
11303 result ends in a NL.
11304 Note that on MS-Windows you may get trailing CR characters.
11305
11306 To see the difference between "echo hello" and "echo -n hello"
11307 use |system()| and |split()|: >
11308 echo system('echo hello')->split('\n', 1)
11309<
11310 Returns an empty string on error.
11311
11312 Can also be used as a |method|: >
11313 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011314<
11315 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011316
11317
11318tabpagebuflist([{arg}]) *tabpagebuflist()*
11319 The result is a |List|, where each item is the number of the
11320 buffer associated with each window in the current tab page.
11321 {arg} specifies the number of the tab page to be used. When
11322 omitted the current tab page is used.
11323 When {arg} is invalid the number zero is returned.
11324 To get a list of all buffers in all tabs use this: >
11325 let buflist = []
11326 for i in range(tabpagenr('$'))
11327 call extend(buflist, tabpagebuflist(i + 1))
11328 endfor
11329< Note that a buffer may appear in more than one window.
11330
11331 Can also be used as a |method|: >
11332 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011333<
11334 Return type: list<number>
11335
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011336
11337tabpagenr([{arg}]) *tabpagenr()*
11338 The result is a Number, which is the number of the current
11339 tab page. The first tab page has number 1.
11340
11341 The optional argument {arg} supports the following values:
11342 $ the number of the last tab page (the tab page
11343 count).
11344 # the number of the last accessed tab page
11345 (where |g<Tab>| goes to). if there is no
11346 previous tab page 0 is returned.
11347 The number can be used with the |:tab| command.
11348
Bram Moolenaard592deb2022-06-17 15:42:40 +010011349 Returns zero on error.
11350
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011351 Return type: |Number|
11352
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011353
11354tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11355 Like |winnr()| but for tab page {tabarg}.
11356 {tabarg} specifies the number of tab page to be used.
11357 {arg} is used like with |winnr()|:
11358 - When omitted the current window number is returned. This is
11359 the window which will be used when going to this tab page.
11360 - When "$" the number of windows is returned.
11361 - When "#" the previous window nr is returned.
11362 Useful examples: >
11363 tabpagewinnr(1) " current window of tab page 1
11364 tabpagewinnr(4, '$') " number of windows in tab page 4
11365< When {tabarg} is invalid zero is returned.
11366
11367 Can also be used as a |method|: >
11368 GetTabpage()->tabpagewinnr()
11369<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011370 Return type: |Number|
11371
11372
11373tagfiles() *tagfiles()*
11374 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011375 for the current buffer. This is the 'tags' option expanded.
11376
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011377 Return type: list<string> or list<any>
11378
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011379
11380taglist({expr} [, {filename}]) *taglist()*
11381 Returns a |List| of tags matching the regular expression {expr}.
11382
11383 If {filename} is passed it is used to prioritize the results
11384 in the same way that |:tselect| does. See |tag-priority|.
11385 {filename} should be the full path of the file.
11386
11387 Each list item is a dictionary with at least the following
11388 entries:
11389 name Name of the tag.
11390 filename Name of the file where the tag is
11391 defined. It is either relative to the
11392 current directory or a full path.
11393 cmd Ex command used to locate the tag in
11394 the file.
11395 kind Type of the tag. The value for this
11396 entry depends on the language specific
11397 kind values. Only available when
11398 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011399 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011400 static A file specific tag. Refer to
11401 |static-tag| for more information.
11402 More entries may be present, depending on the content of the
11403 tags file: access, implementation, inherits and signature.
11404 Refer to the ctags documentation for information about these
11405 fields. For C code the fields "struct", "class" and "enum"
11406 may appear, they give the name of the entity the tag is
11407 contained in.
11408
11409 The ex-command "cmd" can be either an ex search pattern, a
11410 line number or a line number followed by a byte number.
11411
11412 If there are no matching tags, then an empty list is returned.
11413
11414 To get an exact tag match, the anchors '^' and '$' should be
11415 used in {expr}. This also make the function work faster.
11416 Refer to |tag-regexp| for more information about the tag
11417 search regular expression pattern.
11418
11419 Refer to |'tags'| for information about how the tags file is
11420 located by Vim. Refer to |tags-file-format| for the format of
11421 the tags file generated by the different ctags tools.
11422
11423 Can also be used as a |method|: >
11424 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011425<
11426 Return type: list<dict<any>> or list<any>
11427
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011428
11429tan({expr}) *tan()*
11430 Return the tangent of {expr}, measured in radians, as a |Float|
11431 in the range [-inf, inf].
11432 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011433 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011434 Examples: >
11435 :echo tan(10)
11436< 0.648361 >
11437 :echo tan(-4.01)
11438< -1.181502
11439
11440 Can also be used as a |method|: >
11441 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011442<
11443 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011444
11445
11446tanh({expr}) *tanh()*
11447 Return the hyperbolic tangent of {expr} as a |Float| in the
11448 range [-1, 1].
11449 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011450 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011451 Examples: >
11452 :echo tanh(0.5)
11453< 0.462117 >
11454 :echo tanh(-1)
11455< -0.761594
11456
11457 Can also be used as a |method|: >
11458 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011459<
11460 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011461
11462
11463tempname() *tempname()* *temp-file-name*
11464 The result is a String, which is the name of a file that
11465 doesn't exist. It can be used for a temporary file. The name
11466 is different for at least 26 consecutive calls. Example: >
11467 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011468 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011469< For Unix, the file will be in a private directory |tempfile|
11470 that is recursively deleted when Vim exits, on other systems
11471 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011472 For MS-Windows forward slashes are used when the 'shellslash'
11473 option is set, or when 'shellcmdflag' starts with '-' and
11474 'shell' does not contain powershell or pwsh.
11475
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011476 Return type: |String|
11477
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011478
11479term_ functions are documented here: |terminal-function-details|
11480
11481
11482terminalprops() *terminalprops()*
11483 Returns a |Dictionary| with properties of the terminal that Vim
11484 detected from the response to |t_RV| request. See
11485 |v:termresponse| for the response itself. If |v:termresponse|
11486 is empty most values here will be 'u' for unknown.
11487 cursor_style whether sending |t_RS| works **
11488 cursor_blink_mode whether sending |t_RC| works **
11489 underline_rgb whether |t_8u| works **
11490 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011491 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011492
11493 ** value 'u' for unknown, 'y' for yes, 'n' for no
11494
11495 If the |+termresponse| feature is missing then the result is
11496 an empty dictionary.
11497
11498 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11499 current cursor style.
11500 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11501 request the cursor blink status.
11502 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11503 is not empty, Vim will detect the working of sending |t_RS|
11504 and |t_RC| on startup.
11505
11506 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11507 This avoids sending it to xterm, which would clear the colors.
11508
11509 For "mouse" the value 'u' is unknown
11510
11511 Also see:
11512 - 'ambiwidth' - detected by using |t_u7|.
11513 - |v:termstyleresp| and |v:termblinkresp| for the response to
11514 |t_RS| and |t_RC|.
11515
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011516 Return type: dict<string>
11517
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011518
11519test_ functions are documented here: |test-functions-details|
11520
11521
11522 *timer_info()*
11523timer_info([{id}])
11524 Return a list with information about timers.
11525 When {id} is given only information about this timer is
11526 returned. When timer {id} does not exist an empty list is
11527 returned.
11528 When {id} is omitted information about all timers is returned.
11529
11530 For each timer the information is stored in a |Dictionary| with
11531 these items:
11532 "id" the timer ID
11533 "time" time the timer was started with
11534 "remaining" time until the timer fires
11535 "repeat" number of times the timer will still fire;
11536 -1 means forever
11537 "callback" the callback
11538 "paused" 1 if the timer is paused, 0 otherwise
11539
11540 Can also be used as a |method|: >
11541 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011542<
11543 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011544
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011545 {only available when compiled with the |+timers| feature}
11546
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011547
11548timer_pause({timer}, {paused}) *timer_pause()*
11549 Pause or unpause a timer. A paused timer does not invoke its
11550 callback when its time expires. Unpausing a timer may cause
11551 the callback to be invoked almost immediately if enough time
11552 has passed.
11553
11554 Pausing a timer is useful to avoid the callback to be called
11555 for a short time.
11556
11557 If {paused} evaluates to a non-zero Number or a non-empty
11558 String, then the timer is paused, otherwise it is unpaused.
11559 See |non-zero-arg|.
11560
11561 Can also be used as a |method|: >
11562 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011563<
11564 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011565
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011566 {only available when compiled with the |+timers| feature}
11567
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011568
11569 *timer_start()* *timer* *timers*
11570timer_start({time}, {callback} [, {options}])
11571 Create a timer and return the timer ID.
11572
11573 {time} is the waiting time in milliseconds. This is the
11574 minimum time before invoking the callback. When the system is
11575 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011576 Zero can be used to execute the callback when Vim is back in
11577 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011578
11579 {callback} is the function to call. It can be the name of a
11580 function or a |Funcref|. It is called with one argument, which
11581 is the timer ID. The callback is only invoked when Vim is
11582 waiting for input.
11583 If you want to show a message look at |popup_notification()|
11584 to avoid interfering with what the user is doing.
11585
11586 {options} is a dictionary. Supported entries:
11587 "repeat" Number of times to repeat calling the
11588 callback. -1 means forever. When not present
11589 the callback will be called once.
11590 If the timer causes an error three times in a
11591 row the repeat is cancelled. This avoids that
11592 Vim becomes unusable because of all the error
11593 messages.
11594
Bram Moolenaard592deb2022-06-17 15:42:40 +010011595 Returns -1 on error.
11596
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011597 Example: >
11598 func MyHandler(timer)
11599 echo 'Handler called'
11600 endfunc
11601 let timer = timer_start(500, 'MyHandler',
11602 \ {'repeat': 3})
11603< This will invoke MyHandler() three times at 500 msec
11604 intervals.
11605
11606 Can also be used as a |method|: >
11607 GetMsec()->timer_start(callback)
11608
11609< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011610
11611 Return type: |Number|
11612
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011613 {only available when compiled with the |+timers| feature}
11614
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011615
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011616timer_stop({timer}) *timer_stop()*
11617 Stop a timer. The timer callback will no longer be invoked.
11618 {timer} is an ID returned by timer_start(), thus it must be a
11619 Number. If {timer} does not exist there is no error.
11620
11621 Can also be used as a |method|: >
11622 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011623<
11624 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011625
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011626 {only available when compiled with the |+timers| feature}
11627
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011628
11629timer_stopall() *timer_stopall()*
11630 Stop all timers. The timer callbacks will no longer be
11631 invoked. Useful if a timer is misbehaving. If there are no
11632 timers there is no error.
11633
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011634 Return type: |Number|
11635
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011636 {only available when compiled with the |+timers| feature}
11637
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011638
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011639tolower({expr}) *tolower()*
11640 The result is a copy of the String given, with all uppercase
11641 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011642 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011643
11644 Can also be used as a |method|: >
11645 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011646<
11647 Return type: |String|
11648
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011649
11650toupper({expr}) *toupper()*
11651 The result is a copy of the String given, with all lowercase
11652 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011653 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011654
11655 Can also be used as a |method|: >
11656 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011657<
11658 Return type: |String|
11659
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011660
11661tr({src}, {fromstr}, {tostr}) *tr()*
11662 The result is a copy of the {src} string with all characters
11663 which appear in {fromstr} replaced by the character in that
11664 position in the {tostr} string. Thus the first character in
11665 {fromstr} is translated into the first character in {tostr}
11666 and so on. Exactly like the unix "tr" command.
11667 This code also deals with multibyte characters properly.
11668
Bram Moolenaard592deb2022-06-17 15:42:40 +010011669 Returns an empty string on error.
11670
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011671 Examples: >
11672 echo tr("hello there", "ht", "HT")
11673< returns "Hello THere" >
11674 echo tr("<blob>", "<>", "{}")
11675< returns "{blob}"
11676
11677 Can also be used as a |method|: >
11678 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011679<
11680 Return type: |String|
11681
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011682
11683trim({text} [, {mask} [, {dir}]]) *trim()*
11684 Return {text} as a String where any character in {mask} is
11685 removed from the beginning and/or end of {text}.
11686
Illia Bobyr80799172023-10-17 18:00:50 +020011687 If {mask} is not given, or is an empty string, {mask} is all
11688 characters up to 0x20, which includes Tab, space, NL and CR,
11689 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011690
11691 The optional {dir} argument specifies where to remove the
11692 characters:
11693 0 remove from the beginning and end of {text}
11694 1 remove only at the beginning of {text}
11695 2 remove only at the end of {text}
11696 When omitted both ends are trimmed.
11697
11698 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011699 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011700
11701 Examples: >
11702 echo trim(" some text ")
11703< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011704 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011705< returns "RESERVE_TAIL" >
11706 echo trim("rm<Xrm<>X>rrm", "rm<>")
11707< returns "Xrm<>X" (characters in the middle are not removed) >
11708 echo trim(" vim ", " ", 2)
11709< returns " vim"
11710
11711 Can also be used as a |method|: >
11712 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011713<
11714 Return type: |String|
11715
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011716
11717trunc({expr}) *trunc()*
11718 Return the largest integral value with magnitude less than or
11719 equal to {expr} as a |Float| (truncate towards zero).
11720 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011721 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011722 Examples: >
11723 echo trunc(1.456)
11724< 1.0 >
11725 echo trunc(-5.456)
11726< -5.0 >
11727 echo trunc(4.0)
11728< 4.0
11729
11730 Can also be used as a |method|: >
11731 Compute()->trunc()
11732<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011733 Return type: |Float|
11734
11735
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011736 *type()*
11737type({expr}) The result is a Number representing the type of {expr}.
11738 Instead of using the number directly, it is better to use the
11739 v:t_ variable that has the value:
11740 Number: 0 |v:t_number|
11741 String: 1 |v:t_string|
11742 Funcref: 2 |v:t_func|
11743 List: 3 |v:t_list|
11744 Dictionary: 4 |v:t_dict|
11745 Float: 5 |v:t_float|
11746 Boolean: 6 |v:t_bool| (v:false and v:true)
11747 None: 7 |v:t_none| (v:null and v:none)
11748 Job: 8 |v:t_job|
11749 Channel: 9 |v:t_channel|
11750 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090011751 Class: 12 |v:t_class|
11752 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010011753 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011754 Enum: 15 |v:t_enum|
11755 EnumValue: 16 |v:t_enumvalue|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011756 For backward compatibility, this method can be used: >
11757 :if type(myvar) == type(0)
11758 :if type(myvar) == type("")
11759 :if type(myvar) == type(function("tr"))
11760 :if type(myvar) == type([])
11761 :if type(myvar) == type({})
11762 :if type(myvar) == type(0.0)
11763 :if type(myvar) == type(v:false)
11764 :if type(myvar) == type(v:none)
11765< To check if the v:t_ variables exist use this: >
11766 :if exists('v:t_number')
11767
11768< Can also be used as a |method|: >
11769 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011770<
11771 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011772
11773
11774typename({expr}) *typename()*
11775 Return a string representation of the type of {expr}.
11776 Example: >
11777 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000011778< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011779
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011780 Return type: |String|
11781
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011782
11783undofile({name}) *undofile()*
11784 Return the name of the undo file that would be used for a file
11785 with name {name} when writing. This uses the 'undodir'
11786 option, finding directories that exist. It does not check if
11787 the undo file exists.
11788 {name} is always expanded to the full path, since that is what
11789 is used internally.
11790 If {name} is empty undofile() returns an empty string, since a
11791 buffer without a file name will not write an undo file.
11792 Useful in combination with |:wundo| and |:rundo|.
11793 When compiled without the |+persistent_undo| option this always
11794 returns an empty string.
11795
11796 Can also be used as a |method|: >
11797 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011798<
11799 Return type: |String|
11800
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011801
Devin J. Pohly5fee1112023-04-23 20:26:59 -050011802undotree([{buf}]) *undotree()*
11803 Return the current state of the undo tree for the current
11804 buffer, or for a specific buffer if {buf} is given. The
11805 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011806 "seq_last" The highest undo sequence number used.
11807 "seq_cur" The sequence number of the current position in
11808 the undo tree. This differs from "seq_last"
11809 when some changes were undone.
11810 "time_cur" Time last used for |:earlier| and related
11811 commands. Use |strftime()| to convert to
11812 something readable.
11813 "save_last" Number of the last file write. Zero when no
11814 write yet.
11815 "save_cur" Number of the current position in the undo
11816 tree.
11817 "synced" Non-zero when the last undo block was synced.
11818 This happens when waiting from input from the
11819 user. See |undo-blocks|.
11820 "entries" A list of dictionaries with information about
11821 undo blocks.
11822
11823 The first item in the "entries" list is the oldest undo item.
11824 Each List item is a |Dictionary| with these items:
11825 "seq" Undo sequence number. Same as what appears in
11826 |:undolist|.
11827 "time" Timestamp when the change happened. Use
11828 |strftime()| to convert to something readable.
11829 "newhead" Only appears in the item that is the last one
11830 that was added. This marks the last change
11831 and where further changes will be added.
11832 "curhead" Only appears in the item that is the last one
11833 that was undone. This marks the current
11834 position in the undo tree, the block that will
11835 be used by a redo command. When nothing was
11836 undone after the last change this item will
11837 not appear anywhere.
11838 "save" Only appears on the last block before a file
11839 write. The number is the write count. The
11840 first write has number 1, the last one the
11841 "save_last" mentioned above.
11842 "alt" Alternate entry. This is again a List of undo
11843 blocks. Each item may again have an "alt"
11844 item.
11845
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011846 Return type: dict<any>
11847
11848
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011849uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
11850 Remove second and succeeding copies of repeated adjacent
11851 {list} items in-place. Returns {list}. If you want a list
11852 to remain unmodified make a copy first: >
11853 :let newlist = uniq(copy(mylist))
11854< The default compare function uses the string representation of
11855 each item. For the use of {func} and {dict} see |sort()|.
11856
Bram Moolenaard592deb2022-06-17 15:42:40 +010011857 Returns zero if {list} is not a |List|.
11858
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011859 Can also be used as a |method|: >
11860 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010011861<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011862 Return type: list<{type}>
11863
11864
Christian Brabandt67672ef2023-04-24 21:09:54 +010011865 *utf16idx()*
11866utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011867 Same as |charidx()| but returns the UTF-16 code unit index of
11868 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010011869
11870 When {charidx} is present and TRUE, {idx} is used as the
11871 character index in the String {string} instead of as the byte
11872 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010011873 An {idx} in the middle of a UTF-8 sequence is rounded
11874 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010011875
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011876 Returns -1 if the arguments are invalid or if there are less
11877 than {idx} bytes in {string}. If there are exactly {idx} bytes
11878 the length of the string in UTF-16 code units is returned.
11879
Christian Brabandt67672ef2023-04-24 21:09:54 +010011880 See |byteidx()| and |byteidxcomp()| for getting the byte index
11881 from the UTF-16 index and |charidx()| for getting the
11882 character index from the UTF-16 index.
11883 Refer to |string-offset-encoding| for more information.
11884 Examples: >
11885 echo utf16idx('a😊😊', 3) returns 2
11886 echo utf16idx('a😊😊', 7) returns 4
11887 echo utf16idx('a😊😊', 1, 0, 1) returns 2
11888 echo utf16idx('a😊😊', 2, 0, 1) returns 4
11889 echo utf16idx('aą́c', 6) returns 2
11890 echo utf16idx('aą́c', 6, 1) returns 4
11891 echo utf16idx('a😊😊', 9) returns -1
11892<
11893 Can also be used as a |method|: >
11894 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011895<
11896 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010011897
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011898
11899values({dict}) *values()*
11900 Return a |List| with all the values of {dict}. The |List| is
11901 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011902 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011903
11904 Can also be used as a |method|: >
11905 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011906<
11907 Return type: list<any>
11908
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011909
zeertzjq825cf812023-08-17 22:55:25 +020011910virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011911 The result is a Number, which is the screen column of the file
11912 position given with {expr}. That is, the last screen position
11913 occupied by the character at that position, when the screen
11914 would be of unlimited width. When there is a <Tab> at the
11915 position, the returned Number will be the column at the end of
11916 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
11917 set to 8, it returns 8. |conceal| is ignored.
11918 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011919
zeertzjq02f3eba2024-06-12 20:45:24 +020011920 For the use of {expr} see |getpos()| and |col()|.
zeertzjqd353d272024-06-13 23:00:25 +080011921 When {expr} is "$", it means the end of the cursor line, so
11922 the result is the number of cells in the cursor line plus one.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011923
11924 When 'virtualedit' is used {expr} can be [lnum, col, off],
11925 where "off" is the offset in screen columns from the start of
11926 the character. E.g., a position within a <Tab> or after the
11927 last character. When "off" is omitted zero is used. When
11928 Virtual editing is active in the current mode, a position
11929 beyond the end of the line can be returned. Also see
11930 |'virtualedit'|
11931
zeertzjq825cf812023-08-17 22:55:25 +020011932 If {list} is present and non-zero then virtcol() returns a
11933 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010011934 character.
11935
zeertzjq825cf812023-08-17 22:55:25 +020011936 With the optional {winid} argument the values are obtained for
11937 that window instead of the current window.
11938
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011939 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +020011940
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011941 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010011942 " With text "foo^Lbar" and cursor on the "^L":
11943
11944 virtcol(".") " returns 5
11945 virtcol(".", 1) " returns [4, 5]
11946 virtcol("$") " returns 9
11947
11948 " With text " there", with 't at 'h':
11949
11950 virtcol("'t") " returns 6
zeertzjq02f3eba2024-06-12 20:45:24 +020011951<
11952 The first column is 1. 0 or [0, 0] is returned for an error.
11953
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011954 A more advanced example that echoes the maximum length of
11955 all lines: >
11956 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
11957
11958< Can also be used as a |method|: >
11959 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011960<
11961 Return type: |Number|
11962
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011963
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011964virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
11965 The result is a Number, which is the byte index of the
11966 character in window {winid} at buffer line {lnum} and virtual
11967 column {col}.
11968
zeertzjqb583eda2023-10-14 11:32:28 +020011969 If buffer line {lnum} is an empty line, 0 is returned.
11970
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011971 If {col} is greater than the last virtual column in line
11972 {lnum}, then the byte index of the character at the last
11973 virtual column is returned.
11974
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020011975 For a multi-byte character, the column number of the first
11976 byte in the character is returned.
11977
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011978 The {winid} argument can be the window number or the
11979 |window-ID|. If this is zero, then the current window is used.
11980
11981 Returns -1 if the window {winid} doesn't exist or the buffer
11982 line {lnum} or virtual column {col} is invalid.
11983
11984 See also |screenpos()|, |virtcol()| and |col()|.
11985
11986 Can also be used as a |method|: >
11987 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011988<
11989 Return type: |Number|
11990
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011991
11992visualmode([{expr}]) *visualmode()*
11993 The result is a String, which describes the last Visual mode
11994 used in the current buffer. Initially it returns an empty
11995 string, but once Visual mode has been used, it returns "v",
11996 "V", or "<CTRL-V>" (a single CTRL-V character) for
11997 character-wise, line-wise, or block-wise Visual mode
11998 respectively.
11999 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012000 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012001< This enters the same Visual mode as before. It is also useful
12002 in scripts if you wish to act differently depending on the
12003 Visual mode that was used.
12004 If Visual mode is active, use |mode()| to get the Visual mode
12005 (e.g., in a |:vmap|).
12006 If {expr} is supplied and it evaluates to a non-zero Number or
12007 a non-empty String, then the Visual mode will be cleared and
12008 the old value is returned. See |non-zero-arg|.
12009
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012010 Return type: |String|
12011
12012
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012013wildmenumode() *wildmenumode()*
12014 Returns |TRUE| when the wildmenu is active and |FALSE|
12015 otherwise. See 'wildmenu' and 'wildmode'.
12016 This can be used in mappings to handle the 'wildcharm' option
12017 gracefully. (Makes only sense with |mapmode-c| mappings).
12018
12019 For example to make <c-j> work like <down> in wildmode, use: >
12020 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
12021<
Milly6c2fc372024-10-16 22:11:17 +020012022 (Note: this needs the 'wildcharm' option set appropriately).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012023
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012024 Return type: |Number|
12025
12026
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012027win_execute({id}, {command} [, {silent}]) *win_execute()*
12028 Like `execute()` but in the context of window {id}.
12029 The window will temporarily be made the current window,
12030 without triggering autocommands or changing directory. When
12031 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010012032 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012033 Example: >
12034 call win_execute(winid, 'set syntax=python')
12035< Doing the same with `setwinvar()` would not trigger
12036 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012037 *E994*
12038 Not all commands are allowed in popup windows.
12039 When window {id} does not exist then no error is given and
12040 an empty string is returned.
12041
12042 Can also be used as a |method|, the base is passed as the
12043 second argument: >
12044 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012045<
12046 Return type: |String|
12047
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012048
12049win_findbuf({bufnr}) *win_findbuf()*
12050 Returns a |List| with |window-ID|s for windows that contain
12051 buffer {bufnr}. When there is none the list is empty.
12052
12053 Can also be used as a |method|: >
12054 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012055<
12056 Return type: list<number> or list<any>
12057
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012058
12059win_getid([{win} [, {tab}]]) *win_getid()*
12060 Get the |window-ID| for the specified window.
12061 When {win} is missing use the current window.
12062 With {win} this is the window number. The top window has
12063 number 1.
12064 Without {tab} use the current tab, otherwise the tab with
12065 number {tab}. The first tab has number one.
12066 Return zero if the window cannot be found.
12067
12068 Can also be used as a |method|: >
12069 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012070<
12071 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012072
12073
12074win_gettype([{nr}]) *win_gettype()*
12075 Return the type of the window:
12076 "autocmd" autocommand window. Temporary window
12077 used to execute autocommands.
12078 "command" command-line window |cmdwin|
12079 (empty) normal window
12080 "loclist" |location-list-window|
12081 "popup" popup window |popup|
12082 "preview" preview window |preview-window|
12083 "quickfix" |quickfix-window|
12084 "unknown" window {nr} not found
12085
12086 When {nr} is omitted return the type of the current window.
12087 When {nr} is given return the type of this window by number or
12088 |window-ID|.
12089
12090 Also see the 'buftype' option. When running a terminal in a
12091 popup window then 'buftype' is "terminal" and win_gettype()
12092 returns "popup".
12093
12094 Can also be used as a |method|: >
12095 GetWinid()->win_gettype()
12096<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012097 Return type: |String|
12098
12099
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012100win_gotoid({expr}) *win_gotoid()*
12101 Go to window with ID {expr}. This may also change the current
12102 tabpage.
12103 Return TRUE if successful, FALSE if the window cannot be found.
12104
12105 Can also be used as a |method|: >
12106 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012107<
12108 Return type: |Number|
12109
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012110
12111win_id2tabwin({expr}) *win_id2tabwin()*
12112 Return a list with the tab number and window number of window
12113 with ID {expr}: [tabnr, winnr].
12114 Return [0, 0] if the window cannot be found.
12115
12116 Can also be used as a |method|: >
12117 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012118<
12119 Return type: list<number>
12120
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012121
12122win_id2win({expr}) *win_id2win()*
12123 Return the window number of window with ID {expr}.
12124 Return 0 if the window cannot be found in the current tabpage.
12125
12126 Can also be used as a |method|: >
12127 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012128<
12129 Return type: |Number|
12130
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012131
Daniel Steinbergee630312022-01-10 13:36:34 +000012132win_move_separator({nr}, {offset}) *win_move_separator()*
12133 Move window {nr}'s vertical separator (i.e., the right border)
12134 by {offset} columns, as if being dragged by the mouse. {nr}
12135 can be a window number or |window-ID|. A positive {offset}
12136 moves right and a negative {offset} moves left. Moving a
12137 window's vertical separator will change the width of the
12138 window and the width of other windows adjacent to the vertical
12139 separator. The magnitude of movement may be smaller than
12140 specified (e.g., as a consequence of maintaining
12141 'winminwidth'). Returns TRUE if the window can be found and
12142 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012143 This will fail for the rightmost window and a full-width
12144 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012145 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000012146
12147 Can also be used as a |method|: >
12148 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012149<
12150 Return type: |Number|
12151
Daniel Steinbergee630312022-01-10 13:36:34 +000012152
12153win_move_statusline({nr}, {offset}) *win_move_statusline()*
12154 Move window {nr}'s status line (i.e., the bottom border) by
12155 {offset} rows, as if being dragged by the mouse. {nr} can be a
12156 window number or |window-ID|. A positive {offset} moves down
12157 and a negative {offset} moves up. Moving a window's status
12158 line will change the height of the window and the height of
12159 other windows adjacent to the status line. The magnitude of
12160 movement may be smaller than specified (e.g., as a consequence
12161 of maintaining 'winminheight'). Returns TRUE if the window can
12162 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012163 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000012164
12165 Can also be used as a |method|: >
12166 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012167<
12168 Return type: |Number|
12169
Daniel Steinbergee630312022-01-10 13:36:34 +000012170
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012171win_screenpos({nr}) *win_screenpos()*
12172 Return the screen position of window {nr} as a list with two
12173 numbers: [row, col]. The first window always has position
12174 [1, 1], unless there is a tabline, then it is [2, 1].
12175 {nr} can be the window number or the |window-ID|. Use zero
12176 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012177 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012178
12179 Can also be used as a |method|: >
12180 GetWinid()->win_screenpos()
12181<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012182 Return type: list<number>
12183
12184
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012185win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012186 Temporarily switch to window {target}, then move window {nr}
12187 to a new split adjacent to {target}.
12188 Unlike commands such as |:split|, no new windows are created
12189 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012190
12191 Both {nr} and {target} can be window numbers or |window-ID|s.
12192 Both must be in the current tab page.
12193
12194 Returns zero for success, non-zero for failure.
12195
12196 {options} is a |Dictionary| with the following optional entries:
12197 "vertical" When TRUE, the split is created vertically,
12198 like with |:vsplit|.
12199 "rightbelow" When TRUE, the split is made below or to the
12200 right (if vertical). When FALSE, it is done
12201 above or to the left (if vertical). When not
12202 present, the values of 'splitbelow' and
12203 'splitright' are used.
12204
12205 Can also be used as a |method|: >
12206 GetWinid()->win_splitmove(target)
12207<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012208 Return type: |Number|
12209
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012210
12211 *winbufnr()*
12212winbufnr({nr}) The result is a Number, which is the number of the buffer
12213 associated with window {nr}. {nr} can be the window number or
12214 the |window-ID|.
12215 When {nr} is zero, the number of the buffer in the current
12216 window is returned.
12217 When window {nr} doesn't exist, -1 is returned.
12218 Example: >
12219 :echo "The file in the current window is " . bufname(winbufnr(0))
12220<
12221 Can also be used as a |method|: >
12222 FindWindow()->winbufnr()->bufname()
12223<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012224 Return type: |Number|
12225
12226
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012227 *wincol()*
12228wincol() The result is a Number, which is the virtual column of the
12229 cursor in the window. This is counting screen cells from the
12230 left side of the window. The leftmost column is one.
12231
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012232 Return type: |Number|
12233
12234
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012235 *windowsversion()*
12236windowsversion()
12237 The result is a String. For MS-Windows it indicates the OS
12238 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12239 Windows XP is "5.1". For non-MS-Windows systems the result is
12240 an empty string.
12241
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012242 Return type: |String|
12243
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012244winheight({nr}) *winheight()*
12245 The result is a Number, which is the height of window {nr}.
12246 {nr} can be the window number or the |window-ID|.
12247 When {nr} is zero, the height of the current window is
12248 returned. When window {nr} doesn't exist, -1 is returned.
12249 An existing window always has a height of zero or more.
12250 This excludes any window toolbar line.
12251 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012252 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012253
12254< Can also be used as a |method|: >
12255 GetWinid()->winheight()
12256<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012257 Return type: |Number|
12258
12259
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012260winlayout([{tabnr}]) *winlayout()*
12261 The result is a nested List containing the layout of windows
12262 in a tabpage.
12263
12264 Without {tabnr} use the current tabpage, otherwise the tabpage
12265 with number {tabnr}. If the tabpage {tabnr} is not found,
12266 returns an empty list.
12267
12268 For a leaf window, it returns:
12269 ['leaf', {winid}]
12270 For horizontally split windows, which form a column, it
12271 returns:
12272 ['col', [{nested list of windows}]]
12273 For vertically split windows, which form a row, it returns:
12274 ['row', [{nested list of windows}]]
12275
12276 Example: >
12277 " Only one window in the tab page
12278 :echo winlayout()
12279 ['leaf', 1000]
12280 " Two horizontally split windows
12281 :echo winlayout()
12282 ['col', [['leaf', 1000], ['leaf', 1001]]]
12283 " The second tab page, with three horizontally split
12284 " windows, with two vertically split windows in the
12285 " middle window
12286 :echo winlayout(2)
12287 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12288 ['leaf', 1001]]], ['leaf', 1000]]]
12289<
12290 Can also be used as a |method|: >
12291 GetTabnr()->winlayout()
12292<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012293 Return type: list<any>
12294
12295
12296winline() *winline()*
12297 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012298 in the window. This is counting screen lines from the top of
12299 the window. The first line is one.
12300 If the cursor was moved the view on the file will be updated
12301 first, this may cause a scroll.
12302
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012303 Return type: |Number|
12304
12305
12306winnr([{arg}]) *winnr()*
12307 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012308 window. The top window has number 1.
12309 Returns zero for a popup window.
12310
12311 The optional argument {arg} supports the following values:
12312 $ the number of the last window (the window
12313 count).
12314 # the number of the last accessed window (where
12315 |CTRL-W_p| goes to). If there is no previous
12316 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012317 returned. May refer to the current window in
12318 some cases (e.g. when evaluating 'statusline'
12319 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012320 {N}j the number of the Nth window below the
12321 current window (where |CTRL-W_j| goes to).
12322 {N}k the number of the Nth window above the current
12323 window (where |CTRL-W_k| goes to).
12324 {N}h the number of the Nth window left of the
12325 current window (where |CTRL-W_h| goes to).
12326 {N}l the number of the Nth window right of the
12327 current window (where |CTRL-W_l| goes to).
12328 The number can be used with |CTRL-W_w| and ":wincmd w"
12329 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012330 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012331 Also see |tabpagewinnr()| and |win_getid()|.
12332 Examples: >
12333 let window_count = winnr('$')
12334 let prev_window = winnr('#')
12335 let wnum = winnr('3k')
12336
12337< Can also be used as a |method|: >
12338 GetWinval()->winnr()
12339<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012340 Return type: |Number|
12341
12342
12343winrestcmd() *winrestcmd()*
12344 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012345 the current window sizes. Only works properly when no windows
12346 are opened or closed and the current window and tab page is
12347 unchanged.
12348 Example: >
12349 :let cmd = winrestcmd()
12350 :call MessWithWindowSizes()
12351 :exe cmd
12352<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012353 Return type: |String|
12354
12355
12356winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012357 Uses the |Dictionary| returned by |winsaveview()| to restore
12358 the view of the current window.
12359 Note: The {dict} does not have to contain all values, that are
12360 returned by |winsaveview()|. If values are missing, those
12361 settings won't be restored. So you can use: >
12362 :call winrestview({'curswant': 4})
12363<
12364 This will only set the curswant value (the column the cursor
12365 wants to move on vertical movements) of the cursor to column 5
12366 (yes, that is 5), while all other settings will remain the
12367 same. This is useful, if you set the cursor position manually.
12368
12369 If you have changed the values the result is unpredictable.
12370 If the window size changed the result won't be the same.
12371
12372 Can also be used as a |method|: >
12373 GetView()->winrestview()
12374<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012375 Return type: |Number|
12376
12377
12378winsaveview() *winsaveview()*
12379 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012380 the view of the current window. Use |winrestview()| to
12381 restore the view.
12382 This is useful if you have a mapping that jumps around in the
12383 buffer and you want to go back to the original view.
12384 This does not save fold information. Use the 'foldenable'
12385 option to temporarily switch off folding, so that folds are
12386 not opened when moving around. This may have side effects.
12387 The return value includes:
12388 lnum cursor line number
12389 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012390 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012391 returns)
12392 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012393 curswant column for vertical movement (Note:
12394 the first column is zero, as opposed
12395 to what |getcurpos()| returns). After
12396 |$| command it will be a very large
12397 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012398 topline first line in the window
12399 topfill filler lines, only in diff mode
12400 leftcol first column displayed; only used when
12401 'wrap' is off
12402 skipcol columns skipped
12403 Note that no option values are saved.
12404
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012405 Return type: dict<number>
12406
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012407
12408winwidth({nr}) *winwidth()*
12409 The result is a Number, which is the width of window {nr}.
12410 {nr} can be the window number or the |window-ID|.
12411 When {nr} is zero, the width of the current window is
12412 returned. When window {nr} doesn't exist, -1 is returned.
12413 An existing window always has a width of zero or more.
12414 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012415 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012416 :if winwidth(0) <= 50
12417 : 50 wincmd |
12418 :endif
12419< For getting the terminal or screen size, see the 'columns'
12420 option.
12421
12422 Can also be used as a |method|: >
12423 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012424<
12425 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012426
12427
12428wordcount() *wordcount()*
12429 The result is a dictionary of byte/chars/word statistics for
12430 the current buffer. This is the same info as provided by
12431 |g_CTRL-G|
12432 The return value includes:
12433 bytes Number of bytes in the buffer
12434 chars Number of chars in the buffer
12435 words Number of words in the buffer
12436 cursor_bytes Number of bytes before cursor position
12437 (not in Visual mode)
12438 cursor_chars Number of chars before cursor position
12439 (not in Visual mode)
12440 cursor_words Number of words before cursor position
12441 (not in Visual mode)
12442 visual_bytes Number of bytes visually selected
12443 (only in Visual mode)
12444 visual_chars Number of chars visually selected
12445 (only in Visual mode)
12446 visual_words Number of words visually selected
12447 (only in Visual mode)
12448
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012449 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012450
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012451
12452writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012453 When {object} is a |List| write it to file {fname}. Each list
12454 item is separated with a NL. Each list item must be a String
12455 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012456 All NL characters are replaced with a NUL character.
12457 Inserting CR characters needs to be done before passing {list}
12458 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012459
12460 When {object} is a |Blob| write the bytes to file {fname}
12461 unmodified, also when binary mode is not specified.
12462
12463 {flags} must be a String. These characters are recognized:
12464
12465 'b' Binary mode is used: There will not be a NL after the
12466 last list item. An empty item at the end does cause the
12467 last line in the file to end in a NL.
12468
12469 'a' Append mode is used, lines are appended to the file: >
12470 :call writefile(["foo"], "event.log", "a")
12471 :call writefile(["bar"], "event.log", "a")
12472<
12473 'D' Delete the file when the current function ends. This
12474 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012475 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012476< Fails when not in a function. Also see |:defer|.
12477
12478 's' fsync() is called after writing the file. This flushes
12479 the file to disk, if possible. This takes more time but
12480 avoids losing the file if the system crashes.
12481
12482 'S' fsync() is not called, even when 'fsync' is set.
12483
12484 When {flags} does not contain "S" or "s" then fsync() is
12485 called if the 'fsync' option is set.
12486
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012487 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012488
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012489 When the write fails -1 is returned, otherwise 0. There is an
12490 error message if the file can't be created or when writing
12491 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012492
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012493 Also see |readfile()|.
12494 To copy a file byte for byte: >
12495 :let fl = readfile("foo", "b")
12496 :call writefile(fl, "foocopy", "b")
12497
12498< Can also be used as a |method|: >
12499 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012500<
12501 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012502
12503
12504xor({expr}, {expr}) *xor()*
12505 Bitwise XOR on the two arguments. The arguments are converted
12506 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012507 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012508 Example: >
12509 :let bits = xor(bits, 0x80)
12510<
12511 Can also be used as a |method|: >
12512 :let bits = bits->xor(0x80)
12513<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012514 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012515
12516==============================================================================
125173. Feature list *feature-list*
12518
12519There are three types of features:
125201. Features that are only supported when they have been enabled when Vim
12521 was compiled |+feature-list|. Example: >
12522 :if has("cindent")
12523< *gui_running*
125242. Features that are only supported when certain conditions have been met.
12525 Example: >
12526 :if has("gui_running")
12527< *has-patch*
125283. Beyond a certain version or at a certain version and including a specific
12529 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12530 later, or it is version 7.4 and patch 248 was included. Example: >
12531 :if has("patch-7.4.248")
12532< Note that it's possible for patch 248 to be omitted even though 249 is
12533 included. Only happens when cherry-picking patches.
12534 Note that this form only works for patch 7.4.237 and later, before that
12535 you need to check for the patch and the v:version. Example (checking
12536 version 6.2.148 or later): >
12537 :if v:version > 602 || (v:version == 602 && has("patch148"))
12538
12539Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12540use: `if exists('+shellslash')`
12541
12542
12543acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012544all_builtin_terms Compiled with all builtin terminals enabled. (always
12545 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012546amiga Amiga version of Vim.
12547arabic Compiled with Arabic support |Arabic|.
12548arp Compiled with ARP support (Amiga).
12549autocmd Compiled with autocommand support. (always true)
12550autochdir Compiled with support for 'autochdir'
12551autoservername Automatically enable |clientserver|
12552balloon_eval Compiled with |balloon-eval| support.
12553balloon_multiline GUI supports multiline balloons.
12554beos BeOS version of Vim.
12555browse Compiled with |:browse| support, and browse() will
12556 work.
12557browsefilter Compiled with support for |browsefilter|.
12558bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012559builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012560byte_offset Compiled with support for 'o' in 'statusline'
12561channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012562cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012563clientserver Compiled with remote invocation support |clientserver|.
12564clipboard Compiled with 'clipboard' support.
12565clipboard_working Compiled with 'clipboard' support and it can be used.
12566cmdline_compl Compiled with |cmdline-completion| support.
12567cmdline_hist Compiled with |cmdline-history| support.
12568cmdline_info Compiled with 'showcmd' and 'ruler' support.
12569comments Compiled with |'comments'| support.
12570compatible Compiled to be very Vi compatible.
12571conpty Platform where |ConPTY| can be used.
12572cryptv Compiled with encryption support |encryption|.
12573cscope Compiled with |cscope| support.
12574cursorbind Compiled with |'cursorbind'| (always true)
12575debug Compiled with "DEBUG" defined.
12576dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012577dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012578dialog_gui Compiled with GUI dialog support.
12579diff Compiled with |vimdiff| and 'diff' support.
12580digraphs Compiled with support for digraphs.
12581directx Compiled with support for DirectX and 'renderoptions'.
12582dnd Compiled with support for the "~ register |quote_~|.
12583drop_file Compiled with |drop_file| support.
12584ebcdic Compiled on a machine with ebcdic character set.
12585emacs_tags Compiled with support for Emacs tags.
12586eval Compiled with expression evaluation support. Always
12587 true, of course!
12588ex_extra |+ex_extra| (always true)
12589extra_search Compiled with support for |'incsearch'| and
12590 |'hlsearch'|
12591farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012592file_in_path Compiled with support for |gf| and |<cfile>| (always
12593 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012594filterpipe When 'shelltemp' is off pipes are used for shell
12595 read/write/filter commands
12596find_in_path Compiled with support for include file searches
12597 |+find_in_path|.
12598float Compiled with support for |Float|.
12599fname_case Case in file names matters (for Amiga and MS-Windows
12600 this is not present).
12601folding Compiled with |folding| support.
12602footer Compiled with GUI footer support. |gui-footer|
12603fork Compiled to use fork()/exec() instead of system().
12604gettext Compiled with message translation |multi-lang|
12605gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012606gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012607gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12608gui_gtk Compiled with GTK+ GUI (any version).
12609gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12610gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12611gui_haiku Compiled with Haiku GUI.
12612gui_mac Compiled with Macintosh GUI.
12613gui_motif Compiled with Motif GUI.
12614gui_photon Compiled with Photon GUI.
12615gui_running Vim is running in the GUI, or it will start soon.
12616gui_win32 Compiled with MS-Windows Win32 GUI.
12617gui_win32s idem, and Win32s system being used (Windows 3.1)
12618haiku Haiku version of Vim.
12619hangul_input Compiled with Hangul input support. |hangul|
12620hpux HP-UX version of Vim.
12621iconv Can use iconv() for conversion.
12622insert_expand Compiled with support for CTRL-X expansion commands in
12623 Insert mode. (always true)
12624job Compiled with support for |channel| and |job|
12625ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012626jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012627keymap Compiled with 'keymap' support.
12628lambda Compiled with |lambda| support.
12629langmap Compiled with 'langmap' support.
12630libcall Compiled with |libcall()| support.
12631linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12632 'breakindent' support.
12633linux Linux version of Vim.
12634lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012635 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012636listcmds Compiled with commands for the buffer list |:files|
12637 and the argument list |arglist|.
12638localmap Compiled with local mappings and abbr. |:map-local|
12639lua Compiled with Lua interface |Lua|.
12640mac Any Macintosh version of Vim cf. osx
12641macunix Synonym for osxdarwin
12642menu Compiled with support for |:menu|.
12643mksession Compiled with support for |:mksession|.
12644modify_fname Compiled with file name modifiers. |filename-modifiers|
12645 (always true)
12646mouse Compiled with support for mouse.
12647mouse_dec Compiled with support for Dec terminal mouse.
12648mouse_gpm Compiled with support for gpm (Linux console mouse)
12649mouse_gpm_enabled GPM mouse is working
12650mouse_netterm Compiled with support for netterm mouse.
12651mouse_pterm Compiled with support for qnx pterm mouse.
12652mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12653mouse_sgr Compiled with support for sgr mouse.
12654mouse_urxvt Compiled with support for urxvt mouse.
12655mouse_xterm Compiled with support for xterm mouse.
12656mouseshape Compiled with support for 'mouseshape'.
12657multi_byte Compiled with support for 'encoding' (always true)
12658multi_byte_encoding 'encoding' is set to a multibyte encoding.
12659multi_byte_ime Compiled with support for IME input method.
12660multi_lang Compiled with support for multiple languages.
12661mzscheme Compiled with MzScheme interface |mzscheme|.
12662nanotime Compiled with sub-second time stamp checks.
12663netbeans_enabled Compiled with support for |netbeans| and connected.
12664netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012665num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012666ole Compiled with OLE automation support for Win32.
12667osx Compiled for macOS cf. mac
12668osxdarwin Compiled for macOS, with |mac-darwin-feature|
12669packages Compiled with |packages| support.
12670path_extra Compiled with up/downwards search in 'path' and 'tags'
12671perl Compiled with Perl interface.
12672persistent_undo Compiled with support for persistent undo history.
12673postscript Compiled with PostScript file printing.
12674printer Compiled with |:hardcopy| support.
12675profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012676prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012677python Python 2.x interface available. |has-python|
12678python_compiled Compiled with Python 2.x interface. |has-python|
12679python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12680python3 Python 3.x interface available. |has-python|
12681python3_compiled Compiled with Python 3.x interface. |has-python|
12682python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012683python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012684pythonx Python 2.x and/or 3.x interface available. |python_x|
12685qnx QNX version of Vim.
12686quickfix Compiled with |quickfix| support.
12687reltime Compiled with |reltime()| support.
12688rightleft Compiled with 'rightleft' support.
12689ruby Compiled with Ruby interface |ruby|.
12690scrollbind Compiled with 'scrollbind' support. (always true)
12691showcmd Compiled with 'showcmd' support.
12692signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012693smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012694sodium Compiled with libsodium for better crypt support
12695sound Compiled with sound support, e.g. `sound_playevent()`
12696spell Compiled with spell checking support |spell|.
12697startuptime Compiled with |--startuptime| support.
12698statusline Compiled with support for 'statusline', 'rulerformat'
12699 and special formats of 'titlestring' and 'iconstring'.
12700sun SunOS version of Vim.
12701sun_workshop Support for Sun |workshop| has been removed.
12702syntax Compiled with syntax highlighting support |syntax|.
12703syntax_items There are active syntax highlighting items for the
12704 current buffer.
12705system Compiled to use system() instead of fork()/exec().
12706tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012707 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012708tag_old_static Support for old static tags was removed, see
12709 |tag-old-static|.
12710tcl Compiled with Tcl interface.
12711termguicolors Compiled with true color in terminal support.
12712terminal Compiled with |terminal| support.
12713terminfo Compiled with terminfo instead of termcap.
12714termresponse Compiled with support for |t_RV| and |v:termresponse|.
12715textobjects Compiled with support for |text-objects|.
12716textprop Compiled with support for |text-properties|.
12717tgetent Compiled with tgetent support, able to use a termcap
12718 or terminfo file.
12719timers Compiled with |timer_start()| support.
12720title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012721 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012722toolbar Compiled with support for |gui-toolbar|.
12723ttyin input is a terminal (tty)
12724ttyout output is a terminal (tty)
12725unix Unix version of Vim. *+unix*
12726unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
12727user_commands User-defined commands. (always true)
12728vartabs Compiled with variable tabstop support |'vartabstop'|.
12729vcon Win32: Virtual console support is working, can use
12730 'termguicolors'. Also see |+vtp|.
12731vertsplit Compiled with vertically split windows |:vsplit|.
12732 (always true)
12733vim_starting True while initial source'ing takes place. |startup|
12734 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000012735vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012736viminfo Compiled with viminfo support.
12737vimscript-1 Compiled Vim script version 1 support
12738vimscript-2 Compiled Vim script version 2 support
12739vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010012740vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012741virtualedit Compiled with 'virtualedit' option. (always true)
12742visual Compiled with Visual mode. (always true)
12743visualextra Compiled with extra Visual mode commands. (always
12744 true) |blockwise-operators|.
12745vms VMS version of Vim.
12746vreplace Compiled with |gR| and |gr| commands. (always true)
12747vtp Compiled for vcon support |+vtp| (check vcon to find
12748 out if it works in the current console).
12749wildignore Compiled with 'wildignore' option.
12750wildmenu Compiled with 'wildmenu' option.
12751win16 old version for MS-Windows 3.1 (always false)
12752win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
12753 64 bits)
12754win32unix Win32 version of Vim, using Unix files (Cygwin)
12755win64 Win64 version of Vim (MS-Windows 64 bit).
12756win95 Win32 version for MS-Windows 95/98/ME (always false)
12757winaltkeys Compiled with 'winaltkeys' option.
12758windows Compiled with support for more than one window.
12759 (always true)
12760writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020012761xattr Compiled with extended attributes support |xattr|
12762 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012763xfontset Compiled with X fontset support |xfontset|.
12764xim Compiled with X input method support |xim|.
12765xpm Compiled with pixmap support.
12766xpm_w32 Compiled with pixmap support for Win32. (Only for
12767 backward compatibility. Use "xpm" instead.)
12768xsmp Compiled with X session management support.
12769xsmp_interact Compiled with interactive X session management support.
12770xterm_clipboard Compiled with support for xterm clipboard.
12771xterm_save Compiled with support for saving and restoring the
12772 xterm screen.
12773x11 Compiled with X11 support.
12774
12775
12776==============================================================================
127774. Matching a pattern in a String *string-match*
12778
12779This is common between several functions. A regexp pattern as explained at
12780|pattern| is normally used to find a match in the buffer lines. When a
12781pattern is used to find a match in a String, almost everything works in the
12782same way. The difference is that a String is handled like it is one line.
12783When it contains a "\n" character, this is not seen as a line break for the
12784pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
12785>
12786 :let a = "aaaa\nxxxx"
12787 :echo matchstr(a, "..\n..")
12788 aa
12789 xx
12790 :echo matchstr(a, "a.x")
12791 a
12792 x
12793
12794Don't forget that "^" will only match at the first character of the String and
12795"$" at the last character of the string. They don't match after or before a
12796"\n".
12797
12798 vim:tw=78:ts=8:noet:ft=help:norl: