blob: ab63681980f233d5c67a45138968a59b564b5fde [file] [log] [blame]
mikoto2000de094dc2024-11-14 22:13:48 +01001*builtin.txt* For Vim version 9.1. Last change: 2024 Nov 14
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7Builtin functions *builtin-functions*
8
Bram Moolenaarf269eab2022-10-03 18:04:35 +01009Note: Expression evaluation can be disabled at compile time, the builtin
10functions are not available then. See |+eval| and |no-eval-feature|.
11
12For functions grouped by what they are used for see |function-list|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000013
141. Overview |builtin-function-list|
152. Details |builtin-function-details|
163. Feature list |feature-list|
174. Matching a pattern in a String |string-match|
18
19==============================================================================
201. Overview *builtin-function-list*
21
22Use CTRL-] on the function name to jump to the full explanation.
23
24USAGE RESULT DESCRIPTION ~
25
26abs({expr}) Float or Number absolute value of {expr}
27acos({expr}) Float arc cosine of {expr}
28add({object}, {item}) List/Blob append {item} to {object}
29and({expr}, {expr}) Number bitwise AND
30append({lnum}, {text}) Number append {text} below line {lnum}
erraelf0837ba2024-06-24 12:27:01 -070031appendbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000032 Number append {text} below line {lnum}
erraelf0837ba2024-06-24 12:27:01 -070033 in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000034argc([{winid}]) Number number of files in the argument list
35argidx() Number current index in the argument list
36arglistid([{winnr} [, {tabnr}]]) Number argument list id
37argv({nr} [, {winid}]) String {nr} entry of the argument list
38argv([-1, {winid}]) List the argument list
39asin({expr}) Float arc sine of {expr}
40assert_beeps({cmd}) Number assert {cmd} causes a beep
41assert_equal({exp}, {act} [, {msg}])
42 Number assert {exp} is equal to {act}
43assert_equalfile({fname-one}, {fname-two} [, {msg}])
44 Number assert file contents are equal
45assert_exception({error} [, {msg}])
46 Number assert {error} is in v:exception
47assert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]])
48 Number assert {cmd} fails
49assert_false({actual} [, {msg}])
50 Number assert {actual} is false
51assert_inrange({lower}, {upper}, {actual} [, {msg}])
52 Number assert {actual} is inside the range
53assert_match({pat}, {text} [, {msg}])
54 Number assert {pat} matches {text}
55assert_nobeep({cmd}) Number assert {cmd} does not cause a beep
56assert_notequal({exp}, {act} [, {msg}])
57 Number assert {exp} is not equal {act}
58assert_notmatch({pat}, {text} [, {msg}])
59 Number assert {pat} not matches {text}
60assert_report({msg}) Number report a test failure
61assert_true({actual} [, {msg}]) Number assert {actual} is true
62atan({expr}) Float arc tangent of {expr}
63atan2({expr1}, {expr2}) Float arc tangent of {expr1} / {expr2}
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +010064autocmd_add({acmds}) Bool add a list of autocmds and groups
65autocmd_delete({acmds}) Bool delete a list of autocmds and groups
66autocmd_get([{opts}]) List return a list of autocmds
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000067balloon_gettext() String current text in the balloon
68balloon_show({expr}) none show {expr} inside the balloon
69balloon_split({msg}) List split {msg} as used for a balloon
Christ van Willegence0ef912024-06-20 23:41:59 +020070bindtextdomain({package}, {path})
Christ van Willegen8252ef12024-07-11 21:36:21 +020071 Bool bind text domain to specified path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000072blob2list({blob}) List convert {blob} into a list of numbers
73browse({save}, {title}, {initdir}, {default})
74 String put up a file requester
75browsedir({title}, {initdir}) String put up a directory requester
76bufadd({name}) Number add a buffer to the buffer list
77bufexists({buf}) Number |TRUE| if buffer {buf} exists
78buflisted({buf}) Number |TRUE| if buffer {buf} is listed
79bufload({buf}) Number load buffer {buf} if not loaded yet
80bufloaded({buf}) Number |TRUE| if buffer {buf} is loaded
81bufname([{buf}]) String Name of the buffer {buf}
82bufnr([{buf} [, {create}]]) Number Number of the buffer {buf}
83bufwinid({buf}) Number window ID of buffer {buf}
84bufwinnr({buf}) Number window number of buffer {buf}
85byte2line({byte}) Number line number at byte count {byte}
Christian Brabandt67672ef2023-04-24 21:09:54 +010086byteidx({expr}, {nr} [, {utf16}])
87 Number byte index of {nr}'th char in {expr}
88byteidxcomp({expr}, {nr} [, {utf16}])
89 Number byte index of {nr}'th char in {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000090call({func}, {arglist} [, {dict}])
91 any call {func} with arguments {arglist}
92ceil({expr}) Float round {expr} up
93ch_canread({handle}) Number check if there is something to read
94ch_close({handle}) none close {handle}
95ch_close_in({handle}) none close in part of {handle}
96ch_evalexpr({handle}, {expr} [, {options}])
97 any evaluate {expr} on JSON {handle}
98ch_evalraw({handle}, {string} [, {options}])
99 any evaluate {string} on raw {handle}
100ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
101ch_getjob({channel}) Job get the Job of {channel}
102ch_info({handle}) String info about channel {handle}
103ch_log({msg} [, {handle}]) none write {msg} in the channel log file
104ch_logfile({fname} [, {mode}]) none start logging channel activity
105ch_open({address} [, {options}])
106 Channel open a channel to {address}
107ch_read({handle} [, {options}]) String read from {handle}
108ch_readblob({handle} [, {options}])
109 Blob read Blob from {handle}
110ch_readraw({handle} [, {options}])
111 String read raw from {handle}
112ch_sendexpr({handle}, {expr} [, {options}])
113 any send {expr} over JSON {handle}
114ch_sendraw({handle}, {expr} [, {options}])
115 any send {expr} over raw {handle}
116ch_setoptions({handle}, {options})
117 none set options for {handle}
118ch_status({handle} [, {options}])
119 String status of channel {handle}
120changenr() Number current change number
121char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr}
122charclass({string}) Number character class of {string}
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000123charcol({expr} [, {winid}]) Number column number of cursor or mark
Christian Brabandt67672ef2023-04-24 21:09:54 +0100124charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000125 Number char index of byte {idx} in {string}
126chdir({dir}) String change current working directory
127cindent({lnum}) Number C indent for line {lnum}
128clearmatches([{win}]) none clear all matches
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000129col({expr} [, {winid}]) Number column byte index of cursor or mark
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000130complete({startcol}, {matches}) none set Insert mode completion
131complete_add({expr}) Number add completion match
132complete_check() Number check for key typed during completion
133complete_info([{what}]) Dict get current completion information
134confirm({msg} [, {choices} [, {default} [, {type}]]])
135 Number number of choice picked by user
136copy({expr}) any make a shallow copy of {expr}
137cos({expr}) Float cosine of {expr}
138cosh({expr}) Float hyperbolic cosine of {expr}
139count({comp}, {expr} [, {ic} [, {start}]])
140 Number count how many {expr} are in {comp}
141cscope_connection([{num}, {dbpath} [, {prepend}]])
142 Number checks existence of cscope connection
143cursor({lnum}, {col} [, {off}])
144 Number move cursor to {lnum}, {col}, {off}
145cursor({list}) Number move cursor to position in {list}
146debugbreak({pid}) Number interrupt process being debugged
147deepcopy({expr} [, {noref}]) any make a full copy of {expr}
148delete({fname} [, {flags}]) Number delete the file or directory {fname}
149deletebufline({buf}, {first} [, {last}])
150 Number delete lines from buffer {buf}
151did_filetype() Number |TRUE| if FileType autocmd event used
Yegappan Lakshmananfa378352024-02-01 22:05:27 +0100152diff({fromlist}, {tolist} [, {options}])
153 List diff two Lists of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000154diff_filler({lnum}) Number diff filler lines about {lnum}
155diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
156digraph_get({chars}) String get the |digraph| of {chars}
157digraph_getlist([{listall}]) List get all |digraph|s
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200158digraph_set({chars}, {digraph}) Bool register |digraph|
159digraph_setlist({digraphlist}) Bool register multiple |digraph|s
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000160echoraw({expr}) none output {expr} as-is
161empty({expr}) Number |TRUE| if {expr} is empty
162environ() Dict return environment variables
Sean Dewarb0efa492023-07-08 10:35:19 +0100163err_teapot([{expr}]) none give E418, or E503 if {expr} is |TRUE|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000164escape({string}, {chars}) String escape {chars} in {string} with '\'
165eval({string}) any evaluate {string} into its value
166eventhandler() Number |TRUE| if inside an event handler
167executable({expr}) Number 1 if executable {expr} exists
168execute({command}) String execute {command} and get the output
169exepath({expr}) String full path of the command {expr}
170exists({expr}) Number |TRUE| if {expr} exists
171exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
172exp({expr}) Float exponential of {expr}
173expand({expr} [, {nosuf} [, {list}]])
174 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100175expandcmd({string} [, {options}])
176 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000177extend({expr1}, {expr2} [, {expr3}])
178 List/Dict insert items of {expr2} into {expr1}
179extendnew({expr1}, {expr2} [, {expr3}])
180 List/Dict like |extend()| but creates a new
181 List or Dictionary
182feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
Shougo Matsushita60c87432024-06-03 22:59:27 +0200183filecopy({from}, {to}) Number |TRUE| if copying file {from} to {to}
184 worked
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000185filereadable({file}) Number |TRUE| if {file} is a readable file
186filewritable({file}) Number |TRUE| if {file} is a writable file
187filter({expr1}, {expr2}) List/Dict/Blob/String
188 remove items from {expr1} where
189 {expr2} is 0
190finddir({name} [, {path} [, {count}]])
191 String find directory {name} in {path}
192findfile({name} [, {path} [, {count}]])
193 String find file {name} in {path}
194flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
195flattennew({list} [, {maxdepth}])
196 List flatten a copy of {list}
197float2nr({expr}) Number convert Float {expr} to a Number
198floor({expr}) Float round {expr} down
199fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
200fnameescape({fname}) String escape special characters in {fname}
201fnamemodify({fname}, {mods}) String modify file name
202foldclosed({lnum}) Number first line of fold at {lnum} if closed
203foldclosedend({lnum}) Number last line of fold at {lnum} if closed
204foldlevel({lnum}) Number fold level at {lnum}
205foldtext() String line displayed for closed fold
206foldtextresult({lnum}) String text for closed fold at {lnum}
Ernie Raele79e2072024-01-13 11:47:33 +0100207foreach({expr1}, {expr2}) List/Dict/Blob/String
208 for each item in {expr1} call {expr2}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000209foreground() Number bring the Vim window to the foreground
Bram Moolenaaraa534142022-09-15 21:46:02 +0100210fullcommand({name} [, {vim9}]) String get full command from {name}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000211funcref({name} [, {arglist}] [, {dict}])
212 Funcref reference to function {name}
213function({name} [, {arglist}] [, {dict}])
214 Funcref named reference to function {name}
215garbagecollect([{atexit}]) none free memory, breaking cyclic references
216get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
217get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
218get({func}, {what}) any get property of funcref/partial {func}
219getbufinfo([{buf}]) List information about buffers
220getbufline({buf}, {lnum} [, {end}])
221 List lines {lnum} to {end} of buffer {buf}
Bram Moolenaarce30ccc2022-11-21 19:57:04 +0000222getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000223getbufvar({buf}, {varname} [, {def}])
224 any variable {varname} in buffer {buf}
mikoto20001083cae2024-11-11 21:24:14 +0100225getcellpixels() List get character cell pixel size
Kota Kato66bb9ae2023-01-17 18:31:56 +0000226getcellwidths() List get character cell width overrides
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000227getchangelist([{buf}]) List list of change list items
Doug Kearns9cd9e752024-04-07 17:42:17 +0200228getchar([{expr}]) Number or String
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000229 get one character from the user
230getcharmod() Number modifiers for the last typed character
231getcharpos({expr}) List position of cursor, mark, etc.
232getcharsearch() Dict last character search
Doug Kearns9cd9e752024-04-07 17:42:17 +0200233getcharstr([{expr}]) String get one character from the user
Ruslan Russkikh0407d622024-10-08 22:21:05 +0200234getcmdcomplpat() String return the completion pattern of the
235 current command-line completion
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100236getcmdcompltype() String return the type of the current
237 command-line completion
Shougo Matsushita69084282024-09-23 20:34:47 +0200238getcmdline() String return the current command-line input
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000239getcmdpos() Number return cursor position in command-line
Shougo Matsushita69084282024-09-23 20:34:47 +0200240getcmdprompt() String return the current command-line prompt
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100241getcmdscreenpos() Number return cursor screen position in
242 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000243getcmdtype() String return current command-line type
244getcmdwintype() String return current command-line window type
245getcompletion({pat}, {type} [, {filtered}])
246 List list of cmdline completion matches
247getcurpos([{winnr}]) List position of the cursor
248getcursorcharpos([{winnr}]) List character position of the cursor
249getcwd([{winnr} [, {tabnr}]]) String get the current working directory
250getenv({name}) String return environment variable
251getfontname([{name}]) String name of font being used
252getfperm({fname}) String file permissions of file {fname}
253getfsize({fname}) Number size in bytes of file {fname}
254getftime({fname}) Number last modification time of file
255getftype({fname}) String description of type of file {fname}
256getimstatus() Number |TRUE| if the IME status is active
257getjumplist([{winnr} [, {tabnr}]])
258 List list of jump list items
259getline({lnum}) String line {lnum} of current buffer
260getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
261getloclist({nr}) List list of location list items
262getloclist({nr}, {what}) Dict get specific location list properties
263getmarklist([{buf}]) List list of global/local marks
264getmatches([{win}]) List list of current matches
265getmousepos() Dict last known mouse position
Bram Moolenaar24dc19c2022-11-14 19:49:15 +0000266getmouseshape() String current mouse shape name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000267getpid() Number process ID of Vim
268getpos({expr}) List position of cursor, mark, etc.
269getqflist() List list of quickfix items
270getqflist({what}) Dict get specific quickfix list properties
271getreg([{regname} [, 1 [, {list}]]])
272 String or List contents of a register
273getreginfo([{regname}]) Dict information about a register
Shougo Matsushita19b71882024-02-28 22:48:12 +0100274getregion({pos1}, {pos2} [, {opts}])
Shougo Matsushita3f905ab2024-02-21 00:02:45 +0100275 List get the text from {pos1} to {pos2}
Shougo Matsushitab4757e62024-05-07 20:49:24 +0200276getregionpos({pos1}, {pos2} [, {opts}])
277 List get a list of positions for a region
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000278getregtype([{regname}]) String type of a register
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +0100279getscriptinfo([{opts}]) List list of sourced scripts
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000280gettabinfo([{expr}]) List list of tab pages
281gettabvar({nr}, {varname} [, {def}])
282 any variable {varname} in tab {nr} or {def}
283gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
284 any {name} in {winnr} in tab page {tabnr}
285gettagstack([{nr}]) Dict get the tag stack of window {nr}
h-east52e7cc22024-07-28 17:03:29 +0200286gettext({text} [, {package}]) String lookup translation of {text}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000287getwininfo([{winid}]) List list of info about each window
Bram Moolenaar938ae282023-02-20 20:44:55 +0000288getwinpos([{timeout}]) List X and Y coord in pixels of Vim window
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000289getwinposx() Number X coord in pixels of the Vim window
290getwinposy() Number Y coord in pixels of the Vim window
291getwinvar({nr}, {varname} [, {def}])
292 any variable {varname} in window {nr}
293glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
294 any expand file wildcards in {expr}
295glob2regpat({expr}) String convert a glob pat into a search pat
296globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
297 String do glob({expr}) for all dirs in {path}
298has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
299has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
300haslocaldir([{winnr} [, {tabnr}]])
301 Number |TRUE| if the window executed |:lcd|
302 or |:tcd|
303hasmapto({what} [, {mode} [, {abbr}]])
304 Number |TRUE| if mapping to {what} exists
305histadd({history}, {item}) Number add an item to a history
306histdel({history} [, {item}]) Number remove an item from a history
307histget({history} [, {index}]) String get the item {index} from a history
308histnr({history}) Number highest index of a history
309hlID({name}) Number syntax ID of highlight group {name}
310hlexists({name}) Number |TRUE| if highlight group {name} exists
311hlget([{name} [, {resolve}]]) List get highlight group attributes
312hlset({list}) Number set highlight group attributes
313hostname() String name of the machine Vim is running on
314iconv({expr}, {from}, {to}) String convert encoding of {expr}
Ernie Rael05124252024-07-11 22:10:45 +0200315id({item}) String get unique identity string of item
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000316indent({lnum}) Number indent of line {lnum}
317index({object}, {expr} [, {start} [, {ic}]])
318 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100319indexof({object}, {expr} [, {opts}]])
320 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000321input({prompt} [, {text} [, {completion}]])
322 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100323inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000324 String like input() but in a GUI dialog
325inputlist({textlist}) Number let the user pick from a choice list
326inputrestore() Number restore typeahead
327inputsave() Number save and clear typeahead
328inputsecret({prompt} [, {text}]) String like input() but hiding the text
329insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
LemonBoyafe04662023-08-23 21:08:11 +0200330instanceof({object}, {class}) Number |TRUE| if {object} is an instance of {class}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000331interrupt() none interrupt script execution
332invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100333isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000334isdirectory({directory}) Number |TRUE| if {directory} is a directory
335isinf({expr}) Number determine if {expr} is infinity value
336 (positive or negative)
337islocked({expr}) Number |TRUE| if {expr} is locked
338isnan({expr}) Number |TRUE| if {expr} is NaN
339items({dict}) List key-value pairs in {dict}
340job_getchannel({job}) Channel get the channel handle for {job}
341job_info([{job}]) Dict get information about {job}
342job_setoptions({job}, {options}) none set options for {job}
343job_start({command} [, {options}])
344 Job start a job
345job_status({job}) String get the status of {job}
346job_stop({job} [, {how}]) Number stop {job}
347join({list} [, {sep}]) String join {list} items into one String
348js_decode({string}) any decode JS style JSON
349js_encode({expr}) String encode JS style JSON
350json_decode({string}) any decode JSON
351json_encode({expr}) String encode JSON
352keys({dict}) List keys in {dict}
zeertzjqcdc83932022-09-12 13:38:41 +0100353keytrans({string}) String translate internal keycodes to a form
354 that can be used by |:map|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000355len({expr}) Number the length of {expr}
356libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
357libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
358line({expr} [, {winid}]) Number line nr of cursor, last line or mark
359line2byte({lnum}) Number byte count of line {lnum}
360lispindent({lnum}) Number Lisp indent for line {lnum}
361list2blob({list}) Blob turn {list} of numbers into a Blob
362list2str({list} [, {utf8}]) String turn {list} of numbers into a String
363listener_add({callback} [, {buf}])
364 Number add a callback to listen to changes
365listener_flush([{buf}]) none invoke listener callbacks
366listener_remove({id}) none remove a listener callback
367localtime() Number current time
368log({expr}) Float natural logarithm (base e) of {expr}
369log10({expr}) Float logarithm of Float {expr} to base 10
370luaeval({expr} [, {expr}]) any evaluate |Lua| expression
371map({expr1}, {expr2}) List/Dict/Blob/String
372 change each item in {expr1} to {expr2}
373maparg({name} [, {mode} [, {abbr} [, {dict}]]])
374 String or Dict
375 rhs of mapping {name} in mode {mode}
376mapcheck({name} [, {mode} [, {abbr}]])
377 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100378maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000379mapnew({expr1}, {expr2}) List/Dict/Blob/String
380 like |map()| but creates a new List or
381 Dictionary
382mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
383match({expr}, {pat} [, {start} [, {count}]])
384 Number position where {pat} matches in {expr}
385matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
386 Number highlight {pattern} with {group}
387matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
388 Number highlight positions with {group}
389matcharg({nr}) List arguments of |:match|
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100390matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict})
391 List all the {pat} matches in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000392matchdelete({id} [, {win}]) Number delete match identified by {id}
393matchend({expr}, {pat} [, {start} [, {count}]])
394 Number position where {pat} ends in {expr}
395matchfuzzy({list}, {str} [, {dict}])
396 List fuzzy match {str} in {list}
397matchfuzzypos({list}, {str} [, {dict}])
398 List fuzzy match {str} in {list}
399matchlist({expr}, {pat} [, {start} [, {count}]])
400 List match and submatches of {pat} in {expr}
401matchstr({expr}, {pat} [, {start} [, {count}]])
402 String {count}'th match of {pat} in {expr}
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100403matchstrlist({list}, {pat} [, {dict})
404 List all the {pat} matches in {list}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000405matchstrpos({expr}, {pat} [, {start} [, {count}]])
406 List {count}'th match of {pat} in {expr}
407max({expr}) Number maximum value of items in {expr}
408menu_info({name} [, {mode}]) Dict get menu item information
409min({expr}) Number minimum value of items in {expr}
Bram Moolenaar938ae282023-02-20 20:44:55 +0000410mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000411 Number create directory {name}
Doug Kearns9cd9e752024-04-07 17:42:17 +0200412mode([{expr}]) String current editing mode
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000413mzeval({expr}) any evaluate |MzScheme| expression
414nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
415nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
416or({expr}, {expr}) Number bitwise OR
417pathshorten({expr} [, {len}]) String shorten directory names in a path
418perleval({expr}) any evaluate |Perl| expression
419popup_atcursor({what}, {options}) Number create popup window near the cursor
420popup_beval({what}, {options}) Number create popup window for 'ballooneval'
421popup_clear() none close all popup windows
422popup_close({id} [, {result}]) none close popup window {id}
423popup_create({what}, {options}) Number create a popup window
424popup_dialog({what}, {options}) Number create a popup window used as a dialog
425popup_filter_menu({id}, {key}) Number filter for a menu popup window
426popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100427popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000428popup_findinfo() Number get window ID of info popup window
429popup_findpreview() Number get window ID of preview popup window
430popup_getoptions({id}) Dict get options of popup window {id}
431popup_getpos({id}) Dict get position of popup window {id}
432popup_hide({id}) none hide popup menu {id}
433popup_list() List get a list of window IDs of all popups
434popup_locate({row}, {col}) Number get window ID of popup at position
435popup_menu({what}, {options}) Number create a popup window used as a menu
436popup_move({id}, {options}) none set position of popup window {id}
437popup_notification({what}, {options})
438 Number create a notification popup window
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200439popup_setbuf({id}, {buf}) Bool set the buffer for the popup window {id}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000440popup_setoptions({id}, {options})
441 none set options for popup window {id}
442popup_settext({id}, {text}) none set the text of popup window {id}
443popup_show({id}) none unhide popup window {id}
444pow({x}, {y}) Float {x} to the power of {y}
445prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
446printf({fmt}, {expr1}...) String format text
447prompt_getprompt({buf}) String get prompt text
448prompt_setcallback({buf}, {expr}) none set prompt callback function
449prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
450prompt_setprompt({buf}, {text}) none set prompt text
451prop_add({lnum}, {col}, {props}) none add one text property
452prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
453 none add multiple text properties
454prop_clear({lnum} [, {lnum-end} [, {props}]])
455 none remove all text properties
456prop_find({props} [, {direction}])
457 Dict search for a text property
458prop_list({lnum} [, {props}]) List text properties in {lnum}
459prop_remove({props} [, {lnum} [, {lnum-end}]])
460 Number remove a text property
461prop_type_add({name}, {props}) none define a new property type
462prop_type_change({name}, {props})
463 none change an existing property type
464prop_type_delete({name} [, {props}])
465 none delete a property type
466prop_type_get({name} [, {props}])
467 Dict get property type values
468prop_type_list([{props}]) List get list of property types
469pum_getpos() Dict position and size of pum if visible
470pumvisible() Number whether popup menu is visible
zeertzjq7c515282024-11-10 20:26:12 +0100471py3eval({expr} [, {locals}]) any evaluate |python3| expression
472pyeval({expr} [, {locals}]) any evaluate |Python| expression
473pyxeval({expr} [, {locals}]) any evaluate |python_x| expression
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000474rand([{expr}]) Number get pseudo-random number
475range({expr} [, {max} [, {stride}]])
476 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100477readblob({fname} [, {offset} [, {size}]])
478 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000479readdir({dir} [, {expr} [, {dict}]])
480 List file names in {dir} selected by {expr}
481readdirex({dir} [, {expr} [, {dict}]])
482 List file info in {dir} selected by {expr}
483readfile({fname} [, {type} [, {max}]])
484 List get list of lines from file {fname}
485reduce({object}, {func} [, {initial}])
486 any reduce {object} using {func}
487reg_executing() String get the executing register name
488reg_recording() String get the recording register name
489reltime([{start} [, {end}]]) List get time value
490reltimefloat({time}) Float turn the time value into a Float
491reltimestr({time}) String turn time value into a String
492remote_expr({server}, {string} [, {idvar} [, {timeout}]])
493 String send expression
494remote_foreground({server}) Number bring Vim server to the foreground
495remote_peek({serverid} [, {retvar}])
496 Number check for reply string
497remote_read({serverid} [, {timeout}])
498 String read reply string
499remote_send({server}, {string} [, {idvar}])
500 String send key sequence
501remote_startserver({name}) none become server {name}
502remove({list}, {idx} [, {end}]) any/List
503 remove items {idx}-{end} from {list}
504remove({blob}, {idx} [, {end}]) Number/Blob
505 remove bytes {idx}-{end} from {blob}
506remove({dict}, {key}) any remove entry {key} from {dict}
507rename({from}, {to}) Number rename (move) file from {from} to {to}
Bakudankun375141e2022-09-09 18:46:47 +0100508repeat({expr}, {count}) List/Blob/String
509 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000510resolve({filename}) String get filename a shortcut points to
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +0100511reverse({obj}) List/Blob/String
512 reverse {obj}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000513round({expr}) Float round off {expr}
514rubyeval({expr}) any evaluate |Ruby| expression
515screenattr({row}, {col}) Number attribute at screen position
516screenchar({row}, {col}) Number character at screen position
517screenchars({row}, {col}) List List of characters at screen position
518screencol() Number current cursor column
519screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
520screenrow() Number current cursor row
521screenstring({row}, {col}) String characters at screen position
522search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
523 Number search for {pattern}
524searchcount([{options}]) Dict get or update search stats
525searchdecl({name} [, {global} [, {thisblock}]])
526 Number search for variable declaration
527searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
528 Number search for other end of start/end pair
529searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
530 List search for other end of start/end pair
531searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
532 List search for {pattern}
533server2client({clientid}, {string})
534 Number send reply string
535serverlist() String get a list of available servers
erraelf0837ba2024-06-24 12:27:01 -0700536setbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000537 Number set line {lnum} to {text} in buffer
erraelf0837ba2024-06-24 12:27:01 -0700538 {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000539setbufvar({buf}, {varname}, {val})
540 none set {varname} in buffer {buf} to {val}
541setcellwidths({list}) none set character cell width overrides
542setcharpos({expr}, {list}) Number set the {expr} position to {list}
543setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100544setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000545setcmdpos({pos}) Number set cursor position in command-line
546setcursorcharpos({list}) Number move cursor to position in {list}
547setenv({name}, {val}) none set environment variable
548setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
549setline({lnum}, {line}) Number set line {lnum} to {line}
550setloclist({nr}, {list} [, {action}])
551 Number modify location list using {list}
552setloclist({nr}, {list}, {action}, {what})
553 Number modify specific location list props
554setmatches({list} [, {win}]) Number restore a list of matches
555setpos({expr}, {list}) Number set the {expr} position to {list}
556setqflist({list} [, {action}]) Number modify quickfix list using {list}
557setqflist({list}, {action}, {what})
558 Number modify specific quickfix list props
559setreg({n}, {v} [, {opt}]) Number set register to value and type
560settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
561settabwinvar({tabnr}, {winnr}, {varname}, {val})
562 none set {varname} in window {winnr} in tab
563 page {tabnr} to {val}
564settagstack({nr}, {dict} [, {action}])
565 Number modify tag stack using {dict}
566setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
567sha256({string}) String SHA256 checksum of {string}
568shellescape({string} [, {special}])
569 String escape {string} for use as shell
570 command argument
571shiftwidth([{col}]) Number effective value of 'shiftwidth'
572sign_define({name} [, {dict}]) Number define or update a sign
573sign_define({list}) List define or update a list of signs
574sign_getdefined([{name}]) List get a list of defined signs
575sign_getplaced([{buf} [, {dict}]])
576 List get a list of placed signs
577sign_jump({id}, {group}, {buf})
578 Number jump to a sign
579sign_place({id}, {group}, {name}, {buf} [, {dict}])
580 Number place a sign
581sign_placelist({list}) List place a list of signs
582sign_undefine([{name}]) Number undefine a sign
583sign_undefine({list}) List undefine a list of signs
584sign_unplace({group} [, {dict}])
585 Number unplace a sign
586sign_unplacelist({list}) List unplace a list of signs
587simplify({filename}) String simplify filename as much as possible
588sin({expr}) Float sine of {expr}
589sinh({expr}) Float hyperbolic sine of {expr}
590slice({expr}, {start} [, {end}]) String, List or Blob
591 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000592sort({list} [, {how} [, {dict}]])
593 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000594sound_clear() none stop playing all sounds
595sound_playevent({name} [, {callback}])
596 Number play an event sound
597sound_playfile({path} [, {callback}])
598 Number play sound file {path}
599sound_stop({id}) none stop playing sound {id}
600soundfold({word}) String sound-fold {word}
601spellbadword() String badly spelled word at cursor
602spellsuggest({word} [, {max} [, {capital}]])
603 List spelling suggestions
604split({expr} [, {pat} [, {keepempty}]])
605 List make |List| from {pat} separated {expr}
606sqrt({expr}) Float square root of {expr}
607srand([{expr}]) List get seed for |rand()|
608state([{what}]) String current state of Vim
609str2float({expr} [, {quoted}]) Float convert String to Float
610str2list({expr} [, {utf8}]) List convert each character of {expr} to
611 ASCII/UTF-8 value
612str2nr({expr} [, {base} [, {quoted}]])
613 Number convert String to Number
614strcharlen({expr}) Number character length of the String {expr}
615strcharpart({str}, {start} [, {len} [, {skipcc}]])
616 String {len} characters of {str} at
617 character {start}
618strchars({expr} [, {skipcc}]) Number character count of the String {expr}
619strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
620strftime({format} [, {time}]) String format time with a specified format
621strgetchar({str}, {index}) Number get char {index} from {str}
622stridx({haystack}, {needle} [, {start}])
623 Number index of {needle} in {haystack}
624string({expr}) String String representation of {expr} value
625strlen({expr}) Number length of the String {expr}
626strpart({str}, {start} [, {len} [, {chars}]])
627 String {len} bytes/chars of {str} at
628 byte {start}
629strptime({format}, {timestring})
630 Number Convert {timestring} to unix timestamp
631strridx({haystack}, {needle} [, {start}])
632 Number last index of {needle} in {haystack}
633strtrans({expr}) String translate string to make it printable
Christian Brabandt67672ef2023-04-24 21:09:54 +0100634strutf16len({string} [, {countcc}])
635 Number number of UTF-16 code units in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000636strwidth({expr}) Number display cell length of the String {expr}
637submatch({nr} [, {list}]) String or List
638 specific match in ":s" or substitute()
639substitute({expr}, {pat}, {sub}, {flags})
640 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000641swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000642swapinfo({fname}) Dict information about swap file {fname}
643swapname({buf}) String swap file of buffer {buf}
644synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
645synIDattr({synID}, {what} [, {mode}])
646 String attribute {what} of syntax ID {synID}
647synIDtrans({synID}) Number translated syntax ID of {synID}
648synconcealed({lnum}, {col}) List info about concealing
649synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
650system({expr} [, {input}]) String output of shell command/filter {expr}
651systemlist({expr} [, {input}]) List output of shell command/filter {expr}
652tabpagebuflist([{arg}]) List list of buffer numbers in tab page
653tabpagenr([{arg}]) Number number of current or last tab page
654tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
655tagfiles() List tags files used
656taglist({expr} [, {filename}]) List list of tags matching {expr}
657tan({expr}) Float tangent of {expr}
658tanh({expr}) Float hyperbolic tangent of {expr}
659tempname() String name for a temporary file
660term_dumpdiff({filename}, {filename} [, {options}])
661 Number display difference between two dumps
662term_dumpload({filename} [, {options}])
663 Number displaying a screen dump
664term_dumpwrite({buf}, {filename} [, {options}])
665 none dump terminal window contents
666term_getaltscreen({buf}) Number get the alternate screen flag
667term_getansicolors({buf}) List get ANSI palette in GUI color mode
668term_getattr({attr}, {what}) Number get the value of attribute {what}
669term_getcursor({buf}) List get the cursor position of a terminal
670term_getjob({buf}) Job get the job associated with a terminal
671term_getline({buf}, {row}) String get a line of text from a terminal
672term_getscrolled({buf}) Number get the scroll count of a terminal
673term_getsize({buf}) List get the size of a terminal
674term_getstatus({buf}) String get the status of a terminal
675term_gettitle({buf}) String get the title of a terminal
676term_gettty({buf}, [{input}]) String get the tty name of a terminal
677term_list() List get the list of terminal buffers
678term_scrape({buf}, {row}) List get row of a terminal screen
679term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
680term_setansicolors({buf}, {colors})
681 none set ANSI palette in GUI color mode
682term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
683term_setkill({buf}, {how}) none set signal to stop job in terminal
684term_setrestore({buf}, {command}) none set command to restore terminal
685term_setsize({buf}, {rows}, {cols})
686 none set the size of a terminal
687term_start({cmd} [, {options}]) Number open a terminal window and run a job
688term_wait({buf} [, {time}]) Number wait for screen to be updated
689terminalprops() Dict properties of the terminal
690test_alloc_fail({id}, {countdown}, {repeat})
691 none make memory allocation fail
692test_autochdir() none enable 'autochdir' during startup
693test_feedinput({string}) none add key sequence to input buffer
694test_garbagecollect_now() none free memory right now for testing
695test_garbagecollect_soon() none free memory soon for testing
696test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000697test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000698test_ignore_error({expr}) none ignore a specific error
Christopher Plewright20b795e2022-12-20 20:01:58 +0000699test_mswin_event({event}, {args})
700 bool generate MS-Windows event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000701test_null_blob() Blob null value for testing
702test_null_channel() Channel null value for testing
703test_null_dict() Dict null value for testing
704test_null_function() Funcref null value for testing
705test_null_job() Job null value for testing
706test_null_list() List null value for testing
707test_null_partial() Funcref null value for testing
708test_null_string() String null value for testing
709test_option_not_set({name}) none reset flag indicating option was set
710test_override({expr}, {val}) none test with Vim internal overrides
711test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000712test_setmouse({row}, {col}) none set the mouse position for testing
713test_settime({expr}) none set current time for testing
Doug Kearns9cd9e752024-04-07 17:42:17 +0200714test_srand_seed([{seed}]) none set seed for testing srand()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000715test_unknown() any unknown value for testing
716test_void() any void value for testing
717timer_info([{id}]) List information about timers
718timer_pause({id}, {pause}) none pause or unpause a timer
719timer_start({time}, {callback} [, {options}])
720 Number create a timer
721timer_stop({timer}) none stop a timer
722timer_stopall() none stop all timers
723tolower({expr}) String the String {expr} switched to lowercase
724toupper({expr}) String the String {expr} switched to uppercase
725tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
726 to chars in {tostr}
727trim({text} [, {mask} [, {dir}]])
728 String trim characters in {mask} from {text}
729trunc({expr}) Float truncate Float {expr}
730type({expr}) Number type of value {expr}
731typename({expr}) String representation of the type of {expr}
732undofile({name}) String undo file name for {name}
Devin J. Pohly5fee1112023-04-23 20:26:59 -0500733undotree([{buf}]) List undo file tree for buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000734uniq({list} [, {func} [, {dict}]])
735 List remove adjacent duplicates from a list
Christian Brabandt67672ef2023-04-24 21:09:54 +0100736utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
737 Number UTF-16 index of byte {idx} in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000738values({dict}) List values in {dict}
zeertzjq825cf812023-08-17 22:55:25 +0200739virtcol({expr} [, {list} [, {winid}])
740 Number or List
LemonBoy0f7a3e12022-05-26 12:10:37 +0100741 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100742virtcol2col({winid}, {lnum}, {col})
743 Number byte index of a character on screen
Doug Kearns9cd9e752024-04-07 17:42:17 +0200744visualmode([{expr}]) String last visual mode used
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000745wildmenumode() Number whether 'wildmenu' mode is active
746win_execute({id}, {command} [, {silent}])
747 String execute {command} in window {id}
748win_findbuf({bufnr}) List find windows containing {bufnr}
749win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
750win_gettype([{nr}]) String type of window {nr}
751win_gotoid({expr}) Number go to window with ID {expr}
752win_id2tabwin({expr}) List get tab and window nr from window ID
753win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000754win_move_separator({nr}) Number move window vertical separator
755win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000756win_screenpos({nr}) List get screen position of window {nr}
757win_splitmove({nr}, {target} [, {options}])
758 Number move window {nr} to split of {target}
759winbufnr({nr}) Number buffer number of window {nr}
760wincol() Number window column of the cursor
761windowsversion() String MS-Windows OS version
762winheight({nr}) Number height of window {nr}
763winlayout([{tabnr}]) List layout of windows in tab {tabnr}
764winline() Number window line of the cursor
765winnr([{expr}]) Number number of current window
766winrestcmd() String returns command to restore window sizes
767winrestview({dict}) none restore view of current window
768winsaveview() Dict save view of current window
769winwidth({nr}) Number width of window {nr}
770wordcount() Dict get byte/char/word statistics
771writefile({object}, {fname} [, {flags}])
772 Number write |Blob| or |List| of lines to file
773xor({expr}, {expr}) Number bitwise XOR
774
775==============================================================================
7762. Details *builtin-function-details*
777
778Not all functions are here, some have been moved to a help file covering the
779specific functionality.
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200780Return type specifies the type for |Vim9-script|, see |vim9-types|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000781
782abs({expr}) *abs()*
783 Return the absolute value of {expr}. When {expr} evaluates to
784 a |Float| abs() returns a |Float|. When {expr} can be
785 converted to a |Number| abs() returns a |Number|. Otherwise
786 abs() gives an error message and returns -1.
787 Examples: >
788 echo abs(1.456)
789< 1.456 >
790 echo abs(-5.456)
791< 5.456 >
792 echo abs(-4)
793< 4
794
795 Can also be used as a |method|: >
796 Compute()->abs()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200797<
798 Return type: |Number| or |Float| depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000799
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000800
801acos({expr}) *acos()*
802 Return the arc cosine of {expr} measured in radians, as a
803 |Float| in the range of [0, pi].
804 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100805 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000806 Examples: >
807 :echo acos(0)
808< 1.570796 >
809 :echo acos(-0.5)
810< 2.094395
811
812 Can also be used as a |method|: >
813 Compute()->acos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200814<
815 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000816
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000817
818add({object}, {expr}) *add()*
819 Append the item {expr} to |List| or |Blob| {object}. Returns
820 the resulting |List| or |Blob|. Examples: >
821 :let alist = add([1, 2, 3], item)
822 :call add(mylist, "woodstock")
823< Note that when {expr} is a |List| it is appended as a single
824 item. Use |extend()| to concatenate |Lists|.
825 When {object} is a |Blob| then {expr} must be a number.
826 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100827 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000828
829 Can also be used as a |method|: >
830 mylist->add(val1)->add(val2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200831<
832 Return type: list<{type}> (depending on the given |List|) or
833 |Blob|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000834
835
836and({expr}, {expr}) *and()*
837 Bitwise AND on the two arguments. The arguments are converted
838 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100839 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000840 Example: >
841 :let flag = and(bits, 0x80)
842< Can also be used as a |method|: >
843 :let flag = bits->and(0x80)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200844<
845 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000846
847
848append({lnum}, {text}) *append()*
849 When {text} is a |List|: Append each item of the |List| as a
850 text line below line {lnum} in the current buffer.
851 Otherwise append {text} as one text line below line {lnum} in
852 the current buffer.
853 Any type of item is accepted and converted to a String.
854 {lnum} can be zero to insert a line before the first one.
855 {lnum} is used like with |getline()|.
856 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000857 0 for success. When {text} is an empty list zero is returned,
858 no matter the value of {lnum}.
859 In |Vim9| script an invalid argument or negative number
860 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000861 :let failed = append(line('$'), "# THE END")
862 :let failed = append(0, ["Chapter 1", "the beginning"])
863
864< Can also be used as a |method| after a List, the base is
865 passed as the second argument: >
866 mylist->append(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200867<
868 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000869
870
871appendbufline({buf}, {lnum}, {text}) *appendbufline()*
872 Like |append()| but append the text in buffer {buf}.
873
874 This function works only for loaded buffers. First call
875 |bufload()| if needed.
876
877 For the use of {buf}, see |bufname()|.
878
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000879 {lnum} is the line number to append below. Note that using
880 |line()| would use the current buffer, not the one appending
881 to. Use "$" to append at the end of the buffer. Other string
882 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000883
884 On success 0 is returned, on failure 1 is returned.
885 In |Vim9| script an error is given for an invalid {lnum}.
886
887 If {buf} is not a valid buffer or {lnum} is not valid, an
888 error message is given. Example: >
889 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000890< However, when {text} is an empty list then no error is given
891 for an invalid {lnum}, since {lnum} isn't actually used.
892
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000893 Can also be used as a |method| after a List, the base is
894 passed as the second argument: >
895 mylist->appendbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200896<
897 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000898
899
900argc([{winid}]) *argc()*
901 The result is the number of files in the argument list. See
902 |arglist|.
903 If {winid} is not supplied, the argument list of the current
904 window is used.
905 If {winid} is -1, the global argument list is used.
906 Otherwise {winid} specifies the window of which the argument
907 list is used: either the window number or the window ID.
908 Returns -1 if the {winid} argument is invalid.
909
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200910 Return type: |Number|
911
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000912 *argidx()*
913argidx() The result is the current index in the argument list. 0 is
914 the first file. argc() - 1 is the last one. See |arglist|.
915
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200916 Return type: |Number|
917
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000918 *arglistid()*
919arglistid([{winnr} [, {tabnr}]])
920 Return the argument list ID. This is a number which
921 identifies the argument list being used. Zero is used for the
922 global argument list. See |arglist|.
923 Returns -1 if the arguments are invalid.
924
925 Without arguments use the current window.
926 With {winnr} only use this window in the current tab page.
927 With {winnr} and {tabnr} use the window in the specified tab
928 page.
929 {winnr} can be the window number or the |window-ID|.
930
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200931 Return type: |Number|
932
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000933 *argv()*
934argv([{nr} [, {winid}]])
935 The result is the {nr}th file in the argument list. See
936 |arglist|. "argv(0)" is the first one. Example: >
937 :let i = 0
938 :while i < argc()
939 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000940 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000941 : let i = i + 1
942 :endwhile
943< Without the {nr} argument, or when {nr} is -1, a |List| with
944 the whole |arglist| is returned.
945
946 The {winid} argument specifies the window ID, see |argc()|.
947 For the Vim command line arguments see |v:argv|.
948
Bram Moolenaar016188f2022-06-06 20:52:59 +0100949 Returns an empty string if {nr}th argument is not present in
950 the argument list. Returns an empty List if the {winid}
951 argument is invalid.
952
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200953 Return type: |String|
954
955
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000956asin({expr}) *asin()*
957 Return the arc sine of {expr} measured in radians, as a |Float|
958 in the range of [-pi/2, pi/2].
959 {expr} must evaluate to a |Float| or a |Number| in the range
960 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100961 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
962 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000963 Examples: >
964 :echo asin(0.8)
965< 0.927295 >
966 :echo asin(-0.5)
967< -0.523599
968
969 Can also be used as a |method|: >
970 Compute()->asin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200971<
972 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000973
974assert_ functions are documented here: |assert-functions-details|
975
976
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000977atan({expr}) *atan()*
978 Return the principal value of the arc tangent of {expr}, in
979 the range [-pi/2, +pi/2] radians, as a |Float|.
980 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100981 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000982 Examples: >
983 :echo atan(100)
984< 1.560797 >
985 :echo atan(-4.01)
986< -1.326405
987
988 Can also be used as a |method|: >
989 Compute()->atan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200990<
991 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000992
993
994atan2({expr1}, {expr2}) *atan2()*
995 Return the arc tangent of {expr1} / {expr2}, measured in
996 radians, as a |Float| in the range [-pi, pi].
997 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100998 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
999 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001000 Examples: >
1001 :echo atan2(-1, 1)
1002< -0.785398 >
1003 :echo atan2(1, -1)
1004< 2.356194
1005
1006 Can also be used as a |method|: >
1007 Compute()->atan2(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001008<
1009 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001010
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001011
1012autocmd_add({acmds}) *autocmd_add()*
1013 Adds a List of autocmds and autocmd groups.
1014
1015 The {acmds} argument is a List where each item is a Dict with
1016 the following optional items:
1017 bufnr buffer number to add a buffer-local autocmd.
1018 If this item is specified, then the "pattern"
1019 item is ignored.
1020 cmd Ex command to execute for this autocmd event
1021 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001022 This can be either a String with a single
1023 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001024 group autocmd group name. Refer to |autocmd-groups|.
1025 If this group doesn't exist then it is
1026 created. If not specified or empty, then the
1027 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001028 nested boolean flag, set to v:true to add a nested
1029 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +01001030 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001031 which executes only once. Refer to
1032 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001033 pattern autocmd pattern string. Refer to
1034 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001035 present, then this item is ignored. This can
1036 be a String with a single pattern or a List of
1037 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001038 replace boolean flag, set to v:true to remove all the
1039 commands associated with the specified autocmd
1040 event and group and add the {cmd}. This is
1041 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +01001042 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001043
1044 Returns v:true on success and v:false on failure.
1045 Examples: >
1046 " Create a buffer-local autocmd for buffer 5
1047 let acmd = {}
1048 let acmd.group = 'MyGroup'
1049 let acmd.event = 'BufEnter'
1050 let acmd.bufnr = 5
1051 let acmd.cmd = 'call BufEnterFunc()'
1052 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00001053<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001054 Can also be used as a |method|: >
1055 GetAutocmdList()->autocmd_add()
1056<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001057 Return type: |vim9-boolean|
1058
1059
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001060autocmd_delete({acmds}) *autocmd_delete()*
1061 Deletes a List of autocmds and autocmd groups.
1062
1063 The {acmds} argument is a List where each item is a Dict with
1064 the following optional items:
1065 bufnr buffer number to delete a buffer-local autocmd.
1066 If this item is specified, then the "pattern"
1067 item is ignored.
1068 cmd Ex command for this autocmd event
1069 event autocmd event name. Refer to |autocmd-events|.
1070 If '*' then all the autocmd events in this
1071 group are deleted.
1072 group autocmd group name. Refer to |autocmd-groups|.
1073 If not specified or empty, then the default
1074 group is used.
1075 nested set to v:true for a nested autocmd.
1076 Refer to |autocmd-nested|.
1077 once set to v:true for an autocmd which executes
1078 only once. Refer to |autocmd-once|.
1079 pattern autocmd pattern string. Refer to
1080 |autocmd-patterns|. If "bufnr" item is
1081 present, then this item is ignored.
1082
1083 If only {group} is specified in a {acmds} entry and {event},
1084 {pattern} and {cmd} are not specified, then that autocmd group
1085 is deleted.
1086
Bram Moolenaar016188f2022-06-06 20:52:59 +01001087 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001088 Examples: >
1089 " :autocmd! BufLeave *.vim
1090 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1091 call autocmd_delete([acmd]})
1092 " :autocmd! MyGroup1 BufLeave
1093 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1094 call autocmd_delete([acmd])
1095 " :autocmd! MyGroup2 BufEnter *.c
1096 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1097 \ pattern: '*.c'}
1098 " :autocmd! MyGroup2 * *.c
1099 let acmd = #{group: 'MyGroup2', event: '*',
1100 \ pattern: '*.c'}
1101 call autocmd_delete([acmd])
1102 " :autocmd! MyGroup3
1103 let acmd = #{group: 'MyGroup3'}
1104 call autocmd_delete([acmd])
1105<
1106 Can also be used as a |method|: >
1107 GetAutocmdList()->autocmd_delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001108<
1109 Return type: |vim9-boolean|
1110
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001111
1112autocmd_get([{opts}]) *autocmd_get()*
1113 Returns a |List| of autocmds. If {opts} is not supplied, then
1114 returns the autocmds for all the events in all the groups.
1115
1116 The optional {opts} Dict argument supports the following
1117 items:
1118 group Autocmd group name. If specified, returns only
1119 the autocmds defined in this group. If the
1120 specified group doesn't exist, results in an
1121 error message. If set to an empty string,
1122 then the default autocmd group is used.
1123 event Autocmd event name. If specified, returns only
1124 the autocmds defined for this event. If set
1125 to "*", then returns autocmds for all the
1126 events. If the specified event doesn't exist,
1127 results in an error message.
1128 pattern Autocmd pattern. If specified, returns only
1129 the autocmds defined for this pattern.
1130 A combination of the above three times can be supplied in
1131 {opts}.
1132
1133 Each Dict in the returned List contains the following items:
1134 bufnr For buffer-local autocmds, buffer number where
1135 the autocmd is defined.
1136 cmd Command executed for this autocmd.
1137 event Autocmd event name.
1138 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001139 nested Boolean flag, set to v:true for a nested
1140 autocmd. See |autocmd-nested|.
1141 once Boolean flag, set to v:true, if the autocmd
1142 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001143 pattern Autocmd pattern. For a buffer-local
1144 autocmd, this will be of the form "<buffer=n>".
1145 If there are multiple commands for an autocmd event in a
1146 group, then separate items are returned for each command.
1147
Bram Moolenaar016188f2022-06-06 20:52:59 +01001148 Returns an empty List if an autocmd with the specified group
1149 or event or pattern is not found.
1150
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001151 Examples: >
1152 " :autocmd MyGroup
1153 echo autocmd_get(#{group: 'Mygroup'})
1154 " :autocmd G BufUnload
1155 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1156 " :autocmd G * *.ts
1157 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1158 echo autocmd_get(acmd)
1159 " :autocmd Syntax
1160 echo autocmd_get(#{event: 'Syntax'})
1161 " :autocmd G BufEnter *.ts
1162 let acmd = #{group: 'G', event: 'BufEnter',
1163 \ pattern: '*.ts'}
1164 echo autocmd_get(acmd)
1165<
1166 Can also be used as a |method|: >
1167 Getopts()->autocmd_get()
1168<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001169 Return type: list<dict<any>>
1170
1171
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001172balloon_gettext() *balloon_gettext()*
1173 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001174 not used for the List. Returns an empty string if balloon
1175 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001176
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001177 Return type: |String|
1178
1179
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001180balloon_show({expr}) *balloon_show()*
1181 Show {expr} inside the balloon. For the GUI {expr} is used as
1182 a string. For a terminal {expr} can be a list, which contains
1183 the lines of the balloon. If {expr} is not a list it will be
1184 split with |balloon_split()|.
1185 If {expr} is an empty string any existing balloon is removed.
1186
1187 Example: >
1188 func GetBalloonContent()
1189 " ... initiate getting the content
1190 return ''
1191 endfunc
1192 set balloonexpr=GetBalloonContent()
1193
1194 func BalloonCallback(result)
1195 call balloon_show(a:result)
1196 endfunc
1197< Can also be used as a |method|: >
1198 GetText()->balloon_show()
1199<
1200 The intended use is that fetching the content of the balloon
1201 is initiated from 'balloonexpr'. It will invoke an
1202 asynchronous method, in which a callback invokes
1203 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001204 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001205
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001206 When showing a balloon is not possible then nothing happens,
1207 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001208 {only available when compiled with the |+balloon_eval| or
1209 |+balloon_eval_term| feature}
1210
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001211 Return type: |Number|
1212
1213
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001214balloon_split({msg}) *balloon_split()*
1215 Split String {msg} into lines to be displayed in a balloon.
1216 The splits are made for the current window size and optimize
1217 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001218 Returns a |List| with the split lines. Returns an empty List
1219 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001220 Can also be used as a |method|: >
1221 GetText()->balloon_split()->balloon_show()
1222
1223< {only available when compiled with the |+balloon_eval_term|
1224 feature}
1225
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001226 Return type: list<any> or list<string>
1227
Christ van Willegence0ef912024-06-20 23:41:59 +02001228bindtextdomain({package}, {path}) *bindtextdomain()*
1229 Bind a specific {package} to a {path} so that the
1230 |gettext()| function can be used to get language-specific
1231 translations for a package. {path} is the directory name
h-east52e7cc22024-07-28 17:03:29 +02001232 for the translations. See |package-translation|.
Christ van Willegence0ef912024-06-20 23:41:59 +02001233
Christ van Willegen8252ef12024-07-11 21:36:21 +02001234 Returns v:true on success and v:false on failure (out of
1235 memory).
1236
1237 Return type: |vim9-boolean|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001238
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001239blob2list({blob}) *blob2list()*
1240 Return a List containing the number value of each byte in Blob
1241 {blob}. Examples: >
1242 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1243 blob2list(0z) returns []
1244< Returns an empty List on error. |list2blob()| does the
1245 opposite.
1246
1247 Can also be used as a |method|: >
1248 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001249<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001250 Return type: list<any> or list<number>
1251
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001252 *browse()*
1253browse({save}, {title}, {initdir}, {default})
1254 Put up a file requester. This only works when "has("browse")"
1255 returns |TRUE| (only in some GUI versions).
1256 The input fields are:
1257 {save} when |TRUE|, select file to write
1258 {title} title for the requester
1259 {initdir} directory to start browsing in
1260 {default} default file name
1261 An empty string is returned when the "Cancel" button is hit,
1262 something went wrong, or browsing is not possible.
1263
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001264 Return type: |String|
1265
1266
1267browsedir({title}, {initdir}) *browsedir()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001268 Put up a directory requester. This only works when
1269 "has("browse")" returns |TRUE| (only in some GUI versions).
1270 On systems where a directory browser is not supported a file
1271 browser is used. In that case: select a file in the directory
1272 to be used.
1273 The input fields are:
1274 {title} title for the requester
1275 {initdir} directory to start browsing in
1276 When the "Cancel" button is hit, something went wrong, or
1277 browsing is not possible, an empty string is returned.
1278
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001279 Return type: |String|
1280
1281
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001282bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001283 Add a buffer to the buffer list with name {name} (must be a
1284 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001285 If a buffer for file {name} already exists, return that buffer
1286 number. Otherwise return the buffer number of the newly
1287 created buffer. When {name} is an empty string then a new
1288 buffer is always created.
1289 The buffer will not have 'buflisted' set and not be loaded
1290 yet. To add some text to the buffer use this: >
1291 let bufnr = bufadd('someName')
1292 call bufload(bufnr)
1293 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001294< Returns 0 on error.
1295 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001296 let bufnr = 'somename'->bufadd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001297<
1298 Return type: |Number|
1299
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001300
1301bufexists({buf}) *bufexists()*
1302 The result is a Number, which is |TRUE| if a buffer called
1303 {buf} exists.
1304 If the {buf} argument is a number, buffer numbers are used.
1305 Number zero is the alternate buffer for the current window.
1306
1307 If the {buf} argument is a string it must match a buffer name
1308 exactly. The name can be:
1309 - Relative to the current directory.
1310 - A full path.
1311 - The name of a buffer with 'buftype' set to "nofile".
1312 - A URL name.
1313 Unlisted buffers will be found.
1314 Note that help files are listed by their short name in the
1315 output of |:buffers|, but bufexists() requires using their
1316 long name to be able to find them.
1317 bufexists() may report a buffer exists, but to use the name
1318 with a |:buffer| command you may need to use |expand()|. Esp
1319 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1320 Use "bufexists(0)" to test for the existence of an alternate
1321 file name.
1322
1323 Can also be used as a |method|: >
1324 let exists = 'somename'->bufexists()
1325<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001326 Return type: |Number|
1327
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001328 Obsolete name: buffer_exists(). *buffer_exists()*
1329
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001330
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001331buflisted({buf}) *buflisted()*
1332 The result is a Number, which is |TRUE| if a buffer called
1333 {buf} exists and is listed (has the 'buflisted' option set).
1334 The {buf} argument is used like with |bufexists()|.
1335
1336 Can also be used as a |method|: >
1337 let listed = 'somename'->buflisted()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001338<
1339 Return type: |Number|
1340
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001341
1342bufload({buf}) *bufload()*
1343 Ensure the buffer {buf} is loaded. When the buffer name
1344 refers to an existing file then the file is read. Otherwise
1345 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001346 then there is no change. If the buffer is not related to a
Daniel Steinbergc2bd2052023-08-09 12:10:59 -04001347 file then no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001348 If there is an existing swap file for the file of the buffer,
1349 there will be no dialog, the buffer will be loaded anyway.
1350 The {buf} argument is used like with |bufexists()|.
1351
1352 Can also be used as a |method|: >
1353 eval 'somename'->bufload()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001354<
1355 Return type: |Number|
1356
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001357
1358bufloaded({buf}) *bufloaded()*
1359 The result is a Number, which is |TRUE| if a buffer called
1360 {buf} exists and is loaded (shown in a window or hidden).
1361 The {buf} argument is used like with |bufexists()|.
1362
1363 Can also be used as a |method|: >
1364 let loaded = 'somename'->bufloaded()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001365<
1366 Return type: |Number|
1367
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001368
1369bufname([{buf}]) *bufname()*
1370 The result is the name of a buffer. Mostly as it is displayed
1371 by the `:ls` command, but not using special names such as
1372 "[No Name]".
1373 If {buf} is omitted the current buffer is used.
1374 If {buf} is a Number, that buffer number's name is given.
1375 Number zero is the alternate buffer for the current window.
1376 If {buf} is a String, it is used as a |file-pattern| to match
1377 with the buffer names. This is always done like 'magic' is
1378 set and 'cpoptions' is empty. When there is more than one
1379 match an empty string is returned.
1380 "" or "%" can be used for the current buffer, "#" for the
1381 alternate buffer.
1382 A full match is preferred, otherwise a match at the start, end
1383 or middle of the buffer name is accepted. If you only want a
1384 full match then put "^" at the start and "$" at the end of the
1385 pattern.
1386 Listed buffers are found first. If there is a single match
1387 with a listed buffer, that one is returned. Next unlisted
1388 buffers are searched for.
1389 If the {buf} is a String, but you want to use it as a buffer
1390 number, force it to be a Number by adding zero to it: >
1391 :echo bufname("3" + 0)
1392< Can also be used as a |method|: >
1393 echo bufnr->bufname()
1394
1395< If the buffer doesn't exist, or doesn't have a name, an empty
1396 string is returned. >
1397 bufname("#") alternate buffer name
1398 bufname(3) name of buffer 3
1399 bufname("%") name of current buffer
1400 bufname("file2") name of buffer where "file2" matches.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001401<
1402 Return type: |String|
1403 *buffer_name()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001404 Obsolete name: buffer_name().
1405
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001406
1407bufnr([{buf} [, {create}]]) *bufnr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001408 The result is the number of a buffer, as it is displayed by
1409 the `:ls` command. For the use of {buf}, see |bufname()|
1410 above.
1411
1412 If the buffer doesn't exist, -1 is returned. Or, if the
1413 {create} argument is present and TRUE, a new, unlisted,
1414 buffer is created and its number is returned. Example: >
1415 let newbuf = bufnr('Scratch001', 1)
1416< Using an empty name uses the current buffer. To create a new
1417 buffer with an empty name use |bufadd()|.
1418
1419 bufnr("$") is the last buffer: >
1420 :let last_buffer = bufnr("$")
1421< The result is a Number, which is the highest buffer number
1422 of existing buffers. Note that not all buffers with a smaller
1423 number necessarily exist, because ":bwipeout" may have removed
1424 them. Use bufexists() to test for the existence of a buffer.
1425
1426 Can also be used as a |method|: >
1427 echo bufref->bufnr()
1428<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001429 Return type: |Number|
1430
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001431 Obsolete name: buffer_number(). *buffer_number()*
1432 *last_buffer_nr()*
1433 Obsolete name for bufnr("$"): last_buffer_nr().
1434
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001435
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001436bufwinid({buf}) *bufwinid()*
1437 The result is a Number, which is the |window-ID| of the first
1438 window associated with buffer {buf}. For the use of {buf},
1439 see |bufname()| above. If buffer {buf} doesn't exist or
1440 there is no such window, -1 is returned. Example: >
1441
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001442 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001443<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001444 Only deals with the current tab page. See |win_findbuf()| for
1445 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001446
1447 Can also be used as a |method|: >
1448 FindBuffer()->bufwinid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001449<
1450 Return type: |Number|
1451
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001452
1453bufwinnr({buf}) *bufwinnr()*
1454 Like |bufwinid()| but return the window number instead of the
1455 |window-ID|.
1456 If buffer {buf} doesn't exist or there is no such window, -1
1457 is returned. Example: >
1458
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001459 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001460
1461< The number can be used with |CTRL-W_w| and ":wincmd w"
1462 |:wincmd|.
1463
1464 Can also be used as a |method|: >
1465 FindBuffer()->bufwinnr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001466<
1467 Return type: |Number|
1468
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001469
1470byte2line({byte}) *byte2line()*
1471 Return the line number that contains the character at byte
1472 count {byte} in the current buffer. This includes the
1473 end-of-line character, depending on the 'fileformat' option
1474 for the current buffer. The first character has byte count
1475 one.
1476 Also see |line2byte()|, |go| and |:goto|.
1477
Bram Moolenaar016188f2022-06-06 20:52:59 +01001478 Returns -1 if the {byte} value is invalid.
1479
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001480 Can also be used as a |method|: >
1481 GetOffset()->byte2line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001482<
1483 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001484
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001485 {not available when compiled without the |+byte_offset|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001486 feature}
1487
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001488
Christian Brabandt67672ef2023-04-24 21:09:54 +01001489byteidx({expr}, {nr} [, {utf16}]) *byteidx()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001490 Return byte index of the {nr}'th character in the String
1491 {expr}. Use zero for the first character, it then returns
1492 zero.
1493 If there are no multibyte characters the returned value is
1494 equal to {nr}.
1495 Composing characters are not counted separately, their byte
1496 length is added to the preceding base character. See
1497 |byteidxcomp()| below for counting composing characters
1498 separately.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001499 When {utf16} is present and TRUE, {nr} is used as the UTF-16
1500 index in the String {expr} instead of as the character index.
1501 The UTF-16 index is the index in the string when it is encoded
1502 with 16-bit words. If the specified UTF-16 index is in the
1503 middle of a character (e.g. in a 4-byte character), then the
1504 byte index of the first byte in the character is returned.
1505 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001506 Example : >
1507 echo matchstr(str, ".", byteidx(str, 3))
1508< will display the fourth character. Another way to do the
1509 same: >
1510 let s = strpart(str, byteidx(str, 3))
1511 echo strpart(s, 0, byteidx(s, 1))
1512< Also see |strgetchar()| and |strcharpart()|.
1513
1514 If there are less than {nr} characters -1 is returned.
1515 If there are exactly {nr} characters the length of the string
1516 in bytes is returned.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001517 See |charidx()| and |utf16idx()| for getting the character and
1518 UTF-16 index respectively from the byte index.
1519 Examples: >
1520 echo byteidx('a😊😊', 2) returns 5
1521 echo byteidx('a😊😊', 2, 1) returns 1
1522 echo byteidx('a😊😊', 3, 1) returns 5
1523<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001524 Can also be used as a |method|: >
1525 GetName()->byteidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001526<
1527 Return type: |Number|
1528
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001529
Christian Brabandt67672ef2023-04-24 21:09:54 +01001530byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001531 Like byteidx(), except that a composing character is counted
1532 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001533 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001534 echo byteidx(s, 1)
1535 echo byteidxcomp(s, 1)
1536 echo byteidxcomp(s, 2)
1537< The first and third echo result in 3 ('e' plus composing
1538 character is 3 bytes), the second echo results in 1 ('e' is
1539 one byte).
1540 Only works differently from byteidx() when 'encoding' is set
1541 to a Unicode encoding.
1542
1543 Can also be used as a |method|: >
1544 GetName()->byteidxcomp(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001545<
1546 Return type: |Number|
1547
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001548
1549call({func}, {arglist} [, {dict}]) *call()* *E699*
1550 Call function {func} with the items in |List| {arglist} as
1551 arguments.
1552 {func} can either be a |Funcref| or the name of a function.
1553 a:firstline and a:lastline are set to the cursor line.
1554 Returns the return value of the called function.
1555 {dict} is for functions with the "dict" attribute. It will be
1556 used to set the local variable "self". |Dictionary-function|
1557
1558 Can also be used as a |method|: >
1559 GetFunc()->call([arg, arg], dict)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001560<
1561 Return type: any, depending on {func}
1562
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001563
1564ceil({expr}) *ceil()*
1565 Return the smallest integral value greater than or equal to
1566 {expr} as a |Float| (round up).
1567 {expr} must evaluate to a |Float| or a |Number|.
1568 Examples: >
1569 echo ceil(1.456)
1570< 2.0 >
1571 echo ceil(-5.456)
1572< -5.0 >
1573 echo ceil(4.0)
1574< 4.0
1575
Bram Moolenaar016188f2022-06-06 20:52:59 +01001576 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1577
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001578 Can also be used as a |method|: >
1579 Compute()->ceil()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001580<
1581 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001582
1583
1584ch_ functions are documented here: |channel-functions-details|
1585
1586
1587changenr() *changenr()*
1588 Return the number of the most recent change. This is the same
1589 number as what is displayed with |:undolist| and can be used
1590 with the |:undo| command.
1591 When a change was made it is the number of that change. After
1592 redo it is the number of the redone change. After undo it is
1593 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001594 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001595
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001596 Return type: |Number|
1597
1598
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001599char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001600 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001601 Examples: >
1602 char2nr(" ") returns 32
1603 char2nr("ABC") returns 65
1604< When {utf8} is omitted or zero, the current 'encoding' is used.
1605 Example for "utf-8": >
1606 char2nr("á") returns 225
1607 char2nr("á"[0]) returns 195
1608< When {utf8} is TRUE, always treat as UTF-8 characters.
1609 A combining character is a separate character.
1610 |nr2char()| does the opposite.
1611 To turn a string into a list of character numbers: >
1612 let str = "ABC"
1613 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1614< Result: [65, 66, 67]
1615
Bram Moolenaar016188f2022-06-06 20:52:59 +01001616 Returns 0 if {string} is not a |String|.
1617
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001618 Can also be used as a |method|: >
1619 GetChar()->char2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001620<
1621 Return type: |Number|
1622
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001623
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001624charclass({string}) *charclass()*
1625 Return the character class of the first character in {string}.
1626 The character class is one of:
1627 0 blank
1628 1 punctuation
Christian Brabandtb5e7da12024-11-01 09:33:00 +01001629 2 word character (depends on 'iskeyword')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001630 3 emoji
1631 other specific Unicode class
1632 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001633 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001634
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001635 Return type: |Number|
1636
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001637
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001638charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001639 Same as |col()| but returns the character index of the column
1640 position given with {expr} instead of the byte position.
1641
1642 Example:
1643 With the cursor on '세' in line 5 with text "여보세요": >
1644 charcol('.') returns 3
1645 col('.') returns 7
1646
1647< Can also be used as a |method|: >
1648 GetPos()->col()
1649<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001650 Return type: |Number|
1651
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001652 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001653charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001654 Return the character index of the byte at {idx} in {string}.
1655 The index of the first character is zero.
1656 If there are no multibyte characters the returned value is
1657 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001658
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001659 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001660 are not counted separately, their byte length is added to the
1661 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001662 When {countcc} is |TRUE|, then composing characters are
1663 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001664
1665 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1666 index in the String {expr} instead of as the byte index.
1667
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001668 Returns -1 if the arguments are invalid or if there are less
1669 than {idx} bytes. If there are exactly {idx} bytes the length
1670 of the string in characters is returned.
1671
1672 An error is given and -1 is returned if the first argument is
1673 not a string, the second argument is not a number or when the
1674 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001675
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001676 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001677 from the character index and |utf16idx()| for getting the
1678 UTF-16 index from the character index.
1679 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001680 Examples: >
1681 echo charidx('áb́ć', 3) returns 1
1682 echo charidx('áb́ć', 6, 1) returns 4
1683 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001684 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001685<
1686 Can also be used as a |method|: >
1687 GetName()->charidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001688<
1689 Return type: |Number|
1690
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001691
1692chdir({dir}) *chdir()*
1693 Change the current working directory to {dir}. The scope of
1694 the directory change depends on the directory of the current
1695 window:
1696 - If the current window has a window-local directory
1697 (|:lcd|), then changes the window local directory.
1698 - Otherwise, if the current tabpage has a local
1699 directory (|:tcd|) then changes the tabpage local
1700 directory.
1701 - Otherwise, changes the global directory.
1702 {dir} must be a String.
1703 If successful, returns the previous working directory. Pass
1704 this to another chdir() to restore the directory.
1705 On failure, returns an empty string.
1706
1707 Example: >
1708 let save_dir = chdir(newdir)
1709 if save_dir != ""
1710 " ... do some work
1711 call chdir(save_dir)
1712 endif
1713
1714< Can also be used as a |method|: >
1715 GetDir()->chdir()
1716<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001717 Return type: |String|
1718
1719
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001720cindent({lnum}) *cindent()*
1721 Get the amount of indent for line {lnum} according the C
1722 indenting rules, as with 'cindent'.
1723 The indent is counted in spaces, the value of 'tabstop' is
1724 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001725 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001726 See |C-indenting|.
1727
1728 Can also be used as a |method|: >
1729 GetLnum()->cindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001730<
1731 Return type: |Number|
1732
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001733
1734clearmatches([{win}]) *clearmatches()*
1735 Clears all matches previously defined for the current window
1736 by |matchadd()| and the |:match| commands.
1737 If {win} is specified, use the window with this number or
1738 window ID instead of the current window.
1739
1740 Can also be used as a |method|: >
1741 GetWin()->clearmatches()
1742<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001743 Return type: |Number|
1744
1745
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001746col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001747 The result is a Number, which is the byte index of the column
zeertzjq02f3eba2024-06-12 20:45:24 +02001748 position given with {expr}.
1749 For accepted positions see |getpos()|.
zeertzjqd353d272024-06-13 23:00:25 +08001750 When {expr} is "$", it means the end of the cursor line, so
1751 the result is the number of bytes in the cursor line plus one.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001752 Additionally {expr} can be [lnum, col]: a |List| with the line
1753 and column number. Most useful when the column is "$", to get
1754 the last column of a specific line. When "lnum" or "col" is
1755 out of range then col() returns zero.
zeertzjq02f3eba2024-06-12 20:45:24 +02001756
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001757 With the optional {winid} argument the values are obtained for
1758 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02001759
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001760 To get the line number use |line()|. To get both use
1761 |getpos()|.
1762 For the screen column position use |virtcol()|. For the
1763 character position use |charcol()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02001764
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001765 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +02001766
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001767 Examples: >
1768 col(".") column of cursor
1769 col("$") length of cursor line plus one
1770 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001771 col("'" .. markname) column of mark markname
zeertzjq02f3eba2024-06-12 20:45:24 +02001772<
1773 The first column is 1. Returns 0 if {expr} is invalid or when
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001774 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001775 For an uppercase mark the column may actually be in another
1776 buffer.
1777 For the cursor position, when 'virtualedit' is active, the
1778 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001779 line. Also, when using a <Cmd> mapping the cursor isn't
1780 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001781 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001782
1783< Can also be used as a |method|: >
1784 GetPos()->col()
1785<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001786 Return type: |Number|
1787
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001788
1789complete({startcol}, {matches}) *complete()* *E785*
1790 Set the matches for Insert mode completion.
1791 Can only be used in Insert mode. You need to use a mapping
1792 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1793 or with an expression mapping.
1794 {startcol} is the byte offset in the line where the completed
1795 text start. The text up to the cursor is the original text
1796 that will be replaced by the matches. Use col('.') for an
1797 empty string. "col('.') - 1" will replace one character by a
1798 match.
1799 {matches} must be a |List|. Each |List| item is one match.
1800 See |complete-items| for the kind of items that are possible.
1801 "longest" in 'completeopt' is ignored.
1802 Note that the after calling this function you need to avoid
1803 inserting anything that would cause completion to stop.
1804 The match can be selected with CTRL-N and CTRL-P as usual with
1805 Insert mode completion. The popup menu will appear if
1806 specified, see |ins-completion-menu|.
1807 Example: >
1808 inoremap <F5> <C-R>=ListMonths()<CR>
1809
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001810 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001811 call complete(col('.'), ['January', 'February', 'March',
1812 \ 'April', 'May', 'June', 'July', 'August', 'September',
1813 \ 'October', 'November', 'December'])
1814 return ''
1815 endfunc
1816< This isn't very useful, but it shows how it works. Note that
1817 an empty string is returned to avoid a zero being inserted.
1818
1819 Can also be used as a |method|, the base is passed as the
1820 second argument: >
1821 GetMatches()->complete(col('.'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001822<
1823 Return type: |Number|
1824
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001825
1826complete_add({expr}) *complete_add()*
1827 Add {expr} to the list of matches. Only to be used by the
1828 function specified with the 'completefunc' option.
1829 Returns 0 for failure (empty string or out of memory),
1830 1 when the match was added, 2 when the match was already in
1831 the list.
1832 See |complete-functions| for an explanation of {expr}. It is
1833 the same as one item in the list that 'omnifunc' would return.
1834
1835 Can also be used as a |method|: >
1836 GetMoreMatches()->complete_add()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001837<
1838 Return type: |Number|
1839
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001840
1841complete_check() *complete_check()*
1842 Check for a key typed while looking for completion matches.
1843 This is to be used when looking for matches takes some time.
1844 Returns |TRUE| when searching for matches is to be aborted,
1845 zero otherwise.
1846 Only to be used by the function specified with the
1847 'completefunc' option.
1848
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001849 Return type: |Number|
1850
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001851
1852complete_info([{what}]) *complete_info()*
1853 Returns a |Dictionary| with information about Insert mode
1854 completion. See |ins-completion|.
1855 The items are:
1856 mode Current completion mode name string.
1857 See |complete_info_mode| for the values.
1858 pum_visible |TRUE| if popup menu is visible.
1859 See |pumvisible()|.
1860 items List of completion matches. Each item is a
1861 dictionary containing the entries "word",
1862 "abbr", "menu", "kind", "info" and "user_data".
1863 See |complete-items|.
1864 selected Selected item index. First index is zero.
1865 Index is -1 if no item is selected (showing
1866 typed text only, or the last completion after
1867 no item is selected when using the <Up> or
1868 <Down> keys)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01001869 inserted Inserted string. [NOT IMPLEMENTED YET]
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001870
1871 *complete_info_mode*
1872 mode values are:
1873 "" Not in completion mode
1874 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1875 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1876 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1877 |i_CTRL-X_CTRL-Y|
1878 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1879 "files" File names |i_CTRL-X_CTRL-F|
1880 "tags" Tags |i_CTRL-X_CTRL-]|
1881 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1882 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1883 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1884 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1885 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1886 "function" User defined completion |i_CTRL-X_CTRL-U|
1887 "omni" Omni completion |i_CTRL-X_CTRL-O|
1888 "spell" Spelling suggestions |i_CTRL-X_s|
1889 "eval" |complete()| completion
1890 "unknown" Other internal modes
1891
1892 If the optional {what} list argument is supplied, then only
1893 the items listed in {what} are returned. Unsupported items in
1894 {what} are silently ignored.
1895
1896 To get the position and size of the popup menu, see
1897 |pum_getpos()|. It's also available in |v:event| during the
1898 |CompleteChanged| event.
1899
Bram Moolenaar016188f2022-06-06 20:52:59 +01001900 Returns an empty |Dictionary| on error.
1901
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001902 Examples: >
1903 " Get all items
1904 call complete_info()
1905 " Get only 'mode'
1906 call complete_info(['mode'])
1907 " Get only 'mode' and 'pum_visible'
1908 call complete_info(['mode', 'pum_visible'])
1909
1910< Can also be used as a |method|: >
1911 GetItems()->complete_info()
1912<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001913 Return type: dict<any>
1914
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001915 *confirm()*
1916confirm({msg} [, {choices} [, {default} [, {type}]]])
1917 confirm() offers the user a dialog, from which a choice can be
1918 made. It returns the number of the choice. For the first
1919 choice this is 1.
1920 Note: confirm() is only supported when compiled with dialog
glepnirdf461152024-04-04 22:23:29 +02001921 support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001922
1923 {msg} is displayed in a |dialog| with {choices} as the
1924 alternatives. When {choices} is missing or empty, "&OK" is
1925 used (and translated).
1926 {msg} is a String, use '\n' to include a newline. Only on
1927 some systems the string is wrapped when it doesn't fit.
1928
1929 {choices} is a String, with the individual choices separated
1930 by '\n', e.g. >
1931 confirm("Save changes?", "&Yes\n&No\n&Cancel")
1932< The letter after the '&' is the shortcut key for that choice.
1933 Thus you can type 'c' to select "Cancel". The shortcut does
1934 not need to be the first letter: >
1935 confirm("file has been modified", "&Save\nSave &All")
1936< For the console, the first letter of each choice is used as
1937 the default shortcut key. Case is ignored.
1938
1939 The optional {default} argument is the number of the choice
1940 that is made if the user hits <CR>. Use 1 to make the first
1941 choice the default one. Use 0 to not set a default. If
1942 {default} is omitted, 1 is used.
1943
1944 The optional {type} String argument gives the type of dialog.
1945 This is only used for the icon of the GTK, Mac, Motif and
1946 Win32 GUI. It can be one of these values: "Error",
1947 "Question", "Info", "Warning" or "Generic". Only the first
1948 character is relevant. When {type} is omitted, "Generic" is
1949 used.
1950
1951 If the user aborts the dialog by pressing <Esc>, CTRL-C,
1952 or another valid interrupt key, confirm() returns 0.
1953
1954 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01001955 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001956 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01001957 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001958 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001959 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001960 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001961 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001962 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01001963 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001964< In a GUI dialog, buttons are used. The layout of the buttons
1965 depends on the 'v' flag in 'guioptions'. If it is included,
1966 the buttons are always put vertically. Otherwise, confirm()
1967 tries to put the buttons in one horizontal line. If they
1968 don't fit, a vertical layout is used anyway. For some systems
1969 the horizontal layout is always used.
1970
1971 Can also be used as a |method|in: >
1972 BuildMessage()->confirm("&Yes\n&No")
1973<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001974 Return type: |Number|
1975
1976
1977copy({expr}) *copy()*
1978 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001979 different from using {expr} directly.
1980 When {expr} is a |List| a shallow copy is created. This means
1981 that the original |List| can be changed without changing the
1982 copy, and vice versa. But the items are identical, thus
1983 changing an item changes the contents of both |Lists|.
1984 A |Dictionary| is copied in a similar way as a |List|.
1985 Also see |deepcopy()|.
1986 Can also be used as a |method|: >
1987 mylist->copy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001988<
1989 Return type: any, depending on {expr}
1990
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001991
1992cos({expr}) *cos()*
1993 Return the cosine of {expr}, measured in radians, as a |Float|.
1994 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001995 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001996 Examples: >
1997 :echo cos(100)
1998< 0.862319 >
1999 :echo cos(-4.01)
2000< -0.646043
2001
2002 Can also be used as a |method|: >
2003 Compute()->cos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002004<
2005 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002006
2007
2008cosh({expr}) *cosh()*
2009 Return the hyperbolic cosine of {expr} as a |Float| in the range
2010 [1, inf].
2011 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002012 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002013 Examples: >
2014 :echo cosh(0.5)
2015< 1.127626 >
2016 :echo cosh(-0.5)
2017< -1.127626
2018
2019 Can also be used as a |method|: >
2020 Compute()->cosh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002021<
2022 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002023
2024
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07002025count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002026 Return the number of times an item with value {expr} appears
2027 in |String|, |List| or |Dictionary| {comp}.
2028
2029 If {start} is given then start with the item with this index.
2030 {start} can only be used with a |List|.
2031
2032 When {ic} is given and it's |TRUE| then case is ignored.
2033
2034 When {comp} is a string then the number of not overlapping
2035 occurrences of {expr} is returned. Zero is returned when
2036 {expr} is an empty string.
2037
2038 Can also be used as a |method|: >
2039 mylist->count(val)
2040<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002041 Return type: |Number|
2042
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002043 *cscope_connection()*
2044cscope_connection([{num} , {dbpath} [, {prepend}]])
2045 Checks for the existence of a |cscope| connection. If no
2046 parameters are specified, then the function returns:
2047 0, if cscope was not available (not compiled in), or
2048 if there are no cscope connections;
2049 1, if there is at least one cscope connection.
2050
2051 If parameters are specified, then the value of {num}
2052 determines how existence of a cscope connection is checked:
2053
2054 {num} Description of existence check
2055 ----- ------------------------------
2056 0 Same as no parameters (e.g., "cscope_connection()").
2057 1 Ignore {prepend}, and use partial string matches for
2058 {dbpath}.
2059 2 Ignore {prepend}, and use exact string matches for
2060 {dbpath}.
2061 3 Use {prepend}, use partial string matches for both
2062 {dbpath} and {prepend}.
2063 4 Use {prepend}, use exact string matches for both
2064 {dbpath} and {prepend}.
2065
2066 Note: All string comparisons are case sensitive!
2067
2068 Examples. Suppose we had the following (from ":cs show"): >
2069
2070 # pid database name prepend path
2071 0 27664 cscope.out /usr/local
2072<
2073 Invocation Return Val ~
2074 ---------- ---------- >
2075 cscope_connection() 1
2076 cscope_connection(1, "out") 1
2077 cscope_connection(2, "out") 0
2078 cscope_connection(3, "out") 0
2079 cscope_connection(3, "out", "local") 1
2080 cscope_connection(4, "out") 0
2081 cscope_connection(4, "out", "local") 0
2082 cscope_connection(4, "cscope.out", "/usr/local") 1
2083<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002084 Return type: |Number|
2085
2086
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002087cursor({lnum}, {col} [, {off}]) *cursor()*
2088cursor({list})
2089 Positions the cursor at the column (byte count) {col} in the
2090 line {lnum}. The first column is one.
2091
2092 When there is one argument {list} this is used as a |List|
2093 with two, three or four item:
2094 [{lnum}, {col}]
2095 [{lnum}, {col}, {off}]
2096 [{lnum}, {col}, {off}, {curswant}]
2097 This is like the return value of |getpos()| or |getcurpos()|,
2098 but without the first item.
2099
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01002100 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002101 |setcursorcharpos()|.
2102
2103 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01002104 {lnum} is used like with |getline()|, except that if {lnum} is
2105 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002106 If {lnum} is greater than the number of lines in the buffer,
2107 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002108 If {col} is greater than the number of bytes in the line,
2109 the cursor will be positioned at the last character in the
2110 line.
2111 If {col} is zero, the cursor will stay in the current column.
2112 If {curswant} is given it is used to set the preferred column
2113 for vertical movement. Otherwise {col} is used.
2114
2115 When 'virtualedit' is used {off} specifies the offset in
2116 screen columns from the start of the character. E.g., a
2117 position within a <Tab> or after the last character.
2118 Returns 0 when the position could be set, -1 otherwise.
2119
2120 Can also be used as a |method|: >
2121 GetCursorPos()->cursor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002122<
2123 Return type: |Number|
2124
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002125
2126debugbreak({pid}) *debugbreak()*
2127 Specifically used to interrupt a program being debugged. It
2128 will cause process {pid} to get a SIGTRAP. Behavior for other
2129 processes is undefined. See |terminal-debugger|.
2130 {only available on MS-Windows}
2131
Bram Moolenaar016188f2022-06-06 20:52:59 +01002132 Returns |TRUE| if successfully interrupted the program.
2133 Otherwise returns |FALSE|.
2134
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002135 Can also be used as a |method|: >
2136 GetPid()->debugbreak()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002137<
2138 Return type: |Number|
2139
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002140
2141deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
2142 Make a copy of {expr}. For Numbers and Strings this isn't
2143 different from using {expr} directly.
2144 When {expr} is a |List| a full copy is created. This means
2145 that the original |List| can be changed without changing the
2146 copy, and vice versa. When an item is a |List| or
2147 |Dictionary|, a copy for it is made, recursively. Thus
2148 changing an item in the copy does not change the contents of
2149 the original |List|.
2150 A |Dictionary| is copied in a similar way as a |List|.
2151
2152 When {noref} is omitted or zero a contained |List| or
2153 |Dictionary| is only copied once. All references point to
2154 this single copy. With {noref} set to 1 every occurrence of a
2155 |List| or |Dictionary| results in a new copy. This also means
2156 that a cyclic reference causes deepcopy() to fail.
2157 *E724*
2158 Nesting is possible up to 100 levels. When there is an item
2159 that refers back to a higher level making a deep copy with
2160 {noref} set to 1 will fail.
2161 Also see |copy()|.
2162
2163 Can also be used as a |method|: >
2164 GetObject()->deepcopy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002165<
2166 Return type: any, depending on {expr}
2167
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002168
2169delete({fname} [, {flags}]) *delete()*
2170 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002171 name {fname}.
2172
2173 This also works when {fname} is a symbolic link. The symbolic
2174 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002175
2176 When {flags} is "d": Deletes the directory by the name
2177 {fname}. This fails when directory {fname} is not empty.
2178
2179 When {flags} is "rf": Deletes the directory by the name
2180 {fname} and everything in it, recursively. BE CAREFUL!
2181 Note: on MS-Windows it is not possible to delete a directory
2182 that is being used.
2183
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002184 The result is a Number, which is 0/false if the delete
2185 operation was successful and -1/true when the deletion failed
2186 or partly failed.
2187
2188 Use |remove()| to delete an item from a |List|.
2189 To delete a line from the buffer use |:delete| or
2190 |deletebufline()|.
2191
2192 Can also be used as a |method|: >
2193 GetName()->delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002194<
2195 Return type: |Number|
2196
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002197
2198deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2199 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2200 If {last} is omitted then delete line {first} only.
2201 On success 0 is returned, on failure 1 is returned.
2202
2203 This function works only for loaded buffers. First call
2204 |bufload()| if needed.
2205
2206 For the use of {buf}, see |bufname()| above.
2207
2208 {first} and {last} are used like with |getline()|. Note that
2209 when using |line()| this refers to the current buffer. Use "$"
2210 to refer to the last line in buffer {buf}.
2211
2212 Can also be used as a |method|: >
2213 GetBuffer()->deletebufline(1)
2214<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002215 Return type: |Number|
2216
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002217 *did_filetype()*
2218did_filetype() Returns |TRUE| when autocommands are being executed and the
2219 FileType event has been triggered at least once. Can be used
2220 to avoid triggering the FileType event again in the scripts
2221 that detect the file type. |FileType|
2222 Returns |FALSE| when `:setf FALLBACK` was used.
2223 When editing another file, the counter is reset, thus this
2224 really checks if the FileType event has been triggered for the
2225 current buffer. This allows an autocommand that starts
2226 editing another buffer to set 'filetype' and load a syntax
2227 file.
2228
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002229 Return type: |Number|
2230
2231
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002232diff({fromlist}, {tolist} [, {options}]) *diff()*
2233 Returns a String or a List containing the diff between the
2234 strings in {fromlist} and {tolist}. Uses the Vim internal
2235 diff library to compute the diff.
2236
2237 *E106*
2238 The optional "output" item in {options} specifies the returned
2239 diff format. The following values are supported:
2240 indices Return a List of the starting and ending
2241 indices and a count of the strings in each
2242 diff hunk.
2243 unified Return the unified diff output as a String.
2244 This is the default.
2245
2246 If the "output" item in {options} is "indices", then a List is
2247 returned. Each List item contains a Dict with the following
2248 items for each diff hunk:
2249 from_idx start index in {fromlist} for this diff hunk.
2250 from_count number of strings in {fromlist} that are
2251 added/removed/modified in this diff hunk.
2252 to_idx start index in {tolist} for this diff hunk.
2253 to_count number of strings in {tolist} that are
2254 added/removed/modified in this diff hunk.
2255
2256 The {options} Dict argument also specifies diff options
2257 (similar to 'diffopt') and supports the following items:
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002258 algorithm Dict specifying the diff algorithm to
2259 use. Supported boolean items are
2260 "myers", "minimal", "patience" and
2261 "histogram".
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002262 context diff context length. Default is 0.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002263 iblank ignore changes where lines are all
2264 blank.
2265 icase ignore changes in case of text.
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002266 indent-heuristic use the indent heuristic for the
2267 internal diff library.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002268 iwhite ignore changes in amount of white
2269 space.
2270 iwhiteall ignore all white space changes.
2271 iwhiteeol ignore white space changes at end of
2272 line.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002273 For more information about these options, refer to 'diffopt'.
2274
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002275 To compute the unified diff, all the items in {fromlist} are
2276 concatenated into a string using a newline separator and the
2277 same for {tolist}. The unified diff output uses line numbers.
2278
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002279 Returns an empty List or String if {fromlist} and {tolist} are
2280 identical.
2281
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002282 Examples: >
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002283 :echo diff(['abc'], ['xxx'])
2284 @@ -1 +1 @@
2285 -abc
2286 +xxx
2287
2288 :echo diff(['abc'], ['xxx'], {'output': 'indices'})
2289 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}]
2290 :echo diff(readfile('oldfile'), readfile('newfile'))
2291 :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$'))
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002292<
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002293 For more examples, refer to |diff-func-examples|
2294
2295 Can also be used as a |method|: >
2296 GetFromList->diff(to_list)
2297<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002298 Return type: |String| or list<dict<number>> or list<any>
2299 depending on {options}
2300
2301
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002302diff_filler({lnum}) *diff_filler()*
2303 Returns the number of filler lines above line {lnum}.
2304 These are the lines that were inserted at this point in
2305 another diff'ed window. These filler lines are shown in the
2306 display but don't exist in the buffer.
2307 {lnum} is used like with |getline()|. Thus "." is the current
2308 line, "'m" mark m, etc.
2309 Returns 0 if the current window is not in diff mode.
2310
2311 Can also be used as a |method|: >
2312 GetLnum()->diff_filler()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002313<
2314 Return type: |Number|
2315
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002316
2317diff_hlID({lnum}, {col}) *diff_hlID()*
2318 Returns the highlight ID for diff mode at line {lnum} column
2319 {col} (byte index). When the current line does not have a
2320 diff change zero is returned.
2321 {lnum} is used like with |getline()|. Thus "." is the current
2322 line, "'m" mark m, etc.
2323 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2324 line.
2325 The highlight ID can be used with |synIDattr()| to obtain
2326 syntax information about the highlighting.
2327
2328 Can also be used as a |method|: >
2329 GetLnum()->diff_hlID(col)
2330<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002331 Return type: |Number|
2332
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002333
2334digraph_get({chars}) *digraph_get()* *E1214*
2335 Return the digraph of {chars}. This should be a string with
2336 exactly two characters. If {chars} are not just two
2337 characters, or the digraph of {chars} does not exist, an error
2338 is given and an empty string is returned.
2339
2340 The character will be converted from Unicode to 'encoding'
2341 when needed. This does require the conversion to be
2342 available, it might fail.
2343
2344 Also see |digraph_getlist()|.
2345
2346 Examples: >
2347 " Get a built-in digraph
2348 :echo digraph_get('00') " Returns '∞'
2349
2350 " Get a user-defined digraph
2351 :call digraph_set('aa', 'あ')
2352 :echo digraph_get('aa') " Returns 'あ'
2353<
2354 Can also be used as a |method|: >
2355 GetChars()->digraph_get()
2356<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002357 Return type: |String|
2358
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002359 This function works only when compiled with the |+digraphs|
2360 feature. If this feature is disabled, this function will
2361 display an error message.
2362
2363
2364digraph_getlist([{listall}]) *digraph_getlist()*
2365 Return a list of digraphs. If the {listall} argument is given
2366 and it is TRUE, return all digraphs, including the default
2367 digraphs. Otherwise, return only user-defined digraphs.
2368
2369 The characters will be converted from Unicode to 'encoding'
2370 when needed. This does require the conservation to be
2371 available, it might fail.
2372
2373 Also see |digraph_get()|.
2374
2375 Examples: >
2376 " Get user-defined digraphs
2377 :echo digraph_getlist()
2378
2379 " Get all the digraphs, including default digraphs
2380 :echo digraph_getlist(1)
2381<
2382 Can also be used as a |method|: >
2383 GetNumber()->digraph_getlist()
2384<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002385 Return type: list<list<string>>
2386
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002387 This function works only when compiled with the |+digraphs|
2388 feature. If this feature is disabled, this function will
2389 display an error message.
2390
2391
Bram Moolenaara2baa732022-02-04 16:09:54 +00002392digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002393 Add digraph {chars} to the list. {chars} must be a string
2394 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002395 encoded character. *E1215*
2396 Be careful, composing characters are NOT ignored. This
2397 function is similar to |:digraphs| command, but useful to add
2398 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002399
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002400 The function returns v:true if |digraph| is registered. If
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002401 this fails an error message is given and v:false is returned.
2402
2403 If you want to define multiple digraphs at once, you can use
2404 |digraph_setlist()|.
2405
2406 Example: >
2407 call digraph_set(' ', 'あ')
2408<
2409 Can be used as a |method|: >
2410 GetString()->digraph_set('あ')
2411<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002412 Return type: |vim9-boolean|
2413
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002414 This function works only when compiled with the |+digraphs|
2415 feature. If this feature is disabled, this function will
2416 display an error message.
2417
2418
2419digraph_setlist({digraphlist}) *digraph_setlist()*
2420 Similar to |digraph_set()| but this function can add multiple
2421 digraphs at once. {digraphlist} is a list composed of lists,
2422 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002423 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002424 Example: >
2425 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2426<
2427 It is similar to the following: >
2428 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2429 call digraph_set(chars, digraph)
2430 endfor
2431< Except that the function returns after the first error,
2432 following digraphs will not be added.
2433
2434 Can be used as a |method|: >
2435 GetList()->digraph_setlist()
2436<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002437 Return type: |vim9-boolean|
2438
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002439 This function works only when compiled with the |+digraphs|
2440 feature. If this feature is disabled, this function will
2441 display an error message.
2442
2443
2444echoraw({string}) *echoraw()*
2445 Output {string} as-is, including unprintable characters.
2446 This can be used to output a terminal code. For example, to
2447 disable modifyOtherKeys: >
2448 call echoraw(&t_TE)
2449< and to enable it again: >
2450 call echoraw(&t_TI)
2451< Use with care, you can mess up the terminal this way.
2452
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002453 Return type: |Number|
2454
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002455
2456empty({expr}) *empty()*
2457 Return the Number 1 if {expr} is empty, zero otherwise.
2458 - A |List| or |Dictionary| is empty when it does not have any
2459 items.
2460 - A |String| is empty when its length is zero.
2461 - A |Number| and |Float| are empty when their value is zero.
2462 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2463 - A |Job| is empty when it failed to start.
2464 - A |Channel| is empty when it is closed.
2465 - A |Blob| is empty when its length is zero.
mityu7f0bba22024-03-29 10:14:41 +01002466 - An |Object| is empty, when the empty() method in the object
2467 (if present) returns true. |object-empty()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002468
2469 For a long |List| this is much faster than comparing the
2470 length with zero.
2471
2472 Can also be used as a |method|: >
2473 mylist->empty()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002474<
2475 Return type: |Number|
2476
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002477
2478environ() *environ()*
2479 Return all of environment variables as dictionary. You can
2480 check if an environment variable exists like this: >
2481 :echo has_key(environ(), 'HOME')
2482< Note that the variable name may be CamelCase; to ignore case
2483 use this: >
2484 :echo index(keys(environ()), 'HOME', 0, 1) != -1
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002485<
2486 Return type: dict<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002487
Bram Moolenaar416bd912023-07-07 23:19:18 +01002488
2489err_teapot([{expr}]) *err_teapot()*
2490 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002491 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002492 If {expr} is present and it is TRUE error 503 is given,
2493 indicating that coffee is temporarily not available.
2494 If {expr} is present it must be a String.
2495
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002496 Return type: |Number|
2497
Bram Moolenaar416bd912023-07-07 23:19:18 +01002498
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002499escape({string}, {chars}) *escape()*
2500 Escape the characters in {chars} that occur in {string} with a
2501 backslash. Example: >
2502 :echo escape('c:\program files\vim', ' \')
2503< results in: >
2504 c:\\program\ files\\vim
2505< Also see |shellescape()| and |fnameescape()|.
2506
2507 Can also be used as a |method|: >
2508 GetText()->escape(' \')
2509<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002510 Return type: |String|
2511
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002512 *eval()*
2513eval({string}) Evaluate {string} and return the result. Especially useful to
2514 turn the result of |string()| back into the original value.
2515 This works for Numbers, Floats, Strings, Blobs and composites
2516 of them. Also works for |Funcref|s that refer to existing
Aliaksei Budavei95740222024-04-04 23:05:33 +03002517 functions. In |Vim9| script, it can be used to obtain |enum|
2518 values from their fully qualified names.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002519
2520 Can also be used as a |method|: >
2521 argv->join()->eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002522<
2523 Return type: any, depending on {string}
2524
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002525
2526eventhandler() *eventhandler()*
2527 Returns 1 when inside an event handler. That is that Vim got
2528 interrupted while waiting for the user to type a character,
2529 e.g., when dropping a file on Vim. This means interactive
2530 commands cannot be used. Otherwise zero is returned.
2531
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002532 Return type: |Number|
2533
2534
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002535executable({expr}) *executable()*
2536 This function checks if an executable with the name {expr}
2537 exists. {expr} must be the name of the program without any
2538 arguments.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002539
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002540 executable() uses the value of $PATH and/or the normal
zeertzjq0cc5dce2024-08-08 21:12:15 +02002541 searchpath for programs.
2542 *PATHEXT*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002543 On MS-Windows the ".exe", ".bat", etc. can optionally be
2544 included. Then the extensions in $PATHEXT are tried. Thus if
2545 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2546 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2547 by itself can be used in $PATHEXT to try using the name
2548 without an extension. When 'shell' looks like a Unix shell,
2549 then the name is also tried without adding an extension.
2550 On MS-Windows it only checks if the file exists and is not a
2551 directory, not if it's really executable.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002552 On MS-Windows an executable in the same directory as the Vim
2553 executable is always found. Since this directory is added to
2554 $PATH it should also work to execute it |win32-PATH|.
2555 *NoDefaultCurrentDirectoryInExePath*
2556 On MS-Windows an executable in Vim's current working directory
2557 is also normally found, but this can be disabled by setting
2558 the $NoDefaultCurrentDirectoryInExePath environment variable.
2559
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002560 The result is a Number:
2561 1 exists
2562 0 does not exist
2563 -1 not implemented on this system
2564 |exepath()| can be used to get the full path of an executable.
2565
2566 Can also be used as a |method|: >
2567 GetCommand()->executable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002568<
2569 Return type: |Number|
2570
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002571
2572execute({command} [, {silent}]) *execute()*
2573 Execute an Ex command or commands and return the output as a
2574 string.
2575 {command} can be a string or a List. In case of a List the
2576 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002577 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002578 redir => var
2579 {command}
2580 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002581< Except that line continuation in {command} is not recognized.
2582
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002583 The optional {silent} argument can have these values:
2584 "" no `:silent` used
2585 "silent" `:silent` used
2586 "silent!" `:silent!` used
2587 The default is "silent". Note that with "silent!", unlike
2588 `:redir`, error messages are dropped. When using an external
2589 command the screen may be messed up, use `system()` instead.
2590 *E930*
2591 It is not possible to use `:redir` anywhere in {command}.
2592
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002593 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002594 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002595
2596< To execute a command in another window than the current one
2597 use `win_execute()`.
2598
2599 When used recursively the output of the recursive call is not
2600 included in the output of the higher level call.
2601
2602 Can also be used as a |method|: >
2603 GetCommand()->execute()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002604<
Marius Gedminasc98bfb92024-06-19 19:59:23 +02002605 Return type: |String|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002606
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002607
2608exepath({expr}) *exepath()*
2609 If {expr} is an executable and is either an absolute path, a
2610 relative path or found in $PATH, return the full path.
2611 Note that the current directory is used when {expr} starts
2612 with "./", which may be a problem for Vim: >
2613 echo exepath(v:progpath)
2614< If {expr} cannot be found in $PATH or is not executable then
2615 an empty string is returned.
2616
2617 Can also be used as a |method|: >
2618 GetCommand()->exepath()
2619<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002620 Return type: |String|
2621
2622
2623exists({expr}) *exists()*
2624 The result is a Number, which is |TRUE| if {expr} is defined,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002625 zero otherwise.
2626
2627 Note: In a compiled |:def| function the evaluation is done at
2628 runtime. Use `exists_compiled()` to evaluate the expression
2629 at compile time.
2630
2631 For checking for a supported feature use |has()|.
2632 For checking if a file exists use |filereadable()|.
2633
2634 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002635 varname internal variable (see
2636 dict.key |internal-variables|). Also works
2637 list[i] for |curly-braces-names|, |Dictionary|
Yegappan Lakshmanana2ebb6e2024-02-25 08:40:10 +01002638 import.Func entries, |List| items, class and
2639 class.Func object methods, imported items, etc.
2640 object.Func Does not work for local variables in a
2641 class.varname compiled `:def` function.
2642 object.varname Also works for a function in |Vim9|
Bram Moolenaar944697a2022-02-20 19:48:20 +00002643 script, since it can be used as a
2644 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002645 Beware that evaluating an index may
2646 cause an error message for an invalid
2647 expression. E.g.: >
2648 :let l = [1, 2, 3]
2649 :echo exists("l[5]")
2650< 0 >
2651 :echo exists("l[xx]")
2652< E121: Undefined variable: xx
2653 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002654 &option-name Vim option (only checks if it exists,
2655 not if it really works)
2656 +option-name Vim option that works.
2657 $ENVNAME environment variable (could also be
2658 done by comparing with an empty
2659 string)
2660 *funcname built-in function (see |functions|)
2661 or user defined function (see
2662 |user-functions|) that is implemented.
2663 Also works for a variable that is a
2664 Funcref.
2665 ?funcname built-in function that could be
2666 implemented; to be used to check if
2667 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002668 :cmdname Ex command: built-in command, user
2669 command or command modifier |:command|.
2670 Returns:
2671 1 for match with start of a command
2672 2 full match with a command
2673 3 matches several user commands
2674 To check for a supported command
2675 always check the return value to be 2.
2676 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002677 :3match The |:3match| command (but you
2678 probably should not use it, it is
2679 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002680 #event autocommand defined for this event
2681 #event#pattern autocommand defined for this event and
2682 pattern (the pattern is taken
2683 literally and compared to the
2684 autocommand patterns character by
2685 character)
2686 #group autocommand group exists
2687 #group#event autocommand defined for this group and
2688 event.
2689 #group#event#pattern
2690 autocommand defined for this group,
2691 event and pattern.
2692 ##event autocommand for this event is
2693 supported.
2694
2695 Examples: >
2696 exists("&shortname")
2697 exists("$HOSTNAME")
2698 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002699 exists("*s:MyFunc") " only for legacy script
2700 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002701 exists("bufcount")
2702 exists(":Make")
2703 exists("#CursorHold")
2704 exists("#BufReadPre#*.gz")
2705 exists("#filetypeindent")
2706 exists("#filetypeindent#FileType")
2707 exists("#filetypeindent#FileType#*")
2708 exists("##ColorScheme")
2709< There must be no space between the symbol (&/$/*/#) and the
2710 name.
2711 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002712 a few cases this is ignored. That may become stricter in the
2713 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002714 Working example: >
2715 exists(":make")
2716< NOT working example: >
2717 exists(":make install")
2718
2719< Note that the argument must be a string, not the name of the
2720 variable itself. For example: >
2721 exists(bufcount)
2722< This doesn't check for existence of the "bufcount" variable,
2723 but gets the value of "bufcount", and checks if that exists.
2724
2725 Can also be used as a |method|: >
2726 Varname()->exists()
2727<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002728 Return type: |String|
2729
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002730
2731exists_compiled({expr}) *exists_compiled()*
2732 Like `exists()` but evaluated at compile time. This is useful
2733 to skip a block where a function is used that would otherwise
2734 give an error: >
2735 if exists_compiled('*ThatFunction')
2736 ThatFunction('works')
2737 endif
2738< If `exists()` were used then a compilation error would be
2739 given if ThatFunction() is not defined.
2740
2741 {expr} must be a literal string. *E1232*
2742 Can only be used in a |:def| function. *E1233*
2743 This does not work to check for arguments or local variables.
2744
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002745 Return type: |String|
2746
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002747
2748exp({expr}) *exp()*
2749 Return the exponential of {expr} as a |Float| in the range
2750 [0, inf].
2751 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002752 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002753 Examples: >
2754 :echo exp(2)
2755< 7.389056 >
2756 :echo exp(-1)
2757< 0.367879
2758
2759 Can also be used as a |method|: >
2760 Compute()->exp()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002761<
2762 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002763
2764
2765expand({string} [, {nosuf} [, {list}]]) *expand()*
2766 Expand wildcards and the following special keywords in
2767 {string}. 'wildignorecase' applies.
2768
2769 If {list} is given and it is |TRUE|, a List will be returned.
2770 Otherwise the result is a String and when there are several
2771 matches, they are separated by <NL> characters. [Note: in
2772 version 5.0 a space was used, which caused problems when a
2773 file name contains a space]
2774
2775 If the expansion fails, the result is an empty string. A name
2776 for a non-existing file is not included, unless {string} does
2777 not start with '%', '#' or '<', see below.
2778
Christian Brabandtec9c3262024-02-21 20:40:05 +01002779 For a |:terminal| window '%' expands to a '!' followed by
h-east53753f62024-05-05 18:42:31 +02002780 the command or shell that is run. |terminal-bufname|
Christian Brabandtec9c3262024-02-21 20:40:05 +01002781
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002782 When {string} starts with '%', '#' or '<', the expansion is
2783 done like for the |cmdline-special| variables with their
2784 associated modifiers. Here is a short overview:
2785
2786 % current file name
2787 # alternate file name
2788 #n alternate file name n
2789 <cfile> file name under the cursor
2790 <afile> autocmd file name
2791 <abuf> autocmd buffer number (as a String!)
2792 <amatch> autocmd matched name
2793 <cexpr> C expression under the cursor
2794 <sfile> sourced script file or function name
2795 <slnum> sourced script line number or function
2796 line number
2797 <sflnum> script file line number, also when in
2798 a function
2799 <SID> "<SNR>123_" where "123" is the
2800 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002801 <script> sourced script file, or script file
2802 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002803 <stack> call stack
2804 <cword> word under the cursor
2805 <cWORD> WORD under the cursor
2806 <client> the {clientid} of the last received
2807 message |server2client()|
2808 Modifiers:
2809 :p expand to full path
2810 :h head (last path component removed)
2811 :t tail (last path component only)
2812 :r root (one extension removed)
2813 :e extension only
2814
2815 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002816 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002817< Note that when expanding a string that starts with '%', '#' or
2818 '<', any following text is ignored. This does NOT work: >
2819 :let doesntwork = expand("%:h.bak")
2820< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002821 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002822< Also note that expanding "<cfile>" and others only returns the
2823 referenced file name without further expansion. If "<cfile>"
2824 is "~/.cshrc", you need to do another expand() to have the
2825 "~/" expanded into the path of the home directory: >
2826 :echo expand(expand("<cfile>"))
2827<
2828 There cannot be white space between the variables and the
2829 following modifier. The |fnamemodify()| function can be used
2830 to modify normal file names.
2831
2832 When using '%' or '#', and the current or alternate file name
2833 is not defined, an empty string is used. Using "%:p" in a
2834 buffer with no name, results in the current directory, with a
2835 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002836 When 'verbose' is set then expanding '%', '#' and <> items
2837 will result in an error message if the argument cannot be
2838 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002839
2840 When {string} does not start with '%', '#' or '<', it is
2841 expanded like a file name is expanded on the command line.
2842 'suffixes' and 'wildignore' are used, unless the optional
2843 {nosuf} argument is given and it is |TRUE|.
2844 Names for non-existing files are included. The "**" item can
2845 be used to search in a directory tree. For example, to find
2846 all "README" files in the current directory and below: >
2847 :echo expand("**/README")
2848<
2849 expand() can also be used to expand variables and environment
2850 variables that are only known in a shell. But this can be
2851 slow, because a shell may be used to do the expansion. See
2852 |expr-env-expand|.
2853 The expanded variable is still handled like a list of file
2854 names. When an environment variable cannot be expanded, it is
2855 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2856 "$FOOBAR".
2857
2858 See |glob()| for finding existing files. See |system()| for
2859 getting the raw output of an external command.
2860
2861 Can also be used as a |method|: >
2862 Getpattern()->expand()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002863<
2864 Return type: |String| or list<string> depending on {list}
2865
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002866
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002867expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002868 Expand special items in String {string} like what is done for
2869 an Ex command such as `:edit`. This expands special keywords,
2870 like with |expand()|, and environment variables, anywhere in
2871 {string}. "~user" and "~/path" are only expanded at the
2872 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002873
2874 The following items are supported in the {options} Dict
2875 argument:
2876 errmsg If set to TRUE, error messages are displayed
2877 if an error is encountered during expansion.
2878 By default, error messages are not displayed.
2879
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002880 Returns the expanded string. If an error is encountered
2881 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002882
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002883 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002884 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002885 make /path/runtime/doc/builtin.o
2886 :echo expandcmd('make %<.o', {'errmsg': v:true})
2887<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002888 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002889 GetCommand()->expandcmd()
2890<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002891 Return type: |String| or list<string> depending on {list}
2892
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002893extend({expr1}, {expr2} [, {expr3}]) *extend()*
2894 {expr1} and {expr2} must be both |Lists| or both
2895 |Dictionaries|.
2896
2897 If they are |Lists|: Append {expr2} to {expr1}.
2898 If {expr3} is given insert the items of {expr2} before the
2899 item with index {expr3} in {expr1}. When {expr3} is zero
2900 insert before the first item. When {expr3} is equal to
2901 len({expr1}) then {expr2} is appended.
2902 Examples: >
2903 :echo sort(extend(mylist, [7, 5]))
2904 :call extend(mylist, [2, 3], 1)
2905< When {expr1} is the same List as {expr2} then the number of
2906 items copied is equal to the original length of the List.
2907 E.g., when {expr3} is 1 you get N new copies of the first item
2908 (where N is the original length of the List).
2909 Use |add()| to concatenate one item to a list. To concatenate
2910 two lists into a new list use the + operator: >
2911 :let newlist = [1, 2, 3] + [4, 5]
2912<
2913 If they are |Dictionaries|:
2914 Add all entries from {expr2} to {expr1}.
2915 If a key exists in both {expr1} and {expr2} then {expr3} is
2916 used to decide what to do:
2917 {expr3} = "keep": keep the value of {expr1}
2918 {expr3} = "force": use the value of {expr2}
2919 {expr3} = "error": give an error message *E737*
2920 When {expr3} is omitted then "force" is assumed.
2921
2922 {expr1} is changed when {expr2} is not empty. If necessary
2923 make a copy of {expr1} first.
2924 {expr2} remains unchanged.
2925 When {expr1} is locked and {expr2} is not empty the operation
2926 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002927 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002928
2929 Can also be used as a |method|: >
2930 mylist->extend(otherlist)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002931<
2932 Return type: list<{type}> or dict<{type}> depending on {expr1}
2933 and {expr2}, in case of error: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002934
2935
2936extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
2937 Like |extend()| but instead of adding items to {expr1} a new
2938 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00002939 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002940
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002941 Return type: list<{type}> or dict<{type}> depending on {expr1}
2942 and {expr2}, in case of error: |Number|
2943
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002944
2945feedkeys({string} [, {mode}]) *feedkeys()*
2946 Characters in {string} are queued for processing as if they
2947 come from a mapping or were typed by the user.
2948
2949 By default the string is added to the end of the typeahead
2950 buffer, thus if a mapping is still being executed the
2951 characters come after them. Use the 'i' flag to insert before
2952 other characters, they will be executed next, before any
2953 characters from a mapping.
2954
2955 The function does not wait for processing of keys contained in
2956 {string}.
2957
2958 To include special keys into {string}, use double-quotes
2959 and "\..." notation |expr-quote|. For example,
2960 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
2961 feedkeys('\<CR>') pushes 5 characters.
2962 A special code that might be useful is <Ignore>, it exits the
2963 wait for a character without doing anything. *<Ignore>*
2964
2965 {mode} is a String, which can contain these character flags:
2966 'm' Remap keys. This is default. If {mode} is absent,
2967 keys are remapped.
2968 'n' Do not remap keys.
2969 't' Handle keys as if typed; otherwise they are handled as
2970 if coming from a mapping. This matters for undo,
2971 opening folds, etc.
2972 'L' Lowlevel input. Only works for Unix or when using the
2973 GUI. Keys are used as if they were coming from the
2974 terminal. Other flags are not used. *E980*
2975 When a CTRL-C interrupts and 't' is included it sets
2976 the internal "got_int" flag.
2977 'i' Insert the string instead of appending (see above).
2978 'x' Execute commands until typeahead is empty. This is
2979 similar to using ":normal!". You can call feedkeys()
2980 several times without 'x' and then one time with 'x'
2981 (possibly with an empty {string}) to execute all the
2982 typeahead. Note that when Vim ends in Insert mode it
2983 will behave as if <Esc> is typed, to avoid getting
2984 stuck, waiting for a character to be typed before the
2985 script continues.
2986 Note that if you manage to call feedkeys() while
2987 executing commands, thus calling it recursively, then
2988 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00002989 'c' Remove any script context when executing, so that
2990 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01002991 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01002992 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002993 '!' When used with 'x' will not end Insert mode. Can be
2994 used in a test when a timer is set to exit Insert mode
2995 a little later. Useful for testing CursorHoldI.
2996
2997 Return value is always 0.
2998
2999 Can also be used as a |method|: >
3000 GetInput()->feedkeys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003001<
3002 Return type: |String| or list<string> depending on {list}
3003
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003004
Shougo Matsushita60c87432024-06-03 22:59:27 +02003005filecopy({from}, {to}) *filecopy()*
3006 Copy the file pointed to by the name {from} to {to}. The
3007 result is a Number, which is |TRUE| if the file was copied
3008 successfully, and |FALSE| when it failed.
3009 If a file with name {to} already exists, it will fail.
3010 Note that it does not handle directories (yet).
3011
3012 This function is not available in the |sandbox|.
3013
3014 Can also be used as a |method|: >
3015 GetOldName()->filecopy(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003016<
3017 Return type: |Number|
3018
Shougo Matsushita60c87432024-06-03 22:59:27 +02003019
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003020filereadable({file}) *filereadable()*
3021 The result is a Number, which is |TRUE| when a file with the
3022 name {file} exists, and can be read. If {file} doesn't exist,
3023 or is a directory, the result is |FALSE|. {file} is any
3024 expression, which is used as a String.
3025 If you don't care about the file being readable you can use
3026 |glob()|.
3027 {file} is used as-is, you may want to expand wildcards first: >
3028 echo filereadable('~/.vimrc')
3029 0
3030 echo filereadable(expand('~/.vimrc'))
3031 1
3032
3033< Can also be used as a |method|: >
3034 GetName()->filereadable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003035<
3036 Return type: |Number|
3037
3038 *file_readable()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003039 Obsolete name: file_readable().
3040
3041
3042filewritable({file}) *filewritable()*
3043 The result is a Number, which is 1 when a file with the
3044 name {file} exists, and can be written. If {file} doesn't
3045 exist, or is not writable, the result is 0. If {file} is a
3046 directory, and we can write to it, the result is 2.
3047
3048 Can also be used as a |method|: >
3049 GetName()->filewritable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003050<
3051 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003052
3053
3054filter({expr1}, {expr2}) *filter()*
3055 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3056 For each item in {expr1} evaluate {expr2} and when the result
3057 is zero or false remove the item from the |List| or
3058 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003059 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003060
3061 {expr2} must be a |string| or |Funcref|.
3062
3063 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3064 of the current item. For a |Dictionary| |v:key| has the key
3065 of the current item and for a |List| |v:key| has the index of
3066 the current item. For a |Blob| |v:key| has the index of the
3067 current byte. For a |String| |v:key| has the index of the
3068 current character.
3069 Examples: >
3070 call filter(mylist, 'v:val !~ "OLD"')
3071< Removes the items where "OLD" appears. >
3072 call filter(mydict, 'v:key >= 8')
3073< Removes the items with a key below 8. >
3074 call filter(var, 0)
3075< Removes all the items, thus clears the |List| or |Dictionary|.
3076
3077 Note that {expr2} is the result of expression and is then
3078 used as an expression again. Often it is good to use a
3079 |literal-string| to avoid having to double backslashes.
3080
3081 If {expr2} is a |Funcref| it must take two arguments:
3082 1. the key or the index of the current item.
3083 2. the value of the current item.
3084 The function must return |TRUE| if the item should be kept.
3085 Example that keeps the odd items of a list: >
3086 func Odd(idx, val)
3087 return a:idx % 2 == 1
3088 endfunc
3089 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003090< It is shorter when using a |lambda|. In |Vim9| syntax: >
3091 call filter(myList, (idx, val) => idx * val <= 42)
3092< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003093 call filter(myList, {idx, val -> idx * val <= 42})
3094< If you do not use "val" you can leave it out: >
3095 call filter(myList, {idx -> idx % 2 == 1})
3096<
3097 In |Vim9| script the result must be true, false, zero or one.
3098 Other values will result in a type error.
3099
3100 For a |List| and a |Dictionary| the operation is done
3101 in-place. If you want it to remain unmodified make a copy
3102 first: >
3103 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
3104
3105< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00003106 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003107 When an error is encountered while evaluating {expr2} no
3108 further items in {expr1} are processed.
3109 When {expr2} is a Funcref errors inside a function are ignored,
3110 unless it was defined with the "abort" flag.
3111
3112 Can also be used as a |method|: >
3113 mylist->filter(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003114<
3115 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
3116 depending on {expr1}
3117
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003118
3119finddir({name} [, {path} [, {count}]]) *finddir()*
3120 Find directory {name} in {path}. Supports both downwards and
3121 upwards recursive directory searches. See |file-searching|
3122 for the syntax of {path}.
3123
3124 Returns the path of the first found match. When the found
3125 directory is below the current directory a relative path is
3126 returned. Otherwise a full path is returned.
3127 If {path} is omitted or empty then 'path' is used.
3128
3129 If the optional {count} is given, find {count}'s occurrence of
3130 {name} in {path} instead of the first one.
3131 When {count} is negative return all the matches in a |List|.
3132
Bram Moolenaar016188f2022-06-06 20:52:59 +01003133 Returns an empty string if the directory is not found.
3134
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003135 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003136
3137 Can also be used as a |method|: >
3138 GetName()->finddir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003139<
3140 Return type: |String|
3141
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003142
3143findfile({name} [, {path} [, {count}]]) *findfile()*
3144 Just like |finddir()|, but find a file instead of a directory.
3145 Uses 'suffixesadd'.
3146 Example: >
3147 :echo findfile("tags.vim", ".;")
3148< Searches from the directory of the current file upwards until
3149 it finds the file "tags.vim".
3150
3151 Can also be used as a |method|: >
3152 GetName()->findfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003153<
3154 Return type: |String|
3155
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003156
3157flatten({list} [, {maxdepth}]) *flatten()*
3158 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
3159 the result is a |List| without nesting, as if {maxdepth} is
3160 a very large number.
3161 The {list} is changed in place, use |flattennew()| if you do
3162 not want that.
3163 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00003164 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003165 *E900*
3166 {maxdepth} means how deep in nested lists changes are made.
3167 {list} is not modified when {maxdepth} is 0.
3168 {maxdepth} must be positive number.
3169
3170 If there is an error the number zero is returned.
3171
3172 Example: >
3173 :echo flatten([1, [2, [3, 4]], 5])
3174< [1, 2, 3, 4, 5] >
3175 :echo flatten([1, [2, [3, 4]], 5], 1)
3176< [1, 2, [3, 4], 5]
3177
3178 Can also be used as a |method|: >
3179 mylist->flatten()
3180<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003181 Return type: list<{type}>
3182
3183
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003184flattennew({list} [, {maxdepth}]) *flattennew()*
3185 Like |flatten()| but first make a copy of {list}.
3186
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003187 Return type: list<{type}>
3188
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003189
3190float2nr({expr}) *float2nr()*
3191 Convert {expr} to a Number by omitting the part after the
3192 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00003193 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003194 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003195 When the value of {expr} is out of range for a |Number| the
3196 result is truncated to 0x7fffffff or -0x7fffffff (or when
3197 64-bit Number support is enabled, 0x7fffffffffffffff or
3198 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
3199 64-bit Number support is enabled, -0x8000000000000000).
3200 Examples: >
3201 echo float2nr(3.95)
3202< 3 >
3203 echo float2nr(-23.45)
3204< -23 >
3205 echo float2nr(1.0e100)
3206< 2147483647 (or 9223372036854775807) >
3207 echo float2nr(-1.0e150)
3208< -2147483647 (or -9223372036854775807) >
3209 echo float2nr(1.0e-100)
3210< 0
3211
3212 Can also be used as a |method|: >
3213 Compute()->float2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003214<
3215 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003216
3217
3218floor({expr}) *floor()*
3219 Return the largest integral value less than or equal to
3220 {expr} as a |Float| (round down).
3221 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003222 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003223 Examples: >
3224 echo floor(1.856)
3225< 1.0 >
3226 echo floor(-5.456)
3227< -6.0 >
3228 echo floor(4.0)
3229< 4.0
3230
3231 Can also be used as a |method|: >
3232 Compute()->floor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003233<
3234 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003235
3236
3237fmod({expr1}, {expr2}) *fmod()*
3238 Return the remainder of {expr1} / {expr2}, even if the
3239 division is not representable. Returns {expr1} - i * {expr2}
3240 for some integer i such that if {expr2} is non-zero, the
3241 result has the same sign as {expr1} and magnitude less than
3242 the magnitude of {expr2}. If {expr2} is zero, the value
3243 returned is zero. The value returned is a |Float|.
3244 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003245 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
3246 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003247 Examples: >
3248 :echo fmod(12.33, 1.22)
3249< 0.13 >
3250 :echo fmod(-12.33, 1.22)
3251< -0.13
3252
3253 Can also be used as a |method|: >
3254 Compute()->fmod(1.22)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003255<
3256 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003257
3258
3259fnameescape({string}) *fnameescape()*
3260 Escape {string} for use as file name command argument. All
3261 characters that have a special meaning, such as '%' and '|'
3262 are escaped with a backslash.
3263 For most systems the characters escaped are
3264 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3265 appears in a filename, it depends on the value of 'isfname'.
3266 A leading '+' and '>' is also escaped (special after |:edit|
3267 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01003268 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003269 Example: >
3270 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003271 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003272< results in executing: >
3273 edit \+some\ str\%nge\|name
3274<
3275 Can also be used as a |method|: >
3276 GetName()->fnameescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003277<
3278 Return type: |String|
3279
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003280
3281fnamemodify({fname}, {mods}) *fnamemodify()*
3282 Modify file name {fname} according to {mods}. {mods} is a
3283 string of characters like it is used for file names on the
3284 command line. See |filename-modifiers|.
3285 Example: >
3286 :echo fnamemodify("main.c", ":p:h")
3287< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01003288 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01003289< If {mods} is empty or an unsupported modifier is used then
3290 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01003291 When {fname} is empty then with {mods} ":h" returns ".", so
3292 that `:cd` can be used with it. This is different from
3293 expand('%:h') without a buffer name, which returns an empty
3294 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003295 Note: Environment variables don't work in {fname}, use
3296 |expand()| first then.
3297
3298 Can also be used as a |method|: >
3299 GetName()->fnamemodify(':p:h')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003300<
3301 Return type: |String|
3302
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003303
3304foldclosed({lnum}) *foldclosed()*
3305 The result is a Number. If the line {lnum} is in a closed
3306 fold, the result is the number of the first line in that fold.
3307 If the line {lnum} is not in a closed fold, -1 is returned.
3308 {lnum} is used like with |getline()|. Thus "." is the current
3309 line, "'m" mark m, etc.
3310
3311 Can also be used as a |method|: >
3312 GetLnum()->foldclosed()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003313<
3314 Return type: |Number|
3315
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003316
3317foldclosedend({lnum}) *foldclosedend()*
3318 The result is a Number. If the line {lnum} is in a closed
3319 fold, the result is the number of the last line in that fold.
3320 If the line {lnum} is not in a closed fold, -1 is returned.
3321 {lnum} is used like with |getline()|. Thus "." is the current
3322 line, "'m" mark m, etc.
3323
3324 Can also be used as a |method|: >
3325 GetLnum()->foldclosedend()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003326<
3327 Return type: |Number|
3328
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003329
3330foldlevel({lnum}) *foldlevel()*
3331 The result is a Number, which is the foldlevel of line {lnum}
3332 in the current buffer. For nested folds the deepest level is
3333 returned. If there is no fold at line {lnum}, zero is
3334 returned. It doesn't matter if the folds are open or closed.
3335 When used while updating folds (from 'foldexpr') -1 is
3336 returned for lines where folds are still to be updated and the
3337 foldlevel is unknown. As a special case the level of the
3338 previous line is usually available.
3339 {lnum} is used like with |getline()|. Thus "." is the current
3340 line, "'m" mark m, etc.
3341
3342 Can also be used as a |method|: >
3343 GetLnum()->foldlevel()
3344<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003345 Return type: |Number|
3346
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003347 *foldtext()*
3348foldtext() Returns a String, to be displayed for a closed fold. This is
3349 the default function used for the 'foldtext' option and should
3350 only be called from evaluating 'foldtext'. It uses the
3351 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3352 The returned string looks like this: >
3353 +-- 45 lines: abcdef
3354< The number of leading dashes depends on the foldlevel. The
3355 "45" is the number of lines in the fold. "abcdef" is the text
3356 in the first non-blank line of the fold. Leading white space,
3357 "//" or "/*" and the text from the 'foldmarker' and
3358 'commentstring' options is removed.
3359 When used to draw the actual foldtext, the rest of the line
3360 will be filled with the fold char from the 'fillchars'
3361 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003362 Returns an empty string when there is no fold.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003363
3364 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003365 {not available when compiled without the |+folding| feature}
3366
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003367
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003368foldtextresult({lnum}) *foldtextresult()*
3369 Returns the text that is displayed for the closed fold at line
3370 {lnum}. Evaluates 'foldtext' in the appropriate context.
3371 When there is no closed fold at {lnum} an empty string is
3372 returned.
3373 {lnum} is used like with |getline()|. Thus "." is the current
3374 line, "'m" mark m, etc.
3375 Useful when exporting folded text, e.g., to HTML.
3376 {not available when compiled without the |+folding| feature}
3377
3378
3379 Can also be used as a |method|: >
3380 GetLnum()->foldtextresult()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003381<
3382 Return type: |String|
3383
Ernie Raele79e2072024-01-13 11:47:33 +01003384
3385foreach({expr1}, {expr2}) *foreach()*
3386 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3387 For each item in {expr1} execute {expr2}. {expr1} is not
erraelc92b8be2024-01-14 10:11:07 -08003388 modified; its values may be, as with |:lockvar| 1. |E741|
Ernie Raele79e2072024-01-13 11:47:33 +01003389 See |map()| and |filter()| to modify {expr1}.
3390
3391 {expr2} must be a |string| or |Funcref|.
3392
3393 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3394 of the current item. For a |Dictionary| |v:key| has the key
3395 of the current item and for a |List| |v:key| has the index of
3396 the current item. For a |Blob| |v:key| has the index of the
3397 current byte. For a |String| |v:key| has the index of the
3398 current character.
3399 Examples: >
3400 call foreach(mylist, 'used[v:val] = true')
3401< This records the items that are in the {expr1} list.
3402
3403 Note that {expr2} is the result of expression and is then used
3404 as a command. Often it is good to use a |literal-string| to
3405 avoid having to double backslashes.
3406
3407 If {expr2} is a |Funcref| it must take two arguments:
3408 1. the key or the index of the current item.
3409 2. the value of the current item.
3410 With a legacy script lambda you don't get an error if it only
3411 accepts one argument, but with a Vim9 lambda you get "E1106:
3412 One argument too many", the number of arguments must match.
3413 If the function returns a value, it is ignored.
3414
3415 Returns {expr1} in all cases.
3416 When an error is encountered while executing {expr2} no
3417 further items in {expr1} are processed.
3418 When {expr2} is a Funcref errors inside a function are ignored,
3419 unless it was defined with the "abort" flag.
3420
3421 Can also be used as a |method|: >
3422 mylist->foreach(expr2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003423<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003424 Return type: |String|, |Blob| list<{type}> or dict<{type}>
3425 depending on {expr1}
3426
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003427 *foreground()*
3428foreground() Move the Vim window to the foreground. Useful when sent from
3429 a client to a Vim server. |remote_send()|
3430 On Win32 systems this might not work, the OS does not always
3431 allow a window to bring itself to the foreground. Use
3432 |remote_foreground()| instead.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003433
3434 Return type: |Number|
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003435 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003436 Win32 console version}
3437
Bram Moolenaaraa534142022-09-15 21:46:02 +01003438fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003439 Get the full command name from a short abbreviated command
3440 name; see |20.2| for details on command abbreviations.
3441
3442 The string argument {name} may start with a `:` and can
3443 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003444 Returns an empty string if a command doesn't exist, if it's
3445 ambiguous (for user-defined commands) or cannot be shortened
3446 this way. |vim9-no-shorten|
3447
3448 Without the {vim9} argument uses the current script version.
3449 If {vim9} is present and FALSE then legacy script rules are
3450 used. When {vim9} is present and TRUE then Vim9 rules are
3451 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003452
3453 For example `fullcommand('s')`, `fullcommand('sub')`,
3454 `fullcommand(':%substitute')` all return "substitute".
3455
3456 Can also be used as a |method|: >
3457 GetName()->fullcommand()
3458<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003459 Return type: |String|
3460
3461
3462funcref({name} [, {arglist}] [, {dict}]) *funcref()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003463 Just like |function()|, but the returned Funcref will lookup
3464 the function by reference, not by name. This matters when the
3465 function {name} is redefined later.
3466
3467 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003468 It only works for an autoloaded function if it has already
3469 been loaded (to avoid mistakenly loading the autoload script
3470 when only intending to use the function name, use |function()|
3471 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003472 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003473
3474 Can also be used as a |method|: >
3475 GetFuncname()->funcref([arg])
3476<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003477 Return type: func(...): any or |Number| on error
3478
Dominique Pellee764d1b2023-03-12 21:20:59 +00003479 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003480function({name} [, {arglist}] [, {dict}])
3481 Return a |Funcref| variable that refers to function {name}.
3482 {name} can be the name of a user defined function or an
3483 internal function.
3484
3485 {name} can also be a Funcref or a partial. When it is a
3486 partial the dict stored in it will be used and the {dict}
3487 argument is not allowed. E.g.: >
3488 let FuncWithArg = function(dict.Func, [arg])
3489 let Broken = function(dict.Func, [arg], dict)
3490<
3491 When using the Funcref the function will be found by {name},
3492 also when it was redefined later. Use |funcref()| to keep the
3493 same function.
3494
3495 When {arglist} or {dict} is present this creates a partial.
3496 That means the argument list and/or the dictionary is stored in
3497 the Funcref and will be used when the Funcref is called.
3498
3499 The arguments are passed to the function in front of other
3500 arguments, but after any argument from |method|. Example: >
3501 func Callback(arg1, arg2, name)
3502 ...
3503 let Partial = function('Callback', ['one', 'two'])
3504 ...
3505 call Partial('name')
3506< Invokes the function as with: >
3507 call Callback('one', 'two', 'name')
3508
3509< With a |method|: >
3510 func Callback(one, two, three)
3511 ...
3512 let Partial = function('Callback', ['two'])
3513 ...
3514 eval 'one'->Partial('three')
3515< Invokes the function as with: >
3516 call Callback('one', 'two', 'three')
3517
3518< The function() call can be nested to add more arguments to the
3519 Funcref. The extra arguments are appended to the list of
3520 arguments. Example: >
3521 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003522 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003523 let Func = function('Callback', ['one'])
3524 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003525 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003526 call Func2('name')
3527< Invokes the function as with: >
3528 call Callback('one', 'two', 'name')
3529
3530< The Dictionary is only useful when calling a "dict" function.
3531 In that case the {dict} is passed in as "self". Example: >
3532 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003533 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003534 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003535 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003536 let context = {"name": "example"}
3537 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003538 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003539 call Func() " will echo: called for example
3540< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003541 arguments, these two are equivalent, if Callback() is defined
3542 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003543 let Func = function('Callback', context)
3544 let Func = context.Callback
3545
3546< The argument list and the Dictionary can be combined: >
3547 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003548 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003549 let context = {"name": "example"}
3550 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003551 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003552 call Func(500)
3553< Invokes the function as with: >
3554 call context.Callback('one', 500)
3555<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003556 Returns 0 on error.
3557
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003558 Can also be used as a |method|: >
3559 GetFuncname()->function([arg])
3560
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003561<
3562 Return type: func(...): any or |Number| on error
3563
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003564
3565garbagecollect([{atexit}]) *garbagecollect()*
3566 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3567 that have circular references.
3568
3569 There is hardly ever a need to invoke this function, as it is
3570 automatically done when Vim runs out of memory or is waiting
3571 for the user to press a key after 'updatetime'. Items without
3572 circular references are always freed when they become unused.
3573 This is useful if you have deleted a very big |List| and/or
3574 |Dictionary| with circular references in a script that runs
3575 for a long time.
3576
3577 When the optional {atexit} argument is one, garbage
3578 collection will also be done when exiting Vim, if it wasn't
3579 done before. This is useful when checking for memory leaks.
3580
3581 The garbage collection is not done immediately but only when
3582 it's safe to perform. This is when waiting for the user to
3583 type a character. To force garbage collection immediately use
3584 |test_garbagecollect_now()|.
3585
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003586 Return type: |String|
3587
3588
LemonBoy48b7d052024-07-09 18:24:59 +02003589get({list}, {idx} [, {default}]) *get()* *get()-list*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003590 Get item {idx} from |List| {list}. When this item is not
3591 available return {default}. Return zero when {default} is
3592 omitted.
3593 Preferably used as a |method|: >
3594 mylist->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003595<
3596 Return type: any, depending on {list}
3597
LemonBoy48b7d052024-07-09 18:24:59 +02003598get({blob}, {idx} [, {default}]) *get()-blob*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003599 Get byte {idx} from |Blob| {blob}. When this byte is not
3600 available return {default}. Return -1 when {default} is
3601 omitted.
3602 Preferably used as a |method|: >
3603 myblob->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003604<
3605 Return type: |Number|
3606
LemonBoy48b7d052024-07-09 18:24:59 +02003607get({dict}, {key} [, {default}]) *get()-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003608 Get item with key {key} from |Dictionary| {dict}. When this
3609 item is not available return {default}. Return zero when
3610 {default} is omitted. Useful example: >
3611 let val = get(g:, 'var_name', 'default')
3612< This gets the value of g:var_name if it exists, and uses
3613 'default' when it does not exist.
3614 Preferably used as a |method|: >
3615 mydict->get(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003616<
h-east84ac2122024-06-17 18:12:30 +02003617 Return type: any, depending on {dict}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003618
LemonBoy48b7d052024-07-09 18:24:59 +02003619get({func}, {what}) *get()-func*
3620 Get item {what} from |Funcref| {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003621 {what} are:
LemonBoy48b7d052024-07-09 18:24:59 +02003622 "name" The function name
3623 "func" The function
3624 "dict" The dictionary
3625 "args" The list with arguments
3626 "arity" A dictionary with information about the number of
3627 arguments accepted by the function (minus the
3628 {arglist}) with the following fields:
3629 required the number of positional arguments
3630 optional the number of optional arguments,
3631 in addition to the required ones
3632 varargs |TRUE| if the function accepts a
3633 variable number of arguments |...|
3634
3635 Note: There is no error, if the {arglist} of
3636 the Funcref contains more arguments than the
3637 Funcref expects, it's not validated.
3638
Bram Moolenaar016188f2022-06-06 20:52:59 +01003639 Returns zero on error.
LemonBoy48b7d052024-07-09 18:24:59 +02003640
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003641 Preferably used as a |method|: >
3642 myfunc->get(what)
3643<
LemonBoy48b7d052024-07-09 18:24:59 +02003644 Return type: any, depending on {func} and {what}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003645
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003646 *getbufinfo()*
3647getbufinfo([{buf}])
3648getbufinfo([{dict}])
3649 Get information about buffers as a List of Dictionaries.
3650
3651 Without an argument information about all the buffers is
3652 returned.
3653
3654 When the argument is a |Dictionary| only the buffers matching
3655 the specified criteria are returned. The following keys can
3656 be specified in {dict}:
3657 buflisted include only listed buffers.
3658 bufloaded include only loaded buffers.
3659 bufmodified include only modified buffers.
3660
3661 Otherwise, {buf} specifies a particular buffer to return
3662 information for. For the use of {buf}, see |bufname()|
3663 above. If the buffer is found the returned List has one item.
3664 Otherwise the result is an empty list.
3665
3666 Each returned List item is a dictionary with the following
3667 entries:
3668 bufnr Buffer number.
3669 changed TRUE if the buffer is modified.
3670 changedtick Number of changes made to the buffer.
Sean Dewar1fb41032023-08-16 17:15:05 +01003671 command TRUE if the buffer belongs to the
3672 command-line window |cmdwin|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003673 hidden TRUE if the buffer is hidden.
3674 lastused Timestamp in seconds, like
3675 |localtime()|, when the buffer was
3676 last used.
3677 {only with the |+viminfo| feature}
3678 listed TRUE if the buffer is listed.
3679 lnum Line number used for the buffer when
3680 opened in the current window.
3681 Only valid if the buffer has been
3682 displayed in the window in the past.
3683 If you want the line number of the
3684 last known cursor position in a given
3685 window, use |line()|: >
3686 :echo line('.', {winid})
3687<
3688 linecount Number of lines in the buffer (only
3689 valid when loaded)
3690 loaded TRUE if the buffer is loaded.
3691 name Full path to the file in the buffer.
3692 signs List of signs placed in the buffer.
3693 Each list item is a dictionary with
3694 the following fields:
3695 id sign identifier
3696 lnum line number
3697 name sign name
3698 variables A reference to the dictionary with
3699 buffer-local variables.
3700 windows List of |window-ID|s that display this
3701 buffer
3702 popups List of popup |window-ID|s that
3703 display this buffer
3704
3705 Examples: >
3706 for buf in getbufinfo()
3707 echo buf.name
3708 endfor
3709 for buf in getbufinfo({'buflisted':1})
3710 if buf.changed
3711 ....
3712 endif
3713 endfor
3714<
3715 To get buffer-local options use: >
3716 getbufvar({bufnr}, '&option_name')
3717<
3718 Can also be used as a |method|: >
3719 GetBufnr()->getbufinfo()
3720<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003721 Return type: list<dict<any>>
3722
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003723
3724 *getbufline()*
3725getbufline({buf}, {lnum} [, {end}])
3726 Return a |List| with the lines starting from {lnum} to {end}
3727 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003728 |List| with only the line {lnum} is returned. See
3729 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003730
3731 For the use of {buf}, see |bufname()| above.
3732
3733 For {lnum} and {end} "$" can be used for the last line of the
3734 buffer. Otherwise a number must be used.
3735
3736 When {lnum} is smaller than 1 or bigger than the number of
3737 lines in the buffer, an empty |List| is returned.
3738
3739 When {end} is greater than the number of lines in the buffer,
3740 it is treated as {end} is set to the number of lines in the
3741 buffer. When {end} is before {lnum} an empty |List| is
3742 returned.
3743
3744 This function works only for loaded buffers. For unloaded and
3745 non-existing buffers, an empty |List| is returned.
3746
3747 Example: >
3748 :let lines = getbufline(bufnr("myfile"), 1, "$")
3749
3750< Can also be used as a |method|: >
3751 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003752<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003753 Return type: list<string>
3754
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003755 *getbufoneline()*
3756getbufoneline({buf}, {lnum})
3757 Just like `getbufline()` but only get one line and return it
3758 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003759
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003760 Return type: |String|
3761
3762
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003763getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3764 The result is the value of option or local buffer variable
3765 {varname} in buffer {buf}. Note that the name without "b:"
3766 must be used.
3767 The {varname} argument is a string.
3768 When {varname} is empty returns a |Dictionary| with all the
3769 buffer-local variables.
3770 When {varname} is equal to "&" returns a |Dictionary| with all
3771 the buffer-local options.
3772 Otherwise, when {varname} starts with "&" returns the value of
3773 a buffer-local option.
3774 This also works for a global or buffer-local option, but it
3775 doesn't work for a global variable, window-local variable or
3776 window-local option.
3777 For the use of {buf}, see |bufname()| above.
3778 When the buffer or variable doesn't exist {def} or an empty
3779 string is returned, there is no error message.
3780 Examples: >
3781 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003782 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003783
3784< Can also be used as a |method|: >
3785 GetBufnr()->getbufvar(varname)
3786<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003787 Return type: any, depending on {varname}
3788
3789
mikoto20001083cae2024-11-11 21:24:14 +01003790getcellpixels() *getcellpixels()*
3791 Returns a |List| of terminal cell pixel size.
3792 List format is [xpixels, ypixels].
mikoto2000de094dc2024-11-14 22:13:48 +01003793 Only works on (terminal) Unix. For gVim, on other systems and
3794 on failure returns [].
mikoto20001083cae2024-11-11 21:24:14 +01003795
mikoto2000de094dc2024-11-14 22:13:48 +01003796 Return type: list<any>
mikoto20001083cae2024-11-11 21:24:14 +01003797
3798
Kota Kato66bb9ae2023-01-17 18:31:56 +00003799getcellwidths() *getcellwidths()*
3800 Returns a |List| of cell widths of character ranges overridden
3801 by |setcellwidths()|. The format is equal to the argument of
3802 |setcellwidths()|. If no character ranges have their cell
3803 widths overridden, an empty List is returned.
h-east84ac2122024-06-17 18:12:30 +02003804
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003805 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003806
3807
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003808getchangelist([{buf}]) *getchangelist()*
3809 Returns the |changelist| for the buffer {buf}. For the use
3810 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3811 exist, an empty list is returned.
3812
3813 The returned list contains two entries: a list with the change
3814 locations and the current position in the list. Each
3815 entry in the change list is a dictionary with the following
3816 entries:
3817 col column number
3818 coladd column offset for 'virtualedit'
3819 lnum line number
3820 If buffer {buf} is the current buffer, then the current
3821 position refers to the position in the list. For other
3822 buffers, it is set to the length of the list.
3823
3824 Can also be used as a |method|: >
3825 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003826<
3827 Return type: list<any>
3828
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003829
Doug Kearns9cd9e752024-04-07 17:42:17 +02003830getchar([{expr}]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003831 Get a single character from the user or input stream.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003832 If {expr} is omitted, wait until a character is available.
3833 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003834 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003835 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003836 not consumed. Return zero if no character available.
3837 If you prefer always getting a string use |getcharstr()|.
3838
Doug Kearns9cd9e752024-04-07 17:42:17 +02003839 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003840 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003841 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003842 Otherwise a String is returned with the encoded character.
3843 For a special key it's a String with a sequence of bytes
3844 starting with 0x80 (decimal: 128). This is the same value as
3845 the String "\<Key>", e.g., "\<Left>". The returned value is
3846 also a String when a modifier (shift, control, alt) was used
3847 that is not included in the character.
3848
Doug Kearns9cd9e752024-04-07 17:42:17 +02003849 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003850 while Vim waits to see if this is the start of an escape
3851 sequence.
3852
Doug Kearns9cd9e752024-04-07 17:42:17 +02003853 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003854 one-byte character it is the character itself as a number.
3855 Use nr2char() to convert it to a String.
3856
3857 Use getcharmod() to obtain any additional modifiers.
3858
3859 When the user clicks a mouse button, the mouse event will be
3860 returned. The position can then be found in |v:mouse_col|,
3861 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3862 |getmousepos()| can also be used. Mouse move events will be
3863 ignored.
3864 This example positions the mouse as it would normally happen: >
3865 let c = getchar()
3866 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003867 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003868 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003869 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003870 endif
3871<
3872 When using bracketed paste only the first character is
3873 returned, the rest of the pasted text is dropped.
3874 |xterm-bracketed-paste|.
3875
3876 There is no prompt, you will somehow have to make clear to the
3877 user that a character has to be typed. The screen is not
3878 redrawn, e.g. when resizing the window. When using a popup
3879 window it should work better with a |popup-filter|.
3880
3881 There is no mapping for the character.
3882 Key codes are replaced, thus when the user presses the <Del>
3883 key you get the code for the <Del> key, not the raw character
3884 sequence. Examples: >
3885 getchar() == "\<Del>"
3886 getchar() == "\<S-Left>"
3887< This example redefines "f" to ignore case: >
3888 :nmap f :call FindChar()<CR>
3889 :function FindChar()
3890 : let c = nr2char(getchar())
3891 : while col('.') < col('$') - 1
3892 : normal l
3893 : if getline('.')[col('.') - 1] ==? c
3894 : break
3895 : endif
3896 : endwhile
3897 :endfunction
3898<
3899 You may also receive synthetic characters, such as
3900 |<CursorHold>|. Often you will want to ignore this and get
3901 another character: >
3902 :function GetKey()
3903 : let c = getchar()
3904 : while c == "\<CursorHold>"
3905 : let c = getchar()
3906 : endwhile
3907 : return c
3908 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003909<
3910 Return type: |Number| or |String|
3911
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003912
3913getcharmod() *getcharmod()*
3914 The result is a Number which is the state of the modifiers for
3915 the last obtained character with getchar() or in another way.
3916 These values are added together:
3917 2 shift
3918 4 control
3919 8 alt (meta)
3920 16 meta (when it's different from ALT)
3921 32 mouse double click
3922 64 mouse triple click
3923 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01003924 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003925 Only the modifiers that have not been included in the
3926 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01003927 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003928
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003929 Return type: |Number|
3930
3931
3932getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003933 Get the position for String {expr}. Same as |getpos()| but the
3934 column number in the returned List is a character index
3935 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00003936 If |getpos()| returns a very large column number, equal to
3937 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003938 of the last character.
3939
3940 Example:
3941 With the cursor on '세' in line 5 with text "여보세요": >
3942 getcharpos('.') returns [0, 5, 3, 0]
3943 getpos('.') returns [0, 5, 7, 0]
3944<
3945 Can also be used as a |method|: >
3946 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003947<
3948 Return type: list<number>
3949
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003950
3951getcharsearch() *getcharsearch()*
3952 Return the current character search information as a {dict}
3953 with the following entries:
3954
3955 char character previously used for a character
3956 search (|t|, |f|, |T|, or |F|); empty string
3957 if no character search has been performed
3958 forward direction of character search; 1 for forward,
3959 0 for backward
3960 until type of character search; 1 for a |t| or |T|
3961 character search, 0 for an |f| or |F|
3962 character search
3963
3964 This can be useful to always have |;| and |,| search
3965 forward/backward regardless of the direction of the previous
3966 character search: >
3967 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
3968 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
3969< Also see |setcharsearch()|.
3970
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003971 Return type: dict<any>
3972
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003973
Doug Kearns9cd9e752024-04-07 17:42:17 +02003974getcharstr([{expr}]) *getcharstr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003975 Get a single character from the user or input stream as a
3976 string.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003977 If {expr} is omitted, wait until a character is available.
3978 If {expr} is 0 or false, only get a character when one is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003979 available. Return an empty string otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003980 If {expr} is 1 or true, only check if a character is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003981 available, it is not consumed. Return an empty string
3982 if no character is available.
3983 Otherwise this works like |getchar()|, except that a number
3984 result is converted to a string.
3985
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003986 Return type: |String|
3987
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003988getcmdcomplpat() *getcmdcomplpat()*
3989 Return completion pattern of the current command-line.
3990 Only works when the command line is being edited, thus
3991 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
3992 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
3993 |getcmdprompt()|, |getcmdcompltype()| and |setcmdline()|.
3994 Returns an empty string when completion is not defined.
3995
3996 Return type: |String|
3997
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003998
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003999getcmdcompltype() *getcmdcompltype()*
4000 Return the type of the current command-line completion.
4001 Only works when the command line is being edited, thus
4002 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01004003 See |:command-completion| for the return string.
Shougo Matsushita69084282024-09-23 20:34:47 +02004004 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004005 |getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004006 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004007
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004008 Return type: |String|
4009
4010
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004011getcmdline() *getcmdline()*
Shougo Matsushita69084282024-09-23 20:34:47 +02004012 Return the current command-line input. Only works when the
4013 command line is being edited, thus requires use of
4014 |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004015 Example: >
4016 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita69084282024-09-23 20:34:47 +02004017< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()|,
4018 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004019 Returns an empty string when entering a password or using
4020 |inputsecret()|.
4021
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004022 Return type: |String|
4023
4024
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004025getcmdpos() *getcmdpos()*
4026 Return the position of the cursor in the command line as a
4027 byte count. The first column is 1.
4028 Only works when editing the command line, thus requires use of
4029 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4030 Returns 0 otherwise.
Shougo Matsushita69084282024-09-23 20:34:47 +02004031 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4032 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004033
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004034 Return type: |Number|
4035
4036
Shougo Matsushita69084282024-09-23 20:34:47 +02004037getcmdprompt() *getcmdprompt()*
4038 Return the current command-line prompt when using functions
4039 like |input()| or |confirm()|.
4040 Only works when the command line is being edited, thus
4041 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4042 Also see |getcmdtype()|, |getcmdline()|, |getcmdpos()|,
4043 |setcmdpos()| and |setcmdline()|.
4044
4045 Return type: |String|
4046
4047
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004048getcmdscreenpos() *getcmdscreenpos()*
4049 Return the screen position of the cursor in the command line
4050 as a byte count. The first column is 1.
4051 Instead of |getcmdpos()|, it adds the prompt position.
4052 Only works when editing the command line, thus requires use of
4053 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4054 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004055 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
4056 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004057
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004058 Return type: |Number|
4059
4060
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004061getcmdtype() *getcmdtype()*
4062 Return the current command-line type. Possible return values
4063 are:
4064 : normal Ex command
4065 > debug mode command |debug-mode|
4066 / forward search command
4067 ? backward search command
4068 @ |input()| command
4069 - |:insert| or |:append| command
4070 = |i_CTRL-R_=|
4071 Only works when editing the command line, thus requires use of
4072 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4073 Returns an empty string otherwise.
4074 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4075
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004076 Return type: |String|
4077
4078
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004079getcmdwintype() *getcmdwintype()*
4080 Return the current |command-line-window| type. Possible return
4081 values are the same as |getcmdtype()|. Returns an empty string
4082 when not in the command-line window.
4083
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004084 Return type: |String|
4085
4086
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004087getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4088 Return a list of command-line completion matches. The String
4089 {type} argument specifies what for. The following completion
4090 types are supported:
4091
4092 arglist file names in argument list
4093 augroup autocmd groups
4094 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004095 behave |:behave| suboptions
4096 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004097 color color schemes
4098 command Ex command
4099 cmdline |cmdline-completion| result
4100 compiler compilers
4101 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004102 custom,{func} custom completion, defined via {func}
4103 customlist,{func} custom completion, defined via {func}
zeertzjq85f36d62024-10-10 19:14:13 +02004104 diff_buffer |:diffget| and |:diffput| completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004105 dir directory names
LemonBoya20bf692024-07-11 22:35:53 +02004106 dir_in_path directory names in |'cdpath'|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004107 environment environment variable names
4108 event autocommand events
4109 expression Vim expression
4110 file file and directory names
4111 file_in_path file and directory names in |'path'|
4112 filetype filetype names |'filetype'|
4113 function function name
4114 help help subjects
4115 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004116 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004117 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004118 locale locale names (as output of locale -a)
4119 mapclear buffer argument
4120 mapping mapping name
4121 menu menus
4122 messages |:messages| suboptions
4123 option options
4124 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004125 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004126 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004127 shellcmd Shell command
zeertzjq85f36d62024-10-10 19:14:13 +02004128 shellcmdline Shell command line with filename arguments
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004129 sign |:sign| suboptions
4130 syntax syntax file names |'syntax'|
4131 syntime |:syntime| suboptions
4132 tag tags
4133 tag_listfiles tags, file names
4134 user user names
4135 var user variables
4136
4137 If {pat} is an empty string, then all the matches are
4138 returned. Otherwise only items matching {pat} are returned.
4139 See |wildcards| for the use of special characters in {pat}.
4140
4141 If the optional {filtered} flag is set to 1, then 'wildignore'
4142 is applied to filter the results. Otherwise all the matches
4143 are returned. The 'wildignorecase' option always applies.
4144
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004145 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4146 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004147 regular expression matching is used. Thus this function
4148 follows the user preference, what happens on the command line.
4149 If you do not want this you can make 'wildoptions' empty
4150 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004151
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004152 If {type} is "cmdline", then the |cmdline-completion| result is
4153 returned. For example, to complete the possible values after
4154 a ":call" command: >
4155 echo getcompletion('call ', 'cmdline')
4156<
4157 If there are no matches, an empty list is returned. An
4158 invalid value for {type} produces an error.
4159
4160 Can also be used as a |method|: >
4161 GetPattern()->getcompletion('color')
4162<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004163 Return type: list<string>
4164
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004165 *getcurpos()*
4166getcurpos([{winid}])
4167 Get the position of the cursor. This is like getpos('.'), but
4168 includes an extra "curswant" item in the list:
4169 [0, lnum, col, off, curswant] ~
4170 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004171 cursor vertically. After |$| command it will be a very large
4172 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004173 |getpos()|.
4174 The first "bufnum" item is always zero. The byte position of
4175 the cursor is returned in 'col'. To get the character
4176 position, use |getcursorcharpos()|.
4177
4178 The optional {winid} argument can specify the window. It can
4179 be the window number or the |window-ID|. The last known
4180 cursor position is returned, this may be invalid for the
4181 current value of the buffer if it is not the current window.
4182 If {winid} is invalid a list with zeroes is returned.
4183
4184 This can be used to save and restore the cursor position: >
4185 let save_cursor = getcurpos()
4186 MoveTheCursorAround
4187 call setpos('.', save_cursor)
4188< Note that this only works within the window. See
4189 |winrestview()| for restoring more state.
4190
4191 Can also be used as a |method|: >
4192 GetWinid()->getcurpos()
4193<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004194 Return type: list<number>
4195
4196
4197getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004198 Same as |getcurpos()| but the column number in the returned
4199 List is a character index instead of a byte index.
4200
4201 Example:
4202 With the cursor on '보' in line 3 with text "여보세요": >
4203 getcursorcharpos() returns [0, 3, 2, 0, 3]
4204 getcurpos() returns [0, 3, 4, 0, 3]
4205<
4206 Can also be used as a |method|: >
4207 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004208<
4209 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004210
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004211
4212getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004213 The result is a String, which is the name of the current
4214 working directory. 'autochdir' is ignored.
4215
4216 With {winnr} return the local current directory of this window
4217 in the current tab page. {winnr} can be the window number or
4218 the |window-ID|.
4219 If {winnr} is -1 return the name of the global working
4220 directory. See also |haslocaldir()|.
4221
4222 With {winnr} and {tabnr} return the local current directory of
4223 the window in the specified tab page. If {winnr} is -1 return
4224 the working directory of the tabpage.
4225 If {winnr} is zero use the current window, if {tabnr} is zero
4226 use the current tabpage.
4227 Without any arguments, return the actual working directory of
4228 the current window.
4229 Return an empty string if the arguments are invalid.
4230
4231 Examples: >
4232 " Get the working directory of the current window
4233 :echo getcwd()
4234 :echo getcwd(0)
4235 :echo getcwd(0, 0)
4236 " Get the working directory of window 3 in tabpage 2
4237 :echo getcwd(3, 2)
4238 " Get the global working directory
4239 :echo getcwd(-1)
4240 " Get the working directory of tabpage 3
4241 :echo getcwd(-1, 3)
4242 " Get the working directory of current tabpage
4243 :echo getcwd(-1, 0)
4244
4245< Can also be used as a |method|: >
4246 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004247<
4248 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004249
4250getenv({name}) *getenv()*
4251 Return the value of environment variable {name}. The {name}
4252 argument is a string, without a leading '$'. Example: >
4253 myHome = getenv('HOME')
4254
4255< When the variable does not exist |v:null| is returned. That
4256 is different from a variable set to an empty string, although
4257 some systems interpret the empty value as the variable being
4258 deleted. See also |expr-env|.
4259
4260 Can also be used as a |method|: >
4261 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004262<
4263 Return type: |String| or |Number|
4264
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004265
4266getfontname([{name}]) *getfontname()*
4267 Without an argument returns the name of the normal font being
4268 used. Like what is used for the Normal highlight group
4269 |hl-Normal|.
4270 With an argument a check is done whether String {name} is a
4271 valid font name. If not then an empty string is returned.
4272 Otherwise the actual font name is returned, or {name} if the
4273 GUI does not support obtaining the real name.
4274 Only works when the GUI is running, thus not in your vimrc or
4275 gvimrc file. Use the |GUIEnter| autocommand to use this
4276 function just after the GUI has started.
4277 Note that the GTK GUI accepts any font name, thus checking for
4278 a valid name does not work.
4279
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004280 Return type: |String|
4281
4282
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004283getfperm({fname}) *getfperm()*
4284 The result is a String, which is the read, write, and execute
4285 permissions of the given file {fname}.
4286 If {fname} does not exist or its directory cannot be read, an
4287 empty string is returned.
4288 The result is of the form "rwxrwxrwx", where each group of
4289 "rwx" flags represent, in turn, the permissions of the owner
4290 of the file, the group the file belongs to, and other users.
4291 If a user does not have a given permission the flag for this
4292 is replaced with the string "-". Examples: >
4293 :echo getfperm("/etc/passwd")
4294 :echo getfperm(expand("~/.vimrc"))
4295< This will hopefully (from a security point of view) display
4296 the string "rw-r--r--" or even "rw-------".
4297
4298 Can also be used as a |method|: >
4299 GetFilename()->getfperm()
4300<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004301 Return type: |String|
4302
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004303 For setting permissions use |setfperm()|.
4304
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004305
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004306getfsize({fname}) *getfsize()*
4307 The result is a Number, which is the size in bytes of the
4308 given file {fname}.
4309 If {fname} is a directory, 0 is returned.
4310 If the file {fname} can't be found, -1 is returned.
4311 If the size of {fname} is too big to fit in a Number then -2
4312 is returned.
4313
4314 Can also be used as a |method|: >
4315 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004316<
4317 Return type: |Number|
4318
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004319
4320getftime({fname}) *getftime()*
4321 The result is a Number, which is the last modification time of
4322 the given file {fname}. The value is measured as seconds
4323 since 1st Jan 1970, and may be passed to strftime(). See also
4324 |localtime()| and |strftime()|.
4325 If the file {fname} can't be found -1 is returned.
4326
4327 Can also be used as a |method|: >
4328 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004329<
4330 Return type: |Number|
4331
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004332
4333getftype({fname}) *getftype()*
4334 The result is a String, which is a description of the kind of
4335 file of the given file {fname}.
4336 If {fname} does not exist an empty string is returned.
4337 Here is a table over different kinds of files and their
4338 results:
4339 Normal file "file"
4340 Directory "dir"
4341 Symbolic link "link"
4342 Block device "bdev"
4343 Character device "cdev"
4344 Socket "socket"
4345 FIFO "fifo"
4346 All other "other"
4347 Example: >
4348 getftype("/home")
4349< Note that a type such as "link" will only be returned on
4350 systems that support it. On some systems only "dir" and
4351 "file" are returned. On MS-Windows a symbolic link to a
4352 directory returns "dir" instead of "link".
4353
4354 Can also be used as a |method|: >
4355 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004356<
4357 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004358
4359getimstatus() *getimstatus()*
4360 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004361 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004362 See 'imstatusfunc'.
4363
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004364 Return type: |Number|
4365
4366
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004367getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4368 Returns the |jumplist| for the specified window.
4369
4370 Without arguments use the current window.
4371 With {winnr} only use this window in the current tab page.
4372 {winnr} can also be a |window-ID|.
4373 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004374 page. If {winnr} or {tabnr} is invalid, an empty list is
4375 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004376
4377 The returned list contains two entries: a list with the jump
4378 locations and the last used jump position number in the list.
4379 Each entry in the jump location list is a dictionary with
4380 the following entries:
4381 bufnr buffer number
4382 col column number
4383 coladd column offset for 'virtualedit'
4384 filename filename if available
4385 lnum line number
4386
4387 Can also be used as a |method|: >
4388 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004389<
4390 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004391
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004392 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004393getline({lnum} [, {end}])
4394 Without {end} the result is a String, which is line {lnum}
4395 from the current buffer. Example: >
4396 getline(1)
4397< When {lnum} is a String that doesn't start with a
4398 digit, |line()| is called to translate the String into a Number.
4399 To get the line under the cursor: >
4400 getline(".")
4401< When {lnum} is a number smaller than 1 or bigger than the
4402 number of lines in the buffer, an empty string is returned.
4403
4404 When {end} is given the result is a |List| where each item is
4405 a line from the current buffer in the range {lnum} to {end},
4406 including line {end}.
4407 {end} is used in the same way as {lnum}.
4408 Non-existing lines are silently omitted.
4409 When {end} is before {lnum} an empty |List| is returned.
4410 Example: >
4411 :let start = line('.')
4412 :let end = search("^$") - 1
4413 :let lines = getline(start, end)
4414
4415< Can also be used as a |method|: >
4416 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004417<
4418 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004419
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004420 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004421 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004422
4423getloclist({nr} [, {what}]) *getloclist()*
4424 Returns a |List| with all the entries in the location list for
4425 window {nr}. {nr} can be the window number or the |window-ID|.
4426 When {nr} is zero the current window is used.
4427
4428 For a location list window, the displayed location list is
4429 returned. For an invalid window number {nr}, an empty list is
4430 returned. Otherwise, same as |getqflist()|.
4431
4432 If the optional {what} dictionary argument is supplied, then
4433 returns the items listed in {what} as a dictionary. Refer to
4434 |getqflist()| for the supported items in {what}.
4435
4436 In addition to the items supported by |getqflist()| in {what},
4437 the following item is supported by |getloclist()|:
4438
4439 filewinid id of the window used to display files
4440 from the location list. This field is
4441 applicable only when called from a
4442 location list window. See
4443 |location-list-file-window| for more
4444 details.
4445
4446 Returns a |Dictionary| with default values if there is no
4447 location list for the window {nr}.
4448 Returns an empty Dictionary if window {nr} does not exist.
4449
4450 Examples (See also |getqflist-examples|): >
4451 :echo getloclist(3, {'all': 0})
4452 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004453<
4454 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004455
4456
4457getmarklist([{buf}]) *getmarklist()*
4458 Without the {buf} argument returns a |List| with information
4459 about all the global marks. |mark|
4460
4461 If the optional {buf} argument is specified, returns the
4462 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004463 see |bufname()|. If {buf} is invalid, an empty list is
4464 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004465
4466 Each item in the returned List is a |Dict| with the following:
4467 mark name of the mark prefixed by "'"
4468 pos a |List| with the position of the mark:
4469 [bufnum, lnum, col, off]
4470 Refer to |getpos()| for more information.
4471 file file name
4472
4473 Refer to |getpos()| for getting information about a specific
4474 mark.
4475
4476 Can also be used as a |method|: >
4477 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004478<
4479 Return type: list<dict<any>> or list<any>
4480
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004481
4482getmatches([{win}]) *getmatches()*
4483 Returns a |List| with all matches previously defined for the
4484 current window by |matchadd()| and the |:match| commands.
4485 |getmatches()| is useful in combination with |setmatches()|,
4486 as |setmatches()| can restore a list of matches saved by
4487 |getmatches()|.
4488 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004489 window ID instead of the current window. If {win} is invalid,
4490 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004491 Example: >
4492 :echo getmatches()
4493< [{'group': 'MyGroup1', 'pattern': 'TODO',
4494 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4495 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4496 :let m = getmatches()
4497 :call clearmatches()
4498 :echo getmatches()
4499< [] >
4500 :call setmatches(m)
4501 :echo getmatches()
4502< [{'group': 'MyGroup1', 'pattern': 'TODO',
4503 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4504 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4505 :unlet m
4506<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004507 Return type: list<dict<any>> or list<any>
4508
4509
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004510getmousepos() *getmousepos()*
4511 Returns a |Dictionary| with the last known position of the
4512 mouse. This can be used in a mapping for a mouse click or in
4513 a filter of a popup window. The items are:
4514 screenrow screen row
4515 screencol screen column
4516 winid Window ID of the click
4517 winrow row inside "winid"
4518 wincol column inside "winid"
4519 line text line inside "winid"
4520 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004521 coladd offset (in screen columns) from the
4522 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004523 All numbers are 1-based.
4524
4525 If not over a window, e.g. when in the command line, then only
4526 "screenrow" and "screencol" are valid, the others are zero.
4527
4528 When on the status line below a window or the vertical
4529 separator right of a window, the "line" and "column" values
4530 are zero.
4531
4532 When the position is after the text then "column" is the
4533 length of the text in bytes plus one.
4534
4535 If the mouse is over a popup window then that window is used.
4536
4537 When using |getchar()| the Vim variables |v:mouse_lnum|,
4538 |v:mouse_col| and |v:mouse_winid| also provide these values.
4539
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004540 Return type: dict<number>
4541
4542
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004543getmouseshape() *getmouseshape()*
4544 Returns the name of the currently showing mouse pointer.
4545 When the |+mouseshape| feature is not supported or the shape
4546 is unknown an empty string is returned.
4547 This function is mainly intended for testing.
4548
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004549 Return type: |String|
4550
4551
4552getpid() *getpid()*
4553 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004554 On Unix and MS-Windows this is a unique number, until Vim
4555 exits.
4556
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004557 Return type: |Number|
4558
4559
4560getpos({expr}) *getpos()*
zeertzjq02f3eba2024-06-12 20:45:24 +02004561 Get the position for String {expr}.
4562 The accepted values for {expr} are: *E1209*
4563 . The cursor position.
4564 $ The last line in the current buffer.
4565 'x Position of mark x (if the mark is not set, 0 is
zeertzjqd353d272024-06-13 23:00:25 +08004566 returned for all values).
zeertzjq02f3eba2024-06-12 20:45:24 +02004567 w0 First line visible in current window (one if the
4568 display isn't updated, e.g. in silent Ex mode).
4569 w$ Last line visible in current window (this is one
4570 less than "w0" if no lines are visible).
4571 v When not in Visual mode, returns the cursor
4572 position. In Visual mode, returns the other end
4573 of the Visual area. A good way to think about
4574 this is that in Visual mode "v" and "." complement
4575 each other. While "." refers to the cursor
4576 position, "v" refers to where |v_o| would move the
4577 cursor. As a result, you can use "v" and "."
4578 together to work on all of a selection in
4579 characterwise Visual mode. If the cursor is at
4580 the end of a characterwise Visual area, "v" refers
4581 to the start of the same Visual area. And if the
4582 cursor is at the start of a characterwise Visual
4583 area, "v" refers to the end of the same Visual
4584 area. "v" differs from |'<| and |'>| in that it's
4585 updated right away.
4586 Note that a mark in another file can be used. The line number
4587 then applies to another buffer.
4588
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004589 The result is a |List| with four numbers:
4590 [bufnum, lnum, col, off]
4591 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4592 is the buffer number of the mark.
4593 "lnum" and "col" are the position in the buffer. The first
4594 column is 1.
4595 The "off" number is zero, unless 'virtualedit' is used. Then
4596 it is the offset in screen columns from the start of the
4597 character. E.g., a position within a <Tab> or after the last
4598 character.
zeertzjq02f3eba2024-06-12 20:45:24 +02004599
4600 For getting the cursor position see |getcurpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004601 The column number in the returned List is the byte position
4602 within the line. To get the character position in the line,
4603 use |getcharpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02004604
4605 Note that for '< and '> Visual mode matters: when it is "V"
4606 (visual line mode) the column of '< is zero and the column of
4607 '> is a large number equal to |v:maxcol|.
naohiro ono56200ee2022-01-01 14:59:44 +00004608 A very large column number equal to |v:maxcol| can be returned,
4609 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004610 If {expr} is invalid, returns a list with all zeros.
zeertzjq02f3eba2024-06-12 20:45:24 +02004611
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004612 This can be used to save and restore the position of a mark: >
4613 let save_a_mark = getpos("'a")
4614 ...
4615 call setpos("'a", save_a_mark)
zeertzjqd353d272024-06-13 23:00:25 +08004616<
4617 Also see |getcharpos()|, |getcurpos()| and |setpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004618
4619 Can also be used as a |method|: >
4620 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004621<
4622 Return type: list<number>
4623
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004624
4625getqflist([{what}]) *getqflist()*
4626 Returns a |List| with all the current quickfix errors. Each
4627 list item is a dictionary with these entries:
4628 bufnr number of buffer that has the file name, use
4629 bufname() to get the name
4630 module module name
4631 lnum line number in the buffer (first line is 1)
4632 end_lnum
4633 end of line number if the item is multiline
4634 col column number (first column is 1)
4635 end_col end of column number if the item has range
4636 vcol |TRUE|: "col" is visual column
4637 |FALSE|: "col" is byte index
4638 nr error number
h-east84ac2122024-06-17 18:12:30 +02004639 pattern search pattern used to locate the error
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004640 text description of the error
4641 type type of the error, 'E', '1', etc.
4642 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004643 user_data
4644 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004645 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004646
4647 When there is no error list or it's empty, an empty list is
4648 returned. Quickfix list entries with a non-existing buffer
4649 number are returned with "bufnr" set to zero (Note: some
4650 functions accept buffer number zero for the alternate buffer,
4651 you may need to explicitly check for zero).
4652
4653 Useful application: Find pattern matches in multiple files and
4654 do something with them: >
4655 :vimgrep /theword/jg *.c
4656 :for d in getqflist()
4657 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4658 :endfor
4659<
4660 If the optional {what} dictionary argument is supplied, then
4661 returns only the items listed in {what} as a dictionary. The
4662 following string items are supported in {what}:
4663 changedtick get the total number of changes made
4664 to the list |quickfix-changedtick|
4665 context get the |quickfix-context|
4666 efm errorformat to use when parsing "lines". If
4667 not present, then the 'errorformat' option
4668 value is used.
4669 id get information for the quickfix list with
4670 |quickfix-ID|; zero means the id for the
4671 current list or the list specified by "nr"
4672 idx get information for the quickfix entry at this
4673 index in the list specified by 'id' or 'nr'.
4674 If set to zero, then uses the current entry.
4675 See |quickfix-index|
4676 items quickfix list entries
4677 lines parse a list of lines using 'efm' and return
4678 the resulting entries. Only a |List| type is
4679 accepted. The current quickfix list is not
4680 modified. See |quickfix-parse|.
4681 nr get information for this quickfix list; zero
4682 means the current quickfix list and "$" means
4683 the last quickfix list
4684 qfbufnr number of the buffer displayed in the quickfix
4685 window. Returns 0 if the quickfix buffer is
4686 not present. See |quickfix-buffer|.
4687 size number of entries in the quickfix list
4688 title get the list title |quickfix-title|
4689 winid get the quickfix |window-ID|
4690 all all of the above quickfix properties
4691 Non-string items in {what} are ignored. To get the value of a
4692 particular item, set it to zero.
4693 If "nr" is not present then the current quickfix list is used.
4694 If both "nr" and a non-zero "id" are specified, then the list
4695 specified by "id" is used.
4696 To get the number of lists in the quickfix stack, set "nr" to
4697 "$" in {what}. The "nr" value in the returned dictionary
4698 contains the quickfix stack size.
4699 When "lines" is specified, all the other items except "efm"
4700 are ignored. The returned dictionary contains the entry
4701 "items" with the list of entries.
4702
4703 The returned dictionary contains the following entries:
4704 changedtick total number of changes made to the
4705 list |quickfix-changedtick|
4706 context quickfix list context. See |quickfix-context|
4707 If not present, set to "".
4708 id quickfix list ID |quickfix-ID|. If not
4709 present, set to 0.
4710 idx index of the quickfix entry in the list. If not
4711 present, set to 0.
4712 items quickfix list entries. If not present, set to
4713 an empty list.
4714 nr quickfix list number. If not present, set to 0
4715 qfbufnr number of the buffer displayed in the quickfix
4716 window. If not present, set to 0.
4717 size number of entries in the quickfix list. If not
4718 present, set to 0.
4719 title quickfix list title text. If not present, set
4720 to "".
4721 winid quickfix |window-ID|. If not present, set to 0
4722
4723 Examples (See also |getqflist-examples|): >
4724 :echo getqflist({'all': 1})
4725 :echo getqflist({'nr': 2, 'title': 1})
4726 :echo getqflist({'lines' : ["F1:10:L10"]})
4727<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004728 Return type: list<dict<any>> or list<any>
4729
4730
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004731getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4732 The result is a String, which is the contents of register
4733 {regname}. Example: >
4734 :let cliptext = getreg('*')
4735< When register {regname} was not set the result is an empty
4736 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004737 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004738
4739 getreg('=') returns the last evaluated value of the expression
4740 register. (For use in maps.)
4741 getreg('=', 1) returns the expression itself, so that it can
4742 be restored with |setreg()|. For other registers the extra
4743 argument is ignored, thus you can always give it.
4744
4745 If {list} is present and |TRUE|, the result type is changed
4746 to |List|. Each list item is one text line. Use it if you care
4747 about zero bytes possibly present inside register: without
4748 third argument both NLs and zero bytes are represented as NLs
4749 (see |NL-used-for-Nul|).
4750 When the register was not set an empty list is returned.
4751
4752 If {regname} is "", the unnamed register '"' is used.
4753 If {regname} is not specified, |v:register| is used.
4754 In |Vim9-script| {regname} must be one character.
4755
4756 Can also be used as a |method|: >
4757 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004758<
4759 Return type: |String|
4760
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004761
4762getreginfo([{regname}]) *getreginfo()*
4763 Returns detailed information about register {regname} as a
4764 Dictionary with the following entries:
4765 regcontents List of lines contained in register
4766 {regname}, like
4767 |getreg|({regname}, 1, 1).
4768 regtype the type of register {regname}, as in
4769 |getregtype()|.
4770 isunnamed Boolean flag, v:true if this register
4771 is currently pointed to by the unnamed
4772 register.
4773 points_to for the unnamed register, gives the
4774 single letter name of the register
4775 currently pointed to (see |quotequote|).
4776 For example, after deleting a line
4777 with `dd`, this field will be "1",
4778 which is the register that got the
4779 deleted text.
4780
4781 The {regname} argument is a string. If {regname} is invalid
4782 or not set, an empty Dictionary will be returned.
4783 If {regname} is "" or "@", the unnamed register '"' is used.
4784 If {regname} is not specified, |v:register| is used.
4785 The returned Dictionary can be passed to |setreg()|.
4786 In |Vim9-script| {regname} must be one character.
4787
4788 Can also be used as a |method|: >
4789 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004790<
4791 Return type: dict<any>
4792
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004793
Shougo Matsushita19b71882024-02-28 22:48:12 +01004794getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004795 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01004796 buffer.
4797
4798 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004799 See |getpos()| for the format of the list. It's possible
4800 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01004801 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01004802
4803 The optional argument {opts} is a Dict and supports the
4804 following items:
4805
zeertzjqafc22952024-05-24 19:07:12 +02004806 type Specify the region's selection type.
4807 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02004808 except that the width can be omitted
4809 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02004810 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01004811
zeertzjq87410ab2024-03-02 06:00:23 +08004812 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02004813 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08004814 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01004815
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004816 You can get the last selection type by |visualmode()|.
4817 If Visual mode is active, use |mode()| to get the Visual mode
4818 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08004819 This function is useful to get text starting and ending in
4820 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004821
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004822 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004823 Note that:
4824 - Order of {pos1} and {pos2} doesn't matter, it will always
4825 return content from the upper left position to the lower
4826 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08004827 - If 'virtualedit' is enabled and the region is past the end
4828 of the lines, resulting lines are padded with spaces.
4829 - If the region is blockwise and it starts or ends in the
4830 middle of a multi-cell character, it is not included but
4831 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004832 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01004833 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004834 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01004835 - It is evaluated in current window context, which makes a
4836 difference if the buffer is displayed in a window with
4837 different 'virtualedit' or 'list' values.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004838
4839 Examples: >
4840 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01004841 \ <Cmd>echow getregion(
4842 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004843<
4844 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01004845 getpos('.')->getregion(getpos("'a"))
zeertzjqd4d12072024-07-16 20:34:16 +02004846<
4847 Return type: list<string>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004848
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01004849
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004850getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
4851 Same as |getregion()|, but returns a list of positions
4852 describing the buffer text segments bound by {pos1} and
4853 {pos2}.
4854 The segments are a pair of positions for every line: >
4855 [[{start_pos}, {end_pos}], ...]
4856<
4857 The position is a |List| with four numbers:
4858 [bufnum, lnum, col, off]
4859 "bufnum" is the buffer number.
4860 "lnum" and "col" are the position in the buffer. The first
4861 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02004862 If the "off" number of a starting position is non-zero, it is
4863 the offset in screen columns from the start of the character.
4864 E.g., a position within a <Tab> or after the last character.
4865 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02004866 the offset of the character's first cell not included in the
4867 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004868
zeertzjq2b09de92024-05-24 07:48:51 +02004869 Apart from the options supported by |getregion()|, {opts} also
4870 supports the following:
4871
4872 eol If |TRUE|, indicate positions beyond
4873 the end of a line with "col" values
4874 one more than the length of the line.
4875 If |FALSE|, positions are limited
4876 within their lines, and if a line is
4877 empty or the selection is entirely
4878 beyond the end of a line, a "col"
4879 value of 0 is used for both positions.
4880 (default: |FALSE|)
4881
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004882 Can also be used as a |method|: >
4883 getpos('.')->getregionpos(getpos("'a"))
4884<
zeertzjqd4d12072024-07-16 20:34:16 +02004885 Return type: list<list<list<number>>>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004886
4887
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004888getregtype([{regname}]) *getregtype()*
4889 The result is a String, which is type of register {regname}.
4890 The value will be one of:
4891 "v" for |characterwise| text
4892 "V" for |linewise| text
4893 "<CTRL-V>{width}" for |blockwise-visual| text
4894 "" for an empty or unknown register
4895 <CTRL-V> is one character with value 0x16.
4896 The {regname} argument is a string. If {regname} is "", the
4897 unnamed register '"' is used. If {regname} is not specified,
4898 |v:register| is used.
4899 In |Vim9-script| {regname} must be one character.
4900
4901 Can also be used as a |method|: >
4902 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004903<
4904 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004905
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01004906
Bram Moolenaar71badf92023-04-22 22:40:14 +01004907getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004908 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01004909 scripts in the order they were sourced, like what
4910 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004911
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004912 The optional Dict argument {opts} supports the following
4913 optional items:
4914 name Script name match pattern. If specified,
4915 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01004916 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004917 "name" are returned.
4918 sid Script ID |<SID>|. If specified, only
4919 information about the script with ID "sid" is
4920 returned and "name" is ignored.
4921
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004922 Each item in the returned List is a |Dict| with the following
4923 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004924 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01004925 `import autoload` but was not actually sourced
4926 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004927 functions List of script-local function names defined in
4928 the script. Present only when a particular
4929 script is specified using the "sid" item in
4930 {opts}.
4931 name Vim script file name.
4932 sid Script ID |<SID>|.
4933 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01004934 this script name links to, if any, otherwise
4935 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004936 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00004937 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004938 specified using the "sid" item in {opts}.
4939 Note that this is a copy, the value of
4940 script-local variables cannot be changed using
4941 this dictionary.
h_east59858792023-10-25 22:47:05 +09004942 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01004943
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004944 Examples: >
4945 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08004946 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004947<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004948 Return type: list<dict<any>>
4949
4950
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004951gettabinfo([{tabnr}]) *gettabinfo()*
4952 If {tabnr} is not specified, then information about all the
4953 tab pages is returned as a |List|. Each List item is a
4954 |Dictionary|. Otherwise, {tabnr} specifies the tab page
4955 number and information about that one is returned. If the tab
4956 page does not exist an empty List is returned.
4957
4958 Each List item is a |Dictionary| with the following entries:
4959 tabnr tab page number.
4960 variables a reference to the dictionary with
4961 tabpage-local variables
4962 windows List of |window-ID|s in the tab page.
4963
4964 Can also be used as a |method|: >
4965 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004966<
4967 Return type: list<dict<any>>
4968
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004969
4970gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
4971 Get the value of a tab-local variable {varname} in tab page
4972 {tabnr}. |t:var|
4973 Tabs are numbered starting with one.
4974 The {varname} argument is a string. When {varname} is empty a
4975 dictionary with all tab-local variables is returned.
4976 Note that the name without "t:" must be used.
4977 When the tab or variable doesn't exist {def} or an empty
4978 string is returned, there is no error message.
4979
4980 Can also be used as a |method|: >
4981 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004982<
4983 Return type: any, depending on {varname}
4984
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004985
4986gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
4987 Get the value of window-local variable {varname} in window
4988 {winnr} in tab page {tabnr}.
4989 The {varname} argument is a string. When {varname} is empty a
4990 dictionary with all window-local variables is returned.
4991 When {varname} is equal to "&" get the values of all
4992 window-local options in a |Dictionary|.
4993 Otherwise, when {varname} starts with "&" get the value of a
4994 window-local option.
4995 Note that {varname} must be the name without "w:".
4996 Tabs are numbered starting with one. For the current tabpage
4997 use |getwinvar()|.
4998 {winnr} can be the window number or the |window-ID|.
4999 When {winnr} is zero the current window is used.
5000 This also works for a global option, buffer-local option and
5001 window-local option, but it doesn't work for a global variable
5002 or buffer-local variable.
5003 When the tab, window or variable doesn't exist {def} or an
5004 empty string is returned, there is no error message.
5005 Examples: >
5006 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005007 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005008<
5009 To obtain all window-local variables use: >
5010 gettabwinvar({tabnr}, {winnr}, '&')
5011
5012< Can also be used as a |method|: >
5013 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005014<
5015 Return type: any, depending on {varname}
5016
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005017
5018gettagstack([{winnr}]) *gettagstack()*
5019 The result is a Dict, which is the tag stack of window {winnr}.
5020 {winnr} can be the window number or the |window-ID|.
5021 When {winnr} is not specified, the current window is used.
5022 When window {winnr} doesn't exist, an empty Dict is returned.
5023
5024 The returned dictionary contains the following entries:
5025 curidx Current index in the stack. When at
5026 top of the stack, set to (length + 1).
5027 Index of bottom of the stack is 1.
5028 items List of items in the stack. Each item
5029 is a dictionary containing the
5030 entries described below.
5031 length Number of entries in the stack.
5032
5033 Each item in the stack is a dictionary with the following
5034 entries:
5035 bufnr buffer number of the current jump
5036 from cursor position before the tag jump.
5037 See |getpos()| for the format of the
5038 returned list.
5039 matchnr current matching tag number. Used when
5040 multiple matching tags are found for a
5041 name.
5042 tagname name of the tag
5043
5044 See |tagstack| for more information about the tag stack.
5045
5046 Can also be used as a |method|: >
5047 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005048<
5049 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005050
5051
Christ van Willegence0ef912024-06-20 23:41:59 +02005052gettext({text} [, {package}]) *gettext()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005053 Translate String {text} if possible.
RestorerZ96509102024-07-11 21:14:15 +02005054 This is intended for use in Vim scripts. When generating
5055 message translations the {text} is extracted by `xgettext`,
5056 the translator can add translated messages into the .po file
5057 and Vim will lookup the translation when gettext() is called.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005058 For {text} double quoted strings are preferred, because
RestorerZ96509102024-07-11 21:14:15 +02005059 `xgettext` does not support single quoted escaped text.
5060
Christ van Willegence0ef912024-06-20 23:41:59 +02005061 When the {package} is specified, the translation is looked up
RestorerZ96509102024-07-11 21:14:15 +02005062 for that specific package. This is mainly required for
5063 third-party Vim scripts. You need to specify a path to the
5064 translations with the |bindtextdomain()| function before
5065 using the gettext() function.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005066
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005067 Return type: |String|
5068
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005069
5070getwininfo([{winid}]) *getwininfo()*
5071 Returns information about windows as a |List| with Dictionaries.
5072
5073 If {winid} is given Information about the window with that ID
5074 is returned, as a |List| with one item. If the window does not
5075 exist the result is an empty list.
5076
5077 Without {winid} information about all the windows in all the
5078 tab pages is returned.
5079
5080 Each List item is a |Dictionary| with the following entries:
5081 botline last complete displayed buffer line
5082 bufnr number of buffer in the window
5083 height window height (excluding winbar)
5084 loclist 1 if showing a location list
5085 {only with the +quickfix feature}
5086 quickfix 1 if quickfix or location list window
5087 {only with the +quickfix feature}
5088 terminal 1 if a terminal window
5089 {only with the +terminal feature}
5090 tabnr tab page number
5091 topline first displayed buffer line
5092 variables a reference to the dictionary with
5093 window-local variables
5094 width window width
5095 winbar 1 if the window has a toolbar, 0
5096 otherwise
5097 wincol leftmost screen column of the window;
5098 "col" from |win_screenpos()|
5099 textoff number of columns occupied by any
5100 'foldcolumn', 'signcolumn' and line
5101 number in front of the text
5102 winid |window-ID|
5103 winnr window number
5104 winrow topmost screen line of the window;
5105 "row" from |win_screenpos()|
5106
5107 Can also be used as a |method|: >
5108 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005109<
5110 Return type: list<dict<any>>
5111
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005112
5113getwinpos([{timeout}]) *getwinpos()*
5114 The result is a |List| with two numbers, the result of
5115 |getwinposx()| and |getwinposy()| combined:
5116 [x-pos, y-pos]
5117 {timeout} can be used to specify how long to wait in msec for
5118 a response from the terminal. When omitted 100 msec is used.
5119 Use a longer time for a remote terminal.
5120 When using a value less than 10 and no response is received
5121 within that time, a previously reported position is returned,
5122 if available. This can be used to poll for the position and
5123 do some work in the meantime: >
5124 while 1
5125 let res = getwinpos(1)
5126 if res[0] >= 0
5127 break
5128 endif
5129 " Do some work here
5130 endwhile
5131<
5132
5133 Can also be used as a |method|: >
5134 GetTimeout()->getwinpos()
5135<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005136 Return type: list<number>
5137
5138
5139getwinposx() *getwinposx()*
5140 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005141 the left hand side of the GUI Vim window. Also works for an
5142 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005143 The result will be -1 if the information is not available
5144 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005145 The value can be used with `:winpos`.
5146
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005147 Return type: |Number|
5148
5149
5150getwinposy() *getwinposy()*
5151 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005152 the top of the GUI Vim window. Also works for an xterm (uses
5153 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005154 The result will be -1 if the information is not available
5155 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005156 The value can be used with `:winpos`.
5157
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005158 Return type: |Number|
5159
5160
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005161getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5162 Like |gettabwinvar()| for the current tabpage.
5163 Examples: >
5164 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005165 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005166
5167< Can also be used as a |method|: >
5168 GetWinnr()->getwinvar(varname)
5169<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005170 Return type: any, depending on {varname}
5171
5172
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005173glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5174 Expand the file wildcards in {expr}. See |wildcards| for the
5175 use of special characters.
5176
5177 Unless the optional {nosuf} argument is given and is |TRUE|,
5178 the 'suffixes' and 'wildignore' options apply: Names matching
5179 one of the patterns in 'wildignore' will be skipped and
5180 'suffixes' affect the ordering of matches.
5181 'wildignorecase' always applies.
5182
5183 When {list} is present and it is |TRUE| the result is a |List|
5184 with all matching files. The advantage of using a List is,
5185 you also get filenames containing newlines correctly.
5186 Otherwise the result is a String and when there are several
5187 matches, they are separated by <NL> characters.
5188
5189 If the expansion fails, the result is an empty String or List.
5190
5191 You can also use |readdir()| if you need to do complicated
5192 things, such as limiting the number of matches.
5193
5194 A name for a non-existing file is not included. A symbolic
5195 link is only included if it points to an existing file.
5196 However, when the {alllinks} argument is present and it is
5197 |TRUE| then all symbolic links are included.
5198
5199 For most systems backticks can be used to get files names from
5200 any external command. Example: >
5201 :let tagfiles = glob("`find . -name tags -print`")
5202 :let &tags = substitute(tagfiles, "\n", ",", "g")
5203< The result of the program inside the backticks should be one
5204 item per line. Spaces inside an item are allowed.
5205
5206 See |expand()| for expanding special Vim variables. See
5207 |system()| for getting the raw output of an external command.
5208
5209 Can also be used as a |method|: >
5210 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005211<
5212 Return type: |String| or list<string> or list<any> depending
5213 on {list}
5214
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005215
h-east624bb832024-11-09 18:37:32 +01005216glob2regpat({string}) *glob2regpat()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005217 Convert a file pattern, as used by glob(), into a search
5218 pattern. The result can be used to match with a string that
5219 is a file name. E.g. >
5220 if filename =~ glob2regpat('Make*.mak')
5221< This is equivalent to: >
5222 if filename =~ '^Make.*\.mak$'
5223< When {string} is an empty string the result is "^$", match an
5224 empty string.
5225 Note that the result depends on the system. On MS-Windows
5226 a backslash usually means a path separator.
5227
5228 Can also be used as a |method|: >
5229 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005230<
5231 Return type: |String|
5232
5233 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005234globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5235 Perform glob() for String {expr} on all directories in {path}
5236 and concatenate the results. Example: >
5237 :echo globpath(&rtp, "syntax/c.vim")
5238<
5239 {path} is a comma-separated list of directory names. Each
5240 directory name is prepended to {expr} and expanded like with
5241 |glob()|. A path separator is inserted when needed.
5242 To add a comma inside a directory name escape it with a
5243 backslash. Note that on MS-Windows a directory may have a
5244 trailing backslash, remove it if you put a comma after it.
5245 If the expansion fails for one of the directories, there is no
5246 error message.
5247
5248 Unless the optional {nosuf} argument is given and is |TRUE|,
5249 the 'suffixes' and 'wildignore' options apply: Names matching
5250 one of the patterns in 'wildignore' will be skipped and
5251 'suffixes' affect the ordering of matches.
5252
5253 When {list} is present and it is |TRUE| the result is a |List|
5254 with all matching files. The advantage of using a List is, you
5255 also get filenames containing newlines correctly. Otherwise
5256 the result is a String and when there are several matches,
5257 they are separated by <NL> characters. Example: >
5258 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5259<
5260 {alllinks} is used as with |glob()|.
5261
5262 The "**" item can be used to search in a directory tree.
5263 For example, to find all "README.txt" files in the directories
5264 in 'runtimepath' and below: >
5265 :echo globpath(&rtp, "**/README.txt")
5266< Upwards search and limiting the depth of "**" is not
5267 supported, thus using 'path' will not always work properly.
5268
5269 Can also be used as a |method|, the base is passed as the
5270 second argument: >
5271 GetExpr()->globpath(&rtp)
5272<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005273 Return type: |String| or list<string> or list<any> depending
5274 on {list}
5275
5276
5277has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005278 When {check} is omitted or is zero: The result is a Number,
5279 which is 1 if the feature {feature} is supported, zero
5280 otherwise. The {feature} argument is a string, case is
5281 ignored. See |feature-list| below.
5282
5283 When {check} is present and not zero: The result is a Number,
5284 which is 1 if the feature {feature} could ever be supported,
5285 zero otherwise. This is useful to check for a typo in
5286 {feature} and to detect dead code. Keep in mind that an older
5287 Vim version will not know about a feature added later and
5288 features that have been abandoned will not be known by the
5289 current Vim version.
5290
5291 Also see |exists()| and |exists_compiled()|.
5292
5293 Note that to skip code that has a syntax error when the
5294 feature is not available, Vim may skip the rest of the line
5295 and miss a following `endif`. Therefore put the `endif` on a
5296 separate line: >
5297 if has('feature')
5298 let x = this->breaks->without->the->feature
5299 endif
5300< If the `endif` would be moved to the second line as "| endif" it
5301 would not be found.
5302
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005303 Return type: |Number|
5304
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005305
5306has_key({dict}, {key}) *has_key()*
5307 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005308 has an entry with key {key}. FALSE otherwise.
5309 The {key} argument is a string. In |Vim9| script a number is
5310 also accepted (and converted to a string) but no other types.
5311 In legacy script the usual automatic conversion to string is
5312 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005313
5314 Can also be used as a |method|: >
5315 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005316<
5317 Return type: |Number|
5318
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005319
5320haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5321 The result is a Number:
5322 1 when the window has set a local directory via |:lcd|
5323 2 when the tab-page has set a local directory via |:tcd|
5324 0 otherwise.
5325
5326 Without arguments use the current window.
5327 With {winnr} use this window in the current tab page.
5328 With {winnr} and {tabnr} use the window in the specified tab
5329 page.
5330 {winnr} can be the window number or the |window-ID|.
5331 If {winnr} is -1 it is ignored and only the tabpage is used.
5332 Return 0 if the arguments are invalid.
5333 Examples: >
5334 if haslocaldir() == 1
5335 " window local directory case
5336 elseif haslocaldir() == 2
5337 " tab-local directory case
5338 else
5339 " global directory case
5340 endif
5341
5342 " current window
5343 :echo haslocaldir()
5344 :echo haslocaldir(0)
5345 :echo haslocaldir(0, 0)
5346 " window n in current tab page
5347 :echo haslocaldir(n)
5348 :echo haslocaldir(n, 0)
5349 " window n in tab page m
5350 :echo haslocaldir(n, m)
5351 " tab page m
5352 :echo haslocaldir(-1, m)
5353<
5354 Can also be used as a |method|: >
5355 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005356<
5357 Return type: |Number|
5358
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005359
5360hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5361 The result is a Number, which is TRUE if there is a mapping
5362 that contains {what} in somewhere in the rhs (what it is
5363 mapped to) and this mapping exists in one of the modes
5364 indicated by {mode}.
5365 The arguments {what} and {mode} are strings.
5366 When {abbr} is there and it is |TRUE| use abbreviations
5367 instead of mappings. Don't forget to specify Insert and/or
5368 Command-line mode.
5369 Both the global mappings and the mappings local to the current
5370 buffer are checked for a match.
5371 If no matching mapping is found FALSE is returned.
5372 The following characters are recognized in {mode}:
5373 n Normal mode
5374 v Visual and Select mode
5375 x Visual mode
5376 s Select mode
5377 o Operator-pending mode
5378 i Insert mode
5379 l Language-Argument ("r", "f", "t", etc.)
5380 c Command-line mode
5381 When {mode} is omitted, "nvo" is used.
5382
5383 This function is useful to check if a mapping already exists
5384 to a function in a Vim script. Example: >
5385 :if !hasmapto('\ABCdoit')
5386 : map <Leader>d \ABCdoit
5387 :endif
5388< This installs the mapping to "\ABCdoit" only if there isn't
5389 already a mapping to "\ABCdoit".
5390
5391 Can also be used as a |method|: >
5392 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005393<
5394 Return type: |Number|
5395
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005396
5397histadd({history}, {item}) *histadd()*
5398 Add the String {item} to the history {history} which can be
5399 one of: *hist-names*
5400 "cmd" or ":" command line history
5401 "search" or "/" search pattern history
5402 "expr" or "=" typed expression history
5403 "input" or "@" input line history
5404 "debug" or ">" debug command history
5405 empty the current or last used history
5406 The {history} string does not need to be the whole name, one
5407 character is sufficient.
5408 If {item} does already exist in the history, it will be
5409 shifted to become the newest entry.
5410 The result is a Number: TRUE if the operation was successful,
5411 otherwise FALSE is returned.
5412
5413 Example: >
5414 :call histadd("input", strftime("%Y %b %d"))
5415 :let date=input("Enter date: ")
5416< This function is not available in the |sandbox|.
5417
5418 Can also be used as a |method|, the base is passed as the
5419 second argument: >
5420 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005421<
5422 Return type: |Number|
5423
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005424
5425histdel({history} [, {item}]) *histdel()*
5426 Clear {history}, i.e. delete all its entries. See |hist-names|
5427 for the possible values of {history}.
5428
5429 If the parameter {item} evaluates to a String, it is used as a
5430 regular expression. All entries matching that expression will
5431 be removed from the history (if there are any).
5432 Upper/lowercase must match, unless "\c" is used |/\c|.
5433 If {item} evaluates to a Number, it will be interpreted as
5434 an index, see |:history-indexing|. The respective entry will
5435 be removed if it exists.
5436
5437 The result is TRUE for a successful operation, otherwise FALSE
5438 is returned.
5439
5440 Examples:
5441 Clear expression register history: >
5442 :call histdel("expr")
5443<
5444 Remove all entries starting with "*" from the search history: >
5445 :call histdel("/", '^\*')
5446<
5447 The following three are equivalent: >
5448 :call histdel("search", histnr("search"))
5449 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005450 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005451<
5452 To delete the last search pattern and use the last-but-one for
5453 the "n" command and 'hlsearch': >
5454 :call histdel("search", -1)
5455 :let @/ = histget("search", -1)
5456<
5457 Can also be used as a |method|: >
5458 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005459<
5460 Return type: |Number|
5461
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005462
5463histget({history} [, {index}]) *histget()*
5464 The result is a String, the entry with Number {index} from
5465 {history}. See |hist-names| for the possible values of
5466 {history}, and |:history-indexing| for {index}. If there is
5467 no such entry, an empty String is returned. When {index} is
5468 omitted, the most recent item from the history is used.
5469
5470 Examples:
5471 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005472 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005473
5474< Define an Ex command ":H {num}" that supports re-execution of
5475 the {num}th entry from the output of |:history|. >
5476 :command -nargs=1 H execute histget("cmd", 0+<args>)
5477<
5478 Can also be used as a |method|: >
5479 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005480<
5481 Return type: |String|
5482
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005483
5484histnr({history}) *histnr()*
5485 The result is the Number of the current entry in {history}.
5486 See |hist-names| for the possible values of {history}.
5487 If an error occurred, -1 is returned.
5488
5489 Example: >
5490 :let inp_index = histnr("expr")
5491
5492< Can also be used as a |method|: >
5493 GetHistory()->histnr()
5494<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005495 Return type: |Number|
5496
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005497hlexists({name}) *hlexists()*
5498 The result is a Number, which is TRUE if a highlight group
5499 called {name} exists. This is when the group has been
5500 defined in some way. Not necessarily when highlighting has
5501 been defined for it, it may also have been used for a syntax
5502 item.
5503 *highlight_exists()*
5504 Obsolete name: highlight_exists().
5505
5506 Can also be used as a |method|: >
5507 GetName()->hlexists()
5508<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005509 Return type: |Number|
5510
5511
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005512hlget([{name} [, {resolve}]]) *hlget()*
5513 Returns a List of all the highlight group attributes. If the
5514 optional {name} is specified, then returns a List with only
5515 the attributes of the specified highlight group. Returns an
5516 empty List if the highlight group {name} is not present.
5517
5518 If the optional {resolve} argument is set to v:true and the
5519 highlight group {name} is linked to another group, then the
5520 link is resolved recursively and the attributes of the
5521 resolved highlight group are returned.
5522
5523 Each entry in the returned List is a Dictionary with the
5524 following items:
5525 cleared boolean flag, set to v:true if the highlight
5526 group attributes are cleared or not yet
5527 specified. See |highlight-clear|.
5528 cterm cterm attributes. See |highlight-cterm|.
5529 ctermbg cterm background color.
5530 See |highlight-ctermbg|.
5531 ctermfg cterm foreground color.
5532 See |highlight-ctermfg|.
5533 ctermul cterm underline color. See |highlight-ctermul|.
5534 default boolean flag, set to v:true if the highlight
5535 group link is a default link. See
5536 |highlight-default|.
5537 font highlight group font. See |highlight-font|.
5538 gui gui attributes. See |highlight-gui|.
5539 guibg gui background color. See |highlight-guibg|.
5540 guifg gui foreground color. See |highlight-guifg|.
5541 guisp gui special color. See |highlight-guisp|.
5542 id highlight group ID.
5543 linksto linked highlight group name.
5544 See |:highlight-link|.
5545 name highlight group name. See |group-name|.
5546 start start terminal keycode. See |highlight-start|.
5547 stop stop terminal keycode. See |highlight-stop|.
5548 term term attributes. See |highlight-term|.
5549
5550 The 'term', 'cterm' and 'gui' items in the above Dictionary
5551 have a dictionary value with the following optional boolean
5552 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5553 'reverse', 'inverse' and 'strikethrough'.
5554
5555 Example(s): >
5556 :echo hlget()
5557 :echo hlget('ModeMsg')
5558 :echo hlget('Number', v:true)
5559<
5560 Can also be used as a |method|: >
5561 GetName()->hlget()
5562<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005563 Return type: list<dict<any>>
5564
5565
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005566hlset({list}) *hlset()*
5567 Creates or modifies the attributes of a List of highlight
5568 groups. Each item in {list} is a dictionary containing the
5569 attributes of a highlight group. See |hlget()| for the list of
5570 supported items in this dictionary.
5571
5572 In addition to the items described in |hlget()|, the following
5573 additional items are supported in the dictionary:
5574
5575 force boolean flag to force the creation of
5576 a link for an existing highlight group
5577 with attributes.
5578
5579 The highlight group is identified using the 'name' item and
5580 the 'id' item (if supplied) is ignored. If a highlight group
5581 with a specified name doesn't exist, then it is created.
5582 Otherwise the attributes of an existing highlight group are
5583 modified.
5584
5585 If an empty dictionary value is used for the 'term' or 'cterm'
5586 or 'gui' entries, then the corresponding attributes are
5587 cleared. If the 'cleared' item is set to v:true, then all the
5588 attributes of the highlight group are cleared.
5589
5590 The 'linksto' item can be used to link a highlight group to
5591 another highlight group. See |:highlight-link|.
5592
5593 Returns zero for success, -1 for failure.
5594
5595 Example(s): >
5596 " add bold attribute to the Visual highlight group
5597 :call hlset([#{name: 'Visual',
5598 \ term: #{reverse: 1 , bold: 1}}])
5599 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5600 :let l = hlget()
5601 :call hlset(l)
5602 " clear the Search highlight group
5603 :call hlset([#{name: 'Search', cleared: v:true}])
5604 " clear the 'term' attributes for a highlight group
5605 :call hlset([#{name: 'Title', term: {}}])
5606 " create the MyHlg group linking it to DiffAdd
5607 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5608 " remove the MyHlg group link
5609 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5610 " clear the attributes and a link
5611 :call hlset([#{name: 'MyHlg', cleared: v:true,
5612 \ linksto: 'NONE'}])
5613<
5614 Can also be used as a |method|: >
5615 GetAttrList()->hlset()
5616<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005617 Return type: |Number|
5618
5619hlID({name}) *hlID()*
5620 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005621 with name {name}. When the highlight group doesn't exist,
5622 zero is returned.
5623 This can be used to retrieve information about the highlight
5624 group. For example, to get the background color of the
5625 "Comment" group: >
5626 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5627< *highlightID()*
5628 Obsolete name: highlightID().
5629
5630 Can also be used as a |method|: >
5631 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005632<
5633 Return type: |Number|
5634
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005635
5636hostname() *hostname()*
5637 The result is a String, which is the name of the machine on
5638 which Vim is currently running. Machine names greater than
5639 256 characters long are truncated.
5640
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005641 Return type: |String|
5642
5643
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005644iconv({string}, {from}, {to}) *iconv()*
5645 The result is a String, which is the text {string} converted
5646 from encoding {from} to encoding {to}.
5647 When the conversion completely fails an empty string is
5648 returned. When some characters could not be converted they
5649 are replaced with "?".
5650 The encoding names are whatever the iconv() library function
5651 can accept, see ":!man 3 iconv".
5652 Most conversions require Vim to be compiled with the |+iconv|
5653 feature. Otherwise only UTF-8 to latin1 conversion and back
5654 can be done.
5655 This can be used to display messages with special characters,
5656 no matter what 'encoding' is set to. Write the message in
5657 UTF-8 and use: >
5658 echo iconv(utf8_str, "utf-8", &enc)
5659< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5660 from/to UCS-2 is automatically changed to use UTF-8. You
5661 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5662
5663 Can also be used as a |method|: >
5664 GetText()->iconv('latin1', 'utf-8')
5665<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005666 Return type: |String|
5667
5668
h-east624bb832024-11-09 18:37:32 +01005669id({item}) *id()*
Ernie Raelc8e158b2024-07-09 18:39:52 +02005670 The result is a unique String associated with the {item} and
5671 not with the {item}'s contents. It is only valid while the
5672 {item} exists and is referenced. It is valid only in the
5673 instance of vim that produces the result. The whole idea is
5674 that `id({item})` does not change if the contents of {item}
5675 changes. This is useful as a `key` for creating an identity
5676 dictionary, rather than one based on equals.
5677
5678 This operation does not reference {item} and there is no
5679 function to convert the `id` to the {item}. It may be useful to
5680 have a map of `id` to {item}. The following >
5681 var referenceMap: dict<any>
5682 var id = item->id()
5683 referenceMap[id] = item
5684< prevents {item} from being garbage collected and provides a
5685 way to get the {item} from the `id`.
5686
5687 {item} may be a List, Dictionary, Object, Job, Channel or
5688 Blob. If the item is not a permitted type, or it is a null
5689 value, then an empty String is returned.
5690
5691 Can also be used as a |method|: >
5692 GetItem()->id()
5693<
5694 Return type: |String|
5695
5696
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005697indent({lnum}) *indent()*
5698 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005699 current buffer. The indent is counted in spaces, the value
5700 of 'tabstop' is relevant. {lnum} is used just like in
5701 |getline()|.
5702 When {lnum} is invalid -1 is returned. In |Vim9| script an
5703 error is given.
5704
5705 Can also be used as a |method|: >
5706 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005707<
5708 Return type: |Number|
5709
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005710
5711index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005712 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005713 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005714
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005715 If {object} is a |List| return the lowest index where the item
5716 has a value equal to {expr}. There is no automatic
5717 conversion, so the String "4" is different from the Number 4.
5718 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005719 of 'ignorecase' is not used here, case matters as indicated by
5720 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005721
5722 If {object} is |Blob| return the lowest index where the byte
5723 value is equal to {expr}.
5724
5725 If {start} is given then start looking at the item with index
5726 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005727
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005728 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5729 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005730
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005731 -1 is returned when {expr} is not found in {object}.
5732 Example: >
5733 :let idx = index(words, "the")
5734 :if index(numbers, 123) >= 0
5735
5736< Can also be used as a |method|: >
5737 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005738<
5739 Return type: |Number|
5740
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005741
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005742indexof({object}, {expr} [, {opts}]) *indexof()*
5743 Returns the index of an item in {object} where {expr} is
5744 v:true. {object} must be a |List| or a |Blob|.
5745
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005746 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005747 List until the expression is v:true and return the index of
5748 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005749
5750 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005751 Blob until the expression is v:true and return the index of
5752 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005753
5754 {expr} must be a |string| or |Funcref|.
5755
5756 If {expr} is a |string|: If {object} is a |List|, inside
5757 {expr} |v:key| has the index of the current List item and
5758 |v:val| has the value of the item. If {object} is a |Blob|,
5759 inside {expr} |v:key| has the index of the current byte and
5760 |v:val| has the byte value.
5761
5762 If {expr} is a |Funcref| it must take two arguments:
5763 1. the key or the index of the current item.
5764 2. the value of the current item.
5765 The function must return |TRUE| if the item is found and the
5766 search should stop.
5767
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005768 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005769 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005770 startidx start evaluating {expr} at the item with this
5771 index; may be negative for an item relative to
5772 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005773 Returns -1 when {expr} evaluates to v:false for all the items.
5774 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005775 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
5776 :echo indexof(l, "v:val.n == 20")
5777 :echo indexof(l, {i, v -> v.n == 30})
5778 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005779
5780< Can also be used as a |method|: >
5781 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005782<
5783 Return type: |Number|
5784
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005785
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005786input({prompt} [, {text} [, {completion}]]) *input()*
5787 The result is a String, which is whatever the user typed on
5788 the command-line. The {prompt} argument is either a prompt
5789 string, or a blank string (for no prompt). A '\n' can be used
5790 in the prompt to start a new line.
5791 The highlighting set with |:echohl| is used for the prompt.
5792 The input is entered just like a command-line, with the same
5793 editing commands and mappings. There is a separate history
5794 for lines typed for input().
5795 Example: >
5796 :if input("Coffee or beer? ") == "beer"
5797 : echo "Cheers!"
5798 :endif
5799<
5800 If the optional {text} argument is present and not empty, this
5801 is used for the default reply, as if the user typed this.
5802 Example: >
5803 :let color = input("Color? ", "white")
5804
5805< The optional {completion} argument specifies the type of
5806 completion supported for the input. Without it completion is
5807 not performed. The supported completion types are the same as
5808 that can be supplied to a user-defined command using the
5809 "-complete=" argument. Refer to |:command-completion| for
5810 more information. Example: >
5811 let fname = input("File: ", "", "file")
5812<
5813 NOTE: This function must not be used in a startup file, for
5814 the versions that only run in GUI mode (e.g., the Win32 GUI).
5815 Note: When input() is called from within a mapping it will
5816 consume remaining characters from that mapping, because a
5817 mapping is handled like the characters were typed.
5818 Use |inputsave()| before input() and |inputrestore()|
5819 after input() to avoid that. Another solution is to avoid
5820 that further characters follow in the mapping, e.g., by using
5821 |:execute| or |:normal|.
5822
5823 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005824 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005825 :function GetFoo()
5826 : call inputsave()
5827 : let g:Foo = input("enter search pattern: ")
5828 : call inputrestore()
5829 :endfunction
5830
5831< Can also be used as a |method|: >
5832 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005833<
5834 Return type: |String|
5835
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005836
5837inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
5838 Like |input()|, but when the GUI is running and text dialogs
5839 are supported, a dialog window pops up to input the text.
5840 Example: >
5841 :let n = inputdialog("value for shiftwidth", shiftwidth())
5842 :if n != ""
5843 : let &sw = n
5844 :endif
5845< When the dialog is cancelled {cancelreturn} is returned. When
5846 omitted an empty string is returned.
5847 Hitting <Enter> works like pressing the OK button. Hitting
5848 <Esc> works like pressing the Cancel button.
5849 NOTE: Command-line completion is not supported.
5850
5851 Can also be used as a |method|: >
5852 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005853<
5854 Return type: |String|
5855
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005856
5857inputlist({textlist}) *inputlist()*
5858 {textlist} must be a |List| of strings. This |List| is
5859 displayed, one string per line. The user will be prompted to
5860 enter a number, which is returned.
5861 The user can also select an item by clicking on it with the
5862 mouse, if the mouse is enabled in the command line ('mouse' is
5863 "a" or includes "c"). For the first string 0 is returned.
5864 When clicking above the first item a negative number is
5865 returned. When clicking on the prompt one more than the
5866 length of {textlist} is returned.
5867 Make sure {textlist} has less than 'lines' entries, otherwise
5868 it won't work. It's a good idea to put the entry number at
5869 the start of the string. And put a prompt in the first item.
5870 Example: >
5871 let color = inputlist(['Select color:', '1. red',
5872 \ '2. green', '3. blue'])
5873
5874< Can also be used as a |method|: >
5875 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005876<
5877 Return type: |Number|
5878
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005879
5880inputrestore() *inputrestore()*
5881 Restore typeahead that was saved with a previous |inputsave()|.
5882 Should be called the same number of times inputsave() is
5883 called. Calling it more often is harmless though.
5884 Returns TRUE when there is nothing to restore, FALSE otherwise.
5885
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005886 Return type: |Number|
5887
5888
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005889inputsave() *inputsave()*
5890 Preserve typeahead (also from mappings) and clear it, so that
5891 a following prompt gets input from the user. Should be
5892 followed by a matching inputrestore() after the prompt. Can
5893 be used several times, in which case there must be just as
5894 many inputrestore() calls.
5895 Returns TRUE when out of memory, FALSE otherwise.
5896
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005897 Return type: |Number|
5898
5899
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005900inputsecret({prompt} [, {text}]) *inputsecret()*
5901 This function acts much like the |input()| function with but
5902 two exceptions:
5903 a) the user's response will be displayed as a sequence of
5904 asterisks ("*") thereby keeping the entry secret, and
5905 b) the user's response will not be recorded on the input
5906 |history| stack.
5907 The result is a String, which is whatever the user actually
5908 typed on the command-line in response to the issued prompt.
5909 NOTE: Command-line completion is not supported.
5910
5911 Can also be used as a |method|: >
5912 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005913<
5914 Return type: |String|
5915
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005916
5917insert({object}, {item} [, {idx}]) *insert()*
5918 When {object} is a |List| or a |Blob| insert {item} at the start
5919 of it.
5920
5921 If {idx} is specified insert {item} before the item with index
5922 {idx}. If {idx} is zero it goes before the first item, just
5923 like omitting {idx}. A negative {idx} is also possible, see
5924 |list-index|. -1 inserts just before the last item.
5925
5926 Returns the resulting |List| or |Blob|. Examples: >
5927 :let mylist = insert([2, 3, 5], 1)
5928 :call insert(mylist, 4, -1)
5929 :call insert(mylist, 6, len(mylist))
5930< The last example can be done simpler with |add()|.
5931 Note that when {item} is a |List| it is inserted as a single
5932 item. Use |extend()| to concatenate |Lists|.
5933
5934 Can also be used as a |method|: >
5935 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005936<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005937 Return type: |Number|
5938
5939
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005940 *instanceof()* *E614* *E616* *E693*
5941instanceof({object}, {class})
5942 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01005943 argument is a direct or indirect instance of a |Class|,
5944 |Interface|, or class |:type| alias specified by {class}.
5945 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005946 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02005947 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01005948 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02005949
5950< Can also be used as a |method|: >
5951 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005952<
5953 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02005954
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005955interrupt() *interrupt()*
5956 Interrupt script execution. It works more or less like the
5957 user typing CTRL-C, most commands won't execute and control
5958 returns to the user. This is useful to abort execution
5959 from lower down, e.g. in an autocommand. Example: >
5960 :function s:check_typoname(file)
5961 : if fnamemodify(a:file, ':t') == '['
5962 : echomsg 'Maybe typo'
5963 : call interrupt()
5964 : endif
5965 :endfunction
5966 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005967<
5968 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005969
5970invert({expr}) *invert()*
5971 Bitwise invert. The argument is converted to a number. A
5972 List, Dict or Float argument causes an error. Example: >
5973 :let bits = invert(bits)
5974< Can also be used as a |method|: >
5975 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005976<
5977 Return type: |Number|
5978
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005979
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005980isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01005981 The result is a Number, which is |TRUE| when {path} is an
5982 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005983 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01005984 On MS-Windows, it is considered absolute when it starts with an
5985 optional drive prefix and is followed by a '\' or '/'. UNC paths
5986 are always absolute.
5987 Example: >
5988 echo isabsolutepath('/usr/share/') " 1
5989 echo isabsolutepath('./foobar') " 0
5990 echo isabsolutepath('C:\Windows') " 1
5991 echo isabsolutepath('foobar') " 0
5992 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005993<
LemonBoydca1d402022-04-28 15:26:33 +01005994 Can also be used as a |method|: >
5995 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005996<
5997 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01005998
5999
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006000isdirectory({directory}) *isdirectory()*
6001 The result is a Number, which is |TRUE| when a directory
6002 with the name {directory} exists. If {directory} doesn't
6003 exist, or isn't a directory, the result is |FALSE|. {directory}
6004 is any expression, which is used as a String.
6005
6006 Can also be used as a |method|: >
6007 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006008<
6009 Return type: |Number|
6010
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006011
6012isinf({expr}) *isinf()*
6013 Return 1 if {expr} is a positive infinity, or -1 a negative
6014 infinity, otherwise 0. >
6015 :echo isinf(1.0 / 0.0)
6016< 1 >
6017 :echo isinf(-1.0 / 0.0)
6018< -1
6019
6020 Can also be used as a |method|: >
6021 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006022<
6023 Return type: |Number|
6024
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006025
6026islocked({expr}) *islocked()* *E786*
6027 The result is a Number, which is |TRUE| when {expr} is the
6028 name of a locked variable.
6029 The string argument {expr} must be the name of a variable,
6030 |List| item or |Dictionary| entry, not the variable itself!
6031 Example: >
6032 :let alist = [0, ['a', 'b'], 2, 3]
6033 :lockvar 1 alist
6034 :echo islocked('alist') " 1
6035 :echo islocked('alist[1]') " 0
6036
Bram Moolenaar9da17d72022-02-09 21:50:44 +00006037< When {expr} is a variable that does not exist -1 is returned.
6038 If {expr} uses a range, list or dict index that is out of
6039 range or does not exist you get an error message. Use
6040 |exists()| to check for existence.
6041 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006042
6043 Can also be used as a |method|: >
6044 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006045<
6046 Return type: |Number|
6047
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006048
6049isnan({expr}) *isnan()*
6050 Return |TRUE| if {expr} is a float with value NaN. >
6051 echo isnan(0.0 / 0.0)
6052< 1
6053
6054 Can also be used as a |method|: >
6055 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006056<
6057 Return type: |Number|
6058
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006059
6060items({dict}) *items()*
6061 Return a |List| with all the key-value pairs of {dict}. Each
6062 |List| item is a list with two items: the key of a {dict}
6063 entry and the value of this entry. The |List| is in arbitrary
6064 order. Also see |keys()| and |values()|.
6065 Example: >
6066 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006067 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006068 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006069<
6070 A List or a String argument is also supported. In these
6071 cases, items() returns a List with the index and the value at
6072 the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006073
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006074 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006075 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006076<
6077 Return type: list<list<any>> or list<any>
6078
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006079
6080job_ functions are documented here: |job-functions-details|
6081
6082
6083join({list} [, {sep}]) *join()*
6084 Join the items in {list} together into one String.
6085 When {sep} is specified it is put in between the items. If
6086 {sep} is omitted a single space is used.
6087 Note that {sep} is not added at the end. You might want to
6088 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006089 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006090< String items are used as-is. |Lists| and |Dictionaries| are
6091 converted into a string like with |string()|.
6092 The opposite function is |split()|.
6093
6094 Can also be used as a |method|: >
6095 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006096<
6097 Return type: |String|
6098
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006099
6100js_decode({string}) *js_decode()*
6101 This is similar to |json_decode()| with these differences:
6102 - Object key names do not have to be in quotes.
6103 - Strings can be in single quotes.
6104 - Empty items in an array (between two commas) are allowed and
6105 result in v:none items.
6106
6107 Can also be used as a |method|: >
6108 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006109<
6110 Return type: any, depending on {varname}
6111
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006112
6113js_encode({expr}) *js_encode()*
6114 This is similar to |json_encode()| with these differences:
6115 - Object key names are not in quotes.
6116 - v:none items in an array result in an empty item between
6117 commas.
6118 For example, the Vim object:
6119 [1,v:none,{"one":1},v:none] ~
6120 Will be encoded as:
6121 [1,,{one:1},,] ~
6122 While json_encode() would produce:
6123 [1,null,{"one":1},null] ~
6124 This encoding is valid for JavaScript. It is more efficient
6125 than JSON, especially when using an array with optional items.
6126
6127 Can also be used as a |method|: >
6128 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006129<
6130 Return type: |String|
6131
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006132
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006133json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006134 This parses a JSON formatted string and returns the equivalent
6135 in Vim values. See |json_encode()| for the relation between
6136 JSON and Vim values.
6137 The decoding is permissive:
6138 - A trailing comma in an array and object is ignored, e.g.
6139 "[1, 2, ]" is the same as "[1, 2]".
6140 - Integer keys are accepted in objects, e.g. {1:2} is the
6141 same as {"1":2}.
6142 - More floating point numbers are recognized, e.g. "1." for
6143 "1.0", or "001.2" for "1.2". Special floating point values
6144 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6145 are accepted.
6146 - Leading zeroes in integer numbers are ignored, e.g. "012"
6147 for "12" or "-012" for "-12".
6148 - Capitalization is ignored in literal names null, true or
6149 false, e.g. "NULL" for "null", "True" for "true".
6150 - Control characters U+0000 through U+001F which are not
6151 escaped in strings are accepted, e.g. " " (tab
6152 character in string) for "\t".
6153 - An empty JSON expression or made of only spaces is accepted
6154 and results in v:none.
6155 - Backslash in an invalid 2-character sequence escape is
6156 ignored, e.g. "\a" is decoded as "a".
6157 - A correct surrogate pair in JSON strings should normally be
6158 a 12 character sequence such as "\uD834\uDD1E", but
6159 json_decode() silently accepts truncated surrogate pairs
6160 such as "\uD834" or "\uD834\u"
6161 *E938*
6162 A duplicate key in an object, valid in rfc7159, is not
6163 accepted by json_decode() as the result must be a valid Vim
6164 type, e.g. this fails: {"a":"b", "a":"c"}
6165
6166 Can also be used as a |method|: >
6167 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006168<
6169 Return type: any, depending on {varname}
6170
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006171
6172json_encode({expr}) *json_encode()*
6173 Encode {expr} as JSON and return this as a string.
6174 The encoding is specified in:
6175 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006176 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006177 |Number| decimal number
6178 |Float| floating point number
6179 Float nan "NaN"
6180 Float inf "Infinity"
6181 Float -inf "-Infinity"
6182 |String| in double quotes (possibly null)
6183 |Funcref| not possible, error
6184 |List| as an array (possibly null); when
6185 used recursively: []
6186 |Dict| as an object (possibly null); when
6187 used recursively: {}
6188 |Blob| as an array of the individual bytes
6189 v:false "false"
6190 v:true "true"
6191 v:none "null"
6192 v:null "null"
6193 Note that NaN and Infinity are passed on as values. This is
6194 missing in the JSON standard, but several implementations do
6195 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006196 If a string contains an illegal character then the replacement
6197 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006198
6199 Can also be used as a |method|: >
6200 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006201<
6202 Return type: |String|
6203
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006204
6205keys({dict}) *keys()*
6206 Return a |List| with all the keys of {dict}. The |List| is in
6207 arbitrary order. Also see |items()| and |values()|.
6208
6209 Can also be used as a |method|: >
6210 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006211<
6212 Return type: list<string>
6213
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006214
zeertzjqcdc83932022-09-12 13:38:41 +01006215keytrans({string}) *keytrans()*
6216 Turn the internal byte representation of keys into a form that
6217 can be used for |:map|. E.g. >
6218 :let xx = "\<C-Home>"
6219 :echo keytrans(xx)
6220< <C-Home>
6221
6222 Can also be used as a |method|: >
6223 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006224<
6225 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006226
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006227
6228len({expr}) *len()* *E701*
6229 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006230 When {expr} is a String or a Number the length in bytes is
6231 used, as with |strlen()|.
6232 When {expr} is a |List| the number of items in the |List| is
6233 returned.
6234 When {expr} is a |Blob| the number of bytes is returned.
6235 When {expr} is a |Dictionary| the number of entries in the
6236 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006237 When {expr} is an |Object|, invokes the len() method in the
6238 object (if present) to get the length (|object-len()|).
6239 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006240
6241 Can also be used as a |method|: >
6242 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006243<
6244 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006245
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006246
6247 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006248libcall({libname}, {funcname}, {argument})
6249 Call function {funcname} in the run-time library {libname}
6250 with single argument {argument}.
6251 This is useful to call functions in a library that you
6252 especially made to be used with Vim. Since only one argument
6253 is possible, calling standard library functions is rather
6254 limited.
6255 The result is the String returned by the function. If the
6256 function returns NULL, this will appear as an empty string ""
6257 to Vim.
6258 If the function returns a number, use libcallnr()!
6259 If {argument} is a number, it is passed to the function as an
6260 int; if {argument} is a string, it is passed as a
6261 null-terminated string.
6262 This function will fail in |restricted-mode|.
6263
6264 libcall() allows you to write your own 'plug-in' extensions to
6265 Vim without having to recompile the program. It is NOT a
6266 means to call system functions! If you try to do so Vim will
6267 very probably crash.
6268
6269 For Win32, the functions you write must be placed in a DLL
6270 and use the normal C calling convention (NOT Pascal which is
6271 used in Windows System DLLs). The function must take exactly
6272 one parameter, either a character pointer or a long integer,
6273 and must return a character pointer or NULL. The character
6274 pointer returned must point to memory that will remain valid
6275 after the function has returned (e.g. in static data in the
6276 DLL). If it points to allocated memory, that memory will
6277 leak away. Using a static buffer in the function should work,
6278 it's then freed when the DLL is unloaded.
6279
6280 WARNING: If the function returns a non-valid pointer, Vim may
6281 crash! This also happens if the function returns a number,
6282 because Vim thinks it's a pointer.
6283 For Win32 systems, {libname} should be the filename of the DLL
6284 without the ".DLL" suffix. A full path is only required if
6285 the DLL is not in the usual places.
6286 For Unix: When compiling your own plugins, remember that the
6287 object code must be compiled as position-independent ('PIC').
6288 {only in Win32 and some Unix versions, when the |+libcall|
6289 feature is present}
6290 Examples: >
6291 :echo libcall("libc.so", "getenv", "HOME")
6292
6293< Can also be used as a |method|, the base is passed as the
6294 third argument: >
6295 GetValue()->libcall("libc.so", "getenv")
6296<
6297 *libcallnr()*
6298libcallnr({libname}, {funcname}, {argument})
6299 Just like |libcall()|, but used for a function that returns an
6300 int instead of a string.
6301 {only in Win32 on some Unix versions, when the |+libcall|
6302 feature is present}
6303 Examples: >
6304 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6305 :call libcallnr("libc.so", "printf", "Hello World!\n")
6306 :call libcallnr("libc.so", "sleep", 10)
6307<
6308 Can also be used as a |method|, the base is passed as the
6309 third argument: >
6310 GetValue()->libcallnr("libc.so", "printf")
6311<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006312 Return type: |String|
6313
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006314
6315line({expr} [, {winid}]) *line()*
6316 The result is a Number, which is the line number of the file
6317 position given with {expr}. The {expr} argument is a string.
zeertzjq02f3eba2024-06-12 20:45:24 +02006318 See |getpos()| for accepted positions.
6319
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006320 To get the column number use |col()|. To get both use
6321 |getpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02006322
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006323 With the optional {winid} argument the values are obtained for
6324 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02006325
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006326 Returns 0 for invalid values of {expr} and {winid}.
zeertzjq02f3eba2024-06-12 20:45:24 +02006327
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006328 Examples: >
6329 line(".") line number of the cursor
6330 line(".", winid) idem, in window "winid"
6331 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006332 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006333<
6334 To jump to the last known position when opening a file see
6335 |last-position-jump|.
6336
6337 Can also be used as a |method|: >
6338 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006339<
6340 Return type: |Number|
6341
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006342
6343line2byte({lnum}) *line2byte()*
6344 Return the byte count from the start of the buffer for line
6345 {lnum}. This includes the end-of-line character, depending on
6346 the 'fileformat' option for the current buffer. The first
6347 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6348 This can also be used to get the byte count for the line just
6349 below the last line: >
6350 line2byte(line("$") + 1)
6351< This is the buffer size plus one. If 'fileencoding' is empty
6352 it is the file size plus one. {lnum} is used like with
6353 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6354 feature has been disabled at compile time, -1 is returned.
6355 Also see |byte2line()|, |go| and |:goto|.
6356
6357 Can also be used as a |method|: >
6358 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006359<
6360 Return type: |Number|
6361
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006362
6363lispindent({lnum}) *lispindent()*
6364 Get the amount of indent for line {lnum} according the lisp
6365 indenting rules, as with 'lisp'.
6366 The indent is counted in spaces, the value of 'tabstop' is
6367 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006368 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006369 error is given.
6370
6371 Can also be used as a |method|: >
6372 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006373<
6374 Return type: |Number|
6375
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006376
6377list2blob({list}) *list2blob()*
6378 Return a Blob concatenating all the number values in {list}.
6379 Examples: >
6380 list2blob([1, 2, 3, 4]) returns 0z01020304
6381 list2blob([]) returns 0z
6382< Returns an empty Blob on error. If one of the numbers is
6383 negative or more than 255 error *E1239* is given.
6384
6385 |blob2list()| does the opposite.
6386
6387 Can also be used as a |method|: >
6388 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006389<
6390 Return type: |Blob|
6391
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006392
6393list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006394 Convert each number in {list} to a character string and
6395 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006396 list2str([32]) returns " "
6397 list2str([65, 66, 67]) returns "ABC"
6398< The same can be done (slowly) with: >
6399 join(map(list, {nr, val -> nr2char(val)}), '')
6400< |str2list()| does the opposite.
6401
6402 When {utf8} is omitted or zero, the current 'encoding' is used.
6403 When {utf8} is TRUE, always return UTF-8 characters.
6404 With UTF-8 composing characters work as expected: >
6405 list2str([97, 769]) returns "á"
6406<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006407 Returns an empty string on error.
6408
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006409 Can also be used as a |method|: >
6410 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006411<
6412 Return type: |String|
6413
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006414
6415listener_add({callback} [, {buf}]) *listener_add()*
6416 Add a callback function that will be invoked when changes have
6417 been made to buffer {buf}.
6418 {buf} refers to a buffer name or number. For the accepted
6419 values, see |bufname()|. When {buf} is omitted the current
6420 buffer is used.
6421 Returns a unique ID that can be passed to |listener_remove()|.
6422
6423 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006424 bufnr the buffer that was changed
6425 start first changed line number
6426 end first line number below the change
6427 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006428 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006429 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006430
6431 Example: >
6432 func Listener(bufnr, start, end, added, changes)
6433 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6434 endfunc
6435 call listener_add('Listener', bufnr)
6436
Bram Moolenaar944697a2022-02-20 19:48:20 +00006437< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006438 dictionary with these entries:
6439 lnum the first line number of the change
6440 end the first line below the change
6441 added number of lines added; negative if lines were
6442 deleted
6443 col first column in "lnum" that was affected by
6444 the change; one if unknown or the whole line
6445 was affected; this is a byte index, first
6446 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006447 When lines are inserted (not when a line is split, e.g. by
6448 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006449 lnum line above which the new line is added
6450 end equal to "lnum"
6451 added number of lines inserted
6452 col 1
6453 When lines are deleted the values are:
6454 lnum the first deleted line
6455 end the line below the first deleted line, before
6456 the deletion was done
6457 added negative, number of lines deleted
6458 col 1
6459 When lines are changed:
6460 lnum the first changed line
6461 end the line below the last changed line
6462 added 0
6463 col first column with a change or 1
6464
6465 The entries are in the order the changes were made, thus the
6466 most recent change is at the end. The line numbers are valid
6467 when the callback is invoked, but later changes may make them
6468 invalid, thus keeping a copy for later might not work.
6469
6470 The {callback} is invoked just before the screen is updated,
6471 when |listener_flush()| is called or when a change is being
6472 made that changes the line count in a way it causes a line
6473 number in the list of changes to become invalid.
6474
6475 The {callback} is invoked with the text locked, see
6476 |textlock|. If you do need to make changes to the buffer, use
6477 a timer to do this later |timer_start()|.
6478
6479 The {callback} is not invoked when the buffer is first loaded.
6480 Use the |BufReadPost| autocmd event to handle the initial text
6481 of a buffer.
6482 The {callback} is also not invoked when the buffer is
6483 unloaded, use the |BufUnload| autocmd event for that.
6484
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006485 Returns zero if {callback} or {buf} is invalid.
6486
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006487 Can also be used as a |method|, the base is passed as the
6488 second argument: >
6489 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006490<
6491 Return type: |Number|
6492
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006493
6494listener_flush([{buf}]) *listener_flush()*
6495 Invoke listener callbacks for buffer {buf}. If there are no
6496 pending changes then no callbacks are invoked.
6497
6498 {buf} refers to a buffer name or number. For the accepted
6499 values, see |bufname()|. When {buf} is omitted the current
6500 buffer is used.
6501
6502 Can also be used as a |method|: >
6503 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006504<
6505 Return type: |Number|
6506
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006507
6508listener_remove({id}) *listener_remove()*
6509 Remove a listener previously added with listener_add().
6510 Returns FALSE when {id} could not be found, TRUE when {id} was
6511 removed.
6512
6513 Can also be used as a |method|: >
6514 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006515<
6516 Return type: |Number|
6517
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006518
6519localtime() *localtime()*
6520 Return the current time, measured as seconds since 1st Jan
6521 1970. See also |strftime()|, |strptime()| and |getftime()|.
6522
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006523 Return type: |Number|
6524
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006525
6526log({expr}) *log()*
6527 Return the natural logarithm (base e) of {expr} as a |Float|.
6528 {expr} must evaluate to a |Float| or a |Number| in the range
6529 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006530 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006531 Examples: >
6532 :echo log(10)
6533< 2.302585 >
6534 :echo log(exp(5))
6535< 5.0
6536
6537 Can also be used as a |method|: >
6538 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006539<
6540 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006541
6542
6543log10({expr}) *log10()*
6544 Return the logarithm of Float {expr} to base 10 as a |Float|.
6545 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006546 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006547 Examples: >
6548 :echo log10(1000)
6549< 3.0 >
6550 :echo log10(0.01)
6551< -2.0
6552
6553 Can also be used as a |method|: >
6554 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006555<
6556 Return type: |Float|
6557
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006558
6559luaeval({expr} [, {expr}]) *luaeval()*
6560 Evaluate Lua expression {expr} and return its result converted
6561 to Vim data structures. Second {expr} may hold additional
6562 argument accessible as _A inside first {expr}.
6563 Strings are returned as they are.
6564 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006565 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006566 Dictionaries and lists obtained by vim.eval() are returned
6567 as-is.
6568 Other objects are returned as zero without any errors.
6569 See |lua-luaeval| for more details.
6570 Note that in a `:def` function local variables are not visible
6571 to {expr}.
6572
6573 Can also be used as a |method|: >
6574 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006575<
6576 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006577
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006578 {only available when compiled with the |+lua| feature}
6579
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006580
6581map({expr1}, {expr2}) *map()*
6582 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006583 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006584 item in {expr1} with the result of evaluating {expr2}.
6585 For a |Blob| each byte is replaced.
6586 For a |String|, each character, including composing
6587 characters, is replaced.
6588 If the item type changes you may want to use |mapnew()| to
6589 create a new List or Dictionary. This is required when using
6590 Vim9 script.
6591
6592 {expr2} must be a |String| or |Funcref|.
6593
6594 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6595 of the current item. For a |Dictionary| |v:key| has the key
6596 of the current item and for a |List| |v:key| has the index of
6597 the current item. For a |Blob| |v:key| has the index of the
6598 current byte. For a |String| |v:key| has the index of the
6599 current character.
6600 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006601 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006602< This puts "> " before and " <" after each item in "mylist".
6603
6604 Note that {expr2} is the result of an expression and is then
6605 used as an expression again. Often it is good to use a
6606 |literal-string| to avoid having to double backslashes. You
6607 still have to double ' quotes
6608
6609 If {expr2} is a |Funcref| it is called with two arguments:
6610 1. The key or the index of the current item.
6611 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006612 With a legacy script lambda you don't get an error if it only
6613 accepts one argument, but with a Vim9 lambda you get "E1106:
6614 One argument too many", the number of arguments must match.
6615
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006616 The function must return the new value of the item. Example
6617 that changes each value by "key-value": >
6618 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006619 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006620 endfunc
6621 call map(myDict, function('KeyValue'))
6622< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006623 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006624< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006625 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006626< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006627 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006628<
6629 The operation is done in-place for a |List| and |Dictionary|.
6630 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006631 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006632
6633< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6634 or a new |Blob| or |String|.
6635 When an error is encountered while evaluating {expr2} no
6636 further items in {expr1} are processed.
6637 When {expr2} is a Funcref errors inside a function are ignored,
6638 unless it was defined with the "abort" flag.
6639
6640 Can also be used as a |method|: >
6641 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006642<
6643 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6644 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006645
6646
6647maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6648 When {dict} is omitted or zero: Return the rhs of mapping
6649 {name} in mode {mode}. The returned String has special
6650 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006651 listing. When {dict} is TRUE a dictionary is returned, see
6652 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006653
6654 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006655 returned if {dict} is FALSE, otherwise returns an empty Dict.
6656 When the mapping for {name} is empty, then "<Nop>" is
6657 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006658
6659 The {name} can have special key names, like in the ":map"
6660 command.
6661
6662 {mode} can be one of these strings:
6663 "n" Normal
6664 "v" Visual (including Select)
6665 "o" Operator-pending
6666 "i" Insert
6667 "c" Cmd-line
6668 "s" Select
6669 "x" Visual
6670 "l" langmap |language-mapping|
6671 "t" Terminal-Job
6672 "" Normal, Visual and Operator-pending
6673 When {mode} is omitted, the modes for "" are used.
6674
6675 When {abbr} is there and it is |TRUE| use abbreviations
6676 instead of mappings.
6677
6678 When {dict} is there and it is |TRUE| return a dictionary
6679 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006680 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006681 "lhs" The {lhs} of the mapping as it would be typed
6682 "lhsraw" The {lhs} of the mapping as raw bytes
6683 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6684 form, only present when it differs from "lhsraw"
6685 "rhs" The {rhs} of the mapping as typed.
6686 "silent" 1 for a |:map-silent| mapping, else 0.
6687 "noremap" 1 if the {rhs} of the mapping is not remappable.
6688 "script" 1 if mapping was defined with <script>.
6689 "expr" 1 for an expression mapping (|:map-<expr>|).
6690 "buffer" 1 for a buffer local mapping (|:map-local|).
6691 "mode" Modes for which the mapping is defined. In
6692 addition to the modes mentioned above, these
6693 characters will be used:
6694 " " Normal, Visual and Operator-pending
6695 "!" Insert and Commandline mode
6696 (|mapmode-ic|)
6697 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006698 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006699 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006700 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006701 "lnum" The line number in "sid", zero if unknown.
6702 "nowait" Do not wait for other, longer mappings.
6703 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006704 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006705 "mode_bits" Vim's internal binary representation of "mode".
6706 |mapset()| ignores this; only "mode" is used.
6707 See |maplist()| for usage examples. The values
6708 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006709
6710 The dictionary can be used to restore a mapping with
6711 |mapset()|.
6712
6713 The mappings local to the current buffer are checked first,
6714 then the global mappings.
6715 This function can be used to map a key even when it's already
6716 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006717 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006718
6719< Can also be used as a |method|: >
6720 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006721<
6722 Return type: |String| or dict<any> depending on {dict}
6723
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006724
6725mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6726 Check if there is a mapping that matches with {name} in mode
6727 {mode}. See |maparg()| for {mode} and special names in
6728 {name}.
6729 When {abbr} is there and it is |TRUE| use abbreviations
6730 instead of mappings.
6731 A match happens with a mapping that starts with {name} and
6732 with a mapping which is equal to the start of {name}.
6733
6734 matches mapping "a" "ab" "abc" ~
6735 mapcheck("a") yes yes yes
6736 mapcheck("abc") yes yes yes
6737 mapcheck("ax") yes no no
6738 mapcheck("b") no no no
6739
6740 The difference with maparg() is that mapcheck() finds a
6741 mapping that matches with {name}, while maparg() only finds a
6742 mapping for {name} exactly.
6743 When there is no mapping that starts with {name}, an empty
6744 String is returned. If there is one, the RHS of that mapping
6745 is returned. If there are several mappings that start with
6746 {name}, the RHS of one of them is returned. This will be
6747 "<Nop>" if the RHS is empty.
6748 The mappings local to the current buffer are checked first,
6749 then the global mappings.
6750 This function can be used to check if a mapping can be added
6751 without being ambiguous. Example: >
6752 :if mapcheck("_vv") == ""
6753 : map _vv :set guifont=7x13<CR>
6754 :endif
6755< This avoids adding the "_vv" mapping when there already is a
6756 mapping for "_v" or for "_vvv".
6757
6758 Can also be used as a |method|: >
6759 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006760<
6761 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006762
6763
Ernie Rael09661202022-04-25 14:40:44 +01006764maplist([{abbr}]) *maplist()*
6765 Returns a |List| of all mappings. Each List item is a |Dict|,
6766 the same as what is returned by |maparg()|, see
6767 |mapping-dict|. When {abbr} is there and it is |TRUE| use
6768 abbreviations instead of mappings.
6769
6770 Example to show all mappings with 'MultiMatch' in rhs: >
6771 vim9script
6772 echo maplist()->filter(
6773 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01006774< It can be tricky to find mappings for particular |:map-modes|.
6775 |mapping-dict|'s "mode_bits" can simplify this. For example,
6776 the mode_bits for Normal, Insert or Command-line modes are
6777 0x19. To find all the mappings available in those modes you
6778 can do: >
6779 vim9script
6780 var saved_maps = []
6781 for m in maplist()
6782 if and(m.mode_bits, 0x19) != 0
6783 saved_maps->add(m)
6784 endif
6785 endfor
6786 echo saved_maps->mapnew((_, m) => m.lhs)
6787< The values of the mode_bits are defined in Vim's src/vim.h
6788 file and they can be discovered at runtime using
6789 |:map-commands| and "maplist()". Example: >
6790 vim9script
6791 omap xyzzy <Nop>
6792 var op_bit = maplist()->filter(
6793 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
6794 ounmap xyzzy
6795 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006796<
6797 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01006798
6799
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006800mapnew({expr1}, {expr2}) *mapnew()*
6801 Like |map()| but instead of replacing items in {expr1} a new
6802 List or Dictionary is created and returned. {expr1} remains
6803 unchanged. Items can still be changed by {expr2}, if you
6804 don't want that use |deepcopy()| first.
6805
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006806 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6807 depending on {expr1}
6808
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006809
6810mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01006811mapset({dict})
6812 Restore a mapping from a dictionary, possibly returned by
6813 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
6814 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006815 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01006816 feature allows copying mappings from one buffer to another.
6817 The dict.mode value may restore a single mapping that covers
6818 more than one mode, like with mode values of '!', ' ', 'nox',
6819 or 'v'. *E1276*
6820
6821 In the first form, {mode} and {abbr} should be the same as
6822 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006823 {mode} is used to define the mode in which the mapping is set,
6824 not the "mode" entry in {dict}.
6825 Example for saving and restoring a mapping: >
6826 let save_map = maparg('K', 'n', 0, 1)
6827 nnoremap K somethingelse
6828 ...
6829 call mapset('n', 0, save_map)
6830< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01006831 e.g. with `:map!`, you need to save/restore the mapping for
6832 all of them, when they might differ.
6833
6834 In the second form, with {dict} as the only argument, mode
6835 and abbr are taken from the dict.
6836 Example: >
6837 vim9script
6838 var save_maps = maplist()->filter(
6839 (_, m) => m.lhs == 'K')
6840 nnoremap K somethingelse
6841 cnoremap K somethingelse2
6842 # ...
6843 unmap K
6844 for d in save_maps
6845 mapset(d)
6846 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006847<
6848 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006849
6850
6851match({expr}, {pat} [, {start} [, {count}]]) *match()*
6852 When {expr} is a |List| then this returns the index of the
6853 first item where {pat} matches. Each item is used as a
6854 String, |Lists| and |Dictionaries| are used as echoed.
6855
6856 Otherwise, {expr} is used as a String. The result is a
6857 Number, which gives the index (byte offset) in {expr} where
6858 {pat} matches.
6859
6860 A match at the first character or |List| item returns zero.
6861 If there is no match -1 is returned.
6862
6863 For getting submatches see |matchlist()|.
6864 Example: >
6865 :echo match("testing", "ing") " results in 4
6866 :echo match([1, 'x'], '\a') " results in 1
6867< See |string-match| for how {pat} is used.
6868 *strpbrk()*
6869 Vim doesn't have a strpbrk() function. But you can do: >
6870 :let sepidx = match(line, '[.,;: \t]')
6871< *strcasestr()*
6872 Vim doesn't have a strcasestr() function. But you can add
6873 "\c" to the pattern to ignore case: >
6874 :let idx = match(haystack, '\cneedle')
6875<
6876 If {start} is given, the search starts from byte index
6877 {start} in a String or item {start} in a |List|.
6878 The result, however, is still the index counted from the
6879 first character/item. Example: >
6880 :echo match("testing", "ing", 2)
6881< result is again "4". >
6882 :echo match("testing", "ing", 4)
6883< result is again "4". >
6884 :echo match("testing", "t", 2)
6885< result is "3".
6886 For a String, if {start} > 0 then it is like the string starts
6887 {start} bytes later, thus "^" will match at {start}. Except
6888 when {count} is given, then it's like matches before the
6889 {start} byte are ignored (this is a bit complicated to keep it
6890 backwards compatible).
6891 For a String, if {start} < 0, it will be set to 0. For a list
6892 the index is counted from the end.
6893 If {start} is out of range ({start} > strlen({expr}) for a
6894 String or {start} > len({expr}) for a |List|) -1 is returned.
6895
6896 When {count} is given use the {count}'th match. When a match
6897 is found in a String the search for the next one starts one
6898 character further. Thus this example results in 1: >
6899 echo match("testing", "..", 0, 2)
6900< In a |List| the search continues in the next item.
6901 Note that when {count} is added the way {start} works changes,
6902 see above.
6903
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01006904 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006905 See |pattern| for the patterns that are accepted.
6906 The 'ignorecase' option is used to set the ignore-caseness of
6907 the pattern. 'smartcase' is NOT used. The matching is always
6908 done like 'magic' is set and 'cpoptions' is empty.
6909 Note that a match at the start is preferred, thus when the
6910 pattern is using "*" (any number of matches) it tends to find
6911 zero matches at the start instead of a number of matches
6912 further down in the text.
6913
6914 Can also be used as a |method|: >
6915 GetText()->match('word')
6916 GetList()->match('word')
6917<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006918 Return type: |Number|
6919
6920
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006921 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006922matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
6923 Defines a pattern to be highlighted in the current window (a
6924 "match"). It will be highlighted with {group}. Returns an
6925 identification number (ID), which can be used to delete the
6926 match using |matchdelete()|. The ID is bound to the window.
6927 Matching is case sensitive and magic, unless case sensitivity
6928 or magicness are explicitly overridden in {pattern}. The
6929 'magic', 'smartcase' and 'ignorecase' options are not used.
6930 The "Conceal" value is special, it causes the match to be
6931 concealed.
6932
6933 The optional {priority} argument assigns a priority to the
6934 match. A match with a high priority will have its
6935 highlighting overrule that of a match with a lower priority.
6936 A priority is specified as an integer (negative numbers are no
6937 exception). If the {priority} argument is not specified, the
6938 default priority is 10. The priority of 'hlsearch' is zero,
6939 hence all matches with a priority greater than zero will
6940 overrule it. Syntax highlighting (see 'syntax') is a separate
6941 mechanism, and regardless of the chosen priority a match will
6942 always overrule syntax highlighting.
6943
6944 The optional {id} argument allows the request for a specific
6945 match ID. If a specified ID is already taken, an error
6946 message will appear and the match will not be added. An ID
6947 is specified as a positive integer (zero excluded). IDs 1, 2
6948 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01006949 respectively. 3 is reserved for use by the |matchparen|
6950 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01006951 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01006952 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006953
6954 The optional {dict} argument allows for further custom
6955 values. Currently this is used to specify a match specific
6956 conceal character that will be shown for |hl-Conceal|
6957 highlighted matches. The dict can have the following members:
6958
6959 conceal Special character to show instead of the
6960 match (only for |hl-Conceal| highlighted
6961 matches, see |:syn-cchar|)
6962 window Instead of the current window use the
6963 window with this number or window ID.
6964
6965 The number of matches is not limited, as it is the case with
6966 the |:match| commands.
6967
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006968 Returns -1 on error.
6969
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006970 Example: >
6971 :highlight MyGroup ctermbg=green guibg=green
6972 :let m = matchadd("MyGroup", "TODO")
6973< Deletion of the pattern: >
6974 :call matchdelete(m)
6975
6976< A list of matches defined by |matchadd()| and |:match| are
6977 available from |getmatches()|. All matches can be deleted in
6978 one operation by |clearmatches()|.
6979
6980 Can also be used as a |method|: >
6981 GetGroup()->matchadd('TODO')
6982<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006983 Return type: |Number|
6984
6985
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006986 *matchaddpos()*
6987matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
6988 Same as |matchadd()|, but requires a list of positions {pos}
6989 instead of a pattern. This command is faster than |matchadd()|
Shane Harperc1b39842024-07-17 19:40:40 +02006990 because it does not handle regular expressions and it sets
6991 buffer line boundaries to redraw screen. It is supposed to be
6992 used when fast match additions and deletions are required, for
6993 example to highlight matching parentheses.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006994
6995 {pos} is a list of positions. Each position can be one of
6996 these:
6997 - A number. This whole line will be highlighted. The first
6998 line has number 1.
6999 - A list with one number, e.g., [23]. The whole line with this
7000 number will be highlighted.
7001 - A list with two numbers, e.g., [23, 11]. The first number is
7002 the line number, the second one is the column number (first
7003 column is 1, the value must correspond to the byte index as
7004 |col()| would return). The character at this position will
7005 be highlighted.
7006 - A list with three numbers, e.g., [23, 11, 3]. As above, but
7007 the third number gives the length of the highlight in bytes.
7008
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007009 Returns -1 on error.
7010
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007011 Example: >
7012 :highlight MyGroup ctermbg=green guibg=green
7013 :let m = matchaddpos("MyGroup", [[23, 24], 34])
7014< Deletion of the pattern: >
7015 :call matchdelete(m)
7016
7017< Matches added by |matchaddpos()| are returned by
7018 |getmatches()|.
7019
7020 Can also be used as a |method|: >
7021 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007022<
7023 Return type: |Number|
7024
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007025
7026matcharg({nr}) *matcharg()*
7027 Selects the {nr} match item, as set with a |:match|,
7028 |:2match| or |:3match| command.
7029 Return a |List| with two elements:
7030 The name of the highlight group used
7031 The pattern used.
7032 When {nr} is not 1, 2 or 3 returns an empty |List|.
7033 When there is no match item set returns ['', ''].
7034 This is useful to save and restore a |:match|.
7035 Highlighting matches using the |:match| commands are limited
7036 to three matches. |matchadd()| does not have this limitation.
7037
7038 Can also be used as a |method|: >
7039 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007040<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007041 Return type: list<string>
7042
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007043 *matchbufline()*
7044matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
7045 Returns the |List| of matches in lines from {lnum} to {end} in
7046 buffer {buf} where {pat} matches.
7047
7048 {lnum} and {end} can either be a line number or the string "$"
7049 to refer to the last line in {buf}.
7050
7051 The {dict} argument supports following items:
7052 submatches include submatch information (|/\(|)
7053
7054 For each match, a |Dict| with the following items is returned:
7055 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007056 lnum line number where there is a match
7057 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007058 Note that there can be multiple matches in a single line.
7059
7060 This function works only for loaded buffers. First call
7061 |bufload()| if needed.
7062
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007063 See |match-pattern| for information about the effect of some
7064 option settings on the pattern.
7065
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007066 When {buf} is not a valid buffer, the buffer is not loaded or
7067 {lnum} or {end} is not valid then an error is given and an
7068 empty |List| is returned.
7069
7070 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007071 " Assuming line 3 in buffer 5 contains "a"
7072 :echo matchbufline(5, '\<\k\+\>', 3, 3)
7073 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
7074 " Assuming line 4 in buffer 10 contains "tik tok"
7075 :echo matchbufline(10, '\<\k\+\>', 1, 4)
7076 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007077<
7078 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007079 "\1", "\2", etc. are also returned. Example: >
7080 " Assuming line 2 in buffer 2 contains "acd"
7081 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007082 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007083 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007084< The "submatches" List always contains 9 items. If a submatch
7085 is not found, then an empty string is returned for that
7086 submatch.
7087
7088 Can also be used as a |method|: >
7089 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007090<
7091 Return type: list<dict<any>> or list<any>
7092
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007093
h-east624bb832024-11-09 18:37:32 +01007094matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007095 Deletes a match with ID {id} previously defined by |matchadd()|
7096 or one of the |:match| commands. Returns 0 if successful,
7097 otherwise -1. See example for |matchadd()|. All matches can
7098 be deleted in one operation by |clearmatches()|.
7099 If {win} is specified, use the window with this number or
7100 window ID instead of the current window.
7101
7102 Can also be used as a |method|: >
7103 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007104<
7105 Return type: |Number|
7106
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007107
7108matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
7109 Same as |match()|, but return the index of first character
7110 after the match. Example: >
7111 :echo matchend("testing", "ing")
7112< results in "7".
7113 *strspn()* *strcspn()*
7114 Vim doesn't have a strspn() or strcspn() function, but you can
7115 do it with matchend(): >
7116 :let span = matchend(line, '[a-zA-Z]')
7117 :let span = matchend(line, '[^a-zA-Z]')
7118< Except that -1 is returned when there are no matches.
7119
7120 The {start}, if given, has the same meaning as for |match()|. >
7121 :echo matchend("testing", "ing", 2)
7122< results in "7". >
7123 :echo matchend("testing", "ing", 5)
7124< result is "-1".
7125 When {expr} is a |List| the result is equal to |match()|.
7126
7127 Can also be used as a |method|: >
7128 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007129<
7130 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007131
7132
7133matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7134 If {list} is a list of strings, then returns a |List| with all
7135 the strings in {list} that fuzzy match {str}. The strings in
7136 the returned list are sorted based on the matching score.
7137
7138 The optional {dict} argument always supports the following
7139 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007140 matchseq When this item is present return only matches
7141 that contain the characters in {str} in the
7142 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007143 limit Maximum number of matches in {list} to be
7144 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007145
7146 If {list} is a list of dictionaries, then the optional {dict}
7147 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007148 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007149 {str}. The value of this item should be a
7150 string.
7151 text_cb |Funcref| that will be called for every item
7152 in {list} to get the text for fuzzy matching.
7153 This should accept a dictionary item as the
7154 argument and return the text for that item to
7155 use for fuzzy matching.
7156
7157 {str} is treated as a literal string and regular expression
7158 matching is NOT supported. The maximum supported {str} length
7159 is 256.
7160
7161 When {str} has multiple words each separated by white space,
7162 then the list of strings that have all the words is returned.
7163
7164 If there are no matching strings or there is an error, then an
7165 empty list is returned. If length of {str} is greater than
7166 256, then returns an empty list.
7167
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007168 When {limit} is given, matchfuzzy() will find up to this
7169 number of matches in {list} and return them in sorted order.
7170
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007171 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007172 matching strings.
7173
7174 Example: >
7175 :echo matchfuzzy(["clay", "crow"], "cay")
7176< results in ["clay"]. >
7177 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7178< results in a list of buffer names fuzzy matching "ndl". >
7179 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7180< results in a list of buffer information dicts with buffer
7181 names fuzzy matching "ndl". >
7182 :echo getbufinfo()->matchfuzzy("spl",
7183 \ {'text_cb' : {v -> v.name}})
7184< results in a list of buffer information dicts with buffer
7185 names fuzzy matching "spl". >
7186 :echo v:oldfiles->matchfuzzy("test")
7187< results in a list of file names fuzzy matching "test". >
7188 :let l = readfile("buffer.c")->matchfuzzy("str")
7189< results in a list of lines in "buffer.c" fuzzy matching "str". >
7190 :echo ['one two', 'two one']->matchfuzzy('two one')
7191< results in ['two one', 'one two']. >
7192 :echo ['one two', 'two one']->matchfuzzy('two one',
7193 \ {'matchseq': 1})
7194< results in ['two one'].
7195
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007196 Return type: list<string> or list<any>
7197
7198
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007199matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7200 Same as |matchfuzzy()|, but returns the list of matched
7201 strings, the list of character positions where characters
7202 in {str} matches and a list of matching scores. You can
7203 use |byteidx()| to convert a character position to a byte
7204 position.
7205
7206 If {str} matches multiple times in a string, then only the
7207 positions for the best match is returned.
7208
7209 If there are no matching strings or there is an error, then a
7210 list with three empty list items is returned.
7211
7212 Example: >
7213 :echo matchfuzzypos(['testing'], 'tsg')
7214< results in [['testing'], [[0, 2, 6]], [99]] >
7215 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7216< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7217 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7218< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7219
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007220 Return type: list<list<any>>
7221
7222
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007223matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7224 Same as |match()|, but return a |List|. The first item in the
7225 list is the matched string, same as what matchstr() would
7226 return. Following items are submatches, like "\1", "\2", etc.
7227 in |:substitute|. When an optional submatch didn't match an
7228 empty string is used. Example: >
7229 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7230< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7231 When there is no match an empty list is returned.
7232
7233 You can pass in a List, but that is not very useful.
7234
7235 Can also be used as a |method|: >
7236 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007237<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007238 Return type: list<string> or list<any>
7239
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007240 *matchstrlist()*
7241matchstrlist({list}, {pat} [, {dict}])
7242 Returns the |List| of matches in {list} where {pat} matches.
7243 {list} is a |List| of strings. {pat} is matched against each
7244 string in {list}.
7245
7246 The {dict} argument supports following items:
7247 submatches include submatch information (|/\(|)
7248
7249 For each match, a |Dict| with the following items is returned:
7250 byteidx starting byte index of the match.
7251 idx index in {list} of the match.
7252 text matched string
7253 submatches a List of submatches. Present only if
7254 "submatches" is set to v:true in {dict}.
7255
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007256 See |match-pattern| for information about the effect of some
7257 option settings on the pattern.
7258
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007259 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007260 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7261 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7262 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7263 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007264<
7265 If "submatches" is present and is v:true, then submatches like
7266 "\1", "\2", etc. are also returned. Example: >
7267 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7268 \ #{submatches: v:true})
7269 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7270< The "submatches" List always contains 9 items. If a submatch
7271 is not found, then an empty string is returned for that
7272 submatch.
7273
7274 Can also be used as a |method|: >
7275 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007276<
7277 Return type: list<dict<any>> or list<any>
7278
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007279
7280matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7281 Same as |match()|, but return the matched string. Example: >
7282 :echo matchstr("testing", "ing")
7283< results in "ing".
7284 When there is no match "" is returned.
7285 The {start}, if given, has the same meaning as for |match()|. >
7286 :echo matchstr("testing", "ing", 2)
7287< results in "ing". >
7288 :echo matchstr("testing", "ing", 5)
7289< result is "".
7290 When {expr} is a |List| then the matching item is returned.
7291 The type isn't changed, it's not necessarily a String.
7292
7293 Can also be used as a |method|: >
7294 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007295<
7296 Return type: |String|
7297
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007298
7299matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7300 Same as |matchstr()|, but return the matched string, the start
7301 position and the end position of the match. Example: >
7302 :echo matchstrpos("testing", "ing")
7303< results in ["ing", 4, 7].
7304 When there is no match ["", -1, -1] is returned.
7305 The {start}, if given, has the same meaning as for |match()|. >
7306 :echo matchstrpos("testing", "ing", 2)
7307< results in ["ing", 4, 7]. >
7308 :echo matchstrpos("testing", "ing", 5)
7309< result is ["", -1, -1].
7310 When {expr} is a |List| then the matching item, the index
7311 of first item where {pat} matches, the start position and the
7312 end position of the match are returned. >
7313 :echo matchstrpos([1, '__x'], '\a')
7314< result is ["x", 1, 2, 3].
7315 The type isn't changed, it's not necessarily a String.
7316
7317 Can also be used as a |method|: >
7318 GetText()->matchstrpos('word')
7319<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007320 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007321
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007322
7323max({expr}) *max()*
7324 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007325 echo max([apples, pears, oranges])
7326
7327< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7328 it returns the maximum of all values in the Dictionary.
7329 If {expr} is neither a List nor a Dictionary, or one of the
7330 items in {expr} cannot be used as a Number this results in
7331 an error. An empty |List| or |Dictionary| results in zero.
7332
7333 Can also be used as a |method|: >
7334 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007335<
7336 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007337
7338
7339menu_info({name} [, {mode}]) *menu_info()*
7340 Return information about the specified menu {name} in
7341 mode {mode}. The menu name should be specified without the
7342 shortcut character ('&'). If {name} is "", then the top-level
7343 menu names are returned.
7344
7345 {mode} can be one of these strings:
7346 "n" Normal
7347 "v" Visual (including Select)
7348 "o" Operator-pending
7349 "i" Insert
7350 "c" Cmd-line
7351 "s" Select
7352 "x" Visual
7353 "t" Terminal-Job
7354 "" Normal, Visual and Operator-pending
7355 "!" Insert and Cmd-line
7356 When {mode} is omitted, the modes for "" are used.
7357
7358 Returns a |Dictionary| containing the following items:
7359 accel menu item accelerator text |menu-text|
7360 display display name (name without '&')
7361 enabled v:true if this menu item is enabled
7362 Refer to |:menu-enable|
7363 icon name of the icon file (for toolbar)
7364 |toolbar-icon|
7365 iconidx index of a built-in icon
7366 modes modes for which the menu is defined. In
7367 addition to the modes mentioned above, these
7368 characters will be used:
7369 " " Normal, Visual and Operator-pending
7370 name menu item name.
7371 noremenu v:true if the {rhs} of the menu item is not
7372 remappable else v:false.
7373 priority menu order priority |menu-priority|
7374 rhs right-hand-side of the menu item. The returned
7375 string has special characters translated like
7376 in the output of the ":menu" command listing.
7377 When the {rhs} of a menu item is empty, then
7378 "<Nop>" is returned.
7379 script v:true if script-local remapping of {rhs} is
7380 allowed else v:false. See |:menu-script|.
7381 shortcut shortcut key (character after '&' in
7382 the menu name) |menu-shortcut|
7383 silent v:true if the menu item is created
7384 with <silent> argument |:menu-silent|
7385 submenus |List| containing the names of
7386 all the submenus. Present only if the menu
7387 item has submenus.
7388
7389 Returns an empty dictionary if the menu item is not found.
7390
7391 Examples: >
7392 :echo menu_info('Edit.Cut')
7393 :echo menu_info('File.Save', 'n')
7394
7395 " Display the entire menu hierarchy in a buffer
7396 func ShowMenu(name, pfx)
7397 let m = menu_info(a:name)
7398 call append(line('$'), a:pfx .. m.display)
7399 for child in m->get('submenus', [])
7400 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7401 \ a:pfx .. ' ')
7402 endfor
7403 endfunc
7404 new
7405 for topmenu in menu_info('').submenus
7406 call ShowMenu(topmenu, '')
7407 endfor
7408<
7409 Can also be used as a |method|: >
7410 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007411<
7412 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007413
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007414min({expr}) *min()*
7415 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007416 echo min([apples, pears, oranges])
7417
7418< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7419 it returns the minimum of all values in the Dictionary.
7420 If {expr} is neither a List nor a Dictionary, or one of the
7421 items in {expr} cannot be used as a Number this results in
7422 an error. An empty |List| or |Dictionary| results in zero.
7423
7424 Can also be used as a |method|: >
7425 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007426<
7427 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007428
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007429
7430mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007431 Create directory {name}.
7432
Bram Moolenaar938ae282023-02-20 20:44:55 +00007433 When {flags} is present it must be a string. An empty string
7434 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007435
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007436 {flags} can contain these character flags:
7437 "p" intermediate directories will be created as necessary
7438 "D" {name} will be deleted at the end of the current
Christian Brabandtc509c002024-06-14 20:22:05 +02007439 function, but not recursively |:defer|
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007440 "R" {name} will be deleted recursively at the end of the
Christian Brabandtc509c002024-06-14 20:22:05 +02007441 current function |:defer|
Bram Moolenaar938ae282023-02-20 20:44:55 +00007442
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007443 Note that when {name} has more than one part and "p" is used
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007444 some directories may already exist. Only the first one that
7445 is created and what it contains is scheduled to be deleted.
7446 E.g. when using: >
7447 call mkdir('subdir/tmp/autoload', 'pR')
7448< and "subdir" already exists then "subdir/tmp" will be
7449 scheduled for deletion, like with: >
7450 defer delete('subdir/tmp', 'rf')
7451< Note that if scheduling the defer fails the directory is not
7452 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007453
7454 If {prot} is given it is used to set the protection bits of
7455 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7456 the user, readable for others). Use 0o700 to make it
7457 unreadable for others. This is only used for the last part of
7458 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
7459 created with 0o755.
7460 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007461 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007462
7463< This function is not available in the |sandbox|.
7464
7465 There is no error if the directory already exists and the "p"
7466 flag is passed (since patch 8.0.1708). However, without the
7467 "p" option the call will fail.
7468
7469 The function result is a Number, which is TRUE if the call was
7470 successful or FALSE if the directory creation failed or partly
7471 failed.
7472
7473 Not available on all systems. To check use: >
7474 :if exists("*mkdir")
7475
7476< Can also be used as a |method|: >
7477 GetName()->mkdir()
7478<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007479 Return type: |Number|
7480
7481
7482mode([{expr}]) *mode()*
7483 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007484 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007485 a non-empty String (|non-zero-arg|), then the full mode is
7486 returned, otherwise only the first letter is returned.
7487 Also see |state()|.
7488
7489 n Normal
7490 no Operator-pending
7491 nov Operator-pending (forced characterwise |o_v|)
7492 noV Operator-pending (forced linewise |o_V|)
7493 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7494 CTRL-V is one character
7495 niI Normal using |i_CTRL-O| in |Insert-mode|
7496 niR Normal using |i_CTRL-O| in |Replace-mode|
7497 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7498 nt Terminal-Normal (insert goes to Terminal-Job mode)
7499 v Visual by character
7500 vs Visual by character using |v_CTRL-O| in Select mode
7501 V Visual by line
7502 Vs Visual by line using |v_CTRL-O| in Select mode
7503 CTRL-V Visual blockwise
7504 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7505 s Select by character
7506 S Select by line
7507 CTRL-S Select blockwise
7508 i Insert
7509 ic Insert mode completion |compl-generic|
7510 ix Insert mode |i_CTRL-X| completion
7511 R Replace |R|
7512 Rc Replace mode completion |compl-generic|
7513 Rx Replace mode |i_CTRL-X| completion
7514 Rv Virtual Replace |gR|
7515 Rvc Virtual Replace mode completion |compl-generic|
7516 Rvx Virtual Replace mode |i_CTRL-X| completion
7517 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007518 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007519 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007520 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007521 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007522 ce Normal Ex mode |Q|
7523 r Hit-enter prompt
7524 rm The -- more -- prompt
7525 r? A |:confirm| query of some sort
7526 ! Shell or external command is executing
7527 t Terminal-Job mode: keys go to the job
7528
7529 This is useful in the 'statusline' option or when used
7530 with |remote_expr()| In most other places it always returns
7531 "c" or "n".
7532 Note that in the future more modes and more specific modes may
7533 be added. It's better not to compare the whole string but only
7534 the leading character(s).
7535 Also see |visualmode()|.
7536
7537 Can also be used as a |method|: >
7538 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007539<
7540 Return type: |String|
7541
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007542
7543mzeval({expr}) *mzeval()*
7544 Evaluate MzScheme expression {expr} and return its result
7545 converted to Vim data structures.
7546 Numbers and strings are returned as they are.
7547 Pairs (including lists and improper lists) and vectors are
7548 returned as Vim |Lists|.
7549 Hash tables are represented as Vim |Dictionary| type with keys
7550 converted to strings.
7551 All other types are converted to string with display function.
7552 Examples: >
7553 :mz (define l (list 1 2 3))
7554 :mz (define h (make-hash)) (hash-set! h "list" l)
7555 :echo mzeval("l")
7556 :echo mzeval("h")
7557<
7558 Note that in a `:def` function local variables are not visible
7559 to {expr}.
7560
7561 Can also be used as a |method|: >
7562 GetExpr()->mzeval()
7563<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007564 Return type: any, depending on {expr}
7565
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007566 {only available when compiled with the |+mzscheme| feature}
7567
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007568
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007569nextnonblank({lnum}) *nextnonblank()*
7570 Return the line number of the first line at or below {lnum}
7571 that is not blank. Example: >
7572 if getline(nextnonblank(1)) =~ "Java"
7573< When {lnum} is invalid or there is no non-blank line at or
7574 below it, zero is returned.
7575 {lnum} is used like with |getline()|.
7576 See also |prevnonblank()|.
7577
7578 Can also be used as a |method|: >
7579 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007580<
7581 Return type: |Number|
7582
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007583
7584nr2char({expr} [, {utf8}]) *nr2char()*
7585 Return a string with a single character, which has the number
7586 value {expr}. Examples: >
7587 nr2char(64) returns "@"
7588 nr2char(32) returns " "
7589< When {utf8} is omitted or zero, the current 'encoding' is used.
7590 Example for "utf-8": >
7591 nr2char(300) returns I with bow character
7592< When {utf8} is TRUE, always return UTF-8 characters.
7593 Note that a NUL character in the file is specified with
7594 nr2char(10), because NULs are represented with newline
7595 characters. nr2char(0) is a real NUL and terminates the
7596 string, thus results in an empty string.
7597 To turn a list of character numbers into a string: >
7598 let list = [65, 66, 67]
7599 let str = join(map(list, {_, val -> nr2char(val)}), '')
7600< Result: "ABC"
7601
7602 Can also be used as a |method|: >
7603 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007604<
7605 Return type: |String|
7606
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007607
7608or({expr}, {expr}) *or()*
7609 Bitwise OR on the two arguments. The arguments are converted
7610 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007611 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007612 Example: >
7613 :let bits = or(bits, 0x80)
7614< Can also be used as a |method|: >
7615 :let bits = bits->or(0x80)
7616
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007617< Rationale: The reason this is a function and not using the "|"
7618 character like many languages, is that Vi has always used "|"
7619 to separate commands. In many places it would not be clear if
7620 "|" is an operator or a command separator.
7621
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007622 Return type: |Number|
7623
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007624
7625pathshorten({path} [, {len}]) *pathshorten()*
7626 Shorten directory names in the path {path} and return the
7627 result. The tail, the file name, is kept as-is. The other
7628 components in the path are reduced to {len} letters in length.
7629 If {len} is omitted or smaller than 1 then 1 is used (single
7630 letters). Leading '~' and '.' characters are kept. Examples: >
7631 :echo pathshorten('~/.vim/autoload/myfile.vim')
7632< ~/.v/a/myfile.vim ~
7633>
7634 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7635< ~/.vi/au/myfile.vim ~
7636 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007637 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007638
7639 Can also be used as a |method|: >
7640 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007641<
7642 Return type: |String|
7643
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007644
7645perleval({expr}) *perleval()*
7646 Evaluate Perl expression {expr} in scalar context and return
7647 its result converted to Vim data structures. If value can't be
7648 converted, it is returned as a string Perl representation.
7649 Note: If you want an array or hash, {expr} must return a
7650 reference to it.
7651 Example: >
7652 :echo perleval('[1 .. 4]')
7653< [1, 2, 3, 4]
7654
7655 Note that in a `:def` function local variables are not visible
7656 to {expr}.
7657
7658 Can also be used as a |method|: >
7659 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007660<
7661 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007662
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007663 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007664
7665
7666popup_ functions are documented here: |popup-functions|
7667
7668
7669pow({x}, {y}) *pow()*
7670 Return the power of {x} to the exponent {y} as a |Float|.
7671 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007672 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007673 Examples: >
7674 :echo pow(3, 3)
7675< 27.0 >
7676 :echo pow(2, 16)
7677< 65536.0 >
7678 :echo pow(32, 0.20)
7679< 2.0
7680
7681 Can also be used as a |method|: >
7682 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007683<
7684 Return type: |Number|
7685
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007686
7687prevnonblank({lnum}) *prevnonblank()*
7688 Return the line number of the first line at or above {lnum}
7689 that is not blank. Example: >
7690 let ind = indent(prevnonblank(v:lnum - 1))
7691< When {lnum} is invalid or there is no non-blank line at or
7692 above it, zero is returned.
7693 {lnum} is used like with |getline()|.
7694 Also see |nextnonblank()|.
7695
7696 Can also be used as a |method|: >
7697 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007698<
7699 Return type: |Number|
7700
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007701
7702printf({fmt}, {expr1} ...) *printf()*
7703 Return a String with {fmt}, where "%" items are replaced by
7704 the formatted form of their respective arguments. Example: >
7705 printf("%4d: E%d %.30s", lnum, errno, msg)
7706< May result in:
7707 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7708
7709 When used as a |method| the base is passed as the second
7710 argument: >
7711 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007712<
7713 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007714
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007715 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007716 %s string
7717 %6S string right-aligned in 6 display cells
7718 %6s string right-aligned in 6 bytes
7719 %.9s string truncated to 9 bytes
7720 %c single byte
7721 %d decimal number
7722 %5d decimal number padded with spaces to 5 characters
7723 %x hex number
7724 %04x hex number padded with zeros to at least 4 characters
7725 %X hex number using upper case letters
7726 %o octal number
7727 %08b binary number padded with zeros to at least 8 chars
7728 %f floating point number as 12.23, inf, -inf or nan
7729 %F floating point number as 12.23, INF, -INF or NAN
7730 %e floating point number as 1.23e3, inf, -inf or nan
7731 %E floating point number as 1.23E3, INF, -INF or NAN
7732 %g floating point number, as %f or %e depending on value
7733 %G floating point number, as %F or %E depending on value
7734 %% the % character itself
7735
7736 Conversion specifications start with '%' and end with the
7737 conversion type. All other characters are copied unchanged to
7738 the result.
7739
7740 The "%" starts a conversion specification. The following
7741 arguments appear in sequence:
7742
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007743 % [pos-argument] [flags] [field-width] [.precision] type
7744
7745 pos-argument
7746 At most one positional argument specifier. These
7747 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007748
7749 flags
7750 Zero or more of the following flags:
7751
7752 # The value should be converted to an "alternate
7753 form". For c, d, and s conversions, this option
7754 has no effect. For o conversions, the precision
7755 of the number is increased to force the first
7756 character of the output string to a zero (except
7757 if a zero value is printed with an explicit
7758 precision of zero).
7759 For b and B conversions, a non-zero result has
7760 the string "0b" (or "0B" for B conversions)
7761 prepended to it.
7762 For x and X conversions, a non-zero result has
7763 the string "0x" (or "0X" for X conversions)
7764 prepended to it.
7765
7766 0 (zero) Zero padding. For all conversions the converted
7767 value is padded on the left with zeros rather
7768 than blanks. If a precision is given with a
7769 numeric conversion (d, b, B, o, x, and X), the 0
7770 flag is ignored.
7771
7772 - A negative field width flag; the converted value
7773 is to be left adjusted on the field boundary.
7774 The converted value is padded on the right with
7775 blanks, rather than on the left with blanks or
7776 zeros. A - overrides a 0 if both are given.
7777
7778 ' ' (space) A blank should be left before a positive
7779 number produced by a signed conversion (d).
7780
7781 + A sign must always be placed before a number
7782 produced by a signed conversion. A + overrides
7783 a space if both are used.
7784
7785 field-width
7786 An optional decimal digit string specifying a minimum
7787 field width. If the converted value has fewer bytes
7788 than the field width, it will be padded with spaces on
7789 the left (or right, if the left-adjustment flag has
7790 been given) to fill out the field width. For the S
7791 conversion the count is in cells.
7792
7793 .precision
7794 An optional precision, in the form of a period '.'
7795 followed by an optional digit string. If the digit
7796 string is omitted, the precision is taken as zero.
7797 This gives the minimum number of digits to appear for
7798 d, o, x, and X conversions, the maximum number of
7799 bytes to be printed from a string for s conversions,
7800 or the maximum number of cells to be printed from a
7801 string for S conversions.
7802 For floating point it is the number of digits after
7803 the decimal point.
7804
7805 type
7806 A character that specifies the type of conversion to
7807 be applied, see below.
7808
7809 A field width or precision, or both, may be indicated by an
7810 asterisk '*' instead of a digit string. In this case, a
7811 Number argument supplies the field width or precision. A
7812 negative field width is treated as a left adjustment flag
7813 followed by a positive field width; a negative precision is
7814 treated as though it were missing. Example: >
7815 :echo printf("%d: %.*s", nr, width, line)
7816< This limits the length of the text used from "line" to
7817 "width" bytes.
7818
Dominique Pellé17dca3c2023-12-14 20:36:32 +01007819 If the argument to be formatted is specified using a
7820 positional argument specifier, and a '*' is used to indicate
7821 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007822 precision, the argument(s) to be used must also be specified
7823 using a {n$} positional argument specifier. See |printf-$|.
7824
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007825 The conversion specifiers and their meanings are:
7826
7827 *printf-d* *printf-b* *printf-B* *printf-o*
7828 *printf-x* *printf-X*
7829 dbBoxX The Number argument is converted to signed decimal
7830 (d), unsigned binary (b and B), unsigned octal (o), or
7831 unsigned hexadecimal (x and X) notation. The letters
7832 "abcdef" are used for x conversions; the letters
7833 "ABCDEF" are used for X conversions.
7834 The precision, if any, gives the minimum number of
7835 digits that must appear; if the converted value
7836 requires fewer digits, it is padded on the left with
7837 zeros.
7838 In no case does a non-existent or small field width
7839 cause truncation of a numeric field; if the result of
7840 a conversion is wider than the field width, the field
7841 is expanded to contain the conversion result.
7842 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02007843 The 'l' modifier indicates the argument is a long
7844 integer. The size will be 32 bits or 64 bits
7845 depending on your platform.
7846 The "ll" modifier indicates the argument is 64 bits.
7847 The b and B conversion specifiers never take a width
7848 modifier and always assume their argument is a 64 bit
7849 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007850 Generally, these modifiers are not useful. They are
7851 ignored when type is known from the argument.
7852
7853 i alias for d
7854 D alias for ld
7855 U alias for lu
7856 O alias for lo
7857
7858 *printf-c*
7859 c The Number argument is converted to a byte, and the
7860 resulting character is written.
7861
7862 *printf-s*
7863 s The text of the String argument is used. If a
7864 precision is specified, no more bytes than the number
7865 specified are used.
7866 If the argument is not a String type, it is
7867 automatically converted to text with the same format
7868 as ":echo".
7869 *printf-S*
7870 S The text of the String argument is used. If a
7871 precision is specified, no more display cells than the
7872 number specified are used.
7873
7874 *printf-f* *E807*
7875 f F The Float argument is converted into a string of the
7876 form 123.456. The precision specifies the number of
7877 digits after the decimal point. When the precision is
7878 zero the decimal point is omitted. When the precision
7879 is not specified 6 is used. A really big number
7880 (out of range or dividing by zero) results in "inf"
7881 or "-inf" with %f (INF or -INF with %F).
7882 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
7883 Example: >
7884 echo printf("%.2f", 12.115)
7885< 12.12
7886 Note that roundoff depends on the system libraries.
7887 Use |round()| when in doubt.
7888
7889 *printf-e* *printf-E*
7890 e E The Float argument is converted into a string of the
7891 form 1.234e+03 or 1.234E+03 when using 'E'. The
7892 precision specifies the number of digits after the
7893 decimal point, like with 'f'.
7894
7895 *printf-g* *printf-G*
7896 g G The Float argument is converted like with 'f' if the
7897 value is between 0.001 (inclusive) and 10000000.0
7898 (exclusive). Otherwise 'e' is used for 'g' and 'E'
7899 for 'G'. When no precision is specified superfluous
7900 zeroes and '+' signs are removed, except for the zero
7901 immediately after the decimal point. Thus 10000000.0
7902 results in 1.0e7.
7903
7904 *printf-%*
7905 % A '%' is written. No argument is converted. The
7906 complete conversion specification is "%%".
7907
7908 When a Number argument is expected a String argument is also
7909 accepted and automatically converted.
7910 When a Float or String argument is expected a Number argument
7911 is also accepted and automatically converted.
7912 Any other argument type results in an error message.
7913
7914 *E766* *E767*
7915 The number of {exprN} arguments must exactly match the number
7916 of "%" items. If there are not sufficient or too many
7917 arguments an error is given. Up to 18 arguments can be used.
7918
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007919 *printf-$*
7920 In certain languages, error and informative messages are
7921 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02007922 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007923 having a different word order, positional arguments may be
7924 used to indicate this. For instance: >
7925
h_east596a9f22023-11-21 21:24:23 +09007926 #, c-format
7927 msgid "%s returning %s"
7928 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007929<
h_east596a9f22023-11-21 21:24:23 +09007930 In this example, the sentence has its 2 string arguments
7931 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007932
h_east596a9f22023-11-21 21:24:23 +09007933 echo printf(
7934 "In The Netherlands, vim's creator's name is: %1$s %2$s",
7935 "Bram", "Moolenaar")
7936< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007937
h_east596a9f22023-11-21 21:24:23 +09007938 echo printf(
7939 "In Belgium, vim's creator's name is: %2$s %1$s",
7940 "Bram", "Moolenaar")
7941< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007942
7943 Width (and precision) can be specified using the '*' specifier.
7944 In this case, you must specify the field width position in the
7945 argument list. >
7946
h_east596a9f22023-11-21 21:24:23 +09007947 echo printf("%1$*2$.*3$d", 1, 2, 3)
7948< 001 >
7949 echo printf("%2$*3$.*1$d", 1, 2, 3)
7950< 2 >
7951 echo printf("%3$*1$.*2$d", 1, 2, 3)
7952< 03 >
7953 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
7954< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007955
7956 You can mix specifying the width and/or precision directly
7957 and via positional arguments: >
7958
h_east596a9f22023-11-21 21:24:23 +09007959 echo printf("%1$4.*2$f", 1.4142135, 6)
7960< 1.414214 >
7961 echo printf("%1$*2$.4f", 1.4142135, 6)
7962< 1.4142 >
7963 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
7964< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007965
Christ van Willegenc35fc032024-03-14 18:30:41 +01007966 You will get an overflow error |E1510|, when the field-width
7967 or precision will result in a string longer than 6400 chars.
7968
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007969 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007970 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09007971 echo printf("%s%1$s", "One", "Two")
7972< E1500: Cannot mix positional and non-positional arguments:
7973 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007974
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007975 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007976 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09007977 echo printf("%3$s%1$s", "One", "Two", "Three")
7978< E1501: format argument 2 unused in $-style format:
7979 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007980
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007981 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007982 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09007983 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
7984< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007985
7986 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09007987 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
7988< E1502: Positional argument 2 used as field width reused as
7989 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007990
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007991 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007992 When a positional argument is used, but not the correct number
7993 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09007994 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
7995< E1503: Positional argument 3 out of bounds: %1$d at width
7996 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007997
7998 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09007999 echo printf("%01$*2$.*3$d %4$d", 1, 2)
8000< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
8001 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008002
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008003 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008004 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09008005 echo printf("%1$s %2$s %1$s", "One", "Two")
8006< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008007
8008 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09008009 echo printf("%1$s %2$s %1$d", "One", "Two")
8010< E1504: Positional argument 1 type used inconsistently:
8011 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008012
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008013 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008014 Various other errors that lead to a format string being
8015 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09008016 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
8017< E1505: Invalid format specifier: %1$d at width %2$d is:
8018 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008019
Christ van Willegenea746f92023-10-05 20:48:36 +02008020 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08008021 This internal error indicates that the logic to parse a
8022 positional format argument ran into a problem that couldn't be
8023 otherwise reported. Please file a bug against Vim if you run
8024 into this, copying the exact format string and parameters that
8025 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02008026
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008027 Return type: |String|
8028
Christ van Willegenea746f92023-10-05 20:48:36 +02008029
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008030prompt_getprompt({buf}) *prompt_getprompt()*
8031 Returns the effective prompt text for buffer {buf}. {buf} can
8032 be a buffer name or number. See |prompt-buffer|.
8033
8034 If the buffer doesn't exist or isn't a prompt buffer, an empty
8035 string is returned.
8036
8037 Can also be used as a |method|: >
8038 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008039<
8040 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008041
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008042 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008043
8044
8045prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
8046 Set prompt callback for buffer {buf} to {expr}. When {expr}
8047 is an empty string the callback is removed. This has only
8048 effect if {buf} has 'buftype' set to "prompt".
8049
8050 The callback is invoked when pressing Enter. The current
8051 buffer will always be the prompt buffer. A new line for a
8052 prompt is added before invoking the callback, thus the prompt
8053 for which the callback was invoked will be in the last but one
8054 line.
8055 If the callback wants to add text to the buffer, it must
8056 insert it above the last line, since that is where the current
8057 prompt is. This can also be done asynchronously.
8058 The callback is invoked with one argument, which is the text
8059 that was entered at the prompt. This can be an empty string
8060 if the user only typed Enter.
8061 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008062 func s:TextEntered(text)
8063 if a:text == 'exit' || a:text == 'quit'
8064 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008065 " Reset 'modified' to allow the buffer to be closed.
8066 " We assume there is nothing useful to be saved.
8067 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008068 close
8069 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008070 " Do something useful with "a:text". In this example
8071 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008072 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008073 endif
8074 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008075 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008076
8077< Can also be used as a |method|: >
8078 GetBuffer()->prompt_setcallback(callback)
8079
8080< {only available when compiled with the |+channel| feature}
8081
8082prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
8083 Set a callback for buffer {buf} to {expr}. When {expr} is an
8084 empty string the callback is removed. This has only effect if
8085 {buf} has 'buftype' set to "prompt".
8086
8087 This callback will be invoked when pressing CTRL-C in Insert
8088 mode. Without setting a callback Vim will exit Insert mode,
8089 as in any buffer.
8090
8091 Can also be used as a |method|: >
8092 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008093<
8094 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008095
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008096 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008097
8098prompt_setprompt({buf}, {text}) *prompt_setprompt()*
8099 Set prompt for buffer {buf} to {text}. You most likely want
8100 {text} to end in a space.
8101 The result is only visible if {buf} has 'buftype' set to
8102 "prompt". Example: >
8103 call prompt_setprompt(bufnr(), 'command: ')
8104<
8105 Can also be used as a |method|: >
8106 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008107<
8108 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008109
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008110 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008111
8112prop_ functions are documented here: |text-prop-functions|
8113
8114pum_getpos() *pum_getpos()*
8115 If the popup menu (see |ins-completion-menu|) is not visible,
8116 returns an empty |Dictionary|, otherwise, returns a
8117 |Dictionary| with the following keys:
8118 height nr of items visible
8119 width screen cells
8120 row top screen row (0 first row)
8121 col leftmost screen column (0 first col)
8122 size total nr of items
8123 scrollbar |TRUE| if scrollbar is visible
8124
8125 The values are the same as in |v:event| during
8126 |CompleteChanged|.
8127
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008128 Return type: dict<any>
8129
8130
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008131pumvisible() *pumvisible()*
8132 Returns non-zero when the popup menu is visible, zero
8133 otherwise. See |ins-completion-menu|.
8134 This can be used to avoid some things that would remove the
8135 popup menu.
8136
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008137 Return type: |Number|
8138
8139
zeertzjq7c515282024-11-10 20:26:12 +01008140py3eval({expr} [, {locals}]) *py3eval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008141 Evaluate Python expression {expr} and return its result
8142 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008143 If a {locals} |Dictionary| is given, it defines set of local
8144 variables available in the expression. The keys are variable
8145 names and the values are the variable values. |Dictionary| and
8146 |List| values are referenced, and may be updated by the
8147 expression (as if |python-bindeval| was used).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008148 Numbers and strings are returned as they are (strings are
8149 copied though, Unicode strings are additionally converted to
8150 'encoding').
8151 Lists are represented as Vim |List| type.
8152 Dictionaries are represented as Vim |Dictionary| type with
8153 keys converted to strings.
8154 Note that in a `:def` function local variables are not visible
8155 to {expr}.
8156
8157 Can also be used as a |method|: >
8158 GetExpr()->py3eval()
Ben Jacksonea19e782024-11-06 21:50:05 +01008159 'b",".join(l)'->py3eval({'l': ['a', 'b', 'c']})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008160<
8161 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008162
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008163 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008164
8165 *E858* *E859*
zeertzjq7c515282024-11-10 20:26:12 +01008166pyeval({expr} [, {locals}]) *pyeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008167 Evaluate Python expression {expr} and return its result
8168 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008169 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008170 Numbers and strings are returned as they are (strings are
8171 copied though).
8172 Lists are represented as Vim |List| type.
8173 Dictionaries are represented as Vim |Dictionary| type,
8174 non-string keys result in error.
8175 Note that in a `:def` function local variables are not visible
8176 to {expr}.
8177
8178 Can also be used as a |method|: >
8179 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008180<
8181 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008182
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008183 {only available when compiled with the |+python| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008184
zeertzjq7c515282024-11-10 20:26:12 +01008185pyxeval({expr} [, {locals}]) *pyxeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008186 Evaluate Python expression {expr} and return its result
8187 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008188 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008189 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8190 See also: |pyeval()|, |py3eval()|
8191
8192 Can also be used as a |method|: >
h-east52e7cc22024-07-28 17:03:29 +02008193 GetExpr()->pyxeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008194<
8195 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008196
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008197 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008198 |+python3| feature}
8199
8200rand([{expr}]) *rand()* *random*
8201 Return a pseudo-random Number generated with an xoshiro128**
8202 algorithm using seed {expr}. The returned number is 32 bits,
8203 also on 64 bits systems, for consistency.
8204 {expr} can be initialized by |srand()| and will be updated by
8205 rand(). If {expr} is omitted, an internal seed value is used
8206 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008207 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008208
8209 Examples: >
8210 :echo rand()
8211 :let seed = srand()
8212 :echo rand(seed)
8213 :echo rand(seed) % 16 " random number 0 - 15
8214<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008215 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008216
8217 *E726* *E727*
8218range({expr} [, {max} [, {stride}]]) *range()*
8219 Returns a |List| with Numbers:
8220 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8221 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8222 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8223 {max}] (increasing {expr} with {stride} each time, not
8224 producing a value past {max}).
8225 When the maximum is one before the start the result is an
8226 empty list. When the maximum is more than one before the
8227 start this is an error.
8228 Examples: >
8229 range(4) " [0, 1, 2, 3]
8230 range(2, 4) " [2, 3, 4]
8231 range(2, 9, 3) " [2, 5, 8]
8232 range(2, -2, -1) " [2, 1, 0, -1, -2]
8233 range(0) " []
8234 range(2, 0) " error!
8235<
8236 Can also be used as a |method|: >
8237 GetExpr()->range()
8238<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008239 Return type: list<number>
8240
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008241
K.Takata11df3ae2022-10-19 14:02:40 +01008242readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008243 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008244 If {offset} is specified, read the file from the specified
8245 offset. If it is a negative value, it is used as an offset
8246 from the end of the file. E.g., to read the last 12 bytes: >
8247 readblob('file.bin', -12)
8248< If {size} is specified, only the specified size will be read.
8249 E.g. to read the first 100 bytes of a file: >
8250 readblob('file.bin', 0, 100)
8251< If {size} is -1 or omitted, the whole data starting from
8252 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008253 This can be also used to read the data from a character device
8254 on Unix when {size} is explicitly set. Only if the device
8255 supports seeking {offset} can be used. Otherwise it should be
8256 zero. E.g. to read 10 bytes from a serial console: >
8257 readblob('/dev/ttyS0', 0, 10)
8258< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008259 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008260 When the offset is beyond the end of the file the result is an
8261 empty blob.
8262 When trying to read more bytes than are available the result
8263 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008264 Also see |readfile()| and |writefile()|.
8265
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008266 Return type: |Blob|
8267
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008268
8269readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8270 Return a list with file and directory names in {directory}.
8271 You can also use |glob()| if you don't need to do complicated
8272 things, such as limiting the number of matches.
8273 The list will be sorted (case sensitive), see the {dict}
8274 argument below for changing the sort order.
8275
8276 When {expr} is omitted all entries are included.
8277 When {expr} is given, it is evaluated to check what to do:
8278 If {expr} results in -1 then no further entries will
8279 be handled.
8280 If {expr} results in 0 then this entry will not be
8281 added to the list.
8282 If {expr} results in 1 then this entry will be added
8283 to the list.
8284 The entries "." and ".." are always excluded.
8285 Each time {expr} is evaluated |v:val| is set to the entry name.
8286 When {expr} is a function the name is passed as the argument.
8287 For example, to get a list of files ending in ".txt": >
8288 readdir(dirname, {n -> n =~ '.txt$'})
8289< To skip hidden and backup files: >
8290 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008291< *E857*
8292 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008293 values. Currently this is used to specify if and how sorting
8294 should be performed. The dict can have the following members:
8295
8296 sort How to sort the result returned from the system.
8297 Valid values are:
8298 "none" do not sort (fastest method)
8299 "case" sort case sensitive (byte value of
8300 each character, technically, using
8301 strcmp()) (default)
8302 "icase" sort case insensitive (technically
8303 using strcasecmp())
8304 "collate" sort using the collation order
8305 of the "POSIX" or "C" |locale|
8306 (technically using strcoll())
8307 Other values are silently ignored.
8308
8309 For example, to get a list of all files in the current
8310 directory without sorting the individual entries: >
8311 readdir('.', '1', #{sort: 'none'})
8312< If you want to get a directory tree: >
8313 function! s:tree(dir)
8314 return {a:dir : map(readdir(a:dir),
8315 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008316 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008317 endfunction
8318 echo s:tree(".")
8319<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008320 Returns an empty List on error.
8321
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008322 Can also be used as a |method|: >
8323 GetDirName()->readdir()
8324<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008325 Return type: list<string> or list<any>
8326
8327
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008328readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8329 Extended version of |readdir()|.
8330 Return a list of Dictionaries with file and directory
8331 information in {directory}.
8332 This is useful if you want to get the attributes of file and
8333 directory at the same time as getting a list of a directory.
8334 This is much faster than calling |readdir()| then calling
8335 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8336 each file and directory especially on MS-Windows.
8337 The list will by default be sorted by name (case sensitive),
8338 the sorting can be changed by using the optional {dict}
8339 argument, see |readdir()|.
8340
8341 The Dictionary for file and directory information has the
8342 following items:
8343 group Group name of the entry. (Only on Unix)
8344 name Name of the entry.
8345 perm Permissions of the entry. See |getfperm()|.
8346 size Size of the entry. See |getfsize()|.
8347 time Timestamp of the entry. See |getftime()|.
8348 type Type of the entry.
8349 On Unix, almost same as |getftype()| except:
8350 Symlink to a dir "linkd"
8351 Other symlink "link"
8352 On MS-Windows:
8353 Normal file "file"
8354 Directory "dir"
8355 Junction "junction"
8356 Symlink to a dir "linkd"
8357 Other symlink "link"
8358 Other reparse point "reparse"
8359 user User name of the entry's owner. (Only on Unix)
8360 On Unix, if the entry is a symlink, the Dictionary includes
8361 the information of the target (except the "type" item).
8362 On MS-Windows, it includes the information of the symlink
8363 itself because of performance reasons.
8364
8365 When {expr} is omitted all entries are included.
8366 When {expr} is given, it is evaluated to check what to do:
8367 If {expr} results in -1 then no further entries will
8368 be handled.
8369 If {expr} results in 0 then this entry will not be
8370 added to the list.
8371 If {expr} results in 1 then this entry will be added
8372 to the list.
8373 The entries "." and ".." are always excluded.
8374 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8375 of the entry.
8376 When {expr} is a function the entry is passed as the argument.
8377 For example, to get a list of files ending in ".txt": >
8378 readdirex(dirname, {e -> e.name =~ '.txt$'})
8379<
8380 For example, to get a list of all files in the current
8381 directory without sorting the individual entries: >
8382 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008383<
8384 Can also be used as a |method|: >
8385 GetDirName()->readdirex()
8386<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008387 Return type: list<dict<any>> or list<any>
8388
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008389
8390 *readfile()*
8391readfile({fname} [, {type} [, {max}]])
8392 Read file {fname} and return a |List|, each line of the file
8393 as an item. Lines are broken at NL characters. Macintosh
8394 files separated with CR will result in a single long line
8395 (unless a NL appears somewhere).
8396 All NUL characters are replaced with a NL character.
8397 When {type} contains "b" binary mode is used:
8398 - When the last line ends in a NL an extra empty list item is
8399 added.
8400 - No CR characters are removed.
8401 Otherwise:
8402 - CR characters that appear before a NL are removed.
8403 - Whether the last line ends in a NL or not does not matter.
8404 - When 'encoding' is Unicode any UTF-8 byte order mark is
8405 removed from the text.
8406 When {max} is given this specifies the maximum number of lines
8407 to be read. Useful if you only want to check the first ten
8408 lines of a file: >
8409 :for line in readfile(fname, '', 10)
8410 : if line =~ 'Date' | echo line | endif
8411 :endfor
8412< When {max} is negative -{max} lines from the end of the file
8413 are returned, or as many as there are.
8414 When {max} is zero the result is an empty list.
8415 Note that without {max} the whole file is read into memory.
8416 Also note that there is no recognition of encoding. Read a
8417 file into a buffer if you need to.
8418 Deprecated (use |readblob()| instead): When {type} contains
8419 "B" a |Blob| is returned with the binary data of the file
8420 unmodified.
8421 When the file can't be opened an error message is given and
8422 the result is an empty list.
8423 Also see |writefile()|.
8424
8425 Can also be used as a |method|: >
8426 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008427<
8428 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008429
8430reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8431 {func} is called for every item in {object}, which can be a
8432 |String|, |List| or a |Blob|. {func} is called with two
8433 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008434 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008435
8436 {initial} is the initial result. When omitted, the first item
8437 in {object} is used and {func} is first called for the second
8438 item. If {initial} is not given and {object} is empty no
8439 result can be computed, an E998 error is given.
8440
8441 Examples: >
8442 echo reduce([1, 3, 5], { acc, val -> acc + val })
8443 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8444 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8445 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8446<
8447 Can also be used as a |method|: >
8448 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008449<
8450 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8451 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008452
8453
8454reg_executing() *reg_executing()*
8455 Returns the single letter name of the register being executed.
8456 Returns an empty string when no register is being executed.
8457 See |@|.
8458
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008459 Return type: |String|
8460
8461
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008462reg_recording() *reg_recording()*
8463 Returns the single letter name of the register being recorded.
8464 Returns an empty string when not recording. See |q|.
8465
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008466 Return type: |String|
8467
8468
8469reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008470reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008471reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008472 Return an item that represents a time value. The item is a
8473 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008474 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008475 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008476 string or |reltimefloat()| to convert to a Float. For
8477 example, to see the time spent in function Work(): >
8478 var startTime = reltime()
8479 Work()
8480 echo startTime->reltime()->reltimestr()
8481<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008482 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008483 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008484 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008485 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008486 specified in the argument.
8487 With two arguments it returns the time passed between {start}
8488 and {end}.
8489
8490 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008491 reltime(). If there is an error an empty List is returned in
8492 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008493
8494 Can also be used as a |method|: >
8495 GetStart()->reltime()
8496<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008497 Return type: list<number>
8498
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008499 {only available when compiled with the |+reltime| feature}
8500
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008501
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008502reltimefloat({time}) *reltimefloat()*
8503 Return a Float that represents the time value of {time}.
8504 Example: >
8505 let start = reltime()
8506 call MyFunction()
8507 let seconds = reltimefloat(reltime(start))
8508< See the note of reltimestr() about overhead.
8509 Also see |profiling|.
8510 If there is an error 0.0 is returned in legacy script, in Vim9
8511 script an error is given.
8512
8513 Can also be used as a |method|: >
8514 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008515<
8516 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008517
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008518 {only available when compiled with the |+reltime| feature}
8519
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008520
8521reltimestr({time}) *reltimestr()*
8522 Return a String that represents the time value of {time}.
8523 This is the number of seconds, a dot and the number of
8524 microseconds. Example: >
8525 let start = reltime()
8526 call MyFunction()
8527 echo reltimestr(reltime(start))
8528< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008529 The accuracy depends on the system. Use reltimefloat() for the
8530 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008531 Leading spaces are used to make the string align nicely. You
8532 can use split() to remove it. >
8533 echo split(reltimestr(reltime(start)))[0]
8534< Also see |profiling|.
8535 If there is an error an empty string is returned in legacy
8536 script, in Vim9 script an error is given.
8537
8538 Can also be used as a |method|: >
8539 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008540<
8541 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008542
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008543 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008544
8545 *remote_expr()* *E449*
8546remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008547 Send the {string} to {server}. The {server} argument is a
8548 string, also see |{server}|.
8549
8550 The string is sent as an expression and the result is returned
Christian Brabandt1961caf2024-10-12 11:57:12 +02008551 after evaluation. The result must be a String or a |List|
8552 other types will be converted to String. A |List| is turned
8553 into a String by joining the items with a line break in
8554 between (not at the end), like with join(expr, "\n").
Bram Moolenaar944697a2022-02-20 19:48:20 +00008555
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008556 If {idvar} is present and not empty, it is taken as the name
8557 of a variable and a {serverid} for later use with
8558 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008559
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008560 If {timeout} is given the read times out after this many
8561 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008562
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008563 See also |clientserver| |RemoteReply|.
8564 This function is not available in the |sandbox|.
8565 {only available when compiled with the |+clientserver| feature}
8566 Note: Any errors will cause a local error message to be issued
8567 and the result will be the empty string.
8568
8569 Variables will be evaluated in the global namespace,
8570 independent of a function currently being active. Except
8571 when in debug mode, then local function variables and
8572 arguments can be evaluated.
8573
8574 Examples: >
8575 :echo remote_expr("gvim", "2+2")
8576 :echo remote_expr("gvim1", "b:current_syntax")
8577<
8578 Can also be used as a |method|: >
8579 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008580<
8581 Return type: |String| or list<{type}>
8582
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008583
8584remote_foreground({server}) *remote_foreground()*
8585 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008586 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008587 This works like: >
8588 remote_expr({server}, "foreground()")
8589< Except that on Win32 systems the client does the work, to work
8590 around the problem that the OS doesn't always allow the server
8591 to bring itself to the foreground.
8592 Note: This does not restore the window if it was minimized,
8593 like foreground() does.
8594 This function is not available in the |sandbox|.
8595
8596 Can also be used as a |method|: >
8597 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008598<
8599 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008600
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008601 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008602 Win32 console version}
8603
8604
8605remote_peek({serverid} [, {retvar}]) *remote_peek()*
8606 Returns a positive number if there are available strings
8607 from {serverid}. Copies any reply string into the variable
8608 {retvar} if specified. {retvar} must be a string with the
8609 name of a variable.
8610 Returns zero if none are available.
8611 Returns -1 if something is wrong.
8612 See also |clientserver|.
8613 This function is not available in the |sandbox|.
8614 {only available when compiled with the |+clientserver| feature}
8615 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008616 :let repl = ""
8617 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008618
8619< Can also be used as a |method|: >
8620 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008621<
8622 Return type: |Number|
8623
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008624
8625remote_read({serverid}, [{timeout}]) *remote_read()*
8626 Return the oldest available reply from {serverid} and consume
8627 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008628 reply is available. Returns an empty string, if a reply is
8629 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008630 See also |clientserver|.
8631 This function is not available in the |sandbox|.
8632 {only available when compiled with the |+clientserver| feature}
8633 Example: >
8634 :echo remote_read(id)
8635
8636< Can also be used as a |method|: >
8637 ServerId()->remote_read()
8638<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008639 Return type: |String|
8640
8641
8642remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008643 Send the {string} to {server}. The {server} argument is a
8644 string, also see |{server}|.
8645
8646 The string is sent as input keys and the function returns
8647 immediately. At the Vim server the keys are not mapped
8648 |:map|.
8649
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008650 If {idvar} is present, it is taken as the name of a variable
8651 and a {serverid} for later use with remote_read() is stored
8652 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008653
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008654 See also |clientserver| |RemoteReply|.
8655 This function is not available in the |sandbox|.
8656 {only available when compiled with the |+clientserver| feature}
8657
8658 Note: Any errors will be reported in the server and may mess
8659 up the display.
8660 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008661 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008662 \ remote_read(serverid)
8663
8664 :autocmd NONE RemoteReply *
8665 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008666 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008667 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8668<
8669 Can also be used as a |method|: >
8670 ServerName()->remote_send(keys)
8671<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008672 Return type: |String|
8673
8674
8675remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008676 Become the server {name}. {name} must be a non-empty string.
8677 This fails if already running as a server, when |v:servername|
8678 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008679
8680 Can also be used as a |method|: >
8681 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008682<
8683 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008684
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008685 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008686
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008687
8688remove({list}, {idx}) *remove()*
8689remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008690 Without {end}: Remove the item at {idx} from |List| {list} and
8691 return the item.
8692 With {end}: Remove items from {idx} to {end} (inclusive) and
8693 return a |List| with these items. When {idx} points to the same
8694 item as {end} a list with one item is returned. When {end}
8695 points to an item before {idx} this is an error.
8696 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008697 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008698 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008699 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008700 :call remove(mylist, 0, 9)
8701<
8702 Use |delete()| to remove a file.
8703
8704 Can also be used as a |method|: >
8705 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008706<
8707 Return type: any, depending on {list}
8708
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008709
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008710remove({blob}, {idx})
8711remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008712 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8713 return the byte.
8714 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8715 return a |Blob| with these bytes. When {idx} points to the same
8716 byte as {end} a |Blob| with one byte is returned. When {end}
8717 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008718 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008719 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008720 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008721 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008722<
8723 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008724
8725remove({dict}, {key})
8726 Remove the entry from {dict} with key {key} and return it.
8727 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008728 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008729< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008730 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008731
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008732 Return type: any, depending on {dict}
8733
8734
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008735rename({from}, {to}) *rename()*
8736 Rename the file by the name {from} to the name {to}. This
8737 should also work to move files across file systems. The
8738 result is a Number, which is 0 if the file was renamed
8739 successfully, and non-zero when the renaming failed.
8740 NOTE: If {to} exists it is overwritten without warning.
8741 This function is not available in the |sandbox|.
8742
8743 Can also be used as a |method|: >
8744 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008745<
8746 Return type: |Number|
8747
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008748
8749repeat({expr}, {count}) *repeat()*
8750 Repeat {expr} {count} times and return the concatenated
8751 result. Example: >
8752 :let separator = repeat('-', 80)
8753< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01008754 When {expr} is a |List| or a |Blob| the result is {expr}
8755 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008756 :let longlist = repeat(['a', 'b'], 3)
8757< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
8758
8759 Can also be used as a |method|: >
8760 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008761<
8762 Return type: |String|, |Blob| or list<{type}> depending on
8763 {expr}
8764
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008765
8766resolve({filename}) *resolve()* *E655*
8767 On MS-Windows, when {filename} is a shortcut (a .lnk file),
8768 returns the path the shortcut points to in a simplified form.
8769 When {filename} is a symbolic link or junction point, return
8770 the full path to the target. If the target of junction is
8771 removed, return {filename}.
8772 On Unix, repeat resolving symbolic links in all path
8773 components of {filename} and return the simplified result.
8774 To cope with link cycles, resolving of symbolic links is
8775 stopped after 100 iterations.
8776 On other systems, return the simplified {filename}.
8777 The simplification step is done as by |simplify()|.
8778 resolve() keeps a leading path component specifying the
8779 current directory (provided the result is still a relative
8780 path name) and also keeps a trailing path separator.
8781
8782 Can also be used as a |method|: >
8783 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008784<
8785 Return type: |String|
8786
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008787
8788reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01008789 Reverse the order of items in {object}. {object} can be a
8790 |List|, a |Blob| or a |String|. For a List and a Blob the
8791 items are reversed in-place and {object} is returned.
8792 For a String a new String is returned.
8793 Returns zero if {object} is not a List, Blob or a String.
8794 If you want a List or Blob to remain unmodified make a copy
8795 first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008796 :let revlist = reverse(copy(mylist))
8797< Can also be used as a |method|: >
8798 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008799<
8800 Return type: |String|, |Blob| or list<{type}> depending on
8801 {object}
8802
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008803
8804round({expr}) *round()*
8805 Round off {expr} to the nearest integral value and return it
8806 as a |Float|. If {expr} lies halfway between two integral
8807 values, then use the larger one (away from zero).
8808 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008809 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008810 Examples: >
8811 echo round(0.456)
8812< 0.0 >
8813 echo round(4.5)
8814< 5.0 >
8815 echo round(-4.5)
8816< -5.0
8817
8818 Can also be used as a |method|: >
8819 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008820<
8821 Return type: |Float|
8822
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008823
8824rubyeval({expr}) *rubyeval()*
8825 Evaluate Ruby expression {expr} and return its result
8826 converted to Vim data structures.
8827 Numbers, floats and strings are returned as they are (strings
8828 are copied though).
8829 Arrays are represented as Vim |List| type.
8830 Hashes are represented as Vim |Dictionary| type.
8831 Other objects are represented as strings resulted from their
8832 "Object#to_s" method.
8833 Note that in a `:def` function local variables are not visible
8834 to {expr}.
8835
8836 Can also be used as a |method|: >
8837 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008838<
8839 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008840
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008841 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008842
8843screenattr({row}, {col}) *screenattr()*
8844 Like |screenchar()|, but return the attribute. This is a rather
8845 arbitrary number that can only be used to compare to the
8846 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008847 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008848
8849 Can also be used as a |method|: >
8850 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008851<
8852 Return type: |Number|
8853
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008854
8855screenchar({row}, {col}) *screenchar()*
8856 The result is a Number, which is the character at position
8857 [row, col] on the screen. This works for every possible
8858 screen position, also status lines, window separators and the
8859 command line. The top left position is row one, column one
8860 The character excludes composing characters. For double-byte
8861 encodings it may only be the first byte.
8862 This is mainly to be used for testing.
8863 Returns -1 when row or col is out of range.
8864
8865 Can also be used as a |method|: >
8866 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008867<
8868 Return type: |Number|
8869
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008870
8871screenchars({row}, {col}) *screenchars()*
8872 The result is a |List| of Numbers. The first number is the same
8873 as what |screenchar()| returns. Further numbers are
8874 composing characters on top of the base character.
8875 This is mainly to be used for testing.
8876 Returns an empty List when row or col is out of range.
8877
8878 Can also be used as a |method|: >
8879 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008880<
8881 Return type: list<number> or list<any>
8882
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008883
8884screencol() *screencol()*
8885 The result is a Number, which is the current screen column of
8886 the cursor. The leftmost column has number 1.
8887 This function is mainly used for testing.
8888
8889 Note: Always returns the current screen column, thus if used
8890 in a command (e.g. ":echo screencol()") it will return the
8891 column inside the command line, which is 1 when the command is
8892 executed. To get the cursor position in the file use one of
8893 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008894 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008895 nnoremap <silent> GG :echom screencol()<CR>
8896 nnoremap GG <Cmd>echom screencol()<CR>
8897<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008898 Return type: |Number|
8899
8900
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008901screenpos({winid}, {lnum}, {col}) *screenpos()*
8902 The result is a Dict with the screen position of the text
8903 character in window {winid} at buffer line {lnum} and column
8904 {col}. {col} is a one-based byte index.
8905 The Dict has these members:
8906 row screen row
8907 col first screen column
8908 endcol last screen column
8909 curscol cursor screen column
8910 If the specified position is not visible, all values are zero.
8911 The "endcol" value differs from "col" when the character
8912 occupies more than one screen cell. E.g. for a Tab "col" can
8913 be 1 and "endcol" can be 8.
8914 The "curscol" value is where the cursor would be placed. For
8915 a Tab it would be the same as "endcol", while for a double
8916 width character it would be the same as "col".
8917 The |conceal| feature is ignored here, the column numbers are
8918 as if 'conceallevel' is zero. You can set the cursor to the
8919 right position and use |screencol()| to get the value with
8920 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008921 If the position is in a closed fold the screen position of the
8922 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008923 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008924
8925 Can also be used as a |method|: >
8926 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008927<
8928 Return type: dict<number> or dict<any>
8929
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008930
8931screenrow() *screenrow()*
8932 The result is a Number, which is the current screen row of the
8933 cursor. The top line has number one.
8934 This function is mainly used for testing.
8935 Alternatively you can use |winline()|.
8936
8937 Note: Same restrictions as with |screencol()|.
8938
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008939 Return type: |Number|
8940
8941
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008942screenstring({row}, {col}) *screenstring()*
8943 The result is a String that contains the base character and
8944 any composing characters at position [row, col] on the screen.
8945 This is like |screenchars()| but returning a String with the
8946 characters.
8947 This is mainly to be used for testing.
8948 Returns an empty String when row or col is out of range.
8949
8950 Can also be used as a |method|: >
8951 GetRow()->screenstring(col)
8952<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008953 Return type: |String|
8954
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008955 *search()*
8956search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
8957 Search for regexp pattern {pattern}. The search starts at the
8958 cursor position (you can use |cursor()| to set it).
8959
8960 When a match has been found its line number is returned.
8961 If there is no match a 0 is returned and the cursor doesn't
8962 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01008963 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008964
8965 {flags} is a String, which can contain these character flags:
8966 'b' search Backward instead of forward
8967 'c' accept a match at the Cursor position
8968 'e' move to the End of the match
8969 'n' do Not move the cursor
8970 'p' return number of matching sub-Pattern (see below)
8971 's' Set the ' mark at the previous location of the cursor
8972 'w' Wrap around the end of the file
8973 'W' don't Wrap around the end of the file
8974 'z' start searching at the cursor column instead of zero
8975 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
8976
8977 If the 's' flag is supplied, the ' mark is set, only if the
8978 cursor is moved. The 's' flag cannot be combined with the 'n'
8979 flag.
8980
8981 'ignorecase', 'smartcase' and 'magic' are used.
8982
8983 When the 'z' flag is not given, forward searching always
8984 starts in column zero and then matches before the cursor are
8985 skipped. When the 'c' flag is present in 'cpo' the next
8986 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01008987 search starts one column after the start of the match. This
8988 matters for overlapping matches. See |cpo-c|. You can also
8989 insert "\ze" to change where the match ends, see |/\ze|.
8990
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008991 When searching backwards and the 'z' flag is given then the
8992 search starts in column zero, thus no match in the current
8993 line will be found (unless wrapping around the end of the
8994 file).
8995
8996 When the {stopline} argument is given then the search stops
8997 after searching this line. This is useful to restrict the
8998 search to a range of lines. Examples: >
8999 let match = search('(', 'b', line("w0"))
9000 let end = search('END', '', line("w$"))
9001< When {stopline} is used and it is not zero this also implies
9002 that the search does not wrap around the end of the file.
9003 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01009004 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009005 When the {timeout} argument is given the search stops when
9006 more than this many milliseconds have passed. Thus when
9007 {timeout} is 500 the search stops after half a second.
9008 The value must not be negative. A zero value is like not
9009 giving the argument.
Christian Brabandtd657d3d2024-09-10 21:55:49 +02009010
9011 Note: the timeout is only considered when searching, not
9012 while evaluating the {skip} expression.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009013 {only available when compiled with the |+reltime| feature}
9014
9015 If the {skip} expression is given it is evaluated with the
9016 cursor positioned on the start of a match. If it evaluates to
9017 non-zero this match is skipped. This can be used, for
9018 example, to skip a match in a comment or a string.
9019 {skip} can be a string, which is evaluated as an expression, a
9020 function reference or a lambda.
9021 When {skip} is omitted or empty, every match is accepted.
9022 When evaluating {skip} causes an error the search is aborted
9023 and -1 returned.
9024 *search()-sub-match*
9025 With the 'p' flag the returned value is one more than the
9026 first sub-match in \(\). One if none of them matched but the
9027 whole pattern did match.
9028 To get the column number too use |searchpos()|.
9029
9030 The cursor will be positioned at the match, unless the 'n'
9031 flag is used.
9032
9033 Example (goes over all files in the argument list): >
9034 :let n = 1
9035 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009036 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009037 : " start at the last char in the file and wrap for the
9038 : " first search to find match at start of file
9039 : normal G$
9040 : let flags = "w"
9041 : while search("foo", flags) > 0
9042 : s/foo/bar/g
9043 : let flags = "W"
9044 : endwhile
9045 : update " write the file if modified
9046 : let n = n + 1
9047 :endwhile
9048<
9049 Example for using some flags: >
9050 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
9051< This will search for the keywords "if", "else", and "endif"
9052 under or after the cursor. Because of the 'p' flag, it
9053 returns 1, 2, or 3 depending on which keyword is found, or 0
9054 if the search fails. With the cursor on the first word of the
9055 line:
9056 if (foo == 0) | let foo = foo + 1 | endif ~
9057 the function returns 1. Without the 'c' flag, the function
9058 finds the "endif" and returns 3. The same thing happens
9059 without the 'e' flag if the cursor is on the "f" of "if".
9060 The 'n' flag tells the function not to move the cursor.
9061
9062 Can also be used as a |method|: >
9063 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009064<
9065 Return type: |Number|
9066
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009067
9068searchcount([{options}]) *searchcount()*
9069 Get or update the last search count, like what is displayed
9070 without the "S" flag in 'shortmess'. This works even if
9071 'shortmess' does contain the "S" flag.
9072
9073 This returns a |Dictionary|. The dictionary is empty if the
9074 previous pattern was not set and "pattern" was not specified.
9075
9076 key type meaning ~
9077 current |Number| current position of match;
9078 0 if the cursor position is
9079 before the first match
9080 exact_match |Boolean| 1 if "current" is matched on
9081 "pos", otherwise 0
9082 total |Number| total count of matches found
9083 incomplete |Number| 0: search was fully completed
9084 1: recomputing was timed out
9085 2: max count exceeded
9086
9087 For {options} see further down.
9088
9089 To get the last search count when |n| or |N| was pressed, call
9090 this function with `recompute: 0` . This sometimes returns
9091 wrong information because |n| and |N|'s maximum count is 99.
9092 If it exceeded 99 the result must be max count + 1 (100). If
9093 you want to get correct information, specify `recompute: 1`: >
9094
9095 " result == maxcount + 1 (100) when many matches
9096 let result = searchcount(#{recompute: 0})
9097
9098 " Below returns correct result (recompute defaults
9099 " to 1)
9100 let result = searchcount()
9101<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01009102 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009103 function! LastSearchCount() abort
9104 let result = searchcount(#{recompute: 0})
9105 if empty(result)
9106 return ''
9107 endif
9108 if result.incomplete ==# 1 " timed out
9109 return printf(' /%s [?/??]', @/)
9110 elseif result.incomplete ==# 2 " max count exceeded
9111 if result.total > result.maxcount &&
9112 \ result.current > result.maxcount
9113 return printf(' /%s [>%d/>%d]', @/,
9114 \ result.current, result.total)
9115 elseif result.total > result.maxcount
9116 return printf(' /%s [%d/>%d]', @/,
9117 \ result.current, result.total)
9118 endif
9119 endif
9120 return printf(' /%s [%d/%d]', @/,
9121 \ result.current, result.total)
9122 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009123 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009124
9125 " Or if you want to show the count only when
9126 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009127 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009128 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9129<
9130 You can also update the search count, which can be useful in a
9131 |CursorMoved| or |CursorMovedI| autocommand: >
9132
9133 autocmd CursorMoved,CursorMovedI *
9134 \ let s:searchcount_timer = timer_start(
9135 \ 200, function('s:update_searchcount'))
9136 function! s:update_searchcount(timer) abort
9137 if a:timer ==# s:searchcount_timer
9138 call searchcount(#{
9139 \ recompute: 1, maxcount: 0, timeout: 100})
9140 redrawstatus
9141 endif
9142 endfunction
9143<
9144 This can also be used to count matched texts with specified
9145 pattern in the current buffer using "pattern": >
9146
9147 " Count '\<foo\>' in this buffer
9148 " (Note that it also updates search count)
9149 let result = searchcount(#{pattern: '\<foo\>'})
9150
9151 " To restore old search count by old pattern,
9152 " search again
9153 call searchcount()
9154<
9155 {options} must be a |Dictionary|. It can contain:
9156 key type meaning ~
9157 recompute |Boolean| if |TRUE|, recompute the count
9158 like |n| or |N| was executed.
9159 otherwise returns the last
9160 computed result (when |n| or
9161 |N| was used when "S" is not
9162 in 'shortmess', or this
9163 function was called).
9164 (default: |TRUE|)
9165 pattern |String| recompute if this was given
9166 and different with |@/|.
9167 this works as same as the
9168 below command is executed
9169 before calling this function >
9170 let @/ = pattern
9171< (default: |@/|)
9172 timeout |Number| 0 or negative number is no
9173 timeout. timeout milliseconds
9174 for recomputing the result
9175 (default: 0)
9176 maxcount |Number| 0 or negative number is no
9177 limit. max count of matched
9178 text while recomputing the
9179 result. if search exceeded
9180 total count, "total" value
9181 becomes `maxcount + 1`
9182 (default: 99)
9183 pos |List| `[lnum, col, off]` value
9184 when recomputing the result.
9185 this changes "current" result
9186 value. see |cursor()|,
9187 |getpos()|
9188 (default: cursor's position)
9189
9190 Can also be used as a |method|: >
9191 GetSearchOpts()->searchcount()
9192<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009193 Return type: dict<number>
9194
9195
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009196searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9197 Search for the declaration of {name}.
9198
9199 With a non-zero {global} argument it works like |gD|, find
9200 first match in the file. Otherwise it works like |gd|, find
9201 first match in the function.
9202
9203 With a non-zero {thisblock} argument matches in a {} block
9204 that ends before the cursor position are ignored. Avoids
9205 finding variable declarations only valid in another scope.
9206
9207 Moves the cursor to the found match.
9208 Returns zero for success, non-zero for failure.
9209 Example: >
9210 if searchdecl('myvar') == 0
9211 echo getline('.')
9212 endif
9213<
9214 Can also be used as a |method|: >
9215 GetName()->searchdecl()
9216<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009217 Return type: |Number|
9218
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009219 *searchpair()*
9220searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9221 [, {stopline} [, {timeout}]]]])
9222 Search for the match of a nested start-end pair. This can be
9223 used to find the "endif" that matches an "if", while other
9224 if/endif pairs in between are ignored.
9225 The search starts at the cursor. The default is to search
9226 forward, include 'b' in {flags} to search backward.
9227 If a match is found, the cursor is positioned at it and the
9228 line number is returned. If no match is found 0 or -1 is
9229 returned and the cursor doesn't move. No error message is
9230 given.
9231
9232 {start}, {middle} and {end} are patterns, see |pattern|. They
9233 must not contain \( \) pairs. Use of \%( \) is allowed. When
9234 {middle} is not empty, it is found when searching from either
9235 direction, but only when not in a nested start-end pair. A
9236 typical use is: >
9237 searchpair('\<if\>', '\<else\>', '\<endif\>')
9238< By leaving {middle} empty the "else" is skipped.
9239
9240 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9241 |search()|. Additionally:
9242 'r' Repeat until no more matches found; will find the
9243 outer pair. Implies the 'W' flag.
9244 'm' Return number of matches instead of line number with
9245 the match; will be > 1 when 'r' is used.
9246 Note: it's nearly always a good idea to use the 'W' flag, to
9247 avoid wrapping around the end of the file.
9248
9249 When a match for {start}, {middle} or {end} is found, the
9250 {skip} expression is evaluated with the cursor positioned on
9251 the start of the match. It should return non-zero if this
9252 match is to be skipped. E.g., because it is inside a comment
9253 or a string.
9254 When {skip} is omitted or empty, every match is accepted.
9255 When evaluating {skip} causes an error the search is aborted
9256 and -1 returned.
9257 {skip} can be a string, a lambda, a funcref or a partial.
9258 Anything else makes the function fail.
9259 In a `:def` function when the {skip} argument is a string
9260 constant it is compiled into instructions.
9261
9262 For {stopline} and {timeout} see |search()|.
9263
9264 The value of 'ignorecase' is used. 'magic' is ignored, the
9265 patterns are used like it's on.
9266
9267 The search starts exactly at the cursor. A match with
9268 {start}, {middle} or {end} at the next character, in the
9269 direction of searching, is the first one found. Example: >
9270 if 1
9271 if 2
9272 endif 2
9273 endif 1
9274< When starting at the "if 2", with the cursor on the "i", and
9275 searching forwards, the "endif 2" is found. When starting on
9276 the character just before the "if 2", the "endif 1" will be
9277 found. That's because the "if 2" will be found first, and
9278 then this is considered to be a nested if/endif from "if 2" to
9279 "endif 2".
9280 When searching backwards and {end} is more than one character,
9281 it may be useful to put "\zs" at the end of the pattern, so
9282 that when the cursor is inside a match with the end it finds
9283 the matching start.
9284
9285 Example, to find the "endif" command in a Vim script: >
9286
9287 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9288 \ 'getline(".") =~ "^\\s*\""')
9289
9290< The cursor must be at or after the "if" for which a match is
9291 to be found. Note that single-quote strings are used to avoid
9292 having to double the backslashes. The skip expression only
9293 catches comments at the start of a line, not after a command.
9294 Also, a word "en" or "if" halfway a line is considered a
9295 match.
9296 Another example, to search for the matching "{" of a "}": >
9297
9298 :echo searchpair('{', '', '}', 'bW')
9299
9300< This works when the cursor is at or before the "}" for which a
9301 match is to be found. To reject matches that syntax
9302 highlighting recognized as strings: >
9303
9304 :echo searchpair('{', '', '}', 'bW',
9305 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9306<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009307 Return type: |Number|
9308
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009309 *searchpairpos()*
9310searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9311 [, {stopline} [, {timeout}]]]])
9312 Same as |searchpair()|, but returns a |List| with the line and
9313 column position of the match. The first element of the |List|
9314 is the line number and the second element is the byte index of
9315 the column position of the match. If no match is found,
9316 returns [0, 0]. >
9317
9318 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9319<
9320 See |match-parens| for a bigger and more useful example.
9321
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009322 Return type: list<number>
9323
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009324 *searchpos()*
9325searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9326 Same as |search()|, but returns a |List| with the line and
9327 column position of the match. The first element of the |List|
9328 is the line number and the second element is the byte index of
9329 the column position of the match. If no match is found,
9330 returns [0, 0].
9331 Example: >
9332 :let [lnum, col] = searchpos('mypattern', 'n')
9333
9334< When the 'p' flag is given then there is an extra item with
9335 the sub-pattern match number |search()-sub-match|. Example: >
9336 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9337< In this example "submatch" is 2 when a lowercase letter is
9338 found |/\l|, 3 when an uppercase letter is found |/\u|.
9339
9340 Can also be used as a |method|: >
9341 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009342<
9343 Return type: list<number>
9344
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009345
9346server2client({clientid}, {string}) *server2client()*
9347 Send a reply string to {clientid}. The most recent {clientid}
9348 that sent a string can be retrieved with expand("<client>").
9349 {only available when compiled with the |+clientserver| feature}
9350 Returns zero for success, -1 for failure.
9351 Note:
9352 This id has to be stored before the next command can be
9353 received. I.e. before returning from the received command and
9354 before calling any commands that waits for input.
9355 See also |clientserver|.
9356 Example: >
9357 :echo server2client(expand("<client>"), "HELLO")
9358
9359< Can also be used as a |method|: >
9360 GetClientId()->server2client(string)
9361<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009362 Return type: |Number|
9363
9364
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009365serverlist() *serverlist()*
9366 Return a list of available server names, one per line.
9367 When there are no servers or the information is not available
9368 an empty string is returned. See also |clientserver|.
9369 {only available when compiled with the |+clientserver| feature}
9370 Example: >
9371 :echo serverlist()
9372<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009373 Return type: |String|
9374
9375
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009376setbufline({buf}, {lnum}, {text}) *setbufline()*
9377 Set line {lnum} to {text} in buffer {buf}. This works like
9378 |setline()| for the specified buffer.
9379
9380 This function works only for loaded buffers. First call
9381 |bufload()| if needed.
9382
9383 To insert lines use |appendbufline()|.
9384 Any text properties in {lnum} are cleared.
9385
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009386 {text} can be a string to set one line, or a List of strings
9387 to set multiple lines. If the List extends below the last
9388 line then those lines are added. If the List is empty then
9389 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009390
9391 For the use of {buf}, see |bufname()| above.
9392
9393 {lnum} is used like with |setline()|.
9394 Use "$" to refer to the last line in buffer {buf}.
9395 When {lnum} is just below the last line the {text} will be
9396 added below the last line.
9397
9398 When {buf} is not a valid buffer, the buffer is not loaded or
9399 {lnum} is not valid then 1 is returned. In |Vim9| script an
9400 error is given.
9401 On success 0 is returned.
9402
9403 Can also be used as a |method|, the base is passed as the
9404 third argument: >
9405 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009406<
9407 Return type: |Number|
9408
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009409
9410setbufvar({buf}, {varname}, {val}) *setbufvar()*
9411 Set option or local variable {varname} in buffer {buf} to
9412 {val}.
9413 This also works for a global or local window option, but it
9414 doesn't work for a global or local window variable.
9415 For a local window option the global value is unchanged.
9416 For the use of {buf}, see |bufname()| above.
9417 The {varname} argument is a string.
9418 Note that the variable name without "b:" must be used.
9419 Examples: >
9420 :call setbufvar(1, "&mod", 1)
9421 :call setbufvar("todo", "myvar", "foobar")
9422< This function is not available in the |sandbox|.
9423
9424 Can also be used as a |method|, the base is passed as the
9425 third argument: >
9426 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009427<
9428 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009429
9430
9431setcellwidths({list}) *setcellwidths()*
9432 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009433 tells Vim how wide characters are when displayed in the
9434 terminal, counted in screen cells. The values override
9435 'ambiwidth'. Example: >
9436 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009437 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009438 \ [0x2194, 0x2199, 2],
9439 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009440
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009441< The {list} argument is a List of Lists with each three
9442 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9443 {low} and {high} can be the same, in which case this refers to
9444 one character. Otherwise it is the range of characters from
9445 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009446 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009447
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009448 {width} must be either 1 or 2, indicating the character width
9449 in screen cells. *E1112*
9450 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009451 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009452
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009453 If the new value causes 'fillchars' or 'listchars' to become
9454 invalid it is rejected and an error is given.
9455
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009456 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009457 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009458
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009459< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009460 the effect for known emoji characters. Move the cursor
9461 through the text to check if the cell widths of your terminal
9462 match with what Vim knows about each emoji. If it doesn't
9463 look right you need to adjust the {list} argument.
9464
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009465 Return type: |Number|
9466
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009467
9468setcharpos({expr}, {list}) *setcharpos()*
9469 Same as |setpos()| but uses the specified column number as the
9470 character index instead of the byte index in the line.
9471
9472 Example:
9473 With the text "여보세요" in line 8: >
9474 call setcharpos('.', [0, 8, 4, 0])
9475< positions the cursor on the fourth character '요'. >
9476 call setpos('.', [0, 8, 4, 0])
9477< positions the cursor on the second character '보'.
9478
9479 Can also be used as a |method|: >
9480 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009481<
9482 Return type: |Number|
9483
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009484
9485setcharsearch({dict}) *setcharsearch()*
9486 Set the current character search information to {dict},
9487 which contains one or more of the following entries:
9488
9489 char character which will be used for a subsequent
9490 |,| or |;| command; an empty string clears the
9491 character search
9492 forward direction of character search; 1 for forward,
9493 0 for backward
9494 until type of character search; 1 for a |t| or |T|
9495 character search, 0 for an |f| or |F|
9496 character search
9497
9498 This can be useful to save/restore a user's character search
9499 from a script: >
9500 :let prevsearch = getcharsearch()
9501 :" Perform a command which clobbers user's search
9502 :call setcharsearch(prevsearch)
9503< Also see |getcharsearch()|.
9504
9505 Can also be used as a |method|: >
9506 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009507<
9508 Return type: dict<any>
9509
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009510
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009511setcmdline({str} [, {pos}]) *setcmdline()*
9512 Set the command line to {str} and set the cursor position to
9513 {pos}.
9514 If {pos} is omitted, the cursor is positioned after the text.
9515 Returns 0 when successful, 1 when not editing the command
9516 line.
9517
9518 Can also be used as a |method|: >
9519 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009520<
9521 Return type: |Number|
9522
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009523
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009524setcmdpos({pos}) *setcmdpos()*
9525 Set the cursor position in the command line to byte position
9526 {pos}. The first position is 1.
9527 Use |getcmdpos()| to obtain the current position.
9528 Only works while editing the command line, thus you must use
9529 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9530 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9531 set after the command line is set to the expression. For
9532 |c_CTRL-R_=| it is set after evaluating the expression but
9533 before inserting the resulting text.
9534 When the number is too big the cursor is put at the end of the
9535 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009536 Returns 0 when successful, 1 when not editing the command
9537 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009538
9539 Can also be used as a |method|: >
9540 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009541<
9542 Return type: |Number|
9543
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009544
9545setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9546setcursorcharpos({list})
9547 Same as |cursor()| but uses the specified column number as the
9548 character index instead of the byte index in the line.
9549
9550 Example:
9551 With the text "여보세요" in line 4: >
9552 call setcursorcharpos(4, 3)
9553< positions the cursor on the third character '세'. >
9554 call cursor(4, 3)
9555< positions the cursor on the first character '여'.
9556
9557 Can also be used as a |method|: >
9558 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009559<
9560 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009561
9562
9563setenv({name}, {val}) *setenv()*
9564 Set environment variable {name} to {val}. Example: >
9565 call setenv('HOME', '/home/myhome')
9566
9567< When {val} is |v:null| the environment variable is deleted.
9568 See also |expr-env|.
9569
9570 Can also be used as a |method|, the base is passed as the
9571 second argument: >
9572 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009573<
9574 Return type: |Number|
9575
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009576
9577setfperm({fname}, {mode}) *setfperm()* *chmod*
9578 Set the file permissions for {fname} to {mode}.
9579 {mode} must be a string with 9 characters. It is of the form
9580 "rwxrwxrwx", where each group of "rwx" flags represent, in
9581 turn, the permissions of the owner of the file, the group the
9582 file belongs to, and other users. A '-' character means the
9583 permission is off, any other character means on. Multi-byte
9584 characters are not supported.
9585
9586 For example "rw-r-----" means read-write for the user,
9587 readable by the group, not accessible by others. "xx-x-----"
9588 would do the same thing.
9589
9590 Returns non-zero for success, zero for failure.
9591
9592 Can also be used as a |method|: >
9593 GetFilename()->setfperm(mode)
9594<
9595 To read permissions see |getfperm()|.
9596
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009597 Return type: |Number|
9598
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009599
9600setline({lnum}, {text}) *setline()*
9601 Set line {lnum} of the current buffer to {text}. To insert
9602 lines use |append()|. To set lines in another buffer use
Christian Brabandt946f61c2024-06-17 13:17:58 +02009603 |setbufline()|.
h-east52e7cc22024-07-28 17:03:29 +02009604 Any text properties in {lnum} are cleared. See
9605 |text-prop-cleared|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009606
9607 {lnum} is used like with |getline()|.
9608 When {lnum} is just below the last line the {text} will be
9609 added below the last line.
9610 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009611 converted to a String. When {text} is an empty List then
9612 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009613
9614 If this succeeds, FALSE is returned. If this fails (most likely
9615 because {lnum} is invalid) TRUE is returned.
9616 In |Vim9| script an error is given if {lnum} is invalid.
9617
9618 Example: >
9619 :call setline(5, strftime("%c"))
9620
9621< When {text} is a |List| then line {lnum} and following lines
9622 will be set to the items in the list. Example: >
9623 :call setline(5, ['aaa', 'bbb', 'ccc'])
9624< This is equivalent to: >
9625 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9626 : call setline(n, l)
9627 :endfor
9628
9629< Note: The '[ and '] marks are not set.
9630
9631 Can also be used as a |method|, the base is passed as the
9632 second argument: >
9633 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009634<
9635 Return type: |Number|
9636
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009637
9638setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9639 Create or replace or add to the location list for window {nr}.
9640 {nr} can be the window number or the |window-ID|.
9641 When {nr} is zero the current window is used.
9642
9643 For a location list window, the displayed location list is
9644 modified. For an invalid window number {nr}, -1 is returned.
9645 Otherwise, same as |setqflist()|.
9646 Also see |location-list|.
9647
9648 For {action} see |setqflist-action|.
9649
9650 If the optional {what} dictionary argument is supplied, then
9651 only the items listed in {what} are set. Refer to |setqflist()|
9652 for the list of supported keys in {what}.
9653
9654 Can also be used as a |method|, the base is passed as the
9655 second argument: >
9656 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009657<
9658 Return type: |Number|
9659
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009660
9661setmatches({list} [, {win}]) *setmatches()*
9662 Restores a list of matches saved by |getmatches()| for the
9663 current window. Returns 0 if successful, otherwise -1. All
9664 current matches are cleared before the list is restored. See
9665 example for |getmatches()|.
9666 If {win} is specified, use the window with this number or
9667 window ID instead of the current window.
9668
9669 Can also be used as a |method|: >
9670 GetMatches()->setmatches()
9671<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009672 Return type: |Number|
9673
9674
9675setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009676 Set the position for String {expr}. Possible values:
9677 . the cursor
9678 'x mark x
9679
9680 {list} must be a |List| with four or five numbers:
9681 [bufnum, lnum, col, off]
9682 [bufnum, lnum, col, off, curswant]
9683
9684 "bufnum" is the buffer number. Zero can be used for the
9685 current buffer. When setting an uppercase mark "bufnum" is
9686 used for the mark position. For other marks it specifies the
9687 buffer to set the mark in. You can use the |bufnr()| function
9688 to turn a file name into a buffer number.
9689 For setting the cursor and the ' mark "bufnum" is ignored,
9690 since these are associated with a window, not a buffer.
9691 Does not change the jumplist.
9692
9693 "lnum" and "col" are the position in the buffer. The first
9694 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9695 smaller than 1 then 1 is used. To use the character count
9696 instead of the byte count, use |setcharpos()|.
9697
9698 The "off" number is only used when 'virtualedit' is set. Then
9699 it is the offset in screen columns from the start of the
9700 character. E.g., a position within a <Tab> or after the last
9701 character.
9702
9703 The "curswant" number is only used when setting the cursor
9704 position. It sets the preferred column for when moving the
9705 cursor vertically. When the "curswant" number is missing the
9706 preferred column is not set. When it is present and setting a
9707 mark position it is not used.
9708
9709 Note that for '< and '> changing the line number may result in
9710 the marks to be effectively be swapped, so that '< is always
9711 before '>.
9712
9713 Returns 0 when the position could be set, -1 otherwise.
9714 An error message is given if {expr} is invalid.
9715
9716 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9717
9718 This does not restore the preferred column for moving
9719 vertically; if you set the cursor position with this, |j| and
9720 |k| motions will jump to previous columns! Use |cursor()| to
9721 also set the preferred column. Also see the "curswant" key in
9722 |winrestview()|.
9723
9724 Can also be used as a |method|: >
9725 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009726<
9727 Return type: |Number|
9728
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009729
9730setqflist({list} [, {action} [, {what}]]) *setqflist()*
9731 Create or replace or add to the quickfix list.
9732
9733 If the optional {what} dictionary argument is supplied, then
9734 only the items listed in {what} are set. The first {list}
9735 argument is ignored. See below for the supported items in
9736 {what}.
9737 *setqflist-what*
9738 When {what} is not present, the items in {list} are used. Each
9739 item must be a dictionary. Non-dictionary items in {list} are
9740 ignored. Each dictionary item can contain the following
9741 entries:
9742
9743 bufnr buffer number; must be the number of a valid
9744 buffer
9745 filename name of a file; only used when "bufnr" is not
9746 present or it is invalid.
9747 module name of a module; if given it will be used in
9748 quickfix error window instead of the filename.
9749 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00009750 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009751 pattern search pattern used to locate the error
9752 col column number
9753 vcol when non-zero: "col" is visual column
9754 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00009755 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009756 nr error number
9757 text description of the error
9758 type single-character error type, 'E', 'W', etc.
9759 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +02009760 user_data custom data associated with the item, can be
9761 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009762
9763 The "col", "vcol", "nr", "type" and "text" entries are
9764 optional. Either "lnum" or "pattern" entry can be used to
9765 locate a matching error line.
9766 If the "filename" and "bufnr" entries are not present or
9767 neither the "lnum" or "pattern" entries are present, then the
9768 item will not be handled as an error line.
9769 If both "pattern" and "lnum" are present then "pattern" will
9770 be used.
9771 If the "valid" entry is not supplied, then the valid flag is
9772 set when "bufnr" is a valid buffer or "filename" exists.
9773 If you supply an empty {list}, the quickfix list will be
9774 cleared.
9775 Note that the list is not exactly the same as what
9776 |getqflist()| returns.
9777
9778 {action} values: *setqflist-action* *E927*
9779 'a' The items from {list} are added to the existing
9780 quickfix list. If there is no existing list, then a
9781 new list is created.
9782
9783 'r' The items from the current quickfix list are replaced
9784 with the items from {list}. This can also be used to
9785 clear the list: >
9786 :call setqflist([], 'r')
9787<
Jeremy Fleischman27fbf6e2024-10-14 20:46:27 +02009788 'u' Like 'r', but tries to preserve the current selection
9789 in the quickfix list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009790 'f' All the quickfix lists in the quickfix stack are
9791 freed.
9792
9793 If {action} is not present or is set to ' ', then a new list
9794 is created. The new quickfix list is added after the current
9795 quickfix list in the stack and all the following lists are
9796 freed. To add a new quickfix list at the end of the stack,
9797 set "nr" in {what} to "$".
9798
9799 The following items can be specified in dictionary {what}:
9800 context quickfix list context. See |quickfix-context|
9801 efm errorformat to use when parsing text from
9802 "lines". If this is not present, then the
9803 'errorformat' option value is used.
9804 See |quickfix-parse|
9805 id quickfix list identifier |quickfix-ID|
9806 idx index of the current entry in the quickfix
9807 list specified by 'id' or 'nr'. If set to '$',
9808 then the last entry in the list is set as the
9809 current entry. See |quickfix-index|
9810 items list of quickfix entries. Same as the {list}
9811 argument.
9812 lines use 'errorformat' to parse a list of lines and
9813 add the resulting entries to the quickfix list
9814 {nr} or {id}. Only a |List| value is supported.
9815 See |quickfix-parse|
9816 nr list number in the quickfix stack; zero
9817 means the current quickfix list and "$" means
9818 the last quickfix list.
9819 quickfixtextfunc
9820 function to get the text to display in the
9821 quickfix window. The value can be the name of
9822 a function or a funcref or a lambda. Refer to
9823 |quickfix-window-function| for an explanation
9824 of how to write the function and an example.
9825 title quickfix list title text. See |quickfix-title|
9826 Unsupported keys in {what} are ignored.
9827 If the "nr" item is not present, then the current quickfix list
9828 is modified. When creating a new quickfix list, "nr" can be
9829 set to a value one greater than the quickfix stack size.
9830 When modifying a quickfix list, to guarantee that the correct
9831 list is modified, "id" should be used instead of "nr" to
9832 specify the list.
9833
9834 Examples (See also |setqflist-examples|): >
9835 :call setqflist([], 'r', {'title': 'My search'})
9836 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
9837 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
9838<
9839 Returns zero for success, -1 for failure.
9840
9841 This function can be used to create a quickfix list
9842 independent of the 'errorformat' setting. Use a command like
9843 `:cc 1` to jump to the first position.
9844
9845 Can also be used as a |method|, the base is passed as the
9846 second argument: >
9847 GetErrorlist()->setqflist()
9848<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009849 Return type: |Number|
9850
9851
9852setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009853 Set the register {regname} to {value}.
9854 If {regname} is "" or "@", the unnamed register '"' is used.
9855 The {regname} argument is a string. In |Vim9-script|
9856 {regname} must be one character.
9857
9858 {value} may be any value returned by |getreg()| or
9859 |getreginfo()|, including a |List| or |Dict|.
9860 If {options} contains "a" or {regname} is upper case,
9861 then the value is appended.
9862
9863 {options} can also contain a register type specification:
9864 "c" or "v" |characterwise| mode
9865 "l" or "V" |linewise| mode
9866 "b" or "<CTRL-V>" |blockwise-visual| mode
9867 If a number immediately follows "b" or "<CTRL-V>" then this is
9868 used as the width of the selection - if it is not specified
9869 then the width of the block is set to the number of characters
9870 in the longest line (counting a <Tab> as 1 character).
9871
9872 If {options} contains no register settings, then the default
9873 is to use character mode unless {value} ends in a <NL> for
9874 string {value} and linewise mode for list {value}. Blockwise
9875 mode is never selected automatically.
9876 Returns zero for success, non-zero for failure.
9877
9878 *E883*
9879 Note: you may not use |List| containing more than one item to
9880 set search and expression registers. Lists containing no
9881 items act like empty strings.
9882
9883 Examples: >
9884 :call setreg(v:register, @*)
9885 :call setreg('*', @%, 'ac')
9886 :call setreg('a', "1\n2\n3", 'b5')
9887 :call setreg('"', { 'points_to': 'a'})
9888
9889< This example shows using the functions to save and restore a
9890 register: >
9891 :let var_a = getreginfo()
9892 :call setreg('a', var_a)
9893< or: >
9894 :let var_a = getreg('a', 1, 1)
9895 :let var_amode = getregtype('a')
9896 ....
9897 :call setreg('a', var_a, var_amode)
9898< Note: you may not reliably restore register value
9899 without using the third argument to |getreg()| as without it
9900 newlines are represented as newlines AND Nul bytes are
9901 represented as newlines as well, see |NL-used-for-Nul|.
9902
9903 You can also change the type of a register by appending
9904 nothing: >
9905 :call setreg('a', '', 'al')
9906
9907< Can also be used as a |method|, the base is passed as the
9908 second argument: >
9909 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009910<
9911 Return type: |Number|
9912
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009913
9914settabvar({tabnr}, {varname}, {val}) *settabvar()*
9915 Set tab-local variable {varname} to {val} in tab page {tabnr}.
9916 |t:var|
9917 The {varname} argument is a string.
9918 Note that autocommands are blocked, side effects may not be
9919 triggered, e.g. when setting 'filetype'.
9920 Note that the variable name without "t:" must be used.
9921 Tabs are numbered starting with one.
9922 This function is not available in the |sandbox|.
9923
9924 Can also be used as a |method|, the base is passed as the
9925 third argument: >
9926 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009927<
9928 Return type: |Number|
9929
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009930
9931settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
9932 Set option or local variable {varname} in window {winnr} to
9933 {val}.
9934 Tabs are numbered starting with one. For the current tabpage
9935 use |setwinvar()|.
9936 {winnr} can be the window number or the |window-ID|.
9937 When {winnr} is zero the current window is used.
9938 Note that autocommands are blocked, side effects may not be
9939 triggered, e.g. when setting 'filetype' or 'syntax'.
9940 This also works for a global or local buffer option, but it
9941 doesn't work for a global or local buffer variable.
9942 For a local buffer option the global value is unchanged.
9943 Note that the variable name without "w:" must be used.
9944 Examples: >
9945 :call settabwinvar(1, 1, "&list", 0)
9946 :call settabwinvar(3, 2, "myvar", "foobar")
9947< This function is not available in the |sandbox|.
9948
9949 Can also be used as a |method|, the base is passed as the
9950 fourth argument: >
9951 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009952<
9953 Return type: |Number|
9954
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009955
9956settagstack({nr}, {dict} [, {action}]) *settagstack()*
9957 Modify the tag stack of the window {nr} using {dict}.
9958 {nr} can be the window number or the |window-ID|.
9959
9960 For a list of supported items in {dict}, refer to
9961 |gettagstack()|. "curidx" takes effect before changing the tag
9962 stack.
9963 *E962*
9964 How the tag stack is modified depends on the {action}
9965 argument:
9966 - If {action} is not present or is set to 'r', then the tag
9967 stack is replaced.
9968 - If {action} is set to 'a', then new entries from {dict} are
9969 pushed (added) onto the tag stack.
9970 - If {action} is set to 't', then all the entries from the
9971 current entry in the tag stack or "curidx" in {dict} are
9972 removed and then new entries are pushed to the stack.
9973
9974 The current index is set to one after the length of the tag
9975 stack after the modification.
9976
9977 Returns zero for success, -1 for failure.
9978
9979 Examples (for more examples see |tagstack-examples|):
9980 Empty the tag stack of window 3: >
9981 call settagstack(3, {'items' : []})
9982
9983< Save and restore the tag stack: >
9984 let stack = gettagstack(1003)
9985 " do something else
9986 call settagstack(1003, stack)
9987 unlet stack
9988<
9989 Can also be used as a |method|, the base is passed as the
9990 second argument: >
9991 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009992<
9993 Return type: |Number|
9994
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009995
9996setwinvar({winnr}, {varname}, {val}) *setwinvar()*
9997 Like |settabwinvar()| for the current tab page.
9998 Examples: >
9999 :call setwinvar(1, "&list", 0)
10000 :call setwinvar(2, "myvar", "foobar")
10001
10002< Can also be used as a |method|, the base is passed as the
10003 third argument: >
10004 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010005<
10006 Return type: |Number|
10007
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010008
10009sha256({string}) *sha256()*
10010 Returns a String with 64 hex characters, which is the SHA256
10011 checksum of {string}.
10012
10013 Can also be used as a |method|: >
10014 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010015<
10016 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010017
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010018 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010019
10020shellescape({string} [, {special}]) *shellescape()*
10021 Escape {string} for use as a shell command argument.
10022 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +000010023 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010024 in single quotes and will double up all internal single
10025 quotes.
10026 On MS-Windows, when 'shellslash' is not set, it will enclose
10027 {string} in double quotes and double all double quotes within
10028 {string}.
10029 Otherwise it will enclose {string} in single quotes and
10030 replace all "'" with "'\''".
10031
Enno5faeb602024-05-15 21:54:19 +020010032 The {special} argument adds additional escaping of keywords
10033 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +090010034 number or a non-empty String (|non-zero-arg|), then special
10035 items such as "!", "%", "#" and "<cword>" (as listed in
10036 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +020010037 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010038
10039 The "!" character will be escaped (again with a |non-zero-arg|
10040 {special}) when 'shell' contains "csh" in the tail. That is
10041 because for csh and tcsh "!" is used for history replacement
10042 even when inside single quotes.
10043
10044 With a |non-zero-arg| {special} the <NL> character is also
10045 escaped. When 'shell' containing "csh" in the tail it's
10046 escaped a second time.
10047
10048 The "\" character will be escaped when 'shell' contains "fish"
10049 in the tail. That is because for fish "\" is used as an escape
10050 character inside single quotes.
10051
10052 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010053 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010054< This results in a directory listing for the file under the
10055 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010056 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010057< See also |::S|.
10058
10059 Can also be used as a |method|: >
10060 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010061<
10062 Return type: |String|
10063
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010064
10065shiftwidth([{col}]) *shiftwidth()*
10066 Returns the effective value of 'shiftwidth'. This is the
10067 'shiftwidth' value unless it is zero, in which case it is the
10068 'tabstop' value. This function was introduced with patch
10069 7.3.694 in 2012, everybody should have it by now (however it
10070 did not allow for the optional {col} argument until 8.1.542).
10071
10072 When there is one argument {col} this is used as column number
10073 for which to return the 'shiftwidth' value. This matters for the
10074 'vartabstop' feature. If the 'vartabstop' setting is enabled and
10075 no {col} argument is given, column 1 will be assumed.
10076
10077 Can also be used as a |method|: >
10078 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010079<
10080 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010081
10082sign_ functions are documented here: |sign-functions-details|
10083
10084
10085simplify({filename}) *simplify()*
10086 Simplify the file name as much as possible without changing
10087 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
10088 Unix) are not resolved. If the first path component in
10089 {filename} designates the current directory, this will be
10090 valid for the result as well. A trailing path separator is
10091 not removed either. On Unix "//path" is unchanged, but
10092 "///path" is simplified to "/path" (this follows the Posix
10093 standard).
10094 Example: >
10095 simplify("./dir/.././/file/") == "./file/"
10096< Note: The combination "dir/.." is only removed if "dir" is
10097 a searchable directory or does not exist. On Unix, it is also
10098 removed when "dir" is a symbolic link within the same
10099 directory. In order to resolve all the involved symbolic
10100 links before simplifying the path name, use |resolve()|.
10101
10102 Can also be used as a |method|: >
10103 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010104<
10105 Return type: |String|
10106
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010107
10108sin({expr}) *sin()*
10109 Return the sine of {expr}, measured in radians, as a |Float|.
10110 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010111 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010112 Examples: >
10113 :echo sin(100)
10114< -0.506366 >
10115 :echo sin(-4.01)
10116< 0.763301
10117
10118 Can also be used as a |method|: >
10119 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010120<
10121 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010122
10123
10124sinh({expr}) *sinh()*
10125 Return the hyperbolic sine of {expr} as a |Float| in the range
10126 [-inf, inf].
10127 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010128 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010129 Examples: >
10130 :echo sinh(0.5)
10131< 0.521095 >
10132 :echo sinh(-0.9)
10133< -1.026517
10134
10135 Can also be used as a |method|: >
10136 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010137<
10138 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010139
10140
10141slice({expr}, {start} [, {end}]) *slice()*
10142 Similar to using a |slice| "expr[start : end]", but "end" is
10143 used exclusive. And for a string the indexes are used as
10144 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010145 |vim9script|. Also, composing characters are treated as a
10146 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010147 When {end} is omitted the slice continues to the last item.
10148 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010149 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010150
10151 Can also be used as a |method|: >
10152 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010153<
10154 Return type: list<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010155
10156
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010157sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010158 Sort the items in {list} in-place. Returns {list}.
10159
10160 If you want a list to remain unmodified make a copy first: >
10161 :let sortedlist = sort(copy(mylist))
10162
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010163< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010164 string representation of each item to sort on. Numbers sort
10165 after Strings, |Lists| after Numbers. For sorting text in the
10166 current buffer use |:sort|.
10167
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010168 When {how} is given and it is 'i' then case is ignored.
10169 In legacy script, for backwards compatibility, the value one
10170 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010171
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010172 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010173 locale is used for ordering. Implementation details: strcoll()
10174 is used to compare strings. See |:language| check or set the
10175 collation locale. |v:collate| can also be used to check the
10176 current locale. Sorting using the locale typically ignores
10177 case. Example: >
10178 " ö is sorted similarly to o with English locale.
10179 :language collate en_US.UTF8
10180 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10181< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10182>
10183 " ö is sorted after z with Swedish locale.
10184 :language collate sv_SE.UTF8
10185 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10186< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10187 This does not work properly on Mac.
10188
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010189 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010190 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010191 strtod() function to parse numbers. Strings, Lists, Dicts and
10192 Funcrefs will be considered as being 0). Note that this won't
10193 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010194
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010195 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010196 sorted numerical. This is like 'n' but a string containing
10197 digits will be used as the number they represent.
10198
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010199 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010200 sorted numerical. All values must be a Number or a Float.
10201
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010202 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010203 is called to compare items. The function is invoked with two
10204 items as argument and must return zero if they are equal, 1 or
10205 bigger if the first one sorts after the second one, -1 or
10206 smaller if the first one sorts before the second one.
10207
10208 {dict} is for functions with the "dict" attribute. It will be
10209 used to set the local variable "self". |Dictionary-function|
10210
10211 The sort is stable, items which compare equal (as number or as
10212 string) will keep their relative position. E.g., when sorting
10213 on numbers, text strings will sort next to each other, in the
10214 same order as they were originally.
10215
10216 Can also be used as a |method|: >
10217 mylist->sort()
10218
10219< Also see |uniq()|.
10220
10221 Example: >
10222 func MyCompare(i1, i2)
10223 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10224 endfunc
10225 eval mylist->sort("MyCompare")
10226< A shorter compare version for this specific simple case, which
10227 ignores overflow: >
10228 func MyCompare(i1, i2)
10229 return a:i1 - a:i2
10230 endfunc
10231< For a simple expression you can use a lambda: >
10232 eval mylist->sort({i1, i2 -> i1 - i2})
10233<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010234 Return type: list<{type}>
10235
10236
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010237sound_clear() *sound_clear()*
10238 Stop playing all sounds.
10239
10240 On some Linux systems you may need the libcanberra-pulse
10241 package, otherwise sound may not stop.
10242
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010243 Return type: |Number|
10244
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010245 {only available when compiled with the |+sound| feature}
10246
10247 *sound_playevent()*
10248sound_playevent({name} [, {callback}])
10249 Play a sound identified by {name}. Which event names are
10250 supported depends on the system. Often the XDG sound names
10251 are used. On Ubuntu they may be found in
10252 /usr/share/sounds/freedesktop/stereo. Example: >
10253 call sound_playevent('bell')
10254< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10255 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10256 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010257 On macOS, {name} refers to files located in
10258 /System/Library/Sounds (e.g. "Tink"). It will also work for
10259 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010260
10261 When {callback} is specified it is invoked when the sound is
10262 finished. The first argument is the sound ID, the second
10263 argument is the status:
10264 0 sound was played to the end
10265 1 sound was interrupted
10266 2 error occurred after sound started
10267 Example: >
10268 func Callback(id, status)
10269 echomsg "sound " .. a:id .. " finished with " .. a:status
10270 endfunc
10271 call sound_playevent('bell', 'Callback')
10272
10273< MS-Windows: {callback} doesn't work for this function.
10274
10275 Returns the sound ID, which can be passed to `sound_stop()`.
10276 Returns zero if the sound could not be played.
10277
10278 Can also be used as a |method|: >
10279 GetSoundName()->sound_playevent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010280<
10281 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010282
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010283 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010284
10285 *sound_playfile()*
10286sound_playfile({path} [, {callback}])
10287 Like `sound_playevent()` but play sound file {path}. {path}
10288 must be a full path. On Ubuntu you may find files to play
10289 with this command: >
10290 :!find /usr/share/sounds -type f | grep -v index.theme
10291
10292< Can also be used as a |method|: >
10293 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010294<
10295 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010296
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010297 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010298
10299
10300sound_stop({id}) *sound_stop()*
10301 Stop playing sound {id}. {id} must be previously returned by
10302 `sound_playevent()` or `sound_playfile()`.
10303
10304 On some Linux systems you may need the libcanberra-pulse
10305 package, otherwise sound may not stop.
10306
10307 On MS-Windows, this does not work for event sound started by
10308 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10309
10310 Can also be used as a |method|: >
10311 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010312<
10313 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010314
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010315 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010316
10317 *soundfold()*
10318soundfold({word})
10319 Return the sound-folded equivalent of {word}. Uses the first
10320 language in 'spelllang' for the current window that supports
10321 soundfolding. 'spell' must be set. When no sound folding is
10322 possible the {word} is returned unmodified.
10323 This can be used for making spelling suggestions. Note that
10324 the method can be quite slow.
10325
10326 Can also be used as a |method|: >
10327 GetWord()->soundfold()
10328<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010329 Return type: |String|
10330
10331
10332spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010333 Without argument: The result is the badly spelled word under
10334 or after the cursor. The cursor is moved to the start of the
10335 bad word. When no bad word is found in the cursor line the
10336 result is an empty string and the cursor doesn't move.
10337
10338 With argument: The result is the first word in {sentence} that
10339 is badly spelled. If there are no spelling mistakes the
10340 result is an empty string.
10341
10342 The return value is a list with two items:
10343 - The badly spelled word or an empty string.
10344 - The type of the spelling error:
10345 "bad" spelling mistake
10346 "rare" rare word
10347 "local" word only valid in another region
10348 "caps" word should start with Capital
10349 Example: >
10350 echo spellbadword("the quik brown fox")
10351< ['quik', 'bad'] ~
10352
10353 The spelling information for the current window and the value
10354 of 'spelllang' are used.
10355
10356 Can also be used as a |method|: >
10357 GetText()->spellbadword()
10358<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010359 Return type: list<string>
10360
10361
10362spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010363 Return a |List| with spelling suggestions to replace {word}.
10364 When {max} is given up to this number of suggestions are
10365 returned. Otherwise up to 25 suggestions are returned.
10366
10367 When the {capital} argument is given and it's non-zero only
10368 suggestions with a leading capital will be given. Use this
10369 after a match with 'spellcapcheck'.
10370
10371 {word} can be a badly spelled word followed by other text.
10372 This allows for joining two words that were split. The
10373 suggestions also include the following text, thus you can
10374 replace a line.
10375
10376 {word} may also be a good word. Similar words will then be
10377 returned. {word} itself is not included in the suggestions,
10378 although it may appear capitalized.
10379
10380 The spelling information for the current window is used. The
10381 values of 'spelllang' and 'spellsuggest' are used.
10382
10383 Can also be used as a |method|: >
10384 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010385<
10386 Return type: list<string> or list<any>
10387
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010388
10389split({string} [, {pattern} [, {keepempty}]]) *split()*
10390 Make a |List| out of {string}. When {pattern} is omitted or
Shane Harperc1b39842024-07-17 19:40:40 +020010391 empty each white space separated sequence of characters
10392 becomes an item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010393 Otherwise the string is split where {pattern} matches,
10394 removing the matched characters. 'ignorecase' is not used
10395 here, add \c to ignore case. |/\c|
10396 When the first or last item is empty it is omitted, unless the
10397 {keepempty} argument is given and it's non-zero.
10398 Other empty items are kept when {pattern} matches at least one
10399 character or when {keepempty} is non-zero.
10400 Example: >
10401 :let words = split(getline('.'), '\W\+')
10402< To split a string in individual characters: >
10403 :for c in split(mystring, '\zs')
10404< If you want to keep the separator you can also use '\zs' at
10405 the end of the pattern: >
10406 :echo split('abc:def:ghi', ':\zs')
10407< ['abc:', 'def:', 'ghi'] ~
10408 Splitting a table where the first element can be empty: >
10409 :let items = split(line, ':', 1)
10410< The opposite function is |join()|.
10411
10412 Can also be used as a |method|: >
10413 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010414<
10415 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010416
10417sqrt({expr}) *sqrt()*
10418 Return the non-negative square root of Float {expr} as a
10419 |Float|.
10420 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010421 is negative the result is NaN (Not a Number). Returns 0.0 if
10422 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010423 Examples: >
10424 :echo sqrt(100)
10425< 10.0 >
10426 :echo sqrt(-4.01)
10427< nan
10428 "nan" may be different, it depends on system libraries.
10429
10430 Can also be used as a |method|: >
10431 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010432<
10433 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010434
10435
10436srand([{expr}]) *srand()*
10437 Initialize seed used by |rand()|:
10438 - If {expr} is not given, seed values are initialized by
10439 reading from /dev/urandom, if possible, or using time(NULL)
10440 a.k.a. epoch time otherwise; this only has second accuracy.
10441 - If {expr} is given it must be a Number. It is used to
10442 initialize the seed values. This is useful for testing or
10443 when a predictable sequence is intended.
10444
10445 Examples: >
10446 :let seed = srand()
10447 :let seed = srand(userinput)
10448 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010449<
10450 Return type: list<number>
10451
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010452
10453state([{what}]) *state()*
10454 Return a string which contains characters indicating the
10455 current state. Mostly useful in callbacks that want to do
10456 work that may not always be safe. Roughly this works like:
10457 - callback uses state() to check if work is safe to do.
10458 Yes: then do it right away.
10459 No: add to work queue and add a |SafeState| and/or
10460 |SafeStateAgain| autocommand (|SafeState| triggers at
10461 toplevel, |SafeStateAgain| triggers after handling
10462 messages and callbacks).
10463 - When SafeState or SafeStateAgain is triggered and executes
10464 your autocommand, check with `state()` if the work can be
10465 done now, and if yes remove it from the queue and execute.
10466 Remove the autocommand if the queue is now empty.
10467 Also see |mode()|.
10468
10469 When {what} is given only characters in this string will be
10470 added. E.g, this checks if the screen has scrolled: >
10471 if state('s') == ''
10472 " screen has not scrolled
10473<
10474 These characters indicate the state, generally indicating that
10475 something is busy:
10476 m halfway a mapping, :normal command, feedkeys() or
10477 stuffed command
10478 o operator pending, e.g. after |d|
10479 a Insert mode autocomplete active
10480 x executing an autocommand
10481 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10482 ch_readraw() when reading json
10483 S not triggering SafeState or SafeStateAgain, e.g. after
10484 |f| or a count
10485 c callback invoked, including timer (repeats for
10486 recursiveness up to "ccc")
10487 s screen has scrolled for messages
10488
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010489 Return type: |String|
10490
10491
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010492str2float({string} [, {quoted}]) *str2float()*
10493 Convert String {string} to a Float. This mostly works the
10494 same as when using a floating point number in an expression,
10495 see |floating-point-format|. But it's a bit more permissive.
10496 E.g., "1e40" is accepted, while in an expression you need to
10497 write "1.0e40". The hexadecimal form "0x123" is also
10498 accepted, but not others, like binary or octal.
10499 When {quoted} is present and non-zero then embedded single
10500 quotes before the dot are ignored, thus "1'000.0" is a
10501 thousand.
10502 Text after the number is silently ignored.
10503 The decimal point is always '.', no matter what the locale is
10504 set to. A comma ends the number: "12,345.67" is converted to
10505 12.0. You can strip out thousands separators with
10506 |substitute()|: >
10507 let f = str2float(substitute(text, ',', '', 'g'))
10508<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010509 Returns 0.0 if the conversion fails.
10510
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010511 Can also be used as a |method|: >
10512 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010513<
10514 Return type: |Float|
10515
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010516
10517str2list({string} [, {utf8}]) *str2list()*
10518 Return a list containing the number values which represent
10519 each character in String {string}. Examples: >
10520 str2list(" ") returns [32]
10521 str2list("ABC") returns [65, 66, 67]
10522< |list2str()| does the opposite.
10523
10524 When {utf8} is omitted or zero, the current 'encoding' is used.
10525 When {utf8} is TRUE, always treat the String as UTF-8
10526 characters. With UTF-8 composing characters are handled
10527 properly: >
10528 str2list("á") returns [97, 769]
10529
10530< Can also be used as a |method|: >
10531 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010532<
10533 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010534
10535
10536str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10537 Convert string {string} to a number.
10538 {base} is the conversion base, it can be 2, 8, 10 or 16.
10539 When {quoted} is present and non-zero then embedded single
10540 quotes are ignored, thus "1'000'000" is a million.
10541
10542 When {base} is omitted base 10 is used. This also means that
10543 a leading zero doesn't cause octal conversion to be used, as
10544 with the default String to Number conversion. Example: >
10545 let nr = str2nr('0123')
10546<
10547 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10548 different base the result will be zero. Similarly, when
10549 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10550 {base} is 2 a leading "0b" or "0B" is ignored.
10551 Text after the number is silently ignored.
10552
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010553 Returns 0 if {string} is empty or on error.
10554
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010555 Can also be used as a |method|: >
10556 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010557<
10558 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010559
10560
10561strcharlen({string}) *strcharlen()*
10562 The result is a Number, which is the number of characters
10563 in String {string}. Composing characters are ignored.
10564 |strchars()| can count the number of characters, counting
10565 composing characters separately.
10566
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010567 Returns 0 if {string} is empty or on error.
10568
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010569 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10570
10571 Can also be used as a |method|: >
10572 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010573<
10574 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010575
10576
10577strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10578 Like |strpart()| but using character index and length instead
10579 of byte index and length.
10580 When {skipcc} is omitted or zero, composing characters are
10581 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010582 When {skipcc} set to 1, composing characters are treated as a
10583 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010584 When a character index is used where a character does not
10585 exist it is omitted and counted as one character. For
10586 example: >
10587 strcharpart('abc', -1, 2)
10588< results in 'a'.
10589
Bram Moolenaard592deb2022-06-17 15:42:40 +010010590 Returns an empty string on error.
10591
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010592 Can also be used as a |method|: >
10593 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010594<
10595 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010596
10597
10598strchars({string} [, {skipcc}]) *strchars()*
10599 The result is a Number, which is the number of characters
10600 in String {string}.
10601 When {skipcc} is omitted or zero, composing characters are
10602 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010603 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010604 |strcharlen()| always does this.
10605
Bram Moolenaard592deb2022-06-17 15:42:40 +010010606 Returns zero on error.
10607
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010608 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10609
10610 {skipcc} is only available after 7.4.755. For backward
10611 compatibility, you can define a wrapper function: >
10612 if has("patch-7.4.755")
10613 function s:strchars(str, skipcc)
10614 return strchars(a:str, a:skipcc)
10615 endfunction
10616 else
10617 function s:strchars(str, skipcc)
10618 if a:skipcc
10619 return strlen(substitute(a:str, ".", "x", "g"))
10620 else
10621 return strchars(a:str)
10622 endif
10623 endfunction
10624 endif
10625<
10626 Can also be used as a |method|: >
10627 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010628<
10629 Return type: |Number|
10630
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010631
10632strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10633 The result is a Number, which is the number of display cells
10634 String {string} occupies on the screen when it starts at {col}
10635 (first column is zero). When {col} is omitted zero is used.
10636 Otherwise it is the screen column where to start. This
10637 matters for Tab characters.
10638 The option settings of the current window are used. This
10639 matters for anything that's displayed differently, such as
10640 'tabstop' and 'display'.
10641 When {string} contains characters with East Asian Width Class
10642 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010643 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010644 Also see |strlen()|, |strwidth()| and |strchars()|.
10645
10646 Can also be used as a |method|: >
10647 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010648<
10649 Return type: |Number|
10650
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010651
10652strftime({format} [, {time}]) *strftime()*
10653 The result is a String, which is a formatted date and time, as
10654 specified by the {format} string. The given {time} is used,
10655 or the current time if no time is given. The accepted
10656 {format} depends on your system, thus this is not portable!
10657 See the manual page of the C function strftime() for the
10658 format. The maximum length of the result is 80 characters.
10659 See also |localtime()|, |getftime()| and |strptime()|.
10660 The language can be changed with the |:language| command.
10661 Examples: >
10662 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10663 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10664 :echo strftime("%y%m%d %T") 970427 11:53:55
10665 :echo strftime("%H:%M") 11:55
10666 :echo strftime("%c", getftime("file.c"))
10667 Show mod time of file.c.
10668< Not available on all systems. To check use: >
10669 :if exists("*strftime")
10670
10671< Can also be used as a |method|: >
10672 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010673<
10674 Return type: |String|
10675
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010676
10677strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010678 Get a Number corresponding to the character at {index} in
10679 {str}. This uses a zero-based character index, not a byte
10680 index. Composing characters are considered separate
10681 characters here. Use |nr2char()| to convert the Number to a
10682 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010683 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010684 Also see |strcharpart()| and |strchars()|.
10685
10686 Can also be used as a |method|: >
10687 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010688<
10689 Return type: |Number|
10690
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010691
10692stridx({haystack}, {needle} [, {start}]) *stridx()*
10693 The result is a Number, which gives the byte index in
10694 {haystack} of the first occurrence of the String {needle}.
10695 If {start} is specified, the search starts at index {start}.
10696 This can be used to find a second match: >
10697 :let colon1 = stridx(line, ":")
10698 :let colon2 = stridx(line, ":", colon1 + 1)
10699< The search is done case-sensitive.
10700 For pattern searches use |match()|.
10701 -1 is returned if the {needle} does not occur in {haystack}.
10702 See also |strridx()|.
10703 Examples: >
10704 :echo stridx("An Example", "Example") 3
10705 :echo stridx("Starting point", "Start") 0
10706 :echo stridx("Starting point", "start") -1
10707< *strstr()* *strchr()*
10708 stridx() works similar to the C function strstr(). When used
10709 with a single character it works similar to strchr().
10710
10711 Can also be used as a |method|: >
10712 GetHaystack()->stridx(needle)
10713<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010714 Return type: |Number|
10715
10716
10717string({expr}) *string()*
10718 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010719 Float, String, Blob or a composition of them, then the result
10720 can be parsed back with |eval()|.
10721 {expr} type result ~
10722 String 'string' (single quotes are doubled)
10723 Number 123
10724 Float 123.123456 or 1.123456e8
10725 Funcref function('name')
10726 Blob 0z00112233.44556677.8899
10727 List [item, item]
10728 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000010729 Class class SomeName
10730 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010010731 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020010732 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010733
10734 When a |List| or |Dictionary| has a recursive reference it is
10735 replaced by "[...]" or "{...}". Using eval() on the result
10736 will then fail.
10737
mityu7f0bba22024-03-29 10:14:41 +010010738 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010739 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010010740 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010741
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010742 Can also be used as a |method|: >
10743 mylist->string()
10744
10745< Also see |strtrans()|.
10746
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010747 Return type: |String|
10748
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010749
10750strlen({string}) *strlen()*
10751 The result is a Number, which is the length of the String
10752 {string} in bytes.
10753 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010754 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010755 If you want to count the number of multibyte characters use
10756 |strchars()|.
10757 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
10758
10759 Can also be used as a |method|: >
10760 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010761<
10762 Return type: |Number|
10763
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010764
10765strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
10766 The result is a String, which is part of {src}, starting from
10767 byte {start}, with the byte length {len}.
10768 When {chars} is present and TRUE then {len} is the number of
10769 characters positions (composing characters are not counted
10770 separately, thus "1" means one base character and any
10771 following composing characters).
10772 To count {start} as characters instead of bytes use
10773 |strcharpart()|.
10774
10775 When bytes are selected which do not exist, this doesn't
10776 result in an error, the bytes are simply omitted.
10777 If {len} is missing, the copy continues from {start} till the
10778 end of the {src}. >
10779 strpart("abcdefg", 3, 2) == "de"
10780 strpart("abcdefg", -2, 4) == "ab"
10781 strpart("abcdefg", 5, 4) == "fg"
10782 strpart("abcdefg", 3) == "defg"
10783
10784< Note: To get the first character, {start} must be 0. For
10785 example, to get the character under the cursor: >
10786 strpart(getline("."), col(".") - 1, 1, v:true)
10787<
Bram Moolenaard592deb2022-06-17 15:42:40 +010010788 Returns an empty string on error.
10789
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010790 Can also be used as a |method|: >
10791 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010792<
10793 Return type: |String|
10794
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010795
10796strptime({format}, {timestring}) *strptime()*
10797 The result is a Number, which is a unix timestamp representing
10798 the date and time in {timestring}, which is expected to match
10799 the format specified in {format}.
10800
10801 The accepted {format} depends on your system, thus this is not
10802 portable! See the manual page of the C function strptime()
10803 for the format. Especially avoid "%c". The value of $TZ also
10804 matters.
10805
10806 If the {timestring} cannot be parsed with {format} zero is
10807 returned. If you do not know the format of {timestring} you
10808 can try different {format} values until you get a non-zero
10809 result.
10810
10811 See also |strftime()|.
10812 Examples: >
10813 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
10814< 862156163 >
10815 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
10816< Sun Apr 27 11:53:55 1997 >
10817 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
10818< Sun Apr 27 12:53:55 1997
10819
10820 Can also be used as a |method|: >
10821 GetFormat()->strptime(timestring)
10822<
10823 Not available on all systems. To check use: >
10824 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010825<
10826 Return type: |Number|
10827
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010828
10829strridx({haystack}, {needle} [, {start}]) *strridx()*
10830 The result is a Number, which gives the byte index in
10831 {haystack} of the last occurrence of the String {needle}.
10832 When {start} is specified, matches beyond this index are
10833 ignored. This can be used to find a match before a previous
10834 match: >
10835 :let lastcomma = strridx(line, ",")
10836 :let comma2 = strridx(line, ",", lastcomma - 1)
10837< The search is done case-sensitive.
10838 For pattern searches use |match()|.
10839 -1 is returned if the {needle} does not occur in {haystack}.
10840 If the {needle} is empty the length of {haystack} is returned.
10841 See also |stridx()|. Examples: >
10842 :echo strridx("an angry armadillo", "an") 3
10843< *strrchr()*
10844 When used with a single character it works similar to the C
10845 function strrchr().
10846
10847 Can also be used as a |method|: >
10848 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010849<
10850 Return type: |Number|
10851
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010852
10853strtrans({string}) *strtrans()*
10854 The result is a String, which is {string} with all unprintable
10855 characters translated into printable characters |'isprint'|.
10856 Like they are shown in a window. Example: >
10857 echo strtrans(@a)
10858< This displays a newline in register a as "^@" instead of
10859 starting a new line.
10860
Bram Moolenaard592deb2022-06-17 15:42:40 +010010861 Returns an empty string on error.
10862
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010863 Can also be used as a |method|: >
10864 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010865<
10866 Return type: |String|
10867
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010868
Christian Brabandt67672ef2023-04-24 21:09:54 +010010869strutf16len({string} [, {countcc}]) *strutf16len()*
10870 The result is a Number, which is the number of UTF-16 code
10871 units in String {string} (after converting it to UTF-16).
10872
10873 When {countcc} is TRUE, composing characters are counted
10874 separately.
10875 When {countcc} is omitted or FALSE, composing characters are
10876 ignored.
10877
10878 Returns zero on error.
10879
10880 Also see |strlen()| and |strcharlen()|.
10881 Examples: >
10882 echo strutf16len('a') returns 1
10883 echo strutf16len('©') returns 1
10884 echo strutf16len('😊') returns 2
10885 echo strutf16len('ą́') returns 1
10886 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090010887<
Christian Brabandt67672ef2023-04-24 21:09:54 +010010888 Can also be used as a |method|: >
10889 GetText()->strutf16len()
10890<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010891 Return type: |Number|
10892
10893
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010894strwidth({string}) *strwidth()*
10895 The result is a Number, which is the number of display cells
10896 String {string} occupies. A Tab character is counted as one
10897 cell, alternatively use |strdisplaywidth()|.
10898 When {string} contains characters with East Asian Width Class
10899 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010900 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010901 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
10902
10903 Can also be used as a |method|: >
10904 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010905<
10906 Return type: |Number|
10907
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010908
10909submatch({nr} [, {list}]) *submatch()* *E935*
10910 Only for an expression in a |:substitute| command or
10911 substitute() function.
10912 Returns the {nr}'th submatch of the matched text. When {nr}
10913 is 0 the whole matched text is returned.
10914 Note that a NL in the string can stand for a line break of a
10915 multi-line match or a NUL character in the text.
10916 Also see |sub-replace-expression|.
10917
10918 If {list} is present and non-zero then submatch() returns
10919 a list of strings, similar to |getline()| with two arguments.
10920 NL characters in the text represent NUL characters in the
10921 text.
10922 Only returns more than one item for |:substitute|, inside
10923 |substitute()| this list will always contain one or zero
10924 items, since there are no real line breaks.
10925
10926 When substitute() is used recursively only the submatches in
10927 the current (deepest) call can be obtained.
10928
Bram Moolenaard592deb2022-06-17 15:42:40 +010010929 Returns an empty string or list on error.
10930
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010931 Examples: >
10932 :s/\d\+/\=submatch(0) + 1/
10933 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
10934< This finds the first number in the line and adds one to it.
10935 A line break is included as a newline character.
10936
10937 Can also be used as a |method|: >
10938 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010939<
10940 Return type: |String| or list<string> depending on {list}
10941
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010942
10943substitute({string}, {pat}, {sub}, {flags}) *substitute()*
10944 The result is a String, which is a copy of {string}, in which
10945 the first match of {pat} is replaced with {sub}.
10946 When {flags} is "g", all matches of {pat} in {string} are
10947 replaced. Otherwise {flags} should be "".
10948
10949 This works like the ":substitute" command (without any flags).
10950 But the matching with {pat} is always done like the 'magic'
10951 option is set and 'cpoptions' is empty (to make scripts
10952 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
10953 if you want to ignore or match case and ignore 'ignorecase'.
10954 'smartcase' is not used. See |string-match| for how {pat} is
10955 used.
10956
10957 A "~" in {sub} is not replaced with the previous {sub}.
10958 Note that some codes in {sub} have a special meaning
10959 |sub-replace-special|. For example, to replace something with
10960 "\n" (two characters), use "\\\\n" or '\\n'.
10961
10962 When {pat} does not match in {string}, {string} is returned
10963 unmodified.
10964
10965 Example: >
10966 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
10967< This removes the last component of the 'path' option. >
10968 :echo substitute("testing", ".*", "\\U\\0", "")
10969< results in "TESTING".
10970
10971 When {sub} starts with "\=", the remainder is interpreted as
10972 an expression. See |sub-replace-expression|. Example: >
10973 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010974 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010975
10976< When {sub} is a Funcref that function is called, with one
10977 optional argument. Example: >
10978 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
10979< The optional argument is a list which contains the whole
10980 matched string and up to nine submatches, like what
10981 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010982 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010983
Bram Moolenaard592deb2022-06-17 15:42:40 +010010984< Returns an empty string on error.
10985
10986 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010987 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010988<
10989 Return type: |String|
10990
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010991
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000010992swapfilelist() *swapfilelist()*
10993 Returns a list of swap file names, like what "vim -r" shows.
10994 See the |-r| command argument. The 'directory' option is used
10995 for the directories to inspect. If you only want to get a
10996 list of swap files in the current directory then temporarily
10997 set 'directory' to a dot: >
10998 let save_dir = &directory
10999 let &directory = '.'
11000 let swapfiles = swapfilelist()
11001 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011002<
11003 Return type: list<string>
11004
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011005
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011006swapinfo({fname}) *swapinfo()*
11007 The result is a dictionary, which holds information about the
11008 swapfile {fname}. The available fields are:
11009 version Vim version
11010 user user name
11011 host host name
11012 fname original file name
11013 pid PID of the Vim process that created the swap
11014 file
11015 mtime last modification time in seconds
11016 inode Optional: INODE number of the file
11017 dirty 1 if file was modified, 0 if not
11018 Note that "user" and "host" are truncated to at most 39 bytes.
11019 In case of failure an "error" item is added with the reason:
11020 Cannot open file: file not found or in accessible
11021 Cannot read file: cannot read first block
11022 Not a swap file: does not contain correct block ID
11023 Magic number mismatch: Info in first block is invalid
11024
11025 Can also be used as a |method|: >
11026 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011027<
11028 Return type: dict<any> or dict<string>
11029
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011030
11031swapname({buf}) *swapname()*
11032 The result is the swap file path of the buffer {expr}.
11033 For the use of {buf}, see |bufname()| above.
11034 If buffer {buf} is the current buffer, the result is equal to
11035 |:swapname| (unless there is no swap file).
11036 If buffer {buf} has no swap file, returns an empty string.
11037
11038 Can also be used as a |method|: >
11039 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011040<
11041 Return type: |String|
11042
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011043
11044synID({lnum}, {col}, {trans}) *synID()*
11045 The result is a Number, which is the syntax ID at the position
11046 {lnum} and {col} in the current window.
11047 The syntax ID can be used with |synIDattr()| and
11048 |synIDtrans()| to obtain syntax information about text.
11049
11050 {col} is 1 for the leftmost column, {lnum} is 1 for the first
11051 line. 'synmaxcol' applies, in a longer line zero is returned.
11052 Note that when the position is after the last character,
11053 that's where the cursor can be in Insert mode, synID() returns
11054 zero. {lnum} is used like with |getline()|.
11055
11056 When {trans} is |TRUE|, transparent items are reduced to the
11057 item that they reveal. This is useful when wanting to know
11058 the effective color. When {trans} is |FALSE|, the transparent
11059 item is returned. This is useful when wanting to know which
11060 syntax item is effective (e.g. inside parens).
11061 Warning: This function can be very slow. Best speed is
11062 obtained by going through the file in forward direction.
11063
Bram Moolenaard592deb2022-06-17 15:42:40 +010011064 Returns zero on error.
11065
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011066 Example (echoes the name of the syntax item under the cursor): >
11067 :echo synIDattr(synID(line("."), col("."), 1), "name")
11068<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011069 Return type: |Number|
11070
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011071
11072synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
11073 The result is a String, which is the {what} attribute of
11074 syntax ID {synID}. This can be used to obtain information
11075 about a syntax item.
11076 {mode} can be "gui", "cterm" or "term", to get the attributes
11077 for that mode. When {mode} is omitted, or an invalid value is
11078 used, the attributes for the currently active highlighting are
11079 used (GUI, cterm or term).
11080 Use synIDtrans() to follow linked highlight groups.
11081 {what} result
11082 "name" the name of the syntax item
11083 "fg" foreground color (GUI: color name used to set
11084 the color, cterm: color number as a string,
11085 term: empty string)
11086 "bg" background color (as with "fg")
11087 "font" font name (only available in the GUI)
11088 |highlight-font|
11089 "sp" special color for the GUI (as with "fg")
11090 |highlight-guisp|
11091 "ul" underline color for cterm: number as a string
11092 "fg#" like "fg", but for the GUI and the GUI is
11093 running the name in "#RRGGBB" form
11094 "bg#" like "fg#" for "bg"
11095 "sp#" like "fg#" for "sp"
11096 "bold" "1" if bold
11097 "italic" "1" if italic
11098 "reverse" "1" if reverse
11099 "inverse" "1" if inverse (= reverse)
11100 "standout" "1" if standout
11101 "underline" "1" if underlined
11102 "undercurl" "1" if undercurled
11103 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010011104 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011105
Bram Moolenaard592deb2022-06-17 15:42:40 +010011106 Returns an empty string on error.
11107
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011108 Example (echoes the color of the syntax item under the
11109 cursor): >
11110 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
11111<
11112 Can also be used as a |method|: >
11113 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011114<
11115 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011116
11117
11118synIDtrans({synID}) *synIDtrans()*
11119 The result is a Number, which is the translated syntax ID of
11120 {synID}. This is the syntax group ID of what is being used to
11121 highlight the character. Highlight links given with
11122 ":highlight link" are followed.
11123
Bram Moolenaard592deb2022-06-17 15:42:40 +010011124 Returns zero on error.
11125
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011126 Can also be used as a |method|: >
11127 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011128<
11129 Return type: |Number|
11130
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011131
11132synconcealed({lnum}, {col}) *synconcealed()*
11133 The result is a |List| with currently three items:
11134 1. The first item in the list is 0 if the character at the
11135 position {lnum} and {col} is not part of a concealable
11136 region, 1 if it is. {lnum} is used like with |getline()|.
11137 2. The second item in the list is a string. If the first item
11138 is 1, the second item contains the text which will be
11139 displayed in place of the concealed text, depending on the
11140 current setting of 'conceallevel' and 'listchars'.
11141 3. The third and final item in the list is a number
11142 representing the specific syntax region matched in the
11143 line. When the character is not concealed the value is
11144 zero. This allows detection of the beginning of a new
11145 concealable region if there are two consecutive regions
11146 with the same replacement character. For an example, if
11147 the text is "123456" and both "23" and "45" are concealed
11148 and replaced by the character "X", then:
11149 call returns ~
11150 synconcealed(lnum, 1) [0, '', 0]
11151 synconcealed(lnum, 2) [1, 'X', 1]
11152 synconcealed(lnum, 3) [1, 'X', 1]
11153 synconcealed(lnum, 4) [1, 'X', 2]
11154 synconcealed(lnum, 5) [1, 'X', 2]
11155 synconcealed(lnum, 6) [0, '', 0]
11156
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011157 Note: Doesn't consider |matchadd()| highlighting items,
11158 since syntax and matching highlighting are two different
11159 mechanisms |syntax-vs-match|.
h-east52e7cc22024-07-28 17:03:29 +020011160
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011161 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011162
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011163
11164synstack({lnum}, {col}) *synstack()*
11165 Return a |List|, which is the stack of syntax items at the
11166 position {lnum} and {col} in the current window. {lnum} is
11167 used like with |getline()|. Each item in the List is an ID
11168 like what |synID()| returns.
11169 The first item in the List is the outer region, following are
11170 items contained in that one. The last one is what |synID()|
11171 returns, unless not the whole item is highlighted or it is a
11172 transparent item.
11173 This function is useful for debugging a syntax file.
11174 Example that shows the syntax stack under the cursor: >
11175 for id in synstack(line("."), col("."))
11176 echo synIDattr(id, "name")
11177 endfor
11178< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011179 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011180 character in a line and the first column in an empty line are
11181 valid positions.
11182
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011183 Return type: list<number> or list<any>
11184
11185
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011186system({expr} [, {input}]) *system()* *E677*
11187 Get the output of the shell command {expr} as a |String|. See
11188 |systemlist()| to get the output as a |List|.
11189
11190 When {input} is given and is a |String| this string is written
11191 to a file and passed as stdin to the command. The string is
11192 written as-is, you need to take care of using the correct line
11193 separators yourself.
11194 If {input} is given and is a |List| it is written to the file
11195 in a way |writefile()| does with {binary} set to "b" (i.e.
11196 with a newline between each list item with newlines inside
11197 list items converted to NULs).
11198 When {input} is given and is a number that is a valid id for
11199 an existing buffer then the content of the buffer is written
11200 to the file line by line, each line terminated by a NL and
11201 NULs characters where the text has a NL.
11202
11203 Pipes are not used, the 'shelltemp' option is not used.
11204
11205 When prepended by |:silent| the terminal will not be set to
11206 cooked mode. This is meant to be used for commands that do
11207 not need the user to type. It avoids stray characters showing
11208 up on the screen which require |CTRL-L| to remove. >
11209 :silent let f = system('ls *.vim')
11210<
11211 Note: Use |shellescape()| or |::S| with |expand()| or
11212 |fnamemodify()| to escape special characters in a command
11213 argument. Newlines in {expr} may cause the command to fail.
11214 The characters in 'shellquote' and 'shellxquote' may also
11215 cause trouble.
11216 This is not to be used for interactive commands.
11217
11218 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011219 :let files = system('ls ' .. shellescape(expand('%:h')))
11220 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011221
11222< To make the result more system-independent, the shell output
11223 is filtered to replace <CR> with <NL> for Macintosh, and
11224 <CR><NL> with <NL> for DOS-like systems.
11225 To avoid the string being truncated at a NUL, all NUL
11226 characters are replaced with SOH (0x01).
11227
11228 The command executed is constructed using several options:
11229 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11230 ({tmp} is an automatically generated file name).
11231 For Unix, braces are put around {expr} to allow for
11232 concatenated commands.
11233
11234 The command will be executed in "cooked" mode, so that a
11235 CTRL-C will interrupt the command (on Unix at least).
11236
11237 The resulting error code can be found in |v:shell_error|.
11238 This function will fail in |restricted-mode|.
11239
11240 Note that any wrong value in the options mentioned above may
11241 make the function fail. It has also been reported to fail
11242 when using a security agent application.
11243 Unlike ":!cmd" there is no automatic check for changed files.
11244 Use |:checktime| to force a check.
11245
11246 Can also be used as a |method|: >
11247 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011248<
11249 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011250
11251
11252systemlist({expr} [, {input}]) *systemlist()*
11253 Same as |system()|, but returns a |List| with lines (parts of
11254 output separated by NL) with NULs transformed into NLs. Output
11255 is the same as |readfile()| will output with {binary} argument
11256 set to "b", except that there is no extra empty item when the
11257 result ends in a NL.
11258 Note that on MS-Windows you may get trailing CR characters.
11259
11260 To see the difference between "echo hello" and "echo -n hello"
11261 use |system()| and |split()|: >
11262 echo system('echo hello')->split('\n', 1)
11263<
11264 Returns an empty string on error.
11265
11266 Can also be used as a |method|: >
11267 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011268<
11269 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011270
11271
11272tabpagebuflist([{arg}]) *tabpagebuflist()*
11273 The result is a |List|, where each item is the number of the
11274 buffer associated with each window in the current tab page.
11275 {arg} specifies the number of the tab page to be used. When
11276 omitted the current tab page is used.
11277 When {arg} is invalid the number zero is returned.
11278 To get a list of all buffers in all tabs use this: >
11279 let buflist = []
11280 for i in range(tabpagenr('$'))
11281 call extend(buflist, tabpagebuflist(i + 1))
11282 endfor
11283< Note that a buffer may appear in more than one window.
11284
11285 Can also be used as a |method|: >
11286 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011287<
11288 Return type: list<number>
11289
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011290
11291tabpagenr([{arg}]) *tabpagenr()*
11292 The result is a Number, which is the number of the current
11293 tab page. The first tab page has number 1.
11294
11295 The optional argument {arg} supports the following values:
11296 $ the number of the last tab page (the tab page
11297 count).
11298 # the number of the last accessed tab page
11299 (where |g<Tab>| goes to). if there is no
11300 previous tab page 0 is returned.
11301 The number can be used with the |:tab| command.
11302
Bram Moolenaard592deb2022-06-17 15:42:40 +010011303 Returns zero on error.
11304
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011305 Return type: |Number|
11306
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011307
11308tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11309 Like |winnr()| but for tab page {tabarg}.
11310 {tabarg} specifies the number of tab page to be used.
11311 {arg} is used like with |winnr()|:
11312 - When omitted the current window number is returned. This is
11313 the window which will be used when going to this tab page.
11314 - When "$" the number of windows is returned.
11315 - When "#" the previous window nr is returned.
11316 Useful examples: >
11317 tabpagewinnr(1) " current window of tab page 1
11318 tabpagewinnr(4, '$') " number of windows in tab page 4
11319< When {tabarg} is invalid zero is returned.
11320
11321 Can also be used as a |method|: >
11322 GetTabpage()->tabpagewinnr()
11323<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011324 Return type: |Number|
11325
11326
11327tagfiles() *tagfiles()*
11328 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011329 for the current buffer. This is the 'tags' option expanded.
11330
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011331 Return type: list<string> or list<any>
11332
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011333
11334taglist({expr} [, {filename}]) *taglist()*
11335 Returns a |List| of tags matching the regular expression {expr}.
11336
11337 If {filename} is passed it is used to prioritize the results
11338 in the same way that |:tselect| does. See |tag-priority|.
11339 {filename} should be the full path of the file.
11340
11341 Each list item is a dictionary with at least the following
11342 entries:
11343 name Name of the tag.
11344 filename Name of the file where the tag is
11345 defined. It is either relative to the
11346 current directory or a full path.
11347 cmd Ex command used to locate the tag in
11348 the file.
11349 kind Type of the tag. The value for this
11350 entry depends on the language specific
11351 kind values. Only available when
11352 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011353 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011354 static A file specific tag. Refer to
11355 |static-tag| for more information.
11356 More entries may be present, depending on the content of the
11357 tags file: access, implementation, inherits and signature.
11358 Refer to the ctags documentation for information about these
11359 fields. For C code the fields "struct", "class" and "enum"
11360 may appear, they give the name of the entity the tag is
11361 contained in.
11362
11363 The ex-command "cmd" can be either an ex search pattern, a
11364 line number or a line number followed by a byte number.
11365
11366 If there are no matching tags, then an empty list is returned.
11367
11368 To get an exact tag match, the anchors '^' and '$' should be
11369 used in {expr}. This also make the function work faster.
11370 Refer to |tag-regexp| for more information about the tag
11371 search regular expression pattern.
11372
11373 Refer to |'tags'| for information about how the tags file is
11374 located by Vim. Refer to |tags-file-format| for the format of
11375 the tags file generated by the different ctags tools.
11376
11377 Can also be used as a |method|: >
11378 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011379<
11380 Return type: list<dict<any>> or list<any>
11381
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011382
11383tan({expr}) *tan()*
11384 Return the tangent of {expr}, measured in radians, as a |Float|
11385 in the range [-inf, inf].
11386 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011387 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011388 Examples: >
11389 :echo tan(10)
11390< 0.648361 >
11391 :echo tan(-4.01)
11392< -1.181502
11393
11394 Can also be used as a |method|: >
11395 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011396<
11397 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011398
11399
11400tanh({expr}) *tanh()*
11401 Return the hyperbolic tangent of {expr} as a |Float| in the
11402 range [-1, 1].
11403 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011404 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011405 Examples: >
11406 :echo tanh(0.5)
11407< 0.462117 >
11408 :echo tanh(-1)
11409< -0.761594
11410
11411 Can also be used as a |method|: >
11412 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011413<
11414 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011415
11416
11417tempname() *tempname()* *temp-file-name*
11418 The result is a String, which is the name of a file that
11419 doesn't exist. It can be used for a temporary file. The name
11420 is different for at least 26 consecutive calls. Example: >
11421 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011422 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011423< For Unix, the file will be in a private directory |tempfile|
11424 that is recursively deleted when Vim exits, on other systems
11425 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011426 For MS-Windows forward slashes are used when the 'shellslash'
11427 option is set, or when 'shellcmdflag' starts with '-' and
11428 'shell' does not contain powershell or pwsh.
11429
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011430 Return type: |String|
11431
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011432
11433term_ functions are documented here: |terminal-function-details|
11434
11435
11436terminalprops() *terminalprops()*
11437 Returns a |Dictionary| with properties of the terminal that Vim
11438 detected from the response to |t_RV| request. See
11439 |v:termresponse| for the response itself. If |v:termresponse|
11440 is empty most values here will be 'u' for unknown.
11441 cursor_style whether sending |t_RS| works **
11442 cursor_blink_mode whether sending |t_RC| works **
11443 underline_rgb whether |t_8u| works **
11444 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011445 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011446
11447 ** value 'u' for unknown, 'y' for yes, 'n' for no
11448
11449 If the |+termresponse| feature is missing then the result is
11450 an empty dictionary.
11451
11452 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11453 current cursor style.
11454 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11455 request the cursor blink status.
11456 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11457 is not empty, Vim will detect the working of sending |t_RS|
11458 and |t_RC| on startup.
11459
11460 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11461 This avoids sending it to xterm, which would clear the colors.
11462
11463 For "mouse" the value 'u' is unknown
11464
11465 Also see:
11466 - 'ambiwidth' - detected by using |t_u7|.
11467 - |v:termstyleresp| and |v:termblinkresp| for the response to
11468 |t_RS| and |t_RC|.
11469
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011470 Return type: dict<string>
11471
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011472
11473test_ functions are documented here: |test-functions-details|
11474
11475
11476 *timer_info()*
11477timer_info([{id}])
11478 Return a list with information about timers.
11479 When {id} is given only information about this timer is
11480 returned. When timer {id} does not exist an empty list is
11481 returned.
11482 When {id} is omitted information about all timers is returned.
11483
11484 For each timer the information is stored in a |Dictionary| with
11485 these items:
11486 "id" the timer ID
11487 "time" time the timer was started with
11488 "remaining" time until the timer fires
11489 "repeat" number of times the timer will still fire;
11490 -1 means forever
11491 "callback" the callback
11492 "paused" 1 if the timer is paused, 0 otherwise
11493
11494 Can also be used as a |method|: >
11495 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011496<
11497 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011498
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011499 {only available when compiled with the |+timers| feature}
11500
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011501
11502timer_pause({timer}, {paused}) *timer_pause()*
11503 Pause or unpause a timer. A paused timer does not invoke its
11504 callback when its time expires. Unpausing a timer may cause
11505 the callback to be invoked almost immediately if enough time
11506 has passed.
11507
11508 Pausing a timer is useful to avoid the callback to be called
11509 for a short time.
11510
11511 If {paused} evaluates to a non-zero Number or a non-empty
11512 String, then the timer is paused, otherwise it is unpaused.
11513 See |non-zero-arg|.
11514
11515 Can also be used as a |method|: >
11516 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011517<
11518 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011519
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011520 {only available when compiled with the |+timers| feature}
11521
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011522
11523 *timer_start()* *timer* *timers*
11524timer_start({time}, {callback} [, {options}])
11525 Create a timer and return the timer ID.
11526
11527 {time} is the waiting time in milliseconds. This is the
11528 minimum time before invoking the callback. When the system is
11529 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011530 Zero can be used to execute the callback when Vim is back in
11531 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011532
11533 {callback} is the function to call. It can be the name of a
11534 function or a |Funcref|. It is called with one argument, which
11535 is the timer ID. The callback is only invoked when Vim is
11536 waiting for input.
11537 If you want to show a message look at |popup_notification()|
11538 to avoid interfering with what the user is doing.
11539
11540 {options} is a dictionary. Supported entries:
11541 "repeat" Number of times to repeat calling the
11542 callback. -1 means forever. When not present
11543 the callback will be called once.
11544 If the timer causes an error three times in a
11545 row the repeat is cancelled. This avoids that
11546 Vim becomes unusable because of all the error
11547 messages.
11548
Bram Moolenaard592deb2022-06-17 15:42:40 +010011549 Returns -1 on error.
11550
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011551 Example: >
11552 func MyHandler(timer)
11553 echo 'Handler called'
11554 endfunc
11555 let timer = timer_start(500, 'MyHandler',
11556 \ {'repeat': 3})
11557< This will invoke MyHandler() three times at 500 msec
11558 intervals.
11559
11560 Can also be used as a |method|: >
11561 GetMsec()->timer_start(callback)
11562
11563< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011564
11565 Return type: |Number|
11566
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011567 {only available when compiled with the |+timers| feature}
11568
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011569
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011570timer_stop({timer}) *timer_stop()*
11571 Stop a timer. The timer callback will no longer be invoked.
11572 {timer} is an ID returned by timer_start(), thus it must be a
11573 Number. If {timer} does not exist there is no error.
11574
11575 Can also be used as a |method|: >
11576 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011577<
11578 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011579
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011580 {only available when compiled with the |+timers| feature}
11581
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011582
11583timer_stopall() *timer_stopall()*
11584 Stop all timers. The timer callbacks will no longer be
11585 invoked. Useful if a timer is misbehaving. If there are no
11586 timers there is no error.
11587
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011588 Return type: |Number|
11589
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011590 {only available when compiled with the |+timers| feature}
11591
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011592
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011593tolower({expr}) *tolower()*
11594 The result is a copy of the String given, with all uppercase
11595 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011596 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011597
11598 Can also be used as a |method|: >
11599 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011600<
11601 Return type: |String|
11602
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011603
11604toupper({expr}) *toupper()*
11605 The result is a copy of the String given, with all lowercase
11606 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011607 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011608
11609 Can also be used as a |method|: >
11610 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011611<
11612 Return type: |String|
11613
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011614
11615tr({src}, {fromstr}, {tostr}) *tr()*
11616 The result is a copy of the {src} string with all characters
11617 which appear in {fromstr} replaced by the character in that
11618 position in the {tostr} string. Thus the first character in
11619 {fromstr} is translated into the first character in {tostr}
11620 and so on. Exactly like the unix "tr" command.
11621 This code also deals with multibyte characters properly.
11622
Bram Moolenaard592deb2022-06-17 15:42:40 +010011623 Returns an empty string on error.
11624
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011625 Examples: >
11626 echo tr("hello there", "ht", "HT")
11627< returns "Hello THere" >
11628 echo tr("<blob>", "<>", "{}")
11629< returns "{blob}"
11630
11631 Can also be used as a |method|: >
11632 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011633<
11634 Return type: |String|
11635
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011636
11637trim({text} [, {mask} [, {dir}]]) *trim()*
11638 Return {text} as a String where any character in {mask} is
11639 removed from the beginning and/or end of {text}.
11640
Illia Bobyr80799172023-10-17 18:00:50 +020011641 If {mask} is not given, or is an empty string, {mask} is all
11642 characters up to 0x20, which includes Tab, space, NL and CR,
11643 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011644
11645 The optional {dir} argument specifies where to remove the
11646 characters:
11647 0 remove from the beginning and end of {text}
11648 1 remove only at the beginning of {text}
11649 2 remove only at the end of {text}
11650 When omitted both ends are trimmed.
11651
11652 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011653 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011654
11655 Examples: >
11656 echo trim(" some text ")
11657< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011658 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011659< returns "RESERVE_TAIL" >
11660 echo trim("rm<Xrm<>X>rrm", "rm<>")
11661< returns "Xrm<>X" (characters in the middle are not removed) >
11662 echo trim(" vim ", " ", 2)
11663< returns " vim"
11664
11665 Can also be used as a |method|: >
11666 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011667<
11668 Return type: |String|
11669
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011670
11671trunc({expr}) *trunc()*
11672 Return the largest integral value with magnitude less than or
11673 equal to {expr} as a |Float| (truncate towards zero).
11674 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011675 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011676 Examples: >
11677 echo trunc(1.456)
11678< 1.0 >
11679 echo trunc(-5.456)
11680< -5.0 >
11681 echo trunc(4.0)
11682< 4.0
11683
11684 Can also be used as a |method|: >
11685 Compute()->trunc()
11686<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011687 Return type: |Float|
11688
11689
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011690 *type()*
11691type({expr}) The result is a Number representing the type of {expr}.
11692 Instead of using the number directly, it is better to use the
11693 v:t_ variable that has the value:
11694 Number: 0 |v:t_number|
11695 String: 1 |v:t_string|
11696 Funcref: 2 |v:t_func|
11697 List: 3 |v:t_list|
11698 Dictionary: 4 |v:t_dict|
11699 Float: 5 |v:t_float|
11700 Boolean: 6 |v:t_bool| (v:false and v:true)
11701 None: 7 |v:t_none| (v:null and v:none)
11702 Job: 8 |v:t_job|
11703 Channel: 9 |v:t_channel|
11704 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090011705 Class: 12 |v:t_class|
11706 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010011707 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011708 Enum: 15 |v:t_enum|
11709 EnumValue: 16 |v:t_enumvalue|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011710 For backward compatibility, this method can be used: >
11711 :if type(myvar) == type(0)
11712 :if type(myvar) == type("")
11713 :if type(myvar) == type(function("tr"))
11714 :if type(myvar) == type([])
11715 :if type(myvar) == type({})
11716 :if type(myvar) == type(0.0)
11717 :if type(myvar) == type(v:false)
11718 :if type(myvar) == type(v:none)
11719< To check if the v:t_ variables exist use this: >
11720 :if exists('v:t_number')
11721
11722< Can also be used as a |method|: >
11723 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011724<
11725 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011726
11727
11728typename({expr}) *typename()*
11729 Return a string representation of the type of {expr}.
11730 Example: >
11731 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000011732< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011733
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011734 Return type: |String|
11735
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011736
11737undofile({name}) *undofile()*
11738 Return the name of the undo file that would be used for a file
11739 with name {name} when writing. This uses the 'undodir'
11740 option, finding directories that exist. It does not check if
11741 the undo file exists.
11742 {name} is always expanded to the full path, since that is what
11743 is used internally.
11744 If {name} is empty undofile() returns an empty string, since a
11745 buffer without a file name will not write an undo file.
11746 Useful in combination with |:wundo| and |:rundo|.
11747 When compiled without the |+persistent_undo| option this always
11748 returns an empty string.
11749
11750 Can also be used as a |method|: >
11751 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011752<
11753 Return type: |String|
11754
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011755
Devin J. Pohly5fee1112023-04-23 20:26:59 -050011756undotree([{buf}]) *undotree()*
11757 Return the current state of the undo tree for the current
11758 buffer, or for a specific buffer if {buf} is given. The
11759 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011760 "seq_last" The highest undo sequence number used.
11761 "seq_cur" The sequence number of the current position in
11762 the undo tree. This differs from "seq_last"
11763 when some changes were undone.
11764 "time_cur" Time last used for |:earlier| and related
11765 commands. Use |strftime()| to convert to
11766 something readable.
11767 "save_last" Number of the last file write. Zero when no
11768 write yet.
11769 "save_cur" Number of the current position in the undo
11770 tree.
11771 "synced" Non-zero when the last undo block was synced.
11772 This happens when waiting from input from the
11773 user. See |undo-blocks|.
11774 "entries" A list of dictionaries with information about
11775 undo blocks.
11776
11777 The first item in the "entries" list is the oldest undo item.
11778 Each List item is a |Dictionary| with these items:
11779 "seq" Undo sequence number. Same as what appears in
11780 |:undolist|.
11781 "time" Timestamp when the change happened. Use
11782 |strftime()| to convert to something readable.
11783 "newhead" Only appears in the item that is the last one
11784 that was added. This marks the last change
11785 and where further changes will be added.
11786 "curhead" Only appears in the item that is the last one
11787 that was undone. This marks the current
11788 position in the undo tree, the block that will
11789 be used by a redo command. When nothing was
11790 undone after the last change this item will
11791 not appear anywhere.
11792 "save" Only appears on the last block before a file
11793 write. The number is the write count. The
11794 first write has number 1, the last one the
11795 "save_last" mentioned above.
11796 "alt" Alternate entry. This is again a List of undo
11797 blocks. Each item may again have an "alt"
11798 item.
11799
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011800 Return type: dict<any>
11801
11802
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011803uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
11804 Remove second and succeeding copies of repeated adjacent
11805 {list} items in-place. Returns {list}. If you want a list
11806 to remain unmodified make a copy first: >
11807 :let newlist = uniq(copy(mylist))
11808< The default compare function uses the string representation of
11809 each item. For the use of {func} and {dict} see |sort()|.
11810
Bram Moolenaard592deb2022-06-17 15:42:40 +010011811 Returns zero if {list} is not a |List|.
11812
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011813 Can also be used as a |method|: >
11814 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010011815<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011816 Return type: list<{type}>
11817
11818
Christian Brabandt67672ef2023-04-24 21:09:54 +010011819 *utf16idx()*
11820utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011821 Same as |charidx()| but returns the UTF-16 code unit index of
11822 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010011823
11824 When {charidx} is present and TRUE, {idx} is used as the
11825 character index in the String {string} instead of as the byte
11826 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010011827 An {idx} in the middle of a UTF-8 sequence is rounded
11828 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010011829
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011830 Returns -1 if the arguments are invalid or if there are less
11831 than {idx} bytes in {string}. If there are exactly {idx} bytes
11832 the length of the string in UTF-16 code units is returned.
11833
Christian Brabandt67672ef2023-04-24 21:09:54 +010011834 See |byteidx()| and |byteidxcomp()| for getting the byte index
11835 from the UTF-16 index and |charidx()| for getting the
11836 character index from the UTF-16 index.
11837 Refer to |string-offset-encoding| for more information.
11838 Examples: >
11839 echo utf16idx('a😊😊', 3) returns 2
11840 echo utf16idx('a😊😊', 7) returns 4
11841 echo utf16idx('a😊😊', 1, 0, 1) returns 2
11842 echo utf16idx('a😊😊', 2, 0, 1) returns 4
11843 echo utf16idx('aą́c', 6) returns 2
11844 echo utf16idx('aą́c', 6, 1) returns 4
11845 echo utf16idx('a😊😊', 9) returns -1
11846<
11847 Can also be used as a |method|: >
11848 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011849<
11850 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010011851
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011852
11853values({dict}) *values()*
11854 Return a |List| with all the values of {dict}. The |List| is
11855 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011856 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011857
11858 Can also be used as a |method|: >
11859 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011860<
11861 Return type: list<any>
11862
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011863
zeertzjq825cf812023-08-17 22:55:25 +020011864virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011865 The result is a Number, which is the screen column of the file
11866 position given with {expr}. That is, the last screen position
11867 occupied by the character at that position, when the screen
11868 would be of unlimited width. When there is a <Tab> at the
11869 position, the returned Number will be the column at the end of
11870 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
11871 set to 8, it returns 8. |conceal| is ignored.
11872 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011873
zeertzjq02f3eba2024-06-12 20:45:24 +020011874 For the use of {expr} see |getpos()| and |col()|.
zeertzjqd353d272024-06-13 23:00:25 +080011875 When {expr} is "$", it means the end of the cursor line, so
11876 the result is the number of cells in the cursor line plus one.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011877
11878 When 'virtualedit' is used {expr} can be [lnum, col, off],
11879 where "off" is the offset in screen columns from the start of
11880 the character. E.g., a position within a <Tab> or after the
11881 last character. When "off" is omitted zero is used. When
11882 Virtual editing is active in the current mode, a position
11883 beyond the end of the line can be returned. Also see
11884 |'virtualedit'|
11885
zeertzjq825cf812023-08-17 22:55:25 +020011886 If {list} is present and non-zero then virtcol() returns a
11887 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010011888 character.
11889
zeertzjq825cf812023-08-17 22:55:25 +020011890 With the optional {winid} argument the values are obtained for
11891 that window instead of the current window.
11892
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011893 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +020011894
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011895 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010011896 " With text "foo^Lbar" and cursor on the "^L":
11897
11898 virtcol(".") " returns 5
11899 virtcol(".", 1) " returns [4, 5]
11900 virtcol("$") " returns 9
11901
11902 " With text " there", with 't at 'h':
11903
11904 virtcol("'t") " returns 6
zeertzjq02f3eba2024-06-12 20:45:24 +020011905<
11906 The first column is 1. 0 or [0, 0] is returned for an error.
11907
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011908 A more advanced example that echoes the maximum length of
11909 all lines: >
11910 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
11911
11912< Can also be used as a |method|: >
11913 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011914<
11915 Return type: |Number|
11916
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011917
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011918virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
11919 The result is a Number, which is the byte index of the
11920 character in window {winid} at buffer line {lnum} and virtual
11921 column {col}.
11922
zeertzjqb583eda2023-10-14 11:32:28 +020011923 If buffer line {lnum} is an empty line, 0 is returned.
11924
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011925 If {col} is greater than the last virtual column in line
11926 {lnum}, then the byte index of the character at the last
11927 virtual column is returned.
11928
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020011929 For a multi-byte character, the column number of the first
11930 byte in the character is returned.
11931
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011932 The {winid} argument can be the window number or the
11933 |window-ID|. If this is zero, then the current window is used.
11934
11935 Returns -1 if the window {winid} doesn't exist or the buffer
11936 line {lnum} or virtual column {col} is invalid.
11937
11938 See also |screenpos()|, |virtcol()| and |col()|.
11939
11940 Can also be used as a |method|: >
11941 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011942<
11943 Return type: |Number|
11944
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011945
11946visualmode([{expr}]) *visualmode()*
11947 The result is a String, which describes the last Visual mode
11948 used in the current buffer. Initially it returns an empty
11949 string, but once Visual mode has been used, it returns "v",
11950 "V", or "<CTRL-V>" (a single CTRL-V character) for
11951 character-wise, line-wise, or block-wise Visual mode
11952 respectively.
11953 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011954 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011955< This enters the same Visual mode as before. It is also useful
11956 in scripts if you wish to act differently depending on the
11957 Visual mode that was used.
11958 If Visual mode is active, use |mode()| to get the Visual mode
11959 (e.g., in a |:vmap|).
11960 If {expr} is supplied and it evaluates to a non-zero Number or
11961 a non-empty String, then the Visual mode will be cleared and
11962 the old value is returned. See |non-zero-arg|.
11963
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011964 Return type: |String|
11965
11966
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011967wildmenumode() *wildmenumode()*
11968 Returns |TRUE| when the wildmenu is active and |FALSE|
11969 otherwise. See 'wildmenu' and 'wildmode'.
11970 This can be used in mappings to handle the 'wildcharm' option
11971 gracefully. (Makes only sense with |mapmode-c| mappings).
11972
11973 For example to make <c-j> work like <down> in wildmode, use: >
11974 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
11975<
Milly6c2fc372024-10-16 22:11:17 +020011976 (Note: this needs the 'wildcharm' option set appropriately).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011977
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011978 Return type: |Number|
11979
11980
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011981win_execute({id}, {command} [, {silent}]) *win_execute()*
11982 Like `execute()` but in the context of window {id}.
11983 The window will temporarily be made the current window,
11984 without triggering autocommands or changing directory. When
11985 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010011986 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011987 Example: >
11988 call win_execute(winid, 'set syntax=python')
11989< Doing the same with `setwinvar()` would not trigger
11990 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011991 *E994*
11992 Not all commands are allowed in popup windows.
11993 When window {id} does not exist then no error is given and
11994 an empty string is returned.
11995
11996 Can also be used as a |method|, the base is passed as the
11997 second argument: >
11998 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011999<
12000 Return type: |String|
12001
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012002
12003win_findbuf({bufnr}) *win_findbuf()*
12004 Returns a |List| with |window-ID|s for windows that contain
12005 buffer {bufnr}. When there is none the list is empty.
12006
12007 Can also be used as a |method|: >
12008 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012009<
12010 Return type: list<number> or list<any>
12011
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012012
12013win_getid([{win} [, {tab}]]) *win_getid()*
12014 Get the |window-ID| for the specified window.
12015 When {win} is missing use the current window.
12016 With {win} this is the window number. The top window has
12017 number 1.
12018 Without {tab} use the current tab, otherwise the tab with
12019 number {tab}. The first tab has number one.
12020 Return zero if the window cannot be found.
12021
12022 Can also be used as a |method|: >
12023 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012024<
12025 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012026
12027
12028win_gettype([{nr}]) *win_gettype()*
12029 Return the type of the window:
12030 "autocmd" autocommand window. Temporary window
12031 used to execute autocommands.
12032 "command" command-line window |cmdwin|
12033 (empty) normal window
12034 "loclist" |location-list-window|
12035 "popup" popup window |popup|
12036 "preview" preview window |preview-window|
12037 "quickfix" |quickfix-window|
12038 "unknown" window {nr} not found
12039
12040 When {nr} is omitted return the type of the current window.
12041 When {nr} is given return the type of this window by number or
12042 |window-ID|.
12043
12044 Also see the 'buftype' option. When running a terminal in a
12045 popup window then 'buftype' is "terminal" and win_gettype()
12046 returns "popup".
12047
12048 Can also be used as a |method|: >
12049 GetWinid()->win_gettype()
12050<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012051 Return type: |String|
12052
12053
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012054win_gotoid({expr}) *win_gotoid()*
12055 Go to window with ID {expr}. This may also change the current
12056 tabpage.
12057 Return TRUE if successful, FALSE if the window cannot be found.
12058
12059 Can also be used as a |method|: >
12060 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012061<
12062 Return type: |Number|
12063
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012064
12065win_id2tabwin({expr}) *win_id2tabwin()*
12066 Return a list with the tab number and window number of window
12067 with ID {expr}: [tabnr, winnr].
12068 Return [0, 0] if the window cannot be found.
12069
12070 Can also be used as a |method|: >
12071 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012072<
12073 Return type: list<number>
12074
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012075
12076win_id2win({expr}) *win_id2win()*
12077 Return the window number of window with ID {expr}.
12078 Return 0 if the window cannot be found in the current tabpage.
12079
12080 Can also be used as a |method|: >
12081 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012082<
12083 Return type: |Number|
12084
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012085
Daniel Steinbergee630312022-01-10 13:36:34 +000012086win_move_separator({nr}, {offset}) *win_move_separator()*
12087 Move window {nr}'s vertical separator (i.e., the right border)
12088 by {offset} columns, as if being dragged by the mouse. {nr}
12089 can be a window number or |window-ID|. A positive {offset}
12090 moves right and a negative {offset} moves left. Moving a
12091 window's vertical separator will change the width of the
12092 window and the width of other windows adjacent to the vertical
12093 separator. The magnitude of movement may be smaller than
12094 specified (e.g., as a consequence of maintaining
12095 'winminwidth'). Returns TRUE if the window can be found and
12096 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012097 This will fail for the rightmost window and a full-width
12098 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012099 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000012100
12101 Can also be used as a |method|: >
12102 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012103<
12104 Return type: |Number|
12105
Daniel Steinbergee630312022-01-10 13:36:34 +000012106
12107win_move_statusline({nr}, {offset}) *win_move_statusline()*
12108 Move window {nr}'s status line (i.e., the bottom border) by
12109 {offset} rows, as if being dragged by the mouse. {nr} can be a
12110 window number or |window-ID|. A positive {offset} moves down
12111 and a negative {offset} moves up. Moving a window's status
12112 line will change the height of the window and the height of
12113 other windows adjacent to the status line. The magnitude of
12114 movement may be smaller than specified (e.g., as a consequence
12115 of maintaining 'winminheight'). Returns TRUE if the window can
12116 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012117 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000012118
12119 Can also be used as a |method|: >
12120 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012121<
12122 Return type: |Number|
12123
Daniel Steinbergee630312022-01-10 13:36:34 +000012124
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012125win_screenpos({nr}) *win_screenpos()*
12126 Return the screen position of window {nr} as a list with two
12127 numbers: [row, col]. The first window always has position
12128 [1, 1], unless there is a tabline, then it is [2, 1].
12129 {nr} can be the window number or the |window-ID|. Use zero
12130 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012131 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012132
12133 Can also be used as a |method|: >
12134 GetWinid()->win_screenpos()
12135<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012136 Return type: list<number>
12137
12138
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012139win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012140 Temporarily switch to window {target}, then move window {nr}
12141 to a new split adjacent to {target}.
12142 Unlike commands such as |:split|, no new windows are created
12143 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012144
12145 Both {nr} and {target} can be window numbers or |window-ID|s.
12146 Both must be in the current tab page.
12147
12148 Returns zero for success, non-zero for failure.
12149
12150 {options} is a |Dictionary| with the following optional entries:
12151 "vertical" When TRUE, the split is created vertically,
12152 like with |:vsplit|.
12153 "rightbelow" When TRUE, the split is made below or to the
12154 right (if vertical). When FALSE, it is done
12155 above or to the left (if vertical). When not
12156 present, the values of 'splitbelow' and
12157 'splitright' are used.
12158
12159 Can also be used as a |method|: >
12160 GetWinid()->win_splitmove(target)
12161<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012162 Return type: |Number|
12163
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012164
12165 *winbufnr()*
12166winbufnr({nr}) The result is a Number, which is the number of the buffer
12167 associated with window {nr}. {nr} can be the window number or
12168 the |window-ID|.
12169 When {nr} is zero, the number of the buffer in the current
12170 window is returned.
12171 When window {nr} doesn't exist, -1 is returned.
12172 Example: >
12173 :echo "The file in the current window is " . bufname(winbufnr(0))
12174<
12175 Can also be used as a |method|: >
12176 FindWindow()->winbufnr()->bufname()
12177<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012178 Return type: |Number|
12179
12180
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012181 *wincol()*
12182wincol() The result is a Number, which is the virtual column of the
12183 cursor in the window. This is counting screen cells from the
12184 left side of the window. The leftmost column is one.
12185
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012186 Return type: |Number|
12187
12188
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012189 *windowsversion()*
12190windowsversion()
12191 The result is a String. For MS-Windows it indicates the OS
12192 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12193 Windows XP is "5.1". For non-MS-Windows systems the result is
12194 an empty string.
12195
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012196 Return type: |String|
12197
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012198winheight({nr}) *winheight()*
12199 The result is a Number, which is the height of window {nr}.
12200 {nr} can be the window number or the |window-ID|.
12201 When {nr} is zero, the height of the current window is
12202 returned. When window {nr} doesn't exist, -1 is returned.
12203 An existing window always has a height of zero or more.
12204 This excludes any window toolbar line.
12205 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012206 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012207
12208< Can also be used as a |method|: >
12209 GetWinid()->winheight()
12210<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012211 Return type: |Number|
12212
12213
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012214winlayout([{tabnr}]) *winlayout()*
12215 The result is a nested List containing the layout of windows
12216 in a tabpage.
12217
12218 Without {tabnr} use the current tabpage, otherwise the tabpage
12219 with number {tabnr}. If the tabpage {tabnr} is not found,
12220 returns an empty list.
12221
12222 For a leaf window, it returns:
12223 ['leaf', {winid}]
12224 For horizontally split windows, which form a column, it
12225 returns:
12226 ['col', [{nested list of windows}]]
12227 For vertically split windows, which form a row, it returns:
12228 ['row', [{nested list of windows}]]
12229
12230 Example: >
12231 " Only one window in the tab page
12232 :echo winlayout()
12233 ['leaf', 1000]
12234 " Two horizontally split windows
12235 :echo winlayout()
12236 ['col', [['leaf', 1000], ['leaf', 1001]]]
12237 " The second tab page, with three horizontally split
12238 " windows, with two vertically split windows in the
12239 " middle window
12240 :echo winlayout(2)
12241 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12242 ['leaf', 1001]]], ['leaf', 1000]]]
12243<
12244 Can also be used as a |method|: >
12245 GetTabnr()->winlayout()
12246<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012247 Return type: list<any>
12248
12249
12250winline() *winline()*
12251 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012252 in the window. This is counting screen lines from the top of
12253 the window. The first line is one.
12254 If the cursor was moved the view on the file will be updated
12255 first, this may cause a scroll.
12256
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012257 Return type: |Number|
12258
12259
12260winnr([{arg}]) *winnr()*
12261 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012262 window. The top window has number 1.
12263 Returns zero for a popup window.
12264
12265 The optional argument {arg} supports the following values:
12266 $ the number of the last window (the window
12267 count).
12268 # the number of the last accessed window (where
12269 |CTRL-W_p| goes to). If there is no previous
12270 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012271 returned. May refer to the current window in
12272 some cases (e.g. when evaluating 'statusline'
12273 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012274 {N}j the number of the Nth window below the
12275 current window (where |CTRL-W_j| goes to).
12276 {N}k the number of the Nth window above the current
12277 window (where |CTRL-W_k| goes to).
12278 {N}h the number of the Nth window left of the
12279 current window (where |CTRL-W_h| goes to).
12280 {N}l the number of the Nth window right of the
12281 current window (where |CTRL-W_l| goes to).
12282 The number can be used with |CTRL-W_w| and ":wincmd w"
12283 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012284 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012285 Also see |tabpagewinnr()| and |win_getid()|.
12286 Examples: >
12287 let window_count = winnr('$')
12288 let prev_window = winnr('#')
12289 let wnum = winnr('3k')
12290
12291< Can also be used as a |method|: >
12292 GetWinval()->winnr()
12293<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012294 Return type: |Number|
12295
12296
12297winrestcmd() *winrestcmd()*
12298 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012299 the current window sizes. Only works properly when no windows
12300 are opened or closed and the current window and tab page is
12301 unchanged.
12302 Example: >
12303 :let cmd = winrestcmd()
12304 :call MessWithWindowSizes()
12305 :exe cmd
12306<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012307 Return type: |String|
12308
12309
12310winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012311 Uses the |Dictionary| returned by |winsaveview()| to restore
12312 the view of the current window.
12313 Note: The {dict} does not have to contain all values, that are
12314 returned by |winsaveview()|. If values are missing, those
12315 settings won't be restored. So you can use: >
12316 :call winrestview({'curswant': 4})
12317<
12318 This will only set the curswant value (the column the cursor
12319 wants to move on vertical movements) of the cursor to column 5
12320 (yes, that is 5), while all other settings will remain the
12321 same. This is useful, if you set the cursor position manually.
12322
12323 If you have changed the values the result is unpredictable.
12324 If the window size changed the result won't be the same.
12325
12326 Can also be used as a |method|: >
12327 GetView()->winrestview()
12328<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012329 Return type: |Number|
12330
12331
12332winsaveview() *winsaveview()*
12333 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012334 the view of the current window. Use |winrestview()| to
12335 restore the view.
12336 This is useful if you have a mapping that jumps around in the
12337 buffer and you want to go back to the original view.
12338 This does not save fold information. Use the 'foldenable'
12339 option to temporarily switch off folding, so that folds are
12340 not opened when moving around. This may have side effects.
12341 The return value includes:
12342 lnum cursor line number
12343 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012344 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012345 returns)
12346 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012347 curswant column for vertical movement (Note:
12348 the first column is zero, as opposed
12349 to what |getcurpos()| returns). After
12350 |$| command it will be a very large
12351 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012352 topline first line in the window
12353 topfill filler lines, only in diff mode
12354 leftcol first column displayed; only used when
12355 'wrap' is off
12356 skipcol columns skipped
12357 Note that no option values are saved.
12358
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012359 Return type: dict<number>
12360
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012361
12362winwidth({nr}) *winwidth()*
12363 The result is a Number, which is the width of window {nr}.
12364 {nr} can be the window number or the |window-ID|.
12365 When {nr} is zero, the width of the current window is
12366 returned. When window {nr} doesn't exist, -1 is returned.
12367 An existing window always has a width of zero or more.
12368 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012369 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012370 :if winwidth(0) <= 50
12371 : 50 wincmd |
12372 :endif
12373< For getting the terminal or screen size, see the 'columns'
12374 option.
12375
12376 Can also be used as a |method|: >
12377 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012378<
12379 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012380
12381
12382wordcount() *wordcount()*
12383 The result is a dictionary of byte/chars/word statistics for
12384 the current buffer. This is the same info as provided by
12385 |g_CTRL-G|
12386 The return value includes:
12387 bytes Number of bytes in the buffer
12388 chars Number of chars in the buffer
12389 words Number of words in the buffer
12390 cursor_bytes Number of bytes before cursor position
12391 (not in Visual mode)
12392 cursor_chars Number of chars before cursor position
12393 (not in Visual mode)
12394 cursor_words Number of words before cursor position
12395 (not in Visual mode)
12396 visual_bytes Number of bytes visually selected
12397 (only in Visual mode)
12398 visual_chars Number of chars visually selected
12399 (only in Visual mode)
12400 visual_words Number of words visually selected
12401 (only in Visual mode)
12402
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012403 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012404
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012405
12406writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012407 When {object} is a |List| write it to file {fname}. Each list
12408 item is separated with a NL. Each list item must be a String
12409 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012410 All NL characters are replaced with a NUL character.
12411 Inserting CR characters needs to be done before passing {list}
12412 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012413
12414 When {object} is a |Blob| write the bytes to file {fname}
12415 unmodified, also when binary mode is not specified.
12416
12417 {flags} must be a String. These characters are recognized:
12418
12419 'b' Binary mode is used: There will not be a NL after the
12420 last list item. An empty item at the end does cause the
12421 last line in the file to end in a NL.
12422
12423 'a' Append mode is used, lines are appended to the file: >
12424 :call writefile(["foo"], "event.log", "a")
12425 :call writefile(["bar"], "event.log", "a")
12426<
12427 'D' Delete the file when the current function ends. This
12428 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012429 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012430< Fails when not in a function. Also see |:defer|.
12431
12432 's' fsync() is called after writing the file. This flushes
12433 the file to disk, if possible. This takes more time but
12434 avoids losing the file if the system crashes.
12435
12436 'S' fsync() is not called, even when 'fsync' is set.
12437
12438 When {flags} does not contain "S" or "s" then fsync() is
12439 called if the 'fsync' option is set.
12440
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012441 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012442
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012443 When the write fails -1 is returned, otherwise 0. There is an
12444 error message if the file can't be created or when writing
12445 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012446
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012447 Also see |readfile()|.
12448 To copy a file byte for byte: >
12449 :let fl = readfile("foo", "b")
12450 :call writefile(fl, "foocopy", "b")
12451
12452< Can also be used as a |method|: >
12453 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012454<
12455 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012456
12457
12458xor({expr}, {expr}) *xor()*
12459 Bitwise XOR on the two arguments. The arguments are converted
12460 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012461 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012462 Example: >
12463 :let bits = xor(bits, 0x80)
12464<
12465 Can also be used as a |method|: >
12466 :let bits = bits->xor(0x80)
12467<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012468 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012469
12470==============================================================================
124713. Feature list *feature-list*
12472
12473There are three types of features:
124741. Features that are only supported when they have been enabled when Vim
12475 was compiled |+feature-list|. Example: >
12476 :if has("cindent")
12477< *gui_running*
124782. Features that are only supported when certain conditions have been met.
12479 Example: >
12480 :if has("gui_running")
12481< *has-patch*
124823. Beyond a certain version or at a certain version and including a specific
12483 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12484 later, or it is version 7.4 and patch 248 was included. Example: >
12485 :if has("patch-7.4.248")
12486< Note that it's possible for patch 248 to be omitted even though 249 is
12487 included. Only happens when cherry-picking patches.
12488 Note that this form only works for patch 7.4.237 and later, before that
12489 you need to check for the patch and the v:version. Example (checking
12490 version 6.2.148 or later): >
12491 :if v:version > 602 || (v:version == 602 && has("patch148"))
12492
12493Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12494use: `if exists('+shellslash')`
12495
12496
12497acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012498all_builtin_terms Compiled with all builtin terminals enabled. (always
12499 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012500amiga Amiga version of Vim.
12501arabic Compiled with Arabic support |Arabic|.
12502arp Compiled with ARP support (Amiga).
12503autocmd Compiled with autocommand support. (always true)
12504autochdir Compiled with support for 'autochdir'
12505autoservername Automatically enable |clientserver|
12506balloon_eval Compiled with |balloon-eval| support.
12507balloon_multiline GUI supports multiline balloons.
12508beos BeOS version of Vim.
12509browse Compiled with |:browse| support, and browse() will
12510 work.
12511browsefilter Compiled with support for |browsefilter|.
12512bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012513builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012514byte_offset Compiled with support for 'o' in 'statusline'
12515channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012516cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012517clientserver Compiled with remote invocation support |clientserver|.
12518clipboard Compiled with 'clipboard' support.
12519clipboard_working Compiled with 'clipboard' support and it can be used.
12520cmdline_compl Compiled with |cmdline-completion| support.
12521cmdline_hist Compiled with |cmdline-history| support.
12522cmdline_info Compiled with 'showcmd' and 'ruler' support.
12523comments Compiled with |'comments'| support.
12524compatible Compiled to be very Vi compatible.
12525conpty Platform where |ConPTY| can be used.
12526cryptv Compiled with encryption support |encryption|.
12527cscope Compiled with |cscope| support.
12528cursorbind Compiled with |'cursorbind'| (always true)
12529debug Compiled with "DEBUG" defined.
12530dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012531dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012532dialog_gui Compiled with GUI dialog support.
12533diff Compiled with |vimdiff| and 'diff' support.
12534digraphs Compiled with support for digraphs.
12535directx Compiled with support for DirectX and 'renderoptions'.
12536dnd Compiled with support for the "~ register |quote_~|.
12537drop_file Compiled with |drop_file| support.
12538ebcdic Compiled on a machine with ebcdic character set.
12539emacs_tags Compiled with support for Emacs tags.
12540eval Compiled with expression evaluation support. Always
12541 true, of course!
12542ex_extra |+ex_extra| (always true)
12543extra_search Compiled with support for |'incsearch'| and
12544 |'hlsearch'|
12545farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012546file_in_path Compiled with support for |gf| and |<cfile>| (always
12547 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012548filterpipe When 'shelltemp' is off pipes are used for shell
12549 read/write/filter commands
12550find_in_path Compiled with support for include file searches
12551 |+find_in_path|.
12552float Compiled with support for |Float|.
12553fname_case Case in file names matters (for Amiga and MS-Windows
12554 this is not present).
12555folding Compiled with |folding| support.
12556footer Compiled with GUI footer support. |gui-footer|
12557fork Compiled to use fork()/exec() instead of system().
12558gettext Compiled with message translation |multi-lang|
12559gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012560gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012561gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12562gui_gtk Compiled with GTK+ GUI (any version).
12563gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12564gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12565gui_haiku Compiled with Haiku GUI.
12566gui_mac Compiled with Macintosh GUI.
12567gui_motif Compiled with Motif GUI.
12568gui_photon Compiled with Photon GUI.
12569gui_running Vim is running in the GUI, or it will start soon.
12570gui_win32 Compiled with MS-Windows Win32 GUI.
12571gui_win32s idem, and Win32s system being used (Windows 3.1)
12572haiku Haiku version of Vim.
12573hangul_input Compiled with Hangul input support. |hangul|
12574hpux HP-UX version of Vim.
12575iconv Can use iconv() for conversion.
12576insert_expand Compiled with support for CTRL-X expansion commands in
12577 Insert mode. (always true)
12578job Compiled with support for |channel| and |job|
12579ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012580jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012581keymap Compiled with 'keymap' support.
12582lambda Compiled with |lambda| support.
12583langmap Compiled with 'langmap' support.
12584libcall Compiled with |libcall()| support.
12585linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12586 'breakindent' support.
12587linux Linux version of Vim.
12588lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012589 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012590listcmds Compiled with commands for the buffer list |:files|
12591 and the argument list |arglist|.
12592localmap Compiled with local mappings and abbr. |:map-local|
12593lua Compiled with Lua interface |Lua|.
12594mac Any Macintosh version of Vim cf. osx
12595macunix Synonym for osxdarwin
12596menu Compiled with support for |:menu|.
12597mksession Compiled with support for |:mksession|.
12598modify_fname Compiled with file name modifiers. |filename-modifiers|
12599 (always true)
12600mouse Compiled with support for mouse.
12601mouse_dec Compiled with support for Dec terminal mouse.
12602mouse_gpm Compiled with support for gpm (Linux console mouse)
12603mouse_gpm_enabled GPM mouse is working
12604mouse_netterm Compiled with support for netterm mouse.
12605mouse_pterm Compiled with support for qnx pterm mouse.
12606mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12607mouse_sgr Compiled with support for sgr mouse.
12608mouse_urxvt Compiled with support for urxvt mouse.
12609mouse_xterm Compiled with support for xterm mouse.
12610mouseshape Compiled with support for 'mouseshape'.
12611multi_byte Compiled with support for 'encoding' (always true)
12612multi_byte_encoding 'encoding' is set to a multibyte encoding.
12613multi_byte_ime Compiled with support for IME input method.
12614multi_lang Compiled with support for multiple languages.
12615mzscheme Compiled with MzScheme interface |mzscheme|.
12616nanotime Compiled with sub-second time stamp checks.
12617netbeans_enabled Compiled with support for |netbeans| and connected.
12618netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012619num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012620ole Compiled with OLE automation support for Win32.
12621osx Compiled for macOS cf. mac
12622osxdarwin Compiled for macOS, with |mac-darwin-feature|
12623packages Compiled with |packages| support.
12624path_extra Compiled with up/downwards search in 'path' and 'tags'
12625perl Compiled with Perl interface.
12626persistent_undo Compiled with support for persistent undo history.
12627postscript Compiled with PostScript file printing.
12628printer Compiled with |:hardcopy| support.
12629profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012630prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012631python Python 2.x interface available. |has-python|
12632python_compiled Compiled with Python 2.x interface. |has-python|
12633python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12634python3 Python 3.x interface available. |has-python|
12635python3_compiled Compiled with Python 3.x interface. |has-python|
12636python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012637python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012638pythonx Python 2.x and/or 3.x interface available. |python_x|
12639qnx QNX version of Vim.
12640quickfix Compiled with |quickfix| support.
12641reltime Compiled with |reltime()| support.
12642rightleft Compiled with 'rightleft' support.
12643ruby Compiled with Ruby interface |ruby|.
12644scrollbind Compiled with 'scrollbind' support. (always true)
12645showcmd Compiled with 'showcmd' support.
12646signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012647smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012648sodium Compiled with libsodium for better crypt support
12649sound Compiled with sound support, e.g. `sound_playevent()`
12650spell Compiled with spell checking support |spell|.
12651startuptime Compiled with |--startuptime| support.
12652statusline Compiled with support for 'statusline', 'rulerformat'
12653 and special formats of 'titlestring' and 'iconstring'.
12654sun SunOS version of Vim.
12655sun_workshop Support for Sun |workshop| has been removed.
12656syntax Compiled with syntax highlighting support |syntax|.
12657syntax_items There are active syntax highlighting items for the
12658 current buffer.
12659system Compiled to use system() instead of fork()/exec().
12660tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012661 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012662tag_old_static Support for old static tags was removed, see
12663 |tag-old-static|.
12664tcl Compiled with Tcl interface.
12665termguicolors Compiled with true color in terminal support.
12666terminal Compiled with |terminal| support.
12667terminfo Compiled with terminfo instead of termcap.
12668termresponse Compiled with support for |t_RV| and |v:termresponse|.
12669textobjects Compiled with support for |text-objects|.
12670textprop Compiled with support for |text-properties|.
12671tgetent Compiled with tgetent support, able to use a termcap
12672 or terminfo file.
12673timers Compiled with |timer_start()| support.
12674title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012675 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012676toolbar Compiled with support for |gui-toolbar|.
12677ttyin input is a terminal (tty)
12678ttyout output is a terminal (tty)
12679unix Unix version of Vim. *+unix*
12680unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
12681user_commands User-defined commands. (always true)
12682vartabs Compiled with variable tabstop support |'vartabstop'|.
12683vcon Win32: Virtual console support is working, can use
12684 'termguicolors'. Also see |+vtp|.
12685vertsplit Compiled with vertically split windows |:vsplit|.
12686 (always true)
12687vim_starting True while initial source'ing takes place. |startup|
12688 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000012689vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012690viminfo Compiled with viminfo support.
12691vimscript-1 Compiled Vim script version 1 support
12692vimscript-2 Compiled Vim script version 2 support
12693vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010012694vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012695virtualedit Compiled with 'virtualedit' option. (always true)
12696visual Compiled with Visual mode. (always true)
12697visualextra Compiled with extra Visual mode commands. (always
12698 true) |blockwise-operators|.
12699vms VMS version of Vim.
12700vreplace Compiled with |gR| and |gr| commands. (always true)
12701vtp Compiled for vcon support |+vtp| (check vcon to find
12702 out if it works in the current console).
12703wildignore Compiled with 'wildignore' option.
12704wildmenu Compiled with 'wildmenu' option.
12705win16 old version for MS-Windows 3.1 (always false)
12706win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
12707 64 bits)
12708win32unix Win32 version of Vim, using Unix files (Cygwin)
12709win64 Win64 version of Vim (MS-Windows 64 bit).
12710win95 Win32 version for MS-Windows 95/98/ME (always false)
12711winaltkeys Compiled with 'winaltkeys' option.
12712windows Compiled with support for more than one window.
12713 (always true)
12714writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020012715xattr Compiled with extended attributes support |xattr|
12716 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012717xfontset Compiled with X fontset support |xfontset|.
12718xim Compiled with X input method support |xim|.
12719xpm Compiled with pixmap support.
12720xpm_w32 Compiled with pixmap support for Win32. (Only for
12721 backward compatibility. Use "xpm" instead.)
12722xsmp Compiled with X session management support.
12723xsmp_interact Compiled with interactive X session management support.
12724xterm_clipboard Compiled with support for xterm clipboard.
12725xterm_save Compiled with support for saving and restoring the
12726 xterm screen.
12727x11 Compiled with X11 support.
12728
12729
12730==============================================================================
127314. Matching a pattern in a String *string-match*
12732
12733This is common between several functions. A regexp pattern as explained at
12734|pattern| is normally used to find a match in the buffer lines. When a
12735pattern is used to find a match in a String, almost everything works in the
12736same way. The difference is that a String is handled like it is one line.
12737When it contains a "\n" character, this is not seen as a line break for the
12738pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
12739>
12740 :let a = "aaaa\nxxxx"
12741 :echo matchstr(a, "..\n..")
12742 aa
12743 xx
12744 :echo matchstr(a, "a.x")
12745 a
12746 x
12747
12748Don't forget that "^" will only match at the first character of the String and
12749"$" at the last character of the string. They don't match after or before a
12750"\n".
12751
12752 vim:tw=78:ts=8:noet:ft=help:norl: