blob: ac10590b1da67b54407ca1d417876f0f1b0ad106 [file] [log] [blame]
h-eastb534e802024-12-03 20:37:52 +01001*builtin.txt* For Vim version 9.1. Last change: 2024 Dec 03
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.
h-eastb534e802024-12-03 20:37:52 +01003792 List format is [xpixel, ypixel].
mikoto2000a73dfc22024-11-18 21:12:21 +01003793
3794 Only works on Unix (terminal and gVim) and Windows (gVim only).
3795 Returns [] on other systems or on failure.
3796 Note that there could be variations across different terminals.
3797 On macOS, system Terminal.app returns sizes in points (before
3798 Retina scaling), whereas third-party terminals return raw pixel
3799 sizes (post Retina scaling).
mikoto20001083cae2024-11-11 21:24:14 +01003800
mikoto2000de094dc2024-11-14 22:13:48 +01003801 Return type: list<any>
mikoto20001083cae2024-11-11 21:24:14 +01003802
3803
Kota Kato66bb9ae2023-01-17 18:31:56 +00003804getcellwidths() *getcellwidths()*
3805 Returns a |List| of cell widths of character ranges overridden
3806 by |setcellwidths()|. The format is equal to the argument of
3807 |setcellwidths()|. If no character ranges have their cell
3808 widths overridden, an empty List is returned.
h-east84ac2122024-06-17 18:12:30 +02003809
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003810 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003811
3812
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003813getchangelist([{buf}]) *getchangelist()*
3814 Returns the |changelist| for the buffer {buf}. For the use
3815 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3816 exist, an empty list is returned.
3817
3818 The returned list contains two entries: a list with the change
3819 locations and the current position in the list. Each
3820 entry in the change list is a dictionary with the following
3821 entries:
3822 col column number
3823 coladd column offset for 'virtualedit'
3824 lnum line number
3825 If buffer {buf} is the current buffer, then the current
3826 position refers to the position in the list. For other
3827 buffers, it is set to the length of the list.
3828
3829 Can also be used as a |method|: >
3830 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003831<
3832 Return type: list<any>
3833
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003834
Doug Kearns9cd9e752024-04-07 17:42:17 +02003835getchar([{expr}]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003836 Get a single character from the user or input stream.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003837 If {expr} is omitted, wait until a character is available.
3838 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003839 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003840 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003841 not consumed. Return zero if no character available.
3842 If you prefer always getting a string use |getcharstr()|.
3843
Doug Kearns9cd9e752024-04-07 17:42:17 +02003844 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003845 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003846 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003847 Otherwise a String is returned with the encoded character.
3848 For a special key it's a String with a sequence of bytes
3849 starting with 0x80 (decimal: 128). This is the same value as
3850 the String "\<Key>", e.g., "\<Left>". The returned value is
3851 also a String when a modifier (shift, control, alt) was used
3852 that is not included in the character.
3853
Doug Kearns9cd9e752024-04-07 17:42:17 +02003854 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003855 while Vim waits to see if this is the start of an escape
3856 sequence.
3857
Doug Kearns9cd9e752024-04-07 17:42:17 +02003858 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003859 one-byte character it is the character itself as a number.
3860 Use nr2char() to convert it to a String.
3861
3862 Use getcharmod() to obtain any additional modifiers.
3863
3864 When the user clicks a mouse button, the mouse event will be
3865 returned. The position can then be found in |v:mouse_col|,
3866 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3867 |getmousepos()| can also be used. Mouse move events will be
3868 ignored.
3869 This example positions the mouse as it would normally happen: >
3870 let c = getchar()
3871 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003872 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003873 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003874 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003875 endif
3876<
3877 When using bracketed paste only the first character is
3878 returned, the rest of the pasted text is dropped.
3879 |xterm-bracketed-paste|.
3880
3881 There is no prompt, you will somehow have to make clear to the
3882 user that a character has to be typed. The screen is not
3883 redrawn, e.g. when resizing the window. When using a popup
3884 window it should work better with a |popup-filter|.
3885
3886 There is no mapping for the character.
3887 Key codes are replaced, thus when the user presses the <Del>
3888 key you get the code for the <Del> key, not the raw character
3889 sequence. Examples: >
3890 getchar() == "\<Del>"
3891 getchar() == "\<S-Left>"
3892< This example redefines "f" to ignore case: >
3893 :nmap f :call FindChar()<CR>
3894 :function FindChar()
3895 : let c = nr2char(getchar())
3896 : while col('.') < col('$') - 1
3897 : normal l
3898 : if getline('.')[col('.') - 1] ==? c
3899 : break
3900 : endif
3901 : endwhile
3902 :endfunction
3903<
3904 You may also receive synthetic characters, such as
3905 |<CursorHold>|. Often you will want to ignore this and get
3906 another character: >
3907 :function GetKey()
3908 : let c = getchar()
3909 : while c == "\<CursorHold>"
3910 : let c = getchar()
3911 : endwhile
3912 : return c
3913 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003914<
3915 Return type: |Number| or |String|
3916
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003917
3918getcharmod() *getcharmod()*
3919 The result is a Number which is the state of the modifiers for
3920 the last obtained character with getchar() or in another way.
3921 These values are added together:
3922 2 shift
3923 4 control
3924 8 alt (meta)
3925 16 meta (when it's different from ALT)
3926 32 mouse double click
3927 64 mouse triple click
3928 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01003929 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003930 Only the modifiers that have not been included in the
3931 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01003932 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003933
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003934 Return type: |Number|
3935
3936
3937getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003938 Get the position for String {expr}. Same as |getpos()| but the
3939 column number in the returned List is a character index
3940 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00003941 If |getpos()| returns a very large column number, equal to
3942 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003943 of the last character.
3944
3945 Example:
3946 With the cursor on '세' in line 5 with text "여보세요": >
3947 getcharpos('.') returns [0, 5, 3, 0]
3948 getpos('.') returns [0, 5, 7, 0]
3949<
3950 Can also be used as a |method|: >
3951 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003952<
3953 Return type: list<number>
3954
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003955
3956getcharsearch() *getcharsearch()*
3957 Return the current character search information as a {dict}
3958 with the following entries:
3959
3960 char character previously used for a character
3961 search (|t|, |f|, |T|, or |F|); empty string
3962 if no character search has been performed
3963 forward direction of character search; 1 for forward,
3964 0 for backward
3965 until type of character search; 1 for a |t| or |T|
3966 character search, 0 for an |f| or |F|
3967 character search
3968
3969 This can be useful to always have |;| and |,| search
3970 forward/backward regardless of the direction of the previous
3971 character search: >
3972 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
3973 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
3974< Also see |setcharsearch()|.
3975
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003976 Return type: dict<any>
3977
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003978
Doug Kearns9cd9e752024-04-07 17:42:17 +02003979getcharstr([{expr}]) *getcharstr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003980 Get a single character from the user or input stream as a
3981 string.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003982 If {expr} is omitted, wait until a character is available.
3983 If {expr} is 0 or false, only get a character when one is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003984 available. Return an empty string otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003985 If {expr} is 1 or true, only check if a character is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003986 available, it is not consumed. Return an empty string
3987 if no character is available.
3988 Otherwise this works like |getchar()|, except that a number
3989 result is converted to a string.
3990
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003991 Return type: |String|
3992
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003993getcmdcomplpat() *getcmdcomplpat()*
3994 Return completion pattern of the current command-line.
3995 Only works when the command line is being edited, thus
3996 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
3997 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
3998 |getcmdprompt()|, |getcmdcompltype()| and |setcmdline()|.
3999 Returns an empty string when completion is not defined.
4000
4001 Return type: |String|
4002
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004003
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004004getcmdcompltype() *getcmdcompltype()*
4005 Return the type of the current command-line completion.
4006 Only works when the command line is being edited, thus
4007 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01004008 See |:command-completion| for the return string.
Shougo Matsushita69084282024-09-23 20:34:47 +02004009 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004010 |getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004011 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004012
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004013 Return type: |String|
4014
4015
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004016getcmdline() *getcmdline()*
Shougo Matsushita69084282024-09-23 20:34:47 +02004017 Return the current command-line input. Only works when the
4018 command line is being edited, thus requires use of
4019 |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004020 Example: >
4021 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita69084282024-09-23 20:34:47 +02004022< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()|,
4023 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004024 Returns an empty string when entering a password or using
4025 |inputsecret()|.
4026
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004027 Return type: |String|
4028
4029
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004030getcmdpos() *getcmdpos()*
4031 Return the position of the cursor in the command line as a
4032 byte count. The first column is 1.
4033 Only works when editing the command line, thus requires use of
4034 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4035 Returns 0 otherwise.
Shougo Matsushita69084282024-09-23 20:34:47 +02004036 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4037 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004038
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004039 Return type: |Number|
4040
4041
Shougo Matsushita69084282024-09-23 20:34:47 +02004042getcmdprompt() *getcmdprompt()*
4043 Return the current command-line prompt when using functions
4044 like |input()| or |confirm()|.
4045 Only works when the command line is being edited, thus
4046 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4047 Also see |getcmdtype()|, |getcmdline()|, |getcmdpos()|,
4048 |setcmdpos()| and |setcmdline()|.
4049
4050 Return type: |String|
4051
4052
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004053getcmdscreenpos() *getcmdscreenpos()*
4054 Return the screen position of the cursor in the command line
4055 as a byte count. The first column is 1.
4056 Instead of |getcmdpos()|, it adds the prompt position.
4057 Only works when editing the command line, thus requires use of
4058 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4059 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004060 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
4061 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004062
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004063 Return type: |Number|
4064
4065
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004066getcmdtype() *getcmdtype()*
4067 Return the current command-line type. Possible return values
4068 are:
4069 : normal Ex command
4070 > debug mode command |debug-mode|
4071 / forward search command
4072 ? backward search command
4073 @ |input()| command
4074 - |:insert| or |:append| command
4075 = |i_CTRL-R_=|
4076 Only works when editing the command line, thus requires use of
4077 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4078 Returns an empty string otherwise.
4079 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4080
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004081 Return type: |String|
4082
4083
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004084getcmdwintype() *getcmdwintype()*
4085 Return the current |command-line-window| type. Possible return
4086 values are the same as |getcmdtype()|. Returns an empty string
4087 when not in the command-line window.
4088
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004089 Return type: |String|
4090
4091
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004092getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4093 Return a list of command-line completion matches. The String
4094 {type} argument specifies what for. The following completion
4095 types are supported:
4096
4097 arglist file names in argument list
4098 augroup autocmd groups
4099 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004100 behave |:behave| suboptions
4101 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004102 color color schemes
4103 command Ex command
4104 cmdline |cmdline-completion| result
4105 compiler compilers
4106 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004107 custom,{func} custom completion, defined via {func}
4108 customlist,{func} custom completion, defined via {func}
zeertzjq85f36d62024-10-10 19:14:13 +02004109 diff_buffer |:diffget| and |:diffput| completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004110 dir directory names
LemonBoya20bf692024-07-11 22:35:53 +02004111 dir_in_path directory names in |'cdpath'|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004112 environment environment variable names
4113 event autocommand events
4114 expression Vim expression
4115 file file and directory names
4116 file_in_path file and directory names in |'path'|
4117 filetype filetype names |'filetype'|
4118 function function name
4119 help help subjects
4120 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004121 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004122 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004123 locale locale names (as output of locale -a)
4124 mapclear buffer argument
4125 mapping mapping name
4126 menu menus
4127 messages |:messages| suboptions
4128 option options
4129 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004130 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004131 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004132 shellcmd Shell command
zeertzjq85f36d62024-10-10 19:14:13 +02004133 shellcmdline Shell command line with filename arguments
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004134 sign |:sign| suboptions
4135 syntax syntax file names |'syntax'|
4136 syntime |:syntime| suboptions
4137 tag tags
4138 tag_listfiles tags, file names
4139 user user names
4140 var user variables
4141
4142 If {pat} is an empty string, then all the matches are
4143 returned. Otherwise only items matching {pat} are returned.
4144 See |wildcards| for the use of special characters in {pat}.
4145
4146 If the optional {filtered} flag is set to 1, then 'wildignore'
4147 is applied to filter the results. Otherwise all the matches
4148 are returned. The 'wildignorecase' option always applies.
4149
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004150 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4151 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004152 regular expression matching is used. Thus this function
4153 follows the user preference, what happens on the command line.
4154 If you do not want this you can make 'wildoptions' empty
4155 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004156
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004157 If {type} is "cmdline", then the |cmdline-completion| result is
4158 returned. For example, to complete the possible values after
4159 a ":call" command: >
4160 echo getcompletion('call ', 'cmdline')
4161<
4162 If there are no matches, an empty list is returned. An
4163 invalid value for {type} produces an error.
4164
4165 Can also be used as a |method|: >
4166 GetPattern()->getcompletion('color')
4167<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004168 Return type: list<string>
4169
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004170 *getcurpos()*
4171getcurpos([{winid}])
4172 Get the position of the cursor. This is like getpos('.'), but
4173 includes an extra "curswant" item in the list:
4174 [0, lnum, col, off, curswant] ~
4175 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004176 cursor vertically. After |$| command it will be a very large
4177 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004178 |getpos()|.
4179 The first "bufnum" item is always zero. The byte position of
4180 the cursor is returned in 'col'. To get the character
4181 position, use |getcursorcharpos()|.
4182
4183 The optional {winid} argument can specify the window. It can
4184 be the window number or the |window-ID|. The last known
4185 cursor position is returned, this may be invalid for the
4186 current value of the buffer if it is not the current window.
4187 If {winid} is invalid a list with zeroes is returned.
4188
4189 This can be used to save and restore the cursor position: >
4190 let save_cursor = getcurpos()
4191 MoveTheCursorAround
4192 call setpos('.', save_cursor)
4193< Note that this only works within the window. See
4194 |winrestview()| for restoring more state.
4195
4196 Can also be used as a |method|: >
4197 GetWinid()->getcurpos()
4198<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004199 Return type: list<number>
4200
4201
4202getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004203 Same as |getcurpos()| but the column number in the returned
4204 List is a character index instead of a byte index.
4205
4206 Example:
4207 With the cursor on '보' in line 3 with text "여보세요": >
4208 getcursorcharpos() returns [0, 3, 2, 0, 3]
4209 getcurpos() returns [0, 3, 4, 0, 3]
4210<
4211 Can also be used as a |method|: >
4212 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004213<
4214 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004215
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004216
4217getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004218 The result is a String, which is the name of the current
4219 working directory. 'autochdir' is ignored.
4220
4221 With {winnr} return the local current directory of this window
4222 in the current tab page. {winnr} can be the window number or
4223 the |window-ID|.
4224 If {winnr} is -1 return the name of the global working
4225 directory. See also |haslocaldir()|.
4226
4227 With {winnr} and {tabnr} return the local current directory of
4228 the window in the specified tab page. If {winnr} is -1 return
4229 the working directory of the tabpage.
4230 If {winnr} is zero use the current window, if {tabnr} is zero
4231 use the current tabpage.
4232 Without any arguments, return the actual working directory of
4233 the current window.
4234 Return an empty string if the arguments are invalid.
4235
4236 Examples: >
4237 " Get the working directory of the current window
4238 :echo getcwd()
4239 :echo getcwd(0)
4240 :echo getcwd(0, 0)
4241 " Get the working directory of window 3 in tabpage 2
4242 :echo getcwd(3, 2)
4243 " Get the global working directory
4244 :echo getcwd(-1)
4245 " Get the working directory of tabpage 3
4246 :echo getcwd(-1, 3)
4247 " Get the working directory of current tabpage
4248 :echo getcwd(-1, 0)
4249
4250< Can also be used as a |method|: >
4251 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004252<
4253 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004254
4255getenv({name}) *getenv()*
4256 Return the value of environment variable {name}. The {name}
4257 argument is a string, without a leading '$'. Example: >
4258 myHome = getenv('HOME')
4259
4260< When the variable does not exist |v:null| is returned. That
4261 is different from a variable set to an empty string, although
4262 some systems interpret the empty value as the variable being
4263 deleted. See also |expr-env|.
4264
4265 Can also be used as a |method|: >
4266 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004267<
4268 Return type: |String| or |Number|
4269
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004270
4271getfontname([{name}]) *getfontname()*
4272 Without an argument returns the name of the normal font being
4273 used. Like what is used for the Normal highlight group
4274 |hl-Normal|.
4275 With an argument a check is done whether String {name} is a
4276 valid font name. If not then an empty string is returned.
4277 Otherwise the actual font name is returned, or {name} if the
4278 GUI does not support obtaining the real name.
4279 Only works when the GUI is running, thus not in your vimrc or
4280 gvimrc file. Use the |GUIEnter| autocommand to use this
4281 function just after the GUI has started.
4282 Note that the GTK GUI accepts any font name, thus checking for
4283 a valid name does not work.
4284
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004285 Return type: |String|
4286
4287
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004288getfperm({fname}) *getfperm()*
4289 The result is a String, which is the read, write, and execute
4290 permissions of the given file {fname}.
4291 If {fname} does not exist or its directory cannot be read, an
4292 empty string is returned.
4293 The result is of the form "rwxrwxrwx", where each group of
4294 "rwx" flags represent, in turn, the permissions of the owner
4295 of the file, the group the file belongs to, and other users.
4296 If a user does not have a given permission the flag for this
4297 is replaced with the string "-". Examples: >
4298 :echo getfperm("/etc/passwd")
4299 :echo getfperm(expand("~/.vimrc"))
4300< This will hopefully (from a security point of view) display
4301 the string "rw-r--r--" or even "rw-------".
4302
4303 Can also be used as a |method|: >
4304 GetFilename()->getfperm()
4305<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004306 Return type: |String|
4307
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004308 For setting permissions use |setfperm()|.
4309
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004310
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004311getfsize({fname}) *getfsize()*
4312 The result is a Number, which is the size in bytes of the
4313 given file {fname}.
4314 If {fname} is a directory, 0 is returned.
4315 If the file {fname} can't be found, -1 is returned.
4316 If the size of {fname} is too big to fit in a Number then -2
4317 is returned.
4318
4319 Can also be used as a |method|: >
4320 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004321<
4322 Return type: |Number|
4323
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004324
4325getftime({fname}) *getftime()*
4326 The result is a Number, which is the last modification time of
4327 the given file {fname}. The value is measured as seconds
4328 since 1st Jan 1970, and may be passed to strftime(). See also
4329 |localtime()| and |strftime()|.
4330 If the file {fname} can't be found -1 is returned.
4331
4332 Can also be used as a |method|: >
4333 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004334<
4335 Return type: |Number|
4336
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004337
4338getftype({fname}) *getftype()*
4339 The result is a String, which is a description of the kind of
4340 file of the given file {fname}.
4341 If {fname} does not exist an empty string is returned.
4342 Here is a table over different kinds of files and their
4343 results:
4344 Normal file "file"
4345 Directory "dir"
4346 Symbolic link "link"
4347 Block device "bdev"
4348 Character device "cdev"
4349 Socket "socket"
4350 FIFO "fifo"
4351 All other "other"
4352 Example: >
4353 getftype("/home")
4354< Note that a type such as "link" will only be returned on
4355 systems that support it. On some systems only "dir" and
4356 "file" are returned. On MS-Windows a symbolic link to a
4357 directory returns "dir" instead of "link".
4358
4359 Can also be used as a |method|: >
4360 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004361<
4362 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004363
4364getimstatus() *getimstatus()*
4365 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004366 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004367 See 'imstatusfunc'.
4368
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004369 Return type: |Number|
4370
4371
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004372getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4373 Returns the |jumplist| for the specified window.
4374
4375 Without arguments use the current window.
4376 With {winnr} only use this window in the current tab page.
4377 {winnr} can also be a |window-ID|.
4378 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004379 page. If {winnr} or {tabnr} is invalid, an empty list is
4380 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004381
4382 The returned list contains two entries: a list with the jump
4383 locations and the last used jump position number in the list.
4384 Each entry in the jump location list is a dictionary with
4385 the following entries:
4386 bufnr buffer number
4387 col column number
4388 coladd column offset for 'virtualedit'
4389 filename filename if available
4390 lnum line number
4391
4392 Can also be used as a |method|: >
4393 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004394<
4395 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004396
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004397 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004398getline({lnum} [, {end}])
4399 Without {end} the result is a String, which is line {lnum}
4400 from the current buffer. Example: >
4401 getline(1)
4402< When {lnum} is a String that doesn't start with a
4403 digit, |line()| is called to translate the String into a Number.
4404 To get the line under the cursor: >
4405 getline(".")
4406< When {lnum} is a number smaller than 1 or bigger than the
4407 number of lines in the buffer, an empty string is returned.
4408
4409 When {end} is given the result is a |List| where each item is
4410 a line from the current buffer in the range {lnum} to {end},
4411 including line {end}.
4412 {end} is used in the same way as {lnum}.
4413 Non-existing lines are silently omitted.
4414 When {end} is before {lnum} an empty |List| is returned.
4415 Example: >
4416 :let start = line('.')
4417 :let end = search("^$") - 1
4418 :let lines = getline(start, end)
4419
4420< Can also be used as a |method|: >
4421 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004422<
4423 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004424
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004425 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004426 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004427
4428getloclist({nr} [, {what}]) *getloclist()*
4429 Returns a |List| with all the entries in the location list for
4430 window {nr}. {nr} can be the window number or the |window-ID|.
4431 When {nr} is zero the current window is used.
4432
4433 For a location list window, the displayed location list is
4434 returned. For an invalid window number {nr}, an empty list is
4435 returned. Otherwise, same as |getqflist()|.
4436
4437 If the optional {what} dictionary argument is supplied, then
4438 returns the items listed in {what} as a dictionary. Refer to
4439 |getqflist()| for the supported items in {what}.
4440
4441 In addition to the items supported by |getqflist()| in {what},
4442 the following item is supported by |getloclist()|:
4443
4444 filewinid id of the window used to display files
4445 from the location list. This field is
4446 applicable only when called from a
4447 location list window. See
4448 |location-list-file-window| for more
4449 details.
4450
4451 Returns a |Dictionary| with default values if there is no
4452 location list for the window {nr}.
4453 Returns an empty Dictionary if window {nr} does not exist.
4454
4455 Examples (See also |getqflist-examples|): >
4456 :echo getloclist(3, {'all': 0})
4457 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004458<
4459 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004460
4461
4462getmarklist([{buf}]) *getmarklist()*
4463 Without the {buf} argument returns a |List| with information
4464 about all the global marks. |mark|
4465
4466 If the optional {buf} argument is specified, returns the
4467 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004468 see |bufname()|. If {buf} is invalid, an empty list is
4469 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004470
4471 Each item in the returned List is a |Dict| with the following:
4472 mark name of the mark prefixed by "'"
4473 pos a |List| with the position of the mark:
4474 [bufnum, lnum, col, off]
4475 Refer to |getpos()| for more information.
4476 file file name
4477
4478 Refer to |getpos()| for getting information about a specific
4479 mark.
4480
4481 Can also be used as a |method|: >
4482 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004483<
4484 Return type: list<dict<any>> or list<any>
4485
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004486
4487getmatches([{win}]) *getmatches()*
4488 Returns a |List| with all matches previously defined for the
4489 current window by |matchadd()| and the |:match| commands.
4490 |getmatches()| is useful in combination with |setmatches()|,
4491 as |setmatches()| can restore a list of matches saved by
4492 |getmatches()|.
4493 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004494 window ID instead of the current window. If {win} is invalid,
4495 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004496 Example: >
4497 :echo getmatches()
4498< [{'group': 'MyGroup1', 'pattern': 'TODO',
4499 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4500 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4501 :let m = getmatches()
4502 :call clearmatches()
4503 :echo getmatches()
4504< [] >
4505 :call setmatches(m)
4506 :echo getmatches()
4507< [{'group': 'MyGroup1', 'pattern': 'TODO',
4508 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4509 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4510 :unlet m
4511<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004512 Return type: list<dict<any>> or list<any>
4513
4514
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004515getmousepos() *getmousepos()*
4516 Returns a |Dictionary| with the last known position of the
4517 mouse. This can be used in a mapping for a mouse click or in
4518 a filter of a popup window. The items are:
4519 screenrow screen row
4520 screencol screen column
4521 winid Window ID of the click
4522 winrow row inside "winid"
4523 wincol column inside "winid"
4524 line text line inside "winid"
4525 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004526 coladd offset (in screen columns) from the
4527 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004528 All numbers are 1-based.
4529
4530 If not over a window, e.g. when in the command line, then only
4531 "screenrow" and "screencol" are valid, the others are zero.
4532
4533 When on the status line below a window or the vertical
4534 separator right of a window, the "line" and "column" values
4535 are zero.
4536
4537 When the position is after the text then "column" is the
4538 length of the text in bytes plus one.
4539
4540 If the mouse is over a popup window then that window is used.
4541
4542 When using |getchar()| the Vim variables |v:mouse_lnum|,
4543 |v:mouse_col| and |v:mouse_winid| also provide these values.
4544
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004545 Return type: dict<number>
4546
4547
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004548getmouseshape() *getmouseshape()*
4549 Returns the name of the currently showing mouse pointer.
4550 When the |+mouseshape| feature is not supported or the shape
4551 is unknown an empty string is returned.
4552 This function is mainly intended for testing.
4553
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004554 Return type: |String|
4555
4556
4557getpid() *getpid()*
4558 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004559 On Unix and MS-Windows this is a unique number, until Vim
4560 exits.
4561
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004562 Return type: |Number|
4563
4564
4565getpos({expr}) *getpos()*
zeertzjq02f3eba2024-06-12 20:45:24 +02004566 Get the position for String {expr}.
4567 The accepted values for {expr} are: *E1209*
4568 . The cursor position.
4569 $ The last line in the current buffer.
4570 'x Position of mark x (if the mark is not set, 0 is
zeertzjqd353d272024-06-13 23:00:25 +08004571 returned for all values).
zeertzjq02f3eba2024-06-12 20:45:24 +02004572 w0 First line visible in current window (one if the
4573 display isn't updated, e.g. in silent Ex mode).
4574 w$ Last line visible in current window (this is one
4575 less than "w0" if no lines are visible).
4576 v When not in Visual mode, returns the cursor
4577 position. In Visual mode, returns the other end
4578 of the Visual area. A good way to think about
4579 this is that in Visual mode "v" and "." complement
4580 each other. While "." refers to the cursor
4581 position, "v" refers to where |v_o| would move the
4582 cursor. As a result, you can use "v" and "."
4583 together to work on all of a selection in
4584 characterwise Visual mode. If the cursor is at
4585 the end of a characterwise Visual area, "v" refers
4586 to the start of the same Visual area. And if the
4587 cursor is at the start of a characterwise Visual
4588 area, "v" refers to the end of the same Visual
4589 area. "v" differs from |'<| and |'>| in that it's
4590 updated right away.
4591 Note that a mark in another file can be used. The line number
4592 then applies to another buffer.
4593
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004594 The result is a |List| with four numbers:
4595 [bufnum, lnum, col, off]
4596 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4597 is the buffer number of the mark.
4598 "lnum" and "col" are the position in the buffer. The first
4599 column is 1.
4600 The "off" number is zero, unless 'virtualedit' is used. Then
4601 it is the offset in screen columns from the start of the
4602 character. E.g., a position within a <Tab> or after the last
4603 character.
zeertzjq02f3eba2024-06-12 20:45:24 +02004604
4605 For getting the cursor position see |getcurpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004606 The column number in the returned List is the byte position
4607 within the line. To get the character position in the line,
4608 use |getcharpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02004609
4610 Note that for '< and '> Visual mode matters: when it is "V"
4611 (visual line mode) the column of '< is zero and the column of
4612 '> is a large number equal to |v:maxcol|.
naohiro ono56200ee2022-01-01 14:59:44 +00004613 A very large column number equal to |v:maxcol| can be returned,
4614 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004615 If {expr} is invalid, returns a list with all zeros.
zeertzjq02f3eba2024-06-12 20:45:24 +02004616
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004617 This can be used to save and restore the position of a mark: >
4618 let save_a_mark = getpos("'a")
4619 ...
4620 call setpos("'a", save_a_mark)
zeertzjqd353d272024-06-13 23:00:25 +08004621<
4622 Also see |getcharpos()|, |getcurpos()| and |setpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004623
4624 Can also be used as a |method|: >
4625 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004626<
4627 Return type: list<number>
4628
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004629
4630getqflist([{what}]) *getqflist()*
4631 Returns a |List| with all the current quickfix errors. Each
4632 list item is a dictionary with these entries:
4633 bufnr number of buffer that has the file name, use
4634 bufname() to get the name
4635 module module name
4636 lnum line number in the buffer (first line is 1)
4637 end_lnum
4638 end of line number if the item is multiline
4639 col column number (first column is 1)
4640 end_col end of column number if the item has range
4641 vcol |TRUE|: "col" is visual column
4642 |FALSE|: "col" is byte index
4643 nr error number
h-east84ac2122024-06-17 18:12:30 +02004644 pattern search pattern used to locate the error
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004645 text description of the error
4646 type type of the error, 'E', '1', etc.
4647 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004648 user_data
4649 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004650 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004651
4652 When there is no error list or it's empty, an empty list is
4653 returned. Quickfix list entries with a non-existing buffer
4654 number are returned with "bufnr" set to zero (Note: some
4655 functions accept buffer number zero for the alternate buffer,
4656 you may need to explicitly check for zero).
4657
4658 Useful application: Find pattern matches in multiple files and
4659 do something with them: >
4660 :vimgrep /theword/jg *.c
4661 :for d in getqflist()
4662 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4663 :endfor
4664<
4665 If the optional {what} dictionary argument is supplied, then
4666 returns only the items listed in {what} as a dictionary. The
4667 following string items are supported in {what}:
4668 changedtick get the total number of changes made
4669 to the list |quickfix-changedtick|
4670 context get the |quickfix-context|
4671 efm errorformat to use when parsing "lines". If
4672 not present, then the 'errorformat' option
4673 value is used.
4674 id get information for the quickfix list with
4675 |quickfix-ID|; zero means the id for the
4676 current list or the list specified by "nr"
4677 idx get information for the quickfix entry at this
4678 index in the list specified by 'id' or 'nr'.
4679 If set to zero, then uses the current entry.
4680 See |quickfix-index|
4681 items quickfix list entries
4682 lines parse a list of lines using 'efm' and return
4683 the resulting entries. Only a |List| type is
4684 accepted. The current quickfix list is not
4685 modified. See |quickfix-parse|.
4686 nr get information for this quickfix list; zero
4687 means the current quickfix list and "$" means
4688 the last quickfix list
4689 qfbufnr number of the buffer displayed in the quickfix
4690 window. Returns 0 if the quickfix buffer is
4691 not present. See |quickfix-buffer|.
4692 size number of entries in the quickfix list
4693 title get the list title |quickfix-title|
4694 winid get the quickfix |window-ID|
4695 all all of the above quickfix properties
4696 Non-string items in {what} are ignored. To get the value of a
4697 particular item, set it to zero.
4698 If "nr" is not present then the current quickfix list is used.
4699 If both "nr" and a non-zero "id" are specified, then the list
4700 specified by "id" is used.
4701 To get the number of lists in the quickfix stack, set "nr" to
4702 "$" in {what}. The "nr" value in the returned dictionary
4703 contains the quickfix stack size.
4704 When "lines" is specified, all the other items except "efm"
4705 are ignored. The returned dictionary contains the entry
4706 "items" with the list of entries.
4707
4708 The returned dictionary contains the following entries:
4709 changedtick total number of changes made to the
4710 list |quickfix-changedtick|
4711 context quickfix list context. See |quickfix-context|
4712 If not present, set to "".
4713 id quickfix list ID |quickfix-ID|. If not
4714 present, set to 0.
4715 idx index of the quickfix entry in the list. If not
4716 present, set to 0.
4717 items quickfix list entries. If not present, set to
4718 an empty list.
4719 nr quickfix list number. If not present, set to 0
4720 qfbufnr number of the buffer displayed in the quickfix
4721 window. If not present, set to 0.
4722 size number of entries in the quickfix list. If not
4723 present, set to 0.
4724 title quickfix list title text. If not present, set
4725 to "".
4726 winid quickfix |window-ID|. If not present, set to 0
4727
4728 Examples (See also |getqflist-examples|): >
4729 :echo getqflist({'all': 1})
4730 :echo getqflist({'nr': 2, 'title': 1})
4731 :echo getqflist({'lines' : ["F1:10:L10"]})
4732<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004733 Return type: list<dict<any>> or list<any>
4734
4735
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004736getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4737 The result is a String, which is the contents of register
4738 {regname}. Example: >
4739 :let cliptext = getreg('*')
4740< When register {regname} was not set the result is an empty
4741 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004742 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004743
4744 getreg('=') returns the last evaluated value of the expression
4745 register. (For use in maps.)
4746 getreg('=', 1) returns the expression itself, so that it can
4747 be restored with |setreg()|. For other registers the extra
4748 argument is ignored, thus you can always give it.
4749
4750 If {list} is present and |TRUE|, the result type is changed
4751 to |List|. Each list item is one text line. Use it if you care
4752 about zero bytes possibly present inside register: without
4753 third argument both NLs and zero bytes are represented as NLs
4754 (see |NL-used-for-Nul|).
4755 When the register was not set an empty list is returned.
4756
4757 If {regname} is "", the unnamed register '"' is used.
4758 If {regname} is not specified, |v:register| is used.
4759 In |Vim9-script| {regname} must be one character.
4760
4761 Can also be used as a |method|: >
4762 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004763<
4764 Return type: |String|
4765
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004766
4767getreginfo([{regname}]) *getreginfo()*
4768 Returns detailed information about register {regname} as a
4769 Dictionary with the following entries:
4770 regcontents List of lines contained in register
4771 {regname}, like
4772 |getreg|({regname}, 1, 1).
4773 regtype the type of register {regname}, as in
4774 |getregtype()|.
4775 isunnamed Boolean flag, v:true if this register
4776 is currently pointed to by the unnamed
4777 register.
4778 points_to for the unnamed register, gives the
4779 single letter name of the register
4780 currently pointed to (see |quotequote|).
4781 For example, after deleting a line
4782 with `dd`, this field will be "1",
4783 which is the register that got the
4784 deleted text.
4785
4786 The {regname} argument is a string. If {regname} is invalid
4787 or not set, an empty Dictionary will be returned.
4788 If {regname} is "" or "@", the unnamed register '"' is used.
4789 If {regname} is not specified, |v:register| is used.
4790 The returned Dictionary can be passed to |setreg()|.
4791 In |Vim9-script| {regname} must be one character.
4792
4793 Can also be used as a |method|: >
4794 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004795<
4796 Return type: dict<any>
4797
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004798
Shougo Matsushita19b71882024-02-28 22:48:12 +01004799getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004800 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01004801 buffer.
4802
4803 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004804 See |getpos()| for the format of the list. It's possible
4805 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01004806 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01004807
4808 The optional argument {opts} is a Dict and supports the
4809 following items:
4810
zeertzjqafc22952024-05-24 19:07:12 +02004811 type Specify the region's selection type.
4812 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02004813 except that the width can be omitted
4814 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02004815 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01004816
zeertzjq87410ab2024-03-02 06:00:23 +08004817 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02004818 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08004819 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01004820
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004821 You can get the last selection type by |visualmode()|.
4822 If Visual mode is active, use |mode()| to get the Visual mode
4823 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08004824 This function is useful to get text starting and ending in
4825 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004826
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004827 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004828 Note that:
4829 - Order of {pos1} and {pos2} doesn't matter, it will always
4830 return content from the upper left position to the lower
4831 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08004832 - If 'virtualedit' is enabled and the region is past the end
4833 of the lines, resulting lines are padded with spaces.
4834 - If the region is blockwise and it starts or ends in the
4835 middle of a multi-cell character, it is not included but
4836 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004837 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01004838 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004839 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01004840 - It is evaluated in current window context, which makes a
4841 difference if the buffer is displayed in a window with
4842 different 'virtualedit' or 'list' values.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004843
4844 Examples: >
4845 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01004846 \ <Cmd>echow getregion(
4847 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004848<
4849 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01004850 getpos('.')->getregion(getpos("'a"))
zeertzjqd4d12072024-07-16 20:34:16 +02004851<
4852 Return type: list<string>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004853
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01004854
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004855getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
4856 Same as |getregion()|, but returns a list of positions
4857 describing the buffer text segments bound by {pos1} and
4858 {pos2}.
4859 The segments are a pair of positions for every line: >
4860 [[{start_pos}, {end_pos}], ...]
4861<
4862 The position is a |List| with four numbers:
4863 [bufnum, lnum, col, off]
4864 "bufnum" is the buffer number.
4865 "lnum" and "col" are the position in the buffer. The first
4866 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02004867 If the "off" number of a starting position is non-zero, it is
4868 the offset in screen columns from the start of the character.
4869 E.g., a position within a <Tab> or after the last character.
4870 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02004871 the offset of the character's first cell not included in the
4872 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004873
zeertzjq2b09de92024-05-24 07:48:51 +02004874 Apart from the options supported by |getregion()|, {opts} also
4875 supports the following:
4876
4877 eol If |TRUE|, indicate positions beyond
4878 the end of a line with "col" values
4879 one more than the length of the line.
4880 If |FALSE|, positions are limited
4881 within their lines, and if a line is
4882 empty or the selection is entirely
4883 beyond the end of a line, a "col"
4884 value of 0 is used for both positions.
4885 (default: |FALSE|)
4886
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004887 Can also be used as a |method|: >
4888 getpos('.')->getregionpos(getpos("'a"))
4889<
zeertzjqd4d12072024-07-16 20:34:16 +02004890 Return type: list<list<list<number>>>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004891
4892
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004893getregtype([{regname}]) *getregtype()*
4894 The result is a String, which is type of register {regname}.
4895 The value will be one of:
4896 "v" for |characterwise| text
4897 "V" for |linewise| text
4898 "<CTRL-V>{width}" for |blockwise-visual| text
4899 "" for an empty or unknown register
4900 <CTRL-V> is one character with value 0x16.
4901 The {regname} argument is a string. If {regname} is "", the
4902 unnamed register '"' is used. If {regname} is not specified,
4903 |v:register| is used.
4904 In |Vim9-script| {regname} must be one character.
4905
4906 Can also be used as a |method|: >
4907 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004908<
4909 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004910
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01004911
Bram Moolenaar71badf92023-04-22 22:40:14 +01004912getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004913 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01004914 scripts in the order they were sourced, like what
4915 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004916
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004917 The optional Dict argument {opts} supports the following
4918 optional items:
4919 name Script name match pattern. If specified,
4920 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01004921 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004922 "name" are returned.
4923 sid Script ID |<SID>|. If specified, only
4924 information about the script with ID "sid" is
4925 returned and "name" is ignored.
4926
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004927 Each item in the returned List is a |Dict| with the following
4928 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004929 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01004930 `import autoload` but was not actually sourced
4931 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004932 functions List of script-local function names defined in
4933 the script. Present only when a particular
4934 script is specified using the "sid" item in
4935 {opts}.
4936 name Vim script file name.
4937 sid Script ID |<SID>|.
4938 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01004939 this script name links to, if any, otherwise
4940 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004941 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00004942 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004943 specified using the "sid" item in {opts}.
4944 Note that this is a copy, the value of
4945 script-local variables cannot be changed using
4946 this dictionary.
h_east59858792023-10-25 22:47:05 +09004947 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01004948
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004949 Examples: >
4950 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08004951 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004952<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004953 Return type: list<dict<any>>
4954
4955
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004956gettabinfo([{tabnr}]) *gettabinfo()*
4957 If {tabnr} is not specified, then information about all the
4958 tab pages is returned as a |List|. Each List item is a
4959 |Dictionary|. Otherwise, {tabnr} specifies the tab page
4960 number and information about that one is returned. If the tab
4961 page does not exist an empty List is returned.
4962
4963 Each List item is a |Dictionary| with the following entries:
4964 tabnr tab page number.
4965 variables a reference to the dictionary with
4966 tabpage-local variables
4967 windows List of |window-ID|s in the tab page.
4968
4969 Can also be used as a |method|: >
4970 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004971<
4972 Return type: list<dict<any>>
4973
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004974
4975gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
4976 Get the value of a tab-local variable {varname} in tab page
4977 {tabnr}. |t:var|
4978 Tabs are numbered starting with one.
4979 The {varname} argument is a string. When {varname} is empty a
4980 dictionary with all tab-local variables is returned.
4981 Note that the name without "t:" must be used.
4982 When the tab or variable doesn't exist {def} or an empty
4983 string is returned, there is no error message.
4984
4985 Can also be used as a |method|: >
4986 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004987<
4988 Return type: any, depending on {varname}
4989
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004990
4991gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
4992 Get the value of window-local variable {varname} in window
4993 {winnr} in tab page {tabnr}.
4994 The {varname} argument is a string. When {varname} is empty a
4995 dictionary with all window-local variables is returned.
4996 When {varname} is equal to "&" get the values of all
4997 window-local options in a |Dictionary|.
4998 Otherwise, when {varname} starts with "&" get the value of a
4999 window-local option.
5000 Note that {varname} must be the name without "w:".
5001 Tabs are numbered starting with one. For the current tabpage
5002 use |getwinvar()|.
5003 {winnr} can be the window number or the |window-ID|.
5004 When {winnr} is zero the current window is used.
5005 This also works for a global option, buffer-local option and
5006 window-local option, but it doesn't work for a global variable
5007 or buffer-local variable.
5008 When the tab, window or variable doesn't exist {def} or an
5009 empty string is returned, there is no error message.
5010 Examples: >
5011 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005012 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005013<
5014 To obtain all window-local variables use: >
5015 gettabwinvar({tabnr}, {winnr}, '&')
5016
5017< Can also be used as a |method|: >
5018 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005019<
5020 Return type: any, depending on {varname}
5021
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005022
5023gettagstack([{winnr}]) *gettagstack()*
5024 The result is a Dict, which is the tag stack of window {winnr}.
5025 {winnr} can be the window number or the |window-ID|.
5026 When {winnr} is not specified, the current window is used.
5027 When window {winnr} doesn't exist, an empty Dict is returned.
5028
5029 The returned dictionary contains the following entries:
5030 curidx Current index in the stack. When at
5031 top of the stack, set to (length + 1).
5032 Index of bottom of the stack is 1.
5033 items List of items in the stack. Each item
5034 is a dictionary containing the
5035 entries described below.
5036 length Number of entries in the stack.
5037
5038 Each item in the stack is a dictionary with the following
5039 entries:
5040 bufnr buffer number of the current jump
5041 from cursor position before the tag jump.
5042 See |getpos()| for the format of the
5043 returned list.
5044 matchnr current matching tag number. Used when
5045 multiple matching tags are found for a
5046 name.
5047 tagname name of the tag
5048
5049 See |tagstack| for more information about the tag stack.
5050
5051 Can also be used as a |method|: >
5052 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005053<
5054 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005055
5056
Christ van Willegence0ef912024-06-20 23:41:59 +02005057gettext({text} [, {package}]) *gettext()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005058 Translate String {text} if possible.
RestorerZ96509102024-07-11 21:14:15 +02005059 This is intended for use in Vim scripts. When generating
5060 message translations the {text} is extracted by `xgettext`,
5061 the translator can add translated messages into the .po file
5062 and Vim will lookup the translation when gettext() is called.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005063 For {text} double quoted strings are preferred, because
RestorerZ96509102024-07-11 21:14:15 +02005064 `xgettext` does not support single quoted escaped text.
5065
Christ van Willegence0ef912024-06-20 23:41:59 +02005066 When the {package} is specified, the translation is looked up
RestorerZ96509102024-07-11 21:14:15 +02005067 for that specific package. This is mainly required for
5068 third-party Vim scripts. You need to specify a path to the
5069 translations with the |bindtextdomain()| function before
5070 using the gettext() function.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005071
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005072 Return type: |String|
5073
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005074
5075getwininfo([{winid}]) *getwininfo()*
5076 Returns information about windows as a |List| with Dictionaries.
5077
5078 If {winid} is given Information about the window with that ID
5079 is returned, as a |List| with one item. If the window does not
5080 exist the result is an empty list.
5081
5082 Without {winid} information about all the windows in all the
5083 tab pages is returned.
5084
5085 Each List item is a |Dictionary| with the following entries:
5086 botline last complete displayed buffer line
5087 bufnr number of buffer in the window
5088 height window height (excluding winbar)
glepnir0a850672024-11-25 19:39:04 +01005089 leftcol first column displayed; only used when
5090 'wrap' is off
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005091 loclist 1 if showing a location list
5092 {only with the +quickfix feature}
5093 quickfix 1 if quickfix or location list window
5094 {only with the +quickfix feature}
5095 terminal 1 if a terminal window
5096 {only with the +terminal feature}
5097 tabnr tab page number
5098 topline first displayed buffer line
5099 variables a reference to the dictionary with
5100 window-local variables
5101 width window width
5102 winbar 1 if the window has a toolbar, 0
5103 otherwise
5104 wincol leftmost screen column of the window;
5105 "col" from |win_screenpos()|
5106 textoff number of columns occupied by any
5107 'foldcolumn', 'signcolumn' and line
5108 number in front of the text
5109 winid |window-ID|
5110 winnr window number
5111 winrow topmost screen line of the window;
5112 "row" from |win_screenpos()|
5113
5114 Can also be used as a |method|: >
5115 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005116<
5117 Return type: list<dict<any>>
5118
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005119
5120getwinpos([{timeout}]) *getwinpos()*
5121 The result is a |List| with two numbers, the result of
5122 |getwinposx()| and |getwinposy()| combined:
5123 [x-pos, y-pos]
5124 {timeout} can be used to specify how long to wait in msec for
5125 a response from the terminal. When omitted 100 msec is used.
5126 Use a longer time for a remote terminal.
5127 When using a value less than 10 and no response is received
5128 within that time, a previously reported position is returned,
5129 if available. This can be used to poll for the position and
5130 do some work in the meantime: >
5131 while 1
5132 let res = getwinpos(1)
5133 if res[0] >= 0
5134 break
5135 endif
5136 " Do some work here
5137 endwhile
5138<
5139
5140 Can also be used as a |method|: >
5141 GetTimeout()->getwinpos()
5142<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005143 Return type: list<number>
5144
5145
5146getwinposx() *getwinposx()*
5147 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005148 the left hand side of the GUI Vim window. Also works for an
5149 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005150 The result will be -1 if the information is not available
5151 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005152 The value can be used with `:winpos`.
5153
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005154 Return type: |Number|
5155
5156
5157getwinposy() *getwinposy()*
5158 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005159 the top of the GUI Vim window. Also works for an xterm (uses
5160 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005161 The result will be -1 if the information is not available
5162 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005163 The value can be used with `:winpos`.
5164
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005165 Return type: |Number|
5166
5167
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005168getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5169 Like |gettabwinvar()| for the current tabpage.
5170 Examples: >
5171 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005172 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005173
5174< Can also be used as a |method|: >
5175 GetWinnr()->getwinvar(varname)
5176<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005177 Return type: any, depending on {varname}
5178
5179
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005180glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5181 Expand the file wildcards in {expr}. See |wildcards| for the
5182 use of special characters.
5183
5184 Unless the optional {nosuf} argument is given and is |TRUE|,
5185 the 'suffixes' and 'wildignore' options apply: Names matching
5186 one of the patterns in 'wildignore' will be skipped and
5187 'suffixes' affect the ordering of matches.
5188 'wildignorecase' always applies.
5189
5190 When {list} is present and it is |TRUE| the result is a |List|
5191 with all matching files. The advantage of using a List is,
5192 you also get filenames containing newlines correctly.
5193 Otherwise the result is a String and when there are several
5194 matches, they are separated by <NL> characters.
5195
5196 If the expansion fails, the result is an empty String or List.
5197
5198 You can also use |readdir()| if you need to do complicated
5199 things, such as limiting the number of matches.
5200
5201 A name for a non-existing file is not included. A symbolic
5202 link is only included if it points to an existing file.
5203 However, when the {alllinks} argument is present and it is
5204 |TRUE| then all symbolic links are included.
5205
5206 For most systems backticks can be used to get files names from
5207 any external command. Example: >
5208 :let tagfiles = glob("`find . -name tags -print`")
5209 :let &tags = substitute(tagfiles, "\n", ",", "g")
5210< The result of the program inside the backticks should be one
5211 item per line. Spaces inside an item are allowed.
5212
5213 See |expand()| for expanding special Vim variables. See
5214 |system()| for getting the raw output of an external command.
5215
5216 Can also be used as a |method|: >
5217 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005218<
5219 Return type: |String| or list<string> or list<any> depending
5220 on {list}
5221
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005222
h-east624bb832024-11-09 18:37:32 +01005223glob2regpat({string}) *glob2regpat()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005224 Convert a file pattern, as used by glob(), into a search
5225 pattern. The result can be used to match with a string that
5226 is a file name. E.g. >
5227 if filename =~ glob2regpat('Make*.mak')
5228< This is equivalent to: >
5229 if filename =~ '^Make.*\.mak$'
5230< When {string} is an empty string the result is "^$", match an
5231 empty string.
5232 Note that the result depends on the system. On MS-Windows
5233 a backslash usually means a path separator.
5234
5235 Can also be used as a |method|: >
5236 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005237<
5238 Return type: |String|
5239
5240 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005241globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5242 Perform glob() for String {expr} on all directories in {path}
5243 and concatenate the results. Example: >
5244 :echo globpath(&rtp, "syntax/c.vim")
5245<
5246 {path} is a comma-separated list of directory names. Each
5247 directory name is prepended to {expr} and expanded like with
5248 |glob()|. A path separator is inserted when needed.
5249 To add a comma inside a directory name escape it with a
5250 backslash. Note that on MS-Windows a directory may have a
5251 trailing backslash, remove it if you put a comma after it.
5252 If the expansion fails for one of the directories, there is no
5253 error message.
5254
5255 Unless the optional {nosuf} argument is given and is |TRUE|,
5256 the 'suffixes' and 'wildignore' options apply: Names matching
5257 one of the patterns in 'wildignore' will be skipped and
5258 'suffixes' affect the ordering of matches.
5259
5260 When {list} is present and it is |TRUE| the result is a |List|
5261 with all matching files. The advantage of using a List is, you
5262 also get filenames containing newlines correctly. Otherwise
5263 the result is a String and when there are several matches,
5264 they are separated by <NL> characters. Example: >
5265 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5266<
5267 {alllinks} is used as with |glob()|.
5268
5269 The "**" item can be used to search in a directory tree.
5270 For example, to find all "README.txt" files in the directories
5271 in 'runtimepath' and below: >
5272 :echo globpath(&rtp, "**/README.txt")
5273< Upwards search and limiting the depth of "**" is not
5274 supported, thus using 'path' will not always work properly.
5275
5276 Can also be used as a |method|, the base is passed as the
5277 second argument: >
5278 GetExpr()->globpath(&rtp)
5279<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005280 Return type: |String| or list<string> or list<any> depending
5281 on {list}
5282
5283
5284has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005285 When {check} is omitted or is zero: The result is a Number,
5286 which is 1 if the feature {feature} is supported, zero
5287 otherwise. The {feature} argument is a string, case is
5288 ignored. See |feature-list| below.
5289
5290 When {check} is present and not zero: The result is a Number,
5291 which is 1 if the feature {feature} could ever be supported,
5292 zero otherwise. This is useful to check for a typo in
5293 {feature} and to detect dead code. Keep in mind that an older
5294 Vim version will not know about a feature added later and
5295 features that have been abandoned will not be known by the
5296 current Vim version.
5297
5298 Also see |exists()| and |exists_compiled()|.
5299
5300 Note that to skip code that has a syntax error when the
5301 feature is not available, Vim may skip the rest of the line
5302 and miss a following `endif`. Therefore put the `endif` on a
5303 separate line: >
5304 if has('feature')
5305 let x = this->breaks->without->the->feature
5306 endif
5307< If the `endif` would be moved to the second line as "| endif" it
5308 would not be found.
5309
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005310 Return type: |Number|
5311
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005312
5313has_key({dict}, {key}) *has_key()*
5314 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005315 has an entry with key {key}. FALSE otherwise.
5316 The {key} argument is a string. In |Vim9| script a number is
5317 also accepted (and converted to a string) but no other types.
5318 In legacy script the usual automatic conversion to string is
5319 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005320
5321 Can also be used as a |method|: >
5322 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005323<
5324 Return type: |Number|
5325
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005326
5327haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5328 The result is a Number:
5329 1 when the window has set a local directory via |:lcd|
5330 2 when the tab-page has set a local directory via |:tcd|
5331 0 otherwise.
5332
5333 Without arguments use the current window.
5334 With {winnr} use this window in the current tab page.
5335 With {winnr} and {tabnr} use the window in the specified tab
5336 page.
5337 {winnr} can be the window number or the |window-ID|.
5338 If {winnr} is -1 it is ignored and only the tabpage is used.
5339 Return 0 if the arguments are invalid.
5340 Examples: >
5341 if haslocaldir() == 1
5342 " window local directory case
5343 elseif haslocaldir() == 2
5344 " tab-local directory case
5345 else
5346 " global directory case
5347 endif
5348
5349 " current window
5350 :echo haslocaldir()
5351 :echo haslocaldir(0)
5352 :echo haslocaldir(0, 0)
5353 " window n in current tab page
5354 :echo haslocaldir(n)
5355 :echo haslocaldir(n, 0)
5356 " window n in tab page m
5357 :echo haslocaldir(n, m)
5358 " tab page m
5359 :echo haslocaldir(-1, m)
5360<
5361 Can also be used as a |method|: >
5362 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005363<
5364 Return type: |Number|
5365
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005366
5367hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5368 The result is a Number, which is TRUE if there is a mapping
5369 that contains {what} in somewhere in the rhs (what it is
5370 mapped to) and this mapping exists in one of the modes
5371 indicated by {mode}.
5372 The arguments {what} and {mode} are strings.
5373 When {abbr} is there and it is |TRUE| use abbreviations
5374 instead of mappings. Don't forget to specify Insert and/or
5375 Command-line mode.
5376 Both the global mappings and the mappings local to the current
5377 buffer are checked for a match.
5378 If no matching mapping is found FALSE is returned.
5379 The following characters are recognized in {mode}:
5380 n Normal mode
5381 v Visual and Select mode
5382 x Visual mode
5383 s Select mode
5384 o Operator-pending mode
5385 i Insert mode
5386 l Language-Argument ("r", "f", "t", etc.)
5387 c Command-line mode
5388 When {mode} is omitted, "nvo" is used.
5389
5390 This function is useful to check if a mapping already exists
5391 to a function in a Vim script. Example: >
5392 :if !hasmapto('\ABCdoit')
5393 : map <Leader>d \ABCdoit
5394 :endif
5395< This installs the mapping to "\ABCdoit" only if there isn't
5396 already a mapping to "\ABCdoit".
5397
5398 Can also be used as a |method|: >
5399 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005400<
5401 Return type: |Number|
5402
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005403
5404histadd({history}, {item}) *histadd()*
5405 Add the String {item} to the history {history} which can be
5406 one of: *hist-names*
5407 "cmd" or ":" command line history
5408 "search" or "/" search pattern history
5409 "expr" or "=" typed expression history
5410 "input" or "@" input line history
5411 "debug" or ">" debug command history
5412 empty the current or last used history
5413 The {history} string does not need to be the whole name, one
5414 character is sufficient.
5415 If {item} does already exist in the history, it will be
5416 shifted to become the newest entry.
5417 The result is a Number: TRUE if the operation was successful,
5418 otherwise FALSE is returned.
5419
5420 Example: >
5421 :call histadd("input", strftime("%Y %b %d"))
5422 :let date=input("Enter date: ")
5423< This function is not available in the |sandbox|.
5424
5425 Can also be used as a |method|, the base is passed as the
5426 second argument: >
5427 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005428<
5429 Return type: |Number|
5430
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005431
5432histdel({history} [, {item}]) *histdel()*
5433 Clear {history}, i.e. delete all its entries. See |hist-names|
5434 for the possible values of {history}.
5435
5436 If the parameter {item} evaluates to a String, it is used as a
5437 regular expression. All entries matching that expression will
5438 be removed from the history (if there are any).
5439 Upper/lowercase must match, unless "\c" is used |/\c|.
5440 If {item} evaluates to a Number, it will be interpreted as
5441 an index, see |:history-indexing|. The respective entry will
5442 be removed if it exists.
5443
5444 The result is TRUE for a successful operation, otherwise FALSE
5445 is returned.
5446
5447 Examples:
5448 Clear expression register history: >
5449 :call histdel("expr")
5450<
5451 Remove all entries starting with "*" from the search history: >
5452 :call histdel("/", '^\*')
5453<
5454 The following three are equivalent: >
5455 :call histdel("search", histnr("search"))
5456 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005457 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005458<
5459 To delete the last search pattern and use the last-but-one for
5460 the "n" command and 'hlsearch': >
5461 :call histdel("search", -1)
5462 :let @/ = histget("search", -1)
5463<
5464 Can also be used as a |method|: >
5465 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005466<
5467 Return type: |Number|
5468
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005469
5470histget({history} [, {index}]) *histget()*
5471 The result is a String, the entry with Number {index} from
5472 {history}. See |hist-names| for the possible values of
5473 {history}, and |:history-indexing| for {index}. If there is
5474 no such entry, an empty String is returned. When {index} is
5475 omitted, the most recent item from the history is used.
5476
5477 Examples:
5478 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005479 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005480
5481< Define an Ex command ":H {num}" that supports re-execution of
5482 the {num}th entry from the output of |:history|. >
5483 :command -nargs=1 H execute histget("cmd", 0+<args>)
5484<
5485 Can also be used as a |method|: >
5486 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005487<
5488 Return type: |String|
5489
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005490
5491histnr({history}) *histnr()*
5492 The result is the Number of the current entry in {history}.
5493 See |hist-names| for the possible values of {history}.
5494 If an error occurred, -1 is returned.
5495
5496 Example: >
5497 :let inp_index = histnr("expr")
5498
5499< Can also be used as a |method|: >
5500 GetHistory()->histnr()
5501<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005502 Return type: |Number|
5503
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005504hlexists({name}) *hlexists()*
5505 The result is a Number, which is TRUE if a highlight group
5506 called {name} exists. This is when the group has been
5507 defined in some way. Not necessarily when highlighting has
5508 been defined for it, it may also have been used for a syntax
5509 item.
5510 *highlight_exists()*
5511 Obsolete name: highlight_exists().
5512
5513 Can also be used as a |method|: >
5514 GetName()->hlexists()
5515<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005516 Return type: |Number|
5517
5518
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005519hlget([{name} [, {resolve}]]) *hlget()*
5520 Returns a List of all the highlight group attributes. If the
5521 optional {name} is specified, then returns a List with only
5522 the attributes of the specified highlight group. Returns an
5523 empty List if the highlight group {name} is not present.
5524
5525 If the optional {resolve} argument is set to v:true and the
5526 highlight group {name} is linked to another group, then the
5527 link is resolved recursively and the attributes of the
5528 resolved highlight group are returned.
5529
5530 Each entry in the returned List is a Dictionary with the
5531 following items:
5532 cleared boolean flag, set to v:true if the highlight
5533 group attributes are cleared or not yet
5534 specified. See |highlight-clear|.
5535 cterm cterm attributes. See |highlight-cterm|.
5536 ctermbg cterm background color.
5537 See |highlight-ctermbg|.
5538 ctermfg cterm foreground color.
5539 See |highlight-ctermfg|.
5540 ctermul cterm underline color. See |highlight-ctermul|.
5541 default boolean flag, set to v:true if the highlight
5542 group link is a default link. See
5543 |highlight-default|.
5544 font highlight group font. See |highlight-font|.
5545 gui gui attributes. See |highlight-gui|.
5546 guibg gui background color. See |highlight-guibg|.
5547 guifg gui foreground color. See |highlight-guifg|.
5548 guisp gui special color. See |highlight-guisp|.
5549 id highlight group ID.
5550 linksto linked highlight group name.
5551 See |:highlight-link|.
5552 name highlight group name. See |group-name|.
5553 start start terminal keycode. See |highlight-start|.
5554 stop stop terminal keycode. See |highlight-stop|.
5555 term term attributes. See |highlight-term|.
5556
5557 The 'term', 'cterm' and 'gui' items in the above Dictionary
5558 have a dictionary value with the following optional boolean
5559 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5560 'reverse', 'inverse' and 'strikethrough'.
5561
5562 Example(s): >
5563 :echo hlget()
5564 :echo hlget('ModeMsg')
5565 :echo hlget('Number', v:true)
5566<
5567 Can also be used as a |method|: >
5568 GetName()->hlget()
5569<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005570 Return type: list<dict<any>>
5571
5572
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005573hlset({list}) *hlset()*
5574 Creates or modifies the attributes of a List of highlight
5575 groups. Each item in {list} is a dictionary containing the
5576 attributes of a highlight group. See |hlget()| for the list of
5577 supported items in this dictionary.
5578
5579 In addition to the items described in |hlget()|, the following
5580 additional items are supported in the dictionary:
5581
5582 force boolean flag to force the creation of
5583 a link for an existing highlight group
5584 with attributes.
5585
5586 The highlight group is identified using the 'name' item and
5587 the 'id' item (if supplied) is ignored. If a highlight group
5588 with a specified name doesn't exist, then it is created.
5589 Otherwise the attributes of an existing highlight group are
5590 modified.
5591
5592 If an empty dictionary value is used for the 'term' or 'cterm'
5593 or 'gui' entries, then the corresponding attributes are
5594 cleared. If the 'cleared' item is set to v:true, then all the
5595 attributes of the highlight group are cleared.
5596
5597 The 'linksto' item can be used to link a highlight group to
5598 another highlight group. See |:highlight-link|.
5599
5600 Returns zero for success, -1 for failure.
5601
5602 Example(s): >
5603 " add bold attribute to the Visual highlight group
5604 :call hlset([#{name: 'Visual',
5605 \ term: #{reverse: 1 , bold: 1}}])
5606 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5607 :let l = hlget()
5608 :call hlset(l)
5609 " clear the Search highlight group
5610 :call hlset([#{name: 'Search', cleared: v:true}])
5611 " clear the 'term' attributes for a highlight group
5612 :call hlset([#{name: 'Title', term: {}}])
5613 " create the MyHlg group linking it to DiffAdd
5614 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5615 " remove the MyHlg group link
5616 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5617 " clear the attributes and a link
5618 :call hlset([#{name: 'MyHlg', cleared: v:true,
5619 \ linksto: 'NONE'}])
5620<
5621 Can also be used as a |method|: >
5622 GetAttrList()->hlset()
5623<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005624 Return type: |Number|
5625
5626hlID({name}) *hlID()*
5627 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005628 with name {name}. When the highlight group doesn't exist,
5629 zero is returned.
5630 This can be used to retrieve information about the highlight
5631 group. For example, to get the background color of the
5632 "Comment" group: >
5633 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5634< *highlightID()*
5635 Obsolete name: highlightID().
5636
5637 Can also be used as a |method|: >
5638 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005639<
5640 Return type: |Number|
5641
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005642
5643hostname() *hostname()*
5644 The result is a String, which is the name of the machine on
5645 which Vim is currently running. Machine names greater than
5646 256 characters long are truncated.
5647
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005648 Return type: |String|
5649
5650
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005651iconv({string}, {from}, {to}) *iconv()*
5652 The result is a String, which is the text {string} converted
5653 from encoding {from} to encoding {to}.
5654 When the conversion completely fails an empty string is
5655 returned. When some characters could not be converted they
5656 are replaced with "?".
5657 The encoding names are whatever the iconv() library function
5658 can accept, see ":!man 3 iconv".
5659 Most conversions require Vim to be compiled with the |+iconv|
5660 feature. Otherwise only UTF-8 to latin1 conversion and back
5661 can be done.
5662 This can be used to display messages with special characters,
5663 no matter what 'encoding' is set to. Write the message in
5664 UTF-8 and use: >
5665 echo iconv(utf8_str, "utf-8", &enc)
5666< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5667 from/to UCS-2 is automatically changed to use UTF-8. You
5668 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5669
5670 Can also be used as a |method|: >
5671 GetText()->iconv('latin1', 'utf-8')
5672<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005673 Return type: |String|
5674
5675
h-east624bb832024-11-09 18:37:32 +01005676id({item}) *id()*
Ernie Raelc8e158b2024-07-09 18:39:52 +02005677 The result is a unique String associated with the {item} and
5678 not with the {item}'s contents. It is only valid while the
5679 {item} exists and is referenced. It is valid only in the
5680 instance of vim that produces the result. The whole idea is
5681 that `id({item})` does not change if the contents of {item}
5682 changes. This is useful as a `key` for creating an identity
5683 dictionary, rather than one based on equals.
5684
5685 This operation does not reference {item} and there is no
5686 function to convert the `id` to the {item}. It may be useful to
5687 have a map of `id` to {item}. The following >
5688 var referenceMap: dict<any>
5689 var id = item->id()
5690 referenceMap[id] = item
5691< prevents {item} from being garbage collected and provides a
5692 way to get the {item} from the `id`.
5693
5694 {item} may be a List, Dictionary, Object, Job, Channel or
5695 Blob. If the item is not a permitted type, or it is a null
5696 value, then an empty String is returned.
5697
5698 Can also be used as a |method|: >
5699 GetItem()->id()
5700<
5701 Return type: |String|
5702
5703
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005704indent({lnum}) *indent()*
5705 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005706 current buffer. The indent is counted in spaces, the value
5707 of 'tabstop' is relevant. {lnum} is used just like in
5708 |getline()|.
5709 When {lnum} is invalid -1 is returned. In |Vim9| script an
5710 error is given.
5711
5712 Can also be used as a |method|: >
5713 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005714<
5715 Return type: |Number|
5716
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005717
5718index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005719 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005720 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005721
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005722 If {object} is a |List| return the lowest index where the item
5723 has a value equal to {expr}. There is no automatic
5724 conversion, so the String "4" is different from the Number 4.
5725 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005726 of 'ignorecase' is not used here, case matters as indicated by
5727 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005728
5729 If {object} is |Blob| return the lowest index where the byte
5730 value is equal to {expr}.
5731
5732 If {start} is given then start looking at the item with index
5733 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005734
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005735 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5736 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005737
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005738 -1 is returned when {expr} is not found in {object}.
5739 Example: >
5740 :let idx = index(words, "the")
5741 :if index(numbers, 123) >= 0
5742
5743< Can also be used as a |method|: >
5744 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005745<
5746 Return type: |Number|
5747
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005748
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005749indexof({object}, {expr} [, {opts}]) *indexof()*
5750 Returns the index of an item in {object} where {expr} is
5751 v:true. {object} must be a |List| or a |Blob|.
5752
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005753 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005754 List until the expression is v:true and return the index of
5755 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005756
5757 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005758 Blob until the expression is v:true and return the index of
5759 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005760
5761 {expr} must be a |string| or |Funcref|.
5762
5763 If {expr} is a |string|: If {object} is a |List|, inside
5764 {expr} |v:key| has the index of the current List item and
5765 |v:val| has the value of the item. If {object} is a |Blob|,
5766 inside {expr} |v:key| has the index of the current byte and
5767 |v:val| has the byte value.
5768
5769 If {expr} is a |Funcref| it must take two arguments:
5770 1. the key or the index of the current item.
5771 2. the value of the current item.
5772 The function must return |TRUE| if the item is found and the
5773 search should stop.
5774
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005775 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005776 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005777 startidx start evaluating {expr} at the item with this
5778 index; may be negative for an item relative to
5779 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005780 Returns -1 when {expr} evaluates to v:false for all the items.
5781 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005782 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
5783 :echo indexof(l, "v:val.n == 20")
5784 :echo indexof(l, {i, v -> v.n == 30})
5785 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005786
5787< Can also be used as a |method|: >
5788 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005789<
5790 Return type: |Number|
5791
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005792
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005793input({prompt} [, {text} [, {completion}]]) *input()*
5794 The result is a String, which is whatever the user typed on
5795 the command-line. The {prompt} argument is either a prompt
5796 string, or a blank string (for no prompt). A '\n' can be used
5797 in the prompt to start a new line.
5798 The highlighting set with |:echohl| is used for the prompt.
5799 The input is entered just like a command-line, with the same
5800 editing commands and mappings. There is a separate history
5801 for lines typed for input().
5802 Example: >
5803 :if input("Coffee or beer? ") == "beer"
5804 : echo "Cheers!"
5805 :endif
5806<
5807 If the optional {text} argument is present and not empty, this
5808 is used for the default reply, as if the user typed this.
5809 Example: >
5810 :let color = input("Color? ", "white")
5811
5812< The optional {completion} argument specifies the type of
5813 completion supported for the input. Without it completion is
5814 not performed. The supported completion types are the same as
5815 that can be supplied to a user-defined command using the
5816 "-complete=" argument. Refer to |:command-completion| for
5817 more information. Example: >
5818 let fname = input("File: ", "", "file")
5819<
5820 NOTE: This function must not be used in a startup file, for
5821 the versions that only run in GUI mode (e.g., the Win32 GUI).
5822 Note: When input() is called from within a mapping it will
5823 consume remaining characters from that mapping, because a
5824 mapping is handled like the characters were typed.
5825 Use |inputsave()| before input() and |inputrestore()|
5826 after input() to avoid that. Another solution is to avoid
5827 that further characters follow in the mapping, e.g., by using
5828 |:execute| or |:normal|.
5829
5830 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005831 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005832 :function GetFoo()
5833 : call inputsave()
5834 : let g:Foo = input("enter search pattern: ")
5835 : call inputrestore()
5836 :endfunction
5837
5838< Can also be used as a |method|: >
5839 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005840<
5841 Return type: |String|
5842
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005843
5844inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
5845 Like |input()|, but when the GUI is running and text dialogs
5846 are supported, a dialog window pops up to input the text.
5847 Example: >
5848 :let n = inputdialog("value for shiftwidth", shiftwidth())
5849 :if n != ""
5850 : let &sw = n
5851 :endif
5852< When the dialog is cancelled {cancelreturn} is returned. When
5853 omitted an empty string is returned.
5854 Hitting <Enter> works like pressing the OK button. Hitting
5855 <Esc> works like pressing the Cancel button.
5856 NOTE: Command-line completion is not supported.
5857
5858 Can also be used as a |method|: >
5859 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005860<
5861 Return type: |String|
5862
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005863
5864inputlist({textlist}) *inputlist()*
5865 {textlist} must be a |List| of strings. This |List| is
5866 displayed, one string per line. The user will be prompted to
5867 enter a number, which is returned.
5868 The user can also select an item by clicking on it with the
5869 mouse, if the mouse is enabled in the command line ('mouse' is
5870 "a" or includes "c"). For the first string 0 is returned.
5871 When clicking above the first item a negative number is
5872 returned. When clicking on the prompt one more than the
5873 length of {textlist} is returned.
5874 Make sure {textlist} has less than 'lines' entries, otherwise
5875 it won't work. It's a good idea to put the entry number at
5876 the start of the string. And put a prompt in the first item.
5877 Example: >
5878 let color = inputlist(['Select color:', '1. red',
5879 \ '2. green', '3. blue'])
5880
5881< Can also be used as a |method|: >
5882 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005883<
5884 Return type: |Number|
5885
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005886
5887inputrestore() *inputrestore()*
5888 Restore typeahead that was saved with a previous |inputsave()|.
5889 Should be called the same number of times inputsave() is
5890 called. Calling it more often is harmless though.
5891 Returns TRUE when there is nothing to restore, FALSE otherwise.
5892
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005893 Return type: |Number|
5894
5895
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005896inputsave() *inputsave()*
5897 Preserve typeahead (also from mappings) and clear it, so that
5898 a following prompt gets input from the user. Should be
5899 followed by a matching inputrestore() after the prompt. Can
5900 be used several times, in which case there must be just as
5901 many inputrestore() calls.
5902 Returns TRUE when out of memory, FALSE otherwise.
5903
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005904 Return type: |Number|
5905
5906
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005907inputsecret({prompt} [, {text}]) *inputsecret()*
5908 This function acts much like the |input()| function with but
5909 two exceptions:
5910 a) the user's response will be displayed as a sequence of
5911 asterisks ("*") thereby keeping the entry secret, and
5912 b) the user's response will not be recorded on the input
5913 |history| stack.
5914 The result is a String, which is whatever the user actually
5915 typed on the command-line in response to the issued prompt.
5916 NOTE: Command-line completion is not supported.
5917
5918 Can also be used as a |method|: >
5919 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005920<
5921 Return type: |String|
5922
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005923
5924insert({object}, {item} [, {idx}]) *insert()*
5925 When {object} is a |List| or a |Blob| insert {item} at the start
5926 of it.
5927
5928 If {idx} is specified insert {item} before the item with index
5929 {idx}. If {idx} is zero it goes before the first item, just
5930 like omitting {idx}. A negative {idx} is also possible, see
5931 |list-index|. -1 inserts just before the last item.
5932
5933 Returns the resulting |List| or |Blob|. Examples: >
5934 :let mylist = insert([2, 3, 5], 1)
5935 :call insert(mylist, 4, -1)
5936 :call insert(mylist, 6, len(mylist))
5937< The last example can be done simpler with |add()|.
5938 Note that when {item} is a |List| it is inserted as a single
5939 item. Use |extend()| to concatenate |Lists|.
5940
5941 Can also be used as a |method|: >
5942 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005943<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005944 Return type: |Number|
5945
5946
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005947 *instanceof()* *E614* *E616* *E693*
5948instanceof({object}, {class})
5949 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01005950 argument is a direct or indirect instance of a |Class|,
5951 |Interface|, or class |:type| alias specified by {class}.
5952 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005953 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02005954 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01005955 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02005956
5957< Can also be used as a |method|: >
5958 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005959<
5960 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02005961
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005962interrupt() *interrupt()*
5963 Interrupt script execution. It works more or less like the
5964 user typing CTRL-C, most commands won't execute and control
5965 returns to the user. This is useful to abort execution
5966 from lower down, e.g. in an autocommand. Example: >
5967 :function s:check_typoname(file)
5968 : if fnamemodify(a:file, ':t') == '['
5969 : echomsg 'Maybe typo'
5970 : call interrupt()
5971 : endif
5972 :endfunction
5973 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005974<
5975 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005976
5977invert({expr}) *invert()*
5978 Bitwise invert. The argument is converted to a number. A
5979 List, Dict or Float argument causes an error. Example: >
5980 :let bits = invert(bits)
5981< Can also be used as a |method|: >
5982 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005983<
5984 Return type: |Number|
5985
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005986
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005987isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01005988 The result is a Number, which is |TRUE| when {path} is an
5989 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005990 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01005991 On MS-Windows, it is considered absolute when it starts with an
5992 optional drive prefix and is followed by a '\' or '/'. UNC paths
5993 are always absolute.
5994 Example: >
5995 echo isabsolutepath('/usr/share/') " 1
5996 echo isabsolutepath('./foobar') " 0
5997 echo isabsolutepath('C:\Windows') " 1
5998 echo isabsolutepath('foobar') " 0
5999 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006000<
LemonBoydca1d402022-04-28 15:26:33 +01006001 Can also be used as a |method|: >
6002 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006003<
6004 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01006005
6006
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006007isdirectory({directory}) *isdirectory()*
6008 The result is a Number, which is |TRUE| when a directory
6009 with the name {directory} exists. If {directory} doesn't
6010 exist, or isn't a directory, the result is |FALSE|. {directory}
6011 is any expression, which is used as a String.
6012
6013 Can also be used as a |method|: >
6014 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006015<
6016 Return type: |Number|
6017
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006018
6019isinf({expr}) *isinf()*
6020 Return 1 if {expr} is a positive infinity, or -1 a negative
6021 infinity, otherwise 0. >
6022 :echo isinf(1.0 / 0.0)
6023< 1 >
6024 :echo isinf(-1.0 / 0.0)
6025< -1
6026
6027 Can also be used as a |method|: >
6028 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006029<
6030 Return type: |Number|
6031
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006032
6033islocked({expr}) *islocked()* *E786*
6034 The result is a Number, which is |TRUE| when {expr} is the
6035 name of a locked variable.
6036 The string argument {expr} must be the name of a variable,
6037 |List| item or |Dictionary| entry, not the variable itself!
6038 Example: >
6039 :let alist = [0, ['a', 'b'], 2, 3]
6040 :lockvar 1 alist
6041 :echo islocked('alist') " 1
6042 :echo islocked('alist[1]') " 0
6043
Bram Moolenaar9da17d72022-02-09 21:50:44 +00006044< When {expr} is a variable that does not exist -1 is returned.
6045 If {expr} uses a range, list or dict index that is out of
6046 range or does not exist you get an error message. Use
6047 |exists()| to check for existence.
6048 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006049
6050 Can also be used as a |method|: >
6051 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006052<
6053 Return type: |Number|
6054
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006055
6056isnan({expr}) *isnan()*
6057 Return |TRUE| if {expr} is a float with value NaN. >
6058 echo isnan(0.0 / 0.0)
6059< 1
6060
6061 Can also be used as a |method|: >
6062 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006063<
6064 Return type: |Number|
6065
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006066
6067items({dict}) *items()*
6068 Return a |List| with all the key-value pairs of {dict}. Each
6069 |List| item is a list with two items: the key of a {dict}
6070 entry and the value of this entry. The |List| is in arbitrary
6071 order. Also see |keys()| and |values()|.
6072 Example: >
6073 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006074 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006075 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006076<
6077 A List or a String argument is also supported. In these
6078 cases, items() returns a List with the index and the value at
6079 the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006080
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006081 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006082 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006083<
6084 Return type: list<list<any>> or list<any>
6085
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006086
6087job_ functions are documented here: |job-functions-details|
6088
6089
6090join({list} [, {sep}]) *join()*
6091 Join the items in {list} together into one String.
6092 When {sep} is specified it is put in between the items. If
6093 {sep} is omitted a single space is used.
6094 Note that {sep} is not added at the end. You might want to
6095 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006096 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006097< String items are used as-is. |Lists| and |Dictionaries| are
6098 converted into a string like with |string()|.
6099 The opposite function is |split()|.
6100
6101 Can also be used as a |method|: >
6102 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006103<
6104 Return type: |String|
6105
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006106
6107js_decode({string}) *js_decode()*
6108 This is similar to |json_decode()| with these differences:
6109 - Object key names do not have to be in quotes.
6110 - Strings can be in single quotes.
6111 - Empty items in an array (between two commas) are allowed and
6112 result in v:none items.
6113
6114 Can also be used as a |method|: >
6115 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006116<
6117 Return type: any, depending on {varname}
6118
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006119
6120js_encode({expr}) *js_encode()*
6121 This is similar to |json_encode()| with these differences:
6122 - Object key names are not in quotes.
6123 - v:none items in an array result in an empty item between
6124 commas.
6125 For example, the Vim object:
6126 [1,v:none,{"one":1},v:none] ~
6127 Will be encoded as:
6128 [1,,{one:1},,] ~
6129 While json_encode() would produce:
6130 [1,null,{"one":1},null] ~
6131 This encoding is valid for JavaScript. It is more efficient
6132 than JSON, especially when using an array with optional items.
6133
6134 Can also be used as a |method|: >
6135 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006136<
6137 Return type: |String|
6138
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006139
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006140json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006141 This parses a JSON formatted string and returns the equivalent
6142 in Vim values. See |json_encode()| for the relation between
6143 JSON and Vim values.
6144 The decoding is permissive:
6145 - A trailing comma in an array and object is ignored, e.g.
6146 "[1, 2, ]" is the same as "[1, 2]".
6147 - Integer keys are accepted in objects, e.g. {1:2} is the
6148 same as {"1":2}.
6149 - More floating point numbers are recognized, e.g. "1." for
6150 "1.0", or "001.2" for "1.2". Special floating point values
6151 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6152 are accepted.
6153 - Leading zeroes in integer numbers are ignored, e.g. "012"
6154 for "12" or "-012" for "-12".
6155 - Capitalization is ignored in literal names null, true or
6156 false, e.g. "NULL" for "null", "True" for "true".
6157 - Control characters U+0000 through U+001F which are not
6158 escaped in strings are accepted, e.g. " " (tab
6159 character in string) for "\t".
6160 - An empty JSON expression or made of only spaces is accepted
6161 and results in v:none.
6162 - Backslash in an invalid 2-character sequence escape is
6163 ignored, e.g. "\a" is decoded as "a".
6164 - A correct surrogate pair in JSON strings should normally be
6165 a 12 character sequence such as "\uD834\uDD1E", but
6166 json_decode() silently accepts truncated surrogate pairs
6167 such as "\uD834" or "\uD834\u"
6168 *E938*
6169 A duplicate key in an object, valid in rfc7159, is not
6170 accepted by json_decode() as the result must be a valid Vim
6171 type, e.g. this fails: {"a":"b", "a":"c"}
6172
6173 Can also be used as a |method|: >
6174 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006175<
6176 Return type: any, depending on {varname}
6177
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006178
6179json_encode({expr}) *json_encode()*
6180 Encode {expr} as JSON and return this as a string.
6181 The encoding is specified in:
6182 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006183 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006184 |Number| decimal number
6185 |Float| floating point number
6186 Float nan "NaN"
6187 Float inf "Infinity"
6188 Float -inf "-Infinity"
6189 |String| in double quotes (possibly null)
6190 |Funcref| not possible, error
6191 |List| as an array (possibly null); when
6192 used recursively: []
6193 |Dict| as an object (possibly null); when
6194 used recursively: {}
6195 |Blob| as an array of the individual bytes
6196 v:false "false"
6197 v:true "true"
6198 v:none "null"
6199 v:null "null"
6200 Note that NaN and Infinity are passed on as values. This is
6201 missing in the JSON standard, but several implementations do
6202 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006203 If a string contains an illegal character then the replacement
6204 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006205
6206 Can also be used as a |method|: >
6207 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006208<
6209 Return type: |String|
6210
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006211
6212keys({dict}) *keys()*
6213 Return a |List| with all the keys of {dict}. The |List| is in
6214 arbitrary order. Also see |items()| and |values()|.
6215
6216 Can also be used as a |method|: >
6217 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006218<
6219 Return type: list<string>
6220
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006221
zeertzjqcdc83932022-09-12 13:38:41 +01006222keytrans({string}) *keytrans()*
6223 Turn the internal byte representation of keys into a form that
6224 can be used for |:map|. E.g. >
6225 :let xx = "\<C-Home>"
6226 :echo keytrans(xx)
6227< <C-Home>
6228
6229 Can also be used as a |method|: >
6230 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006231<
6232 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006233
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006234
6235len({expr}) *len()* *E701*
6236 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006237 When {expr} is a String or a Number the length in bytes is
6238 used, as with |strlen()|.
6239 When {expr} is a |List| the number of items in the |List| is
6240 returned.
6241 When {expr} is a |Blob| the number of bytes is returned.
6242 When {expr} is a |Dictionary| the number of entries in the
6243 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006244 When {expr} is an |Object|, invokes the len() method in the
6245 object (if present) to get the length (|object-len()|).
6246 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006247
6248 Can also be used as a |method|: >
6249 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006250<
6251 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006252
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006253
6254 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006255libcall({libname}, {funcname}, {argument})
6256 Call function {funcname} in the run-time library {libname}
6257 with single argument {argument}.
6258 This is useful to call functions in a library that you
6259 especially made to be used with Vim. Since only one argument
6260 is possible, calling standard library functions is rather
6261 limited.
6262 The result is the String returned by the function. If the
6263 function returns NULL, this will appear as an empty string ""
6264 to Vim.
6265 If the function returns a number, use libcallnr()!
6266 If {argument} is a number, it is passed to the function as an
6267 int; if {argument} is a string, it is passed as a
6268 null-terminated string.
6269 This function will fail in |restricted-mode|.
6270
6271 libcall() allows you to write your own 'plug-in' extensions to
6272 Vim without having to recompile the program. It is NOT a
6273 means to call system functions! If you try to do so Vim will
6274 very probably crash.
6275
6276 For Win32, the functions you write must be placed in a DLL
6277 and use the normal C calling convention (NOT Pascal which is
6278 used in Windows System DLLs). The function must take exactly
6279 one parameter, either a character pointer or a long integer,
6280 and must return a character pointer or NULL. The character
6281 pointer returned must point to memory that will remain valid
6282 after the function has returned (e.g. in static data in the
6283 DLL). If it points to allocated memory, that memory will
6284 leak away. Using a static buffer in the function should work,
6285 it's then freed when the DLL is unloaded.
6286
6287 WARNING: If the function returns a non-valid pointer, Vim may
6288 crash! This also happens if the function returns a number,
6289 because Vim thinks it's a pointer.
6290 For Win32 systems, {libname} should be the filename of the DLL
6291 without the ".DLL" suffix. A full path is only required if
6292 the DLL is not in the usual places.
6293 For Unix: When compiling your own plugins, remember that the
6294 object code must be compiled as position-independent ('PIC').
6295 {only in Win32 and some Unix versions, when the |+libcall|
6296 feature is present}
6297 Examples: >
6298 :echo libcall("libc.so", "getenv", "HOME")
6299
6300< Can also be used as a |method|, the base is passed as the
6301 third argument: >
6302 GetValue()->libcall("libc.so", "getenv")
6303<
6304 *libcallnr()*
6305libcallnr({libname}, {funcname}, {argument})
6306 Just like |libcall()|, but used for a function that returns an
6307 int instead of a string.
6308 {only in Win32 on some Unix versions, when the |+libcall|
6309 feature is present}
6310 Examples: >
6311 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6312 :call libcallnr("libc.so", "printf", "Hello World!\n")
6313 :call libcallnr("libc.so", "sleep", 10)
6314<
6315 Can also be used as a |method|, the base is passed as the
6316 third argument: >
6317 GetValue()->libcallnr("libc.so", "printf")
6318<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006319 Return type: |String|
6320
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006321
6322line({expr} [, {winid}]) *line()*
6323 The result is a Number, which is the line number of the file
6324 position given with {expr}. The {expr} argument is a string.
zeertzjq02f3eba2024-06-12 20:45:24 +02006325 See |getpos()| for accepted positions.
6326
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006327 To get the column number use |col()|. To get both use
6328 |getpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02006329
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006330 With the optional {winid} argument the values are obtained for
6331 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02006332
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006333 Returns 0 for invalid values of {expr} and {winid}.
zeertzjq02f3eba2024-06-12 20:45:24 +02006334
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006335 Examples: >
6336 line(".") line number of the cursor
6337 line(".", winid) idem, in window "winid"
6338 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006339 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006340<
6341 To jump to the last known position when opening a file see
6342 |last-position-jump|.
6343
6344 Can also be used as a |method|: >
6345 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006346<
6347 Return type: |Number|
6348
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006349
6350line2byte({lnum}) *line2byte()*
6351 Return the byte count from the start of the buffer for line
6352 {lnum}. This includes the end-of-line character, depending on
6353 the 'fileformat' option for the current buffer. The first
6354 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6355 This can also be used to get the byte count for the line just
6356 below the last line: >
6357 line2byte(line("$") + 1)
6358< This is the buffer size plus one. If 'fileencoding' is empty
6359 it is the file size plus one. {lnum} is used like with
6360 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6361 feature has been disabled at compile time, -1 is returned.
6362 Also see |byte2line()|, |go| and |:goto|.
6363
6364 Can also be used as a |method|: >
6365 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006366<
6367 Return type: |Number|
6368
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006369
6370lispindent({lnum}) *lispindent()*
6371 Get the amount of indent for line {lnum} according the lisp
6372 indenting rules, as with 'lisp'.
6373 The indent is counted in spaces, the value of 'tabstop' is
6374 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006375 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006376 error is given.
6377
6378 Can also be used as a |method|: >
6379 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006380<
6381 Return type: |Number|
6382
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006383
6384list2blob({list}) *list2blob()*
6385 Return a Blob concatenating all the number values in {list}.
6386 Examples: >
6387 list2blob([1, 2, 3, 4]) returns 0z01020304
6388 list2blob([]) returns 0z
6389< Returns an empty Blob on error. If one of the numbers is
6390 negative or more than 255 error *E1239* is given.
6391
6392 |blob2list()| does the opposite.
6393
6394 Can also be used as a |method|: >
6395 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006396<
6397 Return type: |Blob|
6398
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006399
6400list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006401 Convert each number in {list} to a character string and
6402 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006403 list2str([32]) returns " "
6404 list2str([65, 66, 67]) returns "ABC"
6405< The same can be done (slowly) with: >
6406 join(map(list, {nr, val -> nr2char(val)}), '')
6407< |str2list()| does the opposite.
6408
6409 When {utf8} is omitted or zero, the current 'encoding' is used.
6410 When {utf8} is TRUE, always return UTF-8 characters.
6411 With UTF-8 composing characters work as expected: >
6412 list2str([97, 769]) returns "á"
6413<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006414 Returns an empty string on error.
6415
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006416 Can also be used as a |method|: >
6417 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006418<
6419 Return type: |String|
6420
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006421
6422listener_add({callback} [, {buf}]) *listener_add()*
6423 Add a callback function that will be invoked when changes have
6424 been made to buffer {buf}.
6425 {buf} refers to a buffer name or number. For the accepted
6426 values, see |bufname()|. When {buf} is omitted the current
6427 buffer is used.
6428 Returns a unique ID that can be passed to |listener_remove()|.
6429
6430 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006431 bufnr the buffer that was changed
6432 start first changed line number
6433 end first line number below the change
6434 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006435 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006436 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006437
6438 Example: >
6439 func Listener(bufnr, start, end, added, changes)
6440 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6441 endfunc
6442 call listener_add('Listener', bufnr)
6443
Bram Moolenaar944697a2022-02-20 19:48:20 +00006444< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006445 dictionary with these entries:
6446 lnum the first line number of the change
6447 end the first line below the change
6448 added number of lines added; negative if lines were
6449 deleted
6450 col first column in "lnum" that was affected by
6451 the change; one if unknown or the whole line
6452 was affected; this is a byte index, first
6453 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006454 When lines are inserted (not when a line is split, e.g. by
6455 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006456 lnum line above which the new line is added
6457 end equal to "lnum"
6458 added number of lines inserted
6459 col 1
6460 When lines are deleted the values are:
6461 lnum the first deleted line
6462 end the line below the first deleted line, before
6463 the deletion was done
6464 added negative, number of lines deleted
6465 col 1
6466 When lines are changed:
6467 lnum the first changed line
6468 end the line below the last changed line
6469 added 0
6470 col first column with a change or 1
6471
6472 The entries are in the order the changes were made, thus the
6473 most recent change is at the end. The line numbers are valid
6474 when the callback is invoked, but later changes may make them
6475 invalid, thus keeping a copy for later might not work.
6476
6477 The {callback} is invoked just before the screen is updated,
6478 when |listener_flush()| is called or when a change is being
6479 made that changes the line count in a way it causes a line
6480 number in the list of changes to become invalid.
6481
6482 The {callback} is invoked with the text locked, see
6483 |textlock|. If you do need to make changes to the buffer, use
6484 a timer to do this later |timer_start()|.
6485
6486 The {callback} is not invoked when the buffer is first loaded.
6487 Use the |BufReadPost| autocmd event to handle the initial text
6488 of a buffer.
6489 The {callback} is also not invoked when the buffer is
6490 unloaded, use the |BufUnload| autocmd event for that.
6491
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006492 Returns zero if {callback} or {buf} is invalid.
6493
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006494 Can also be used as a |method|, the base is passed as the
6495 second argument: >
6496 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006497<
6498 Return type: |Number|
6499
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006500
6501listener_flush([{buf}]) *listener_flush()*
6502 Invoke listener callbacks for buffer {buf}. If there are no
6503 pending changes then no callbacks are invoked.
6504
6505 {buf} refers to a buffer name or number. For the accepted
6506 values, see |bufname()|. When {buf} is omitted the current
6507 buffer is used.
6508
6509 Can also be used as a |method|: >
6510 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006511<
6512 Return type: |Number|
6513
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006514
6515listener_remove({id}) *listener_remove()*
6516 Remove a listener previously added with listener_add().
6517 Returns FALSE when {id} could not be found, TRUE when {id} was
6518 removed.
6519
6520 Can also be used as a |method|: >
6521 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006522<
6523 Return type: |Number|
6524
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006525
6526localtime() *localtime()*
6527 Return the current time, measured as seconds since 1st Jan
6528 1970. See also |strftime()|, |strptime()| and |getftime()|.
6529
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006530 Return type: |Number|
6531
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006532
6533log({expr}) *log()*
6534 Return the natural logarithm (base e) of {expr} as a |Float|.
6535 {expr} must evaluate to a |Float| or a |Number| in the range
6536 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006537 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006538 Examples: >
6539 :echo log(10)
6540< 2.302585 >
6541 :echo log(exp(5))
6542< 5.0
6543
6544 Can also be used as a |method|: >
6545 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006546<
6547 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006548
6549
6550log10({expr}) *log10()*
6551 Return the logarithm of Float {expr} to base 10 as a |Float|.
6552 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006553 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006554 Examples: >
6555 :echo log10(1000)
6556< 3.0 >
6557 :echo log10(0.01)
6558< -2.0
6559
6560 Can also be used as a |method|: >
6561 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006562<
6563 Return type: |Float|
6564
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006565
6566luaeval({expr} [, {expr}]) *luaeval()*
6567 Evaluate Lua expression {expr} and return its result converted
6568 to Vim data structures. Second {expr} may hold additional
6569 argument accessible as _A inside first {expr}.
6570 Strings are returned as they are.
6571 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006572 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006573 Dictionaries and lists obtained by vim.eval() are returned
6574 as-is.
6575 Other objects are returned as zero without any errors.
6576 See |lua-luaeval| for more details.
6577 Note that in a `:def` function local variables are not visible
6578 to {expr}.
6579
6580 Can also be used as a |method|: >
6581 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006582<
6583 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006584
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006585 {only available when compiled with the |+lua| feature}
6586
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006587
6588map({expr1}, {expr2}) *map()*
6589 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006590 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006591 item in {expr1} with the result of evaluating {expr2}.
6592 For a |Blob| each byte is replaced.
6593 For a |String|, each character, including composing
6594 characters, is replaced.
6595 If the item type changes you may want to use |mapnew()| to
6596 create a new List or Dictionary. This is required when using
6597 Vim9 script.
6598
6599 {expr2} must be a |String| or |Funcref|.
6600
6601 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6602 of the current item. For a |Dictionary| |v:key| has the key
6603 of the current item and for a |List| |v:key| has the index of
6604 the current item. For a |Blob| |v:key| has the index of the
6605 current byte. For a |String| |v:key| has the index of the
6606 current character.
6607 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006608 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006609< This puts "> " before and " <" after each item in "mylist".
6610
6611 Note that {expr2} is the result of an expression and is then
6612 used as an expression again. Often it is good to use a
6613 |literal-string| to avoid having to double backslashes. You
6614 still have to double ' quotes
6615
6616 If {expr2} is a |Funcref| it is called with two arguments:
6617 1. The key or the index of the current item.
6618 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006619 With a legacy script lambda you don't get an error if it only
6620 accepts one argument, but with a Vim9 lambda you get "E1106:
6621 One argument too many", the number of arguments must match.
6622
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006623 The function must return the new value of the item. Example
6624 that changes each value by "key-value": >
6625 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006626 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006627 endfunc
6628 call map(myDict, function('KeyValue'))
6629< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006630 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006631< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006632 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006633< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006634 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006635<
6636 The operation is done in-place for a |List| and |Dictionary|.
6637 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006638 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006639
6640< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6641 or a new |Blob| or |String|.
6642 When an error is encountered while evaluating {expr2} no
6643 further items in {expr1} are processed.
6644 When {expr2} is a Funcref errors inside a function are ignored,
6645 unless it was defined with the "abort" flag.
6646
6647 Can also be used as a |method|: >
6648 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006649<
6650 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6651 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006652
6653
6654maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6655 When {dict} is omitted or zero: Return the rhs of mapping
6656 {name} in mode {mode}. The returned String has special
6657 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006658 listing. When {dict} is TRUE a dictionary is returned, see
6659 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006660
6661 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006662 returned if {dict} is FALSE, otherwise returns an empty Dict.
6663 When the mapping for {name} is empty, then "<Nop>" is
6664 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006665
6666 The {name} can have special key names, like in the ":map"
6667 command.
6668
6669 {mode} can be one of these strings:
6670 "n" Normal
6671 "v" Visual (including Select)
6672 "o" Operator-pending
6673 "i" Insert
6674 "c" Cmd-line
6675 "s" Select
6676 "x" Visual
6677 "l" langmap |language-mapping|
6678 "t" Terminal-Job
6679 "" Normal, Visual and Operator-pending
6680 When {mode} is omitted, the modes for "" are used.
6681
6682 When {abbr} is there and it is |TRUE| use abbreviations
6683 instead of mappings.
6684
6685 When {dict} is there and it is |TRUE| return a dictionary
6686 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006687 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006688 "lhs" The {lhs} of the mapping as it would be typed
6689 "lhsraw" The {lhs} of the mapping as raw bytes
6690 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6691 form, only present when it differs from "lhsraw"
6692 "rhs" The {rhs} of the mapping as typed.
6693 "silent" 1 for a |:map-silent| mapping, else 0.
6694 "noremap" 1 if the {rhs} of the mapping is not remappable.
6695 "script" 1 if mapping was defined with <script>.
6696 "expr" 1 for an expression mapping (|:map-<expr>|).
6697 "buffer" 1 for a buffer local mapping (|:map-local|).
6698 "mode" Modes for which the mapping is defined. In
6699 addition to the modes mentioned above, these
6700 characters will be used:
6701 " " Normal, Visual and Operator-pending
6702 "!" Insert and Commandline mode
6703 (|mapmode-ic|)
6704 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006705 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006706 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006707 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006708 "lnum" The line number in "sid", zero if unknown.
6709 "nowait" Do not wait for other, longer mappings.
6710 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006711 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006712 "mode_bits" Vim's internal binary representation of "mode".
6713 |mapset()| ignores this; only "mode" is used.
6714 See |maplist()| for usage examples. The values
6715 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006716
6717 The dictionary can be used to restore a mapping with
6718 |mapset()|.
6719
6720 The mappings local to the current buffer are checked first,
6721 then the global mappings.
6722 This function can be used to map a key even when it's already
6723 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006724 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006725
6726< Can also be used as a |method|: >
6727 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006728<
6729 Return type: |String| or dict<any> depending on {dict}
6730
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006731
6732mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6733 Check if there is a mapping that matches with {name} in mode
6734 {mode}. See |maparg()| for {mode} and special names in
6735 {name}.
6736 When {abbr} is there and it is |TRUE| use abbreviations
6737 instead of mappings.
6738 A match happens with a mapping that starts with {name} and
6739 with a mapping which is equal to the start of {name}.
6740
6741 matches mapping "a" "ab" "abc" ~
6742 mapcheck("a") yes yes yes
6743 mapcheck("abc") yes yes yes
6744 mapcheck("ax") yes no no
6745 mapcheck("b") no no no
6746
6747 The difference with maparg() is that mapcheck() finds a
6748 mapping that matches with {name}, while maparg() only finds a
6749 mapping for {name} exactly.
6750 When there is no mapping that starts with {name}, an empty
6751 String is returned. If there is one, the RHS of that mapping
6752 is returned. If there are several mappings that start with
6753 {name}, the RHS of one of them is returned. This will be
6754 "<Nop>" if the RHS is empty.
6755 The mappings local to the current buffer are checked first,
6756 then the global mappings.
6757 This function can be used to check if a mapping can be added
6758 without being ambiguous. Example: >
6759 :if mapcheck("_vv") == ""
6760 : map _vv :set guifont=7x13<CR>
6761 :endif
6762< This avoids adding the "_vv" mapping when there already is a
6763 mapping for "_v" or for "_vvv".
6764
6765 Can also be used as a |method|: >
6766 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006767<
6768 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006769
6770
Ernie Rael09661202022-04-25 14:40:44 +01006771maplist([{abbr}]) *maplist()*
6772 Returns a |List| of all mappings. Each List item is a |Dict|,
6773 the same as what is returned by |maparg()|, see
6774 |mapping-dict|. When {abbr} is there and it is |TRUE| use
6775 abbreviations instead of mappings.
6776
6777 Example to show all mappings with 'MultiMatch' in rhs: >
6778 vim9script
6779 echo maplist()->filter(
6780 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01006781< It can be tricky to find mappings for particular |:map-modes|.
6782 |mapping-dict|'s "mode_bits" can simplify this. For example,
6783 the mode_bits for Normal, Insert or Command-line modes are
6784 0x19. To find all the mappings available in those modes you
6785 can do: >
6786 vim9script
6787 var saved_maps = []
6788 for m in maplist()
6789 if and(m.mode_bits, 0x19) != 0
6790 saved_maps->add(m)
6791 endif
6792 endfor
6793 echo saved_maps->mapnew((_, m) => m.lhs)
6794< The values of the mode_bits are defined in Vim's src/vim.h
6795 file and they can be discovered at runtime using
6796 |:map-commands| and "maplist()". Example: >
6797 vim9script
6798 omap xyzzy <Nop>
6799 var op_bit = maplist()->filter(
6800 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
6801 ounmap xyzzy
6802 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006803<
6804 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01006805
6806
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006807mapnew({expr1}, {expr2}) *mapnew()*
6808 Like |map()| but instead of replacing items in {expr1} a new
6809 List or Dictionary is created and returned. {expr1} remains
6810 unchanged. Items can still be changed by {expr2}, if you
6811 don't want that use |deepcopy()| first.
6812
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006813 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6814 depending on {expr1}
6815
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006816
6817mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01006818mapset({dict})
6819 Restore a mapping from a dictionary, possibly returned by
6820 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
6821 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006822 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01006823 feature allows copying mappings from one buffer to another.
6824 The dict.mode value may restore a single mapping that covers
6825 more than one mode, like with mode values of '!', ' ', 'nox',
6826 or 'v'. *E1276*
6827
6828 In the first form, {mode} and {abbr} should be the same as
6829 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006830 {mode} is used to define the mode in which the mapping is set,
6831 not the "mode" entry in {dict}.
6832 Example for saving and restoring a mapping: >
6833 let save_map = maparg('K', 'n', 0, 1)
6834 nnoremap K somethingelse
6835 ...
6836 call mapset('n', 0, save_map)
6837< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01006838 e.g. with `:map!`, you need to save/restore the mapping for
6839 all of them, when they might differ.
6840
6841 In the second form, with {dict} as the only argument, mode
6842 and abbr are taken from the dict.
6843 Example: >
6844 vim9script
6845 var save_maps = maplist()->filter(
6846 (_, m) => m.lhs == 'K')
6847 nnoremap K somethingelse
6848 cnoremap K somethingelse2
6849 # ...
6850 unmap K
6851 for d in save_maps
6852 mapset(d)
6853 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006854<
6855 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006856
6857
6858match({expr}, {pat} [, {start} [, {count}]]) *match()*
6859 When {expr} is a |List| then this returns the index of the
6860 first item where {pat} matches. Each item is used as a
6861 String, |Lists| and |Dictionaries| are used as echoed.
6862
6863 Otherwise, {expr} is used as a String. The result is a
6864 Number, which gives the index (byte offset) in {expr} where
6865 {pat} matches.
6866
6867 A match at the first character or |List| item returns zero.
6868 If there is no match -1 is returned.
6869
6870 For getting submatches see |matchlist()|.
6871 Example: >
6872 :echo match("testing", "ing") " results in 4
6873 :echo match([1, 'x'], '\a') " results in 1
6874< See |string-match| for how {pat} is used.
6875 *strpbrk()*
6876 Vim doesn't have a strpbrk() function. But you can do: >
6877 :let sepidx = match(line, '[.,;: \t]')
6878< *strcasestr()*
6879 Vim doesn't have a strcasestr() function. But you can add
6880 "\c" to the pattern to ignore case: >
6881 :let idx = match(haystack, '\cneedle')
6882<
6883 If {start} is given, the search starts from byte index
6884 {start} in a String or item {start} in a |List|.
6885 The result, however, is still the index counted from the
6886 first character/item. Example: >
6887 :echo match("testing", "ing", 2)
6888< result is again "4". >
6889 :echo match("testing", "ing", 4)
6890< result is again "4". >
6891 :echo match("testing", "t", 2)
6892< result is "3".
6893 For a String, if {start} > 0 then it is like the string starts
6894 {start} bytes later, thus "^" will match at {start}. Except
6895 when {count} is given, then it's like matches before the
6896 {start} byte are ignored (this is a bit complicated to keep it
6897 backwards compatible).
6898 For a String, if {start} < 0, it will be set to 0. For a list
6899 the index is counted from the end.
6900 If {start} is out of range ({start} > strlen({expr}) for a
6901 String or {start} > len({expr}) for a |List|) -1 is returned.
6902
6903 When {count} is given use the {count}'th match. When a match
6904 is found in a String the search for the next one starts one
6905 character further. Thus this example results in 1: >
6906 echo match("testing", "..", 0, 2)
6907< In a |List| the search continues in the next item.
6908 Note that when {count} is added the way {start} works changes,
6909 see above.
6910
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01006911 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006912 See |pattern| for the patterns that are accepted.
6913 The 'ignorecase' option is used to set the ignore-caseness of
6914 the pattern. 'smartcase' is NOT used. The matching is always
6915 done like 'magic' is set and 'cpoptions' is empty.
6916 Note that a match at the start is preferred, thus when the
6917 pattern is using "*" (any number of matches) it tends to find
6918 zero matches at the start instead of a number of matches
6919 further down in the text.
6920
6921 Can also be used as a |method|: >
6922 GetText()->match('word')
6923 GetList()->match('word')
6924<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006925 Return type: |Number|
6926
6927
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006928 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006929matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
6930 Defines a pattern to be highlighted in the current window (a
6931 "match"). It will be highlighted with {group}. Returns an
6932 identification number (ID), which can be used to delete the
6933 match using |matchdelete()|. The ID is bound to the window.
6934 Matching is case sensitive and magic, unless case sensitivity
6935 or magicness are explicitly overridden in {pattern}. The
6936 'magic', 'smartcase' and 'ignorecase' options are not used.
6937 The "Conceal" value is special, it causes the match to be
6938 concealed.
6939
6940 The optional {priority} argument assigns a priority to the
6941 match. A match with a high priority will have its
6942 highlighting overrule that of a match with a lower priority.
6943 A priority is specified as an integer (negative numbers are no
6944 exception). If the {priority} argument is not specified, the
6945 default priority is 10. The priority of 'hlsearch' is zero,
6946 hence all matches with a priority greater than zero will
6947 overrule it. Syntax highlighting (see 'syntax') is a separate
6948 mechanism, and regardless of the chosen priority a match will
6949 always overrule syntax highlighting.
6950
6951 The optional {id} argument allows the request for a specific
6952 match ID. If a specified ID is already taken, an error
6953 message will appear and the match will not be added. An ID
6954 is specified as a positive integer (zero excluded). IDs 1, 2
6955 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01006956 respectively. 3 is reserved for use by the |matchparen|
6957 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01006958 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01006959 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006960
6961 The optional {dict} argument allows for further custom
6962 values. Currently this is used to specify a match specific
6963 conceal character that will be shown for |hl-Conceal|
6964 highlighted matches. The dict can have the following members:
6965
6966 conceal Special character to show instead of the
6967 match (only for |hl-Conceal| highlighted
6968 matches, see |:syn-cchar|)
6969 window Instead of the current window use the
6970 window with this number or window ID.
6971
6972 The number of matches is not limited, as it is the case with
6973 the |:match| commands.
6974
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006975 Returns -1 on error.
6976
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006977 Example: >
6978 :highlight MyGroup ctermbg=green guibg=green
6979 :let m = matchadd("MyGroup", "TODO")
6980< Deletion of the pattern: >
6981 :call matchdelete(m)
6982
6983< A list of matches defined by |matchadd()| and |:match| are
6984 available from |getmatches()|. All matches can be deleted in
6985 one operation by |clearmatches()|.
6986
6987 Can also be used as a |method|: >
6988 GetGroup()->matchadd('TODO')
6989<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006990 Return type: |Number|
6991
6992
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006993 *matchaddpos()*
6994matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
6995 Same as |matchadd()|, but requires a list of positions {pos}
6996 instead of a pattern. This command is faster than |matchadd()|
Shane Harperc1b39842024-07-17 19:40:40 +02006997 because it does not handle regular expressions and it sets
6998 buffer line boundaries to redraw screen. It is supposed to be
6999 used when fast match additions and deletions are required, for
7000 example to highlight matching parentheses.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007001
7002 {pos} is a list of positions. Each position can be one of
7003 these:
7004 - A number. This whole line will be highlighted. The first
7005 line has number 1.
7006 - A list with one number, e.g., [23]. The whole line with this
7007 number will be highlighted.
7008 - A list with two numbers, e.g., [23, 11]. The first number is
7009 the line number, the second one is the column number (first
7010 column is 1, the value must correspond to the byte index as
7011 |col()| would return). The character at this position will
7012 be highlighted.
7013 - A list with three numbers, e.g., [23, 11, 3]. As above, but
7014 the third number gives the length of the highlight in bytes.
7015
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007016 Returns -1 on error.
7017
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007018 Example: >
7019 :highlight MyGroup ctermbg=green guibg=green
7020 :let m = matchaddpos("MyGroup", [[23, 24], 34])
7021< Deletion of the pattern: >
7022 :call matchdelete(m)
7023
7024< Matches added by |matchaddpos()| are returned by
7025 |getmatches()|.
7026
7027 Can also be used as a |method|: >
7028 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007029<
7030 Return type: |Number|
7031
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007032
7033matcharg({nr}) *matcharg()*
7034 Selects the {nr} match item, as set with a |:match|,
7035 |:2match| or |:3match| command.
7036 Return a |List| with two elements:
7037 The name of the highlight group used
7038 The pattern used.
7039 When {nr} is not 1, 2 or 3 returns an empty |List|.
7040 When there is no match item set returns ['', ''].
7041 This is useful to save and restore a |:match|.
7042 Highlighting matches using the |:match| commands are limited
7043 to three matches. |matchadd()| does not have this limitation.
7044
7045 Can also be used as a |method|: >
7046 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007047<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007048 Return type: list<string>
7049
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007050 *matchbufline()*
7051matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
7052 Returns the |List| of matches in lines from {lnum} to {end} in
7053 buffer {buf} where {pat} matches.
7054
7055 {lnum} and {end} can either be a line number or the string "$"
7056 to refer to the last line in {buf}.
7057
7058 The {dict} argument supports following items:
7059 submatches include submatch information (|/\(|)
7060
7061 For each match, a |Dict| with the following items is returned:
7062 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007063 lnum line number where there is a match
7064 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007065 Note that there can be multiple matches in a single line.
7066
7067 This function works only for loaded buffers. First call
7068 |bufload()| if needed.
7069
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007070 See |match-pattern| for information about the effect of some
7071 option settings on the pattern.
7072
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007073 When {buf} is not a valid buffer, the buffer is not loaded or
7074 {lnum} or {end} is not valid then an error is given and an
7075 empty |List| is returned.
7076
7077 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007078 " Assuming line 3 in buffer 5 contains "a"
7079 :echo matchbufline(5, '\<\k\+\>', 3, 3)
7080 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
7081 " Assuming line 4 in buffer 10 contains "tik tok"
7082 :echo matchbufline(10, '\<\k\+\>', 1, 4)
7083 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007084<
7085 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007086 "\1", "\2", etc. are also returned. Example: >
7087 " Assuming line 2 in buffer 2 contains "acd"
7088 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007089 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007090 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007091< The "submatches" List always contains 9 items. If a submatch
7092 is not found, then an empty string is returned for that
7093 submatch.
7094
7095 Can also be used as a |method|: >
7096 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007097<
7098 Return type: list<dict<any>> or list<any>
7099
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007100
h-east624bb832024-11-09 18:37:32 +01007101matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007102 Deletes a match with ID {id} previously defined by |matchadd()|
7103 or one of the |:match| commands. Returns 0 if successful,
7104 otherwise -1. See example for |matchadd()|. All matches can
7105 be deleted in one operation by |clearmatches()|.
7106 If {win} is specified, use the window with this number or
7107 window ID instead of the current window.
7108
7109 Can also be used as a |method|: >
7110 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007111<
7112 Return type: |Number|
7113
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007114
7115matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
7116 Same as |match()|, but return the index of first character
7117 after the match. Example: >
7118 :echo matchend("testing", "ing")
7119< results in "7".
7120 *strspn()* *strcspn()*
7121 Vim doesn't have a strspn() or strcspn() function, but you can
7122 do it with matchend(): >
7123 :let span = matchend(line, '[a-zA-Z]')
7124 :let span = matchend(line, '[^a-zA-Z]')
7125< Except that -1 is returned when there are no matches.
7126
7127 The {start}, if given, has the same meaning as for |match()|. >
7128 :echo matchend("testing", "ing", 2)
7129< results in "7". >
7130 :echo matchend("testing", "ing", 5)
7131< result is "-1".
7132 When {expr} is a |List| the result is equal to |match()|.
7133
7134 Can also be used as a |method|: >
7135 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007136<
7137 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007138
7139
7140matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7141 If {list} is a list of strings, then returns a |List| with all
7142 the strings in {list} that fuzzy match {str}. The strings in
7143 the returned list are sorted based on the matching score.
7144
7145 The optional {dict} argument always supports the following
7146 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007147 matchseq When this item is present return only matches
7148 that contain the characters in {str} in the
7149 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007150 limit Maximum number of matches in {list} to be
7151 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007152
7153 If {list} is a list of dictionaries, then the optional {dict}
7154 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007155 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007156 {str}. The value of this item should be a
7157 string.
7158 text_cb |Funcref| that will be called for every item
7159 in {list} to get the text for fuzzy matching.
7160 This should accept a dictionary item as the
7161 argument and return the text for that item to
7162 use for fuzzy matching.
7163
7164 {str} is treated as a literal string and regular expression
7165 matching is NOT supported. The maximum supported {str} length
7166 is 256.
7167
7168 When {str} has multiple words each separated by white space,
7169 then the list of strings that have all the words is returned.
7170
7171 If there are no matching strings or there is an error, then an
7172 empty list is returned. If length of {str} is greater than
7173 256, then returns an empty list.
7174
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007175 When {limit} is given, matchfuzzy() will find up to this
7176 number of matches in {list} and return them in sorted order.
7177
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007178 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007179 matching strings.
7180
7181 Example: >
7182 :echo matchfuzzy(["clay", "crow"], "cay")
7183< results in ["clay"]. >
7184 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7185< results in a list of buffer names fuzzy matching "ndl". >
7186 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7187< results in a list of buffer information dicts with buffer
7188 names fuzzy matching "ndl". >
7189 :echo getbufinfo()->matchfuzzy("spl",
7190 \ {'text_cb' : {v -> v.name}})
7191< results in a list of buffer information dicts with buffer
7192 names fuzzy matching "spl". >
7193 :echo v:oldfiles->matchfuzzy("test")
7194< results in a list of file names fuzzy matching "test". >
7195 :let l = readfile("buffer.c")->matchfuzzy("str")
7196< results in a list of lines in "buffer.c" fuzzy matching "str". >
7197 :echo ['one two', 'two one']->matchfuzzy('two one')
7198< results in ['two one', 'one two']. >
7199 :echo ['one two', 'two one']->matchfuzzy('two one',
7200 \ {'matchseq': 1})
7201< results in ['two one'].
7202
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007203 Return type: list<string> or list<any>
7204
7205
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007206matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7207 Same as |matchfuzzy()|, but returns the list of matched
7208 strings, the list of character positions where characters
7209 in {str} matches and a list of matching scores. You can
7210 use |byteidx()| to convert a character position to a byte
7211 position.
7212
7213 If {str} matches multiple times in a string, then only the
7214 positions for the best match is returned.
7215
7216 If there are no matching strings or there is an error, then a
7217 list with three empty list items is returned.
7218
7219 Example: >
7220 :echo matchfuzzypos(['testing'], 'tsg')
7221< results in [['testing'], [[0, 2, 6]], [99]] >
7222 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7223< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7224 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7225< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7226
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007227 Return type: list<list<any>>
7228
7229
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007230matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7231 Same as |match()|, but return a |List|. The first item in the
7232 list is the matched string, same as what matchstr() would
7233 return. Following items are submatches, like "\1", "\2", etc.
7234 in |:substitute|. When an optional submatch didn't match an
7235 empty string is used. Example: >
7236 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7237< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7238 When there is no match an empty list is returned.
7239
7240 You can pass in a List, but that is not very useful.
7241
7242 Can also be used as a |method|: >
7243 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007244<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007245 Return type: list<string> or list<any>
7246
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007247 *matchstrlist()*
7248matchstrlist({list}, {pat} [, {dict}])
7249 Returns the |List| of matches in {list} where {pat} matches.
7250 {list} is a |List| of strings. {pat} is matched against each
7251 string in {list}.
7252
7253 The {dict} argument supports following items:
7254 submatches include submatch information (|/\(|)
7255
7256 For each match, a |Dict| with the following items is returned:
7257 byteidx starting byte index of the match.
7258 idx index in {list} of the match.
7259 text matched string
7260 submatches a List of submatches. Present only if
7261 "submatches" is set to v:true in {dict}.
7262
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007263 See |match-pattern| for information about the effect of some
7264 option settings on the pattern.
7265
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007266 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007267 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7268 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7269 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7270 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007271<
7272 If "submatches" is present and is v:true, then submatches like
7273 "\1", "\2", etc. are also returned. Example: >
7274 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7275 \ #{submatches: v:true})
7276 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7277< The "submatches" List always contains 9 items. If a submatch
7278 is not found, then an empty string is returned for that
7279 submatch.
7280
7281 Can also be used as a |method|: >
7282 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007283<
7284 Return type: list<dict<any>> or list<any>
7285
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007286
7287matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7288 Same as |match()|, but return the matched string. Example: >
7289 :echo matchstr("testing", "ing")
7290< results in "ing".
7291 When there is no match "" is returned.
7292 The {start}, if given, has the same meaning as for |match()|. >
7293 :echo matchstr("testing", "ing", 2)
7294< results in "ing". >
7295 :echo matchstr("testing", "ing", 5)
7296< result is "".
7297 When {expr} is a |List| then the matching item is returned.
7298 The type isn't changed, it's not necessarily a String.
7299
7300 Can also be used as a |method|: >
7301 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007302<
7303 Return type: |String|
7304
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007305
7306matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7307 Same as |matchstr()|, but return the matched string, the start
7308 position and the end position of the match. Example: >
7309 :echo matchstrpos("testing", "ing")
7310< results in ["ing", 4, 7].
7311 When there is no match ["", -1, -1] is returned.
7312 The {start}, if given, has the same meaning as for |match()|. >
7313 :echo matchstrpos("testing", "ing", 2)
7314< results in ["ing", 4, 7]. >
7315 :echo matchstrpos("testing", "ing", 5)
7316< result is ["", -1, -1].
7317 When {expr} is a |List| then the matching item, the index
7318 of first item where {pat} matches, the start position and the
7319 end position of the match are returned. >
7320 :echo matchstrpos([1, '__x'], '\a')
7321< result is ["x", 1, 2, 3].
7322 The type isn't changed, it's not necessarily a String.
7323
7324 Can also be used as a |method|: >
7325 GetText()->matchstrpos('word')
7326<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007327 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007328
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007329
7330max({expr}) *max()*
7331 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007332 echo max([apples, pears, oranges])
7333
7334< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7335 it returns the maximum of all values in the Dictionary.
7336 If {expr} is neither a List nor a Dictionary, or one of the
7337 items in {expr} cannot be used as a Number this results in
7338 an error. An empty |List| or |Dictionary| results in zero.
7339
7340 Can also be used as a |method|: >
7341 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007342<
7343 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007344
7345
7346menu_info({name} [, {mode}]) *menu_info()*
7347 Return information about the specified menu {name} in
7348 mode {mode}. The menu name should be specified without the
7349 shortcut character ('&'). If {name} is "", then the top-level
7350 menu names are returned.
7351
7352 {mode} can be one of these strings:
7353 "n" Normal
7354 "v" Visual (including Select)
7355 "o" Operator-pending
7356 "i" Insert
7357 "c" Cmd-line
7358 "s" Select
7359 "x" Visual
7360 "t" Terminal-Job
7361 "" Normal, Visual and Operator-pending
7362 "!" Insert and Cmd-line
7363 When {mode} is omitted, the modes for "" are used.
7364
7365 Returns a |Dictionary| containing the following items:
7366 accel menu item accelerator text |menu-text|
7367 display display name (name without '&')
7368 enabled v:true if this menu item is enabled
7369 Refer to |:menu-enable|
7370 icon name of the icon file (for toolbar)
7371 |toolbar-icon|
7372 iconidx index of a built-in icon
7373 modes modes for which the menu is defined. In
7374 addition to the modes mentioned above, these
7375 characters will be used:
7376 " " Normal, Visual and Operator-pending
7377 name menu item name.
7378 noremenu v:true if the {rhs} of the menu item is not
7379 remappable else v:false.
7380 priority menu order priority |menu-priority|
7381 rhs right-hand-side of the menu item. The returned
7382 string has special characters translated like
7383 in the output of the ":menu" command listing.
7384 When the {rhs} of a menu item is empty, then
7385 "<Nop>" is returned.
7386 script v:true if script-local remapping of {rhs} is
7387 allowed else v:false. See |:menu-script|.
7388 shortcut shortcut key (character after '&' in
7389 the menu name) |menu-shortcut|
7390 silent v:true if the menu item is created
7391 with <silent> argument |:menu-silent|
7392 submenus |List| containing the names of
7393 all the submenus. Present only if the menu
7394 item has submenus.
7395
7396 Returns an empty dictionary if the menu item is not found.
7397
7398 Examples: >
7399 :echo menu_info('Edit.Cut')
7400 :echo menu_info('File.Save', 'n')
7401
7402 " Display the entire menu hierarchy in a buffer
7403 func ShowMenu(name, pfx)
7404 let m = menu_info(a:name)
7405 call append(line('$'), a:pfx .. m.display)
7406 for child in m->get('submenus', [])
7407 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7408 \ a:pfx .. ' ')
7409 endfor
7410 endfunc
7411 new
7412 for topmenu in menu_info('').submenus
7413 call ShowMenu(topmenu, '')
7414 endfor
7415<
7416 Can also be used as a |method|: >
7417 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007418<
7419 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007420
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007421min({expr}) *min()*
7422 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007423 echo min([apples, pears, oranges])
7424
7425< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7426 it returns the minimum of all values in the Dictionary.
7427 If {expr} is neither a List nor a Dictionary, or one of the
7428 items in {expr} cannot be used as a Number this results in
7429 an error. An empty |List| or |Dictionary| results in zero.
7430
7431 Can also be used as a |method|: >
7432 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007433<
7434 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007435
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007436
7437mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007438 Create directory {name}.
7439
Bram Moolenaar938ae282023-02-20 20:44:55 +00007440 When {flags} is present it must be a string. An empty string
7441 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007442
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007443 {flags} can contain these character flags:
7444 "p" intermediate directories will be created as necessary
7445 "D" {name} will be deleted at the end of the current
Christian Brabandtc509c002024-06-14 20:22:05 +02007446 function, but not recursively |:defer|
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007447 "R" {name} will be deleted recursively at the end of the
Christian Brabandtc509c002024-06-14 20:22:05 +02007448 current function |:defer|
Bram Moolenaar938ae282023-02-20 20:44:55 +00007449
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007450 Note that when {name} has more than one part and "p" is used
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007451 some directories may already exist. Only the first one that
7452 is created and what it contains is scheduled to be deleted.
7453 E.g. when using: >
7454 call mkdir('subdir/tmp/autoload', 'pR')
7455< and "subdir" already exists then "subdir/tmp" will be
7456 scheduled for deletion, like with: >
7457 defer delete('subdir/tmp', 'rf')
7458< Note that if scheduling the defer fails the directory is not
7459 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007460
7461 If {prot} is given it is used to set the protection bits of
7462 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7463 the user, readable for others). Use 0o700 to make it
7464 unreadable for others. This is only used for the last part of
7465 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
7466 created with 0o755.
7467 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007468 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007469
7470< This function is not available in the |sandbox|.
7471
7472 There is no error if the directory already exists and the "p"
7473 flag is passed (since patch 8.0.1708). However, without the
7474 "p" option the call will fail.
7475
7476 The function result is a Number, which is TRUE if the call was
7477 successful or FALSE if the directory creation failed or partly
7478 failed.
7479
7480 Not available on all systems. To check use: >
7481 :if exists("*mkdir")
7482
7483< Can also be used as a |method|: >
7484 GetName()->mkdir()
7485<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007486 Return type: |Number|
7487
7488
7489mode([{expr}]) *mode()*
7490 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007491 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007492 a non-empty String (|non-zero-arg|), then the full mode is
7493 returned, otherwise only the first letter is returned.
7494 Also see |state()|.
7495
7496 n Normal
7497 no Operator-pending
7498 nov Operator-pending (forced characterwise |o_v|)
7499 noV Operator-pending (forced linewise |o_V|)
7500 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7501 CTRL-V is one character
7502 niI Normal using |i_CTRL-O| in |Insert-mode|
7503 niR Normal using |i_CTRL-O| in |Replace-mode|
7504 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7505 nt Terminal-Normal (insert goes to Terminal-Job mode)
7506 v Visual by character
7507 vs Visual by character using |v_CTRL-O| in Select mode
7508 V Visual by line
7509 Vs Visual by line using |v_CTRL-O| in Select mode
7510 CTRL-V Visual blockwise
7511 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7512 s Select by character
7513 S Select by line
7514 CTRL-S Select blockwise
7515 i Insert
7516 ic Insert mode completion |compl-generic|
7517 ix Insert mode |i_CTRL-X| completion
7518 R Replace |R|
7519 Rc Replace mode completion |compl-generic|
7520 Rx Replace mode |i_CTRL-X| completion
7521 Rv Virtual Replace |gR|
7522 Rvc Virtual Replace mode completion |compl-generic|
7523 Rvx Virtual Replace mode |i_CTRL-X| completion
7524 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007525 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007526 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007527 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007528 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007529 ce Normal Ex mode |Q|
7530 r Hit-enter prompt
7531 rm The -- more -- prompt
7532 r? A |:confirm| query of some sort
7533 ! Shell or external command is executing
7534 t Terminal-Job mode: keys go to the job
7535
7536 This is useful in the 'statusline' option or when used
7537 with |remote_expr()| In most other places it always returns
7538 "c" or "n".
7539 Note that in the future more modes and more specific modes may
7540 be added. It's better not to compare the whole string but only
7541 the leading character(s).
7542 Also see |visualmode()|.
7543
7544 Can also be used as a |method|: >
7545 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007546<
7547 Return type: |String|
7548
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007549
7550mzeval({expr}) *mzeval()*
7551 Evaluate MzScheme expression {expr} and return its result
7552 converted to Vim data structures.
7553 Numbers and strings are returned as they are.
7554 Pairs (including lists and improper lists) and vectors are
7555 returned as Vim |Lists|.
7556 Hash tables are represented as Vim |Dictionary| type with keys
7557 converted to strings.
7558 All other types are converted to string with display function.
7559 Examples: >
7560 :mz (define l (list 1 2 3))
7561 :mz (define h (make-hash)) (hash-set! h "list" l)
7562 :echo mzeval("l")
7563 :echo mzeval("h")
7564<
7565 Note that in a `:def` function local variables are not visible
7566 to {expr}.
7567
7568 Can also be used as a |method|: >
7569 GetExpr()->mzeval()
7570<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007571 Return type: any, depending on {expr}
7572
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007573 {only available when compiled with the |+mzscheme| feature}
7574
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007575
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007576nextnonblank({lnum}) *nextnonblank()*
7577 Return the line number of the first line at or below {lnum}
7578 that is not blank. Example: >
7579 if getline(nextnonblank(1)) =~ "Java"
7580< When {lnum} is invalid or there is no non-blank line at or
7581 below it, zero is returned.
7582 {lnum} is used like with |getline()|.
7583 See also |prevnonblank()|.
7584
7585 Can also be used as a |method|: >
7586 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007587<
7588 Return type: |Number|
7589
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007590
7591nr2char({expr} [, {utf8}]) *nr2char()*
7592 Return a string with a single character, which has the number
7593 value {expr}. Examples: >
7594 nr2char(64) returns "@"
7595 nr2char(32) returns " "
7596< When {utf8} is omitted or zero, the current 'encoding' is used.
7597 Example for "utf-8": >
7598 nr2char(300) returns I with bow character
7599< When {utf8} is TRUE, always return UTF-8 characters.
7600 Note that a NUL character in the file is specified with
7601 nr2char(10), because NULs are represented with newline
7602 characters. nr2char(0) is a real NUL and terminates the
7603 string, thus results in an empty string.
7604 To turn a list of character numbers into a string: >
7605 let list = [65, 66, 67]
7606 let str = join(map(list, {_, val -> nr2char(val)}), '')
7607< Result: "ABC"
7608
7609 Can also be used as a |method|: >
7610 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007611<
7612 Return type: |String|
7613
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007614
7615or({expr}, {expr}) *or()*
7616 Bitwise OR on the two arguments. The arguments are converted
7617 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007618 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007619 Example: >
7620 :let bits = or(bits, 0x80)
7621< Can also be used as a |method|: >
7622 :let bits = bits->or(0x80)
7623
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007624< Rationale: The reason this is a function and not using the "|"
7625 character like many languages, is that Vi has always used "|"
7626 to separate commands. In many places it would not be clear if
7627 "|" is an operator or a command separator.
7628
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007629 Return type: |Number|
7630
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007631
7632pathshorten({path} [, {len}]) *pathshorten()*
7633 Shorten directory names in the path {path} and return the
7634 result. The tail, the file name, is kept as-is. The other
7635 components in the path are reduced to {len} letters in length.
7636 If {len} is omitted or smaller than 1 then 1 is used (single
7637 letters). Leading '~' and '.' characters are kept. Examples: >
7638 :echo pathshorten('~/.vim/autoload/myfile.vim')
7639< ~/.v/a/myfile.vim ~
7640>
7641 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7642< ~/.vi/au/myfile.vim ~
7643 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007644 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007645
7646 Can also be used as a |method|: >
7647 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007648<
7649 Return type: |String|
7650
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007651
7652perleval({expr}) *perleval()*
7653 Evaluate Perl expression {expr} in scalar context and return
7654 its result converted to Vim data structures. If value can't be
7655 converted, it is returned as a string Perl representation.
7656 Note: If you want an array or hash, {expr} must return a
7657 reference to it.
7658 Example: >
7659 :echo perleval('[1 .. 4]')
7660< [1, 2, 3, 4]
7661
7662 Note that in a `:def` function local variables are not visible
7663 to {expr}.
7664
7665 Can also be used as a |method|: >
7666 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007667<
7668 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007669
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007670 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007671
7672
7673popup_ functions are documented here: |popup-functions|
7674
7675
7676pow({x}, {y}) *pow()*
7677 Return the power of {x} to the exponent {y} as a |Float|.
7678 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007679 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007680 Examples: >
7681 :echo pow(3, 3)
7682< 27.0 >
7683 :echo pow(2, 16)
7684< 65536.0 >
7685 :echo pow(32, 0.20)
7686< 2.0
7687
7688 Can also be used as a |method|: >
7689 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007690<
7691 Return type: |Number|
7692
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007693
7694prevnonblank({lnum}) *prevnonblank()*
7695 Return the line number of the first line at or above {lnum}
7696 that is not blank. Example: >
7697 let ind = indent(prevnonblank(v:lnum - 1))
7698< When {lnum} is invalid or there is no non-blank line at or
7699 above it, zero is returned.
7700 {lnum} is used like with |getline()|.
7701 Also see |nextnonblank()|.
7702
7703 Can also be used as a |method|: >
7704 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007705<
7706 Return type: |Number|
7707
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007708
7709printf({fmt}, {expr1} ...) *printf()*
7710 Return a String with {fmt}, where "%" items are replaced by
7711 the formatted form of their respective arguments. Example: >
7712 printf("%4d: E%d %.30s", lnum, errno, msg)
7713< May result in:
7714 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7715
7716 When used as a |method| the base is passed as the second
7717 argument: >
7718 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007719<
7720 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007721
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007722 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007723 %s string
7724 %6S string right-aligned in 6 display cells
7725 %6s string right-aligned in 6 bytes
7726 %.9s string truncated to 9 bytes
7727 %c single byte
7728 %d decimal number
7729 %5d decimal number padded with spaces to 5 characters
7730 %x hex number
7731 %04x hex number padded with zeros to at least 4 characters
7732 %X hex number using upper case letters
7733 %o octal number
7734 %08b binary number padded with zeros to at least 8 chars
7735 %f floating point number as 12.23, inf, -inf or nan
7736 %F floating point number as 12.23, INF, -INF or NAN
7737 %e floating point number as 1.23e3, inf, -inf or nan
7738 %E floating point number as 1.23E3, INF, -INF or NAN
7739 %g floating point number, as %f or %e depending on value
7740 %G floating point number, as %F or %E depending on value
7741 %% the % character itself
7742
7743 Conversion specifications start with '%' and end with the
7744 conversion type. All other characters are copied unchanged to
7745 the result.
7746
7747 The "%" starts a conversion specification. The following
7748 arguments appear in sequence:
7749
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007750 % [pos-argument] [flags] [field-width] [.precision] type
7751
7752 pos-argument
7753 At most one positional argument specifier. These
7754 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007755
7756 flags
7757 Zero or more of the following flags:
7758
7759 # The value should be converted to an "alternate
7760 form". For c, d, and s conversions, this option
7761 has no effect. For o conversions, the precision
7762 of the number is increased to force the first
7763 character of the output string to a zero (except
7764 if a zero value is printed with an explicit
7765 precision of zero).
7766 For b and B conversions, a non-zero result has
7767 the string "0b" (or "0B" for B conversions)
7768 prepended to it.
7769 For x and X conversions, a non-zero result has
7770 the string "0x" (or "0X" for X conversions)
7771 prepended to it.
7772
7773 0 (zero) Zero padding. For all conversions the converted
7774 value is padded on the left with zeros rather
7775 than blanks. If a precision is given with a
7776 numeric conversion (d, b, B, o, x, and X), the 0
7777 flag is ignored.
7778
7779 - A negative field width flag; the converted value
7780 is to be left adjusted on the field boundary.
7781 The converted value is padded on the right with
7782 blanks, rather than on the left with blanks or
7783 zeros. A - overrides a 0 if both are given.
7784
7785 ' ' (space) A blank should be left before a positive
7786 number produced by a signed conversion (d).
7787
7788 + A sign must always be placed before a number
7789 produced by a signed conversion. A + overrides
7790 a space if both are used.
7791
7792 field-width
7793 An optional decimal digit string specifying a minimum
7794 field width. If the converted value has fewer bytes
7795 than the field width, it will be padded with spaces on
7796 the left (or right, if the left-adjustment flag has
7797 been given) to fill out the field width. For the S
7798 conversion the count is in cells.
7799
7800 .precision
7801 An optional precision, in the form of a period '.'
7802 followed by an optional digit string. If the digit
7803 string is omitted, the precision is taken as zero.
7804 This gives the minimum number of digits to appear for
7805 d, o, x, and X conversions, the maximum number of
7806 bytes to be printed from a string for s conversions,
7807 or the maximum number of cells to be printed from a
7808 string for S conversions.
7809 For floating point it is the number of digits after
7810 the decimal point.
7811
7812 type
7813 A character that specifies the type of conversion to
7814 be applied, see below.
7815
7816 A field width or precision, or both, may be indicated by an
7817 asterisk '*' instead of a digit string. In this case, a
7818 Number argument supplies the field width or precision. A
7819 negative field width is treated as a left adjustment flag
7820 followed by a positive field width; a negative precision is
7821 treated as though it were missing. Example: >
7822 :echo printf("%d: %.*s", nr, width, line)
7823< This limits the length of the text used from "line" to
7824 "width" bytes.
7825
Dominique Pellé17dca3c2023-12-14 20:36:32 +01007826 If the argument to be formatted is specified using a
7827 positional argument specifier, and a '*' is used to indicate
7828 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007829 precision, the argument(s) to be used must also be specified
7830 using a {n$} positional argument specifier. See |printf-$|.
7831
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007832 The conversion specifiers and their meanings are:
7833
7834 *printf-d* *printf-b* *printf-B* *printf-o*
7835 *printf-x* *printf-X*
7836 dbBoxX The Number argument is converted to signed decimal
7837 (d), unsigned binary (b and B), unsigned octal (o), or
7838 unsigned hexadecimal (x and X) notation. The letters
7839 "abcdef" are used for x conversions; the letters
7840 "ABCDEF" are used for X conversions.
7841 The precision, if any, gives the minimum number of
7842 digits that must appear; if the converted value
7843 requires fewer digits, it is padded on the left with
7844 zeros.
7845 In no case does a non-existent or small field width
7846 cause truncation of a numeric field; if the result of
7847 a conversion is wider than the field width, the field
7848 is expanded to contain the conversion result.
7849 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02007850 The 'l' modifier indicates the argument is a long
7851 integer. The size will be 32 bits or 64 bits
7852 depending on your platform.
7853 The "ll" modifier indicates the argument is 64 bits.
7854 The b and B conversion specifiers never take a width
7855 modifier and always assume their argument is a 64 bit
7856 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007857 Generally, these modifiers are not useful. They are
7858 ignored when type is known from the argument.
7859
7860 i alias for d
7861 D alias for ld
7862 U alias for lu
7863 O alias for lo
7864
7865 *printf-c*
7866 c The Number argument is converted to a byte, and the
7867 resulting character is written.
7868
7869 *printf-s*
7870 s The text of the String argument is used. If a
7871 precision is specified, no more bytes than the number
7872 specified are used.
7873 If the argument is not a String type, it is
7874 automatically converted to text with the same format
7875 as ":echo".
7876 *printf-S*
7877 S The text of the String argument is used. If a
7878 precision is specified, no more display cells than the
7879 number specified are used.
7880
7881 *printf-f* *E807*
7882 f F The Float argument is converted into a string of the
7883 form 123.456. The precision specifies the number of
7884 digits after the decimal point. When the precision is
7885 zero the decimal point is omitted. When the precision
7886 is not specified 6 is used. A really big number
7887 (out of range or dividing by zero) results in "inf"
7888 or "-inf" with %f (INF or -INF with %F).
7889 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
7890 Example: >
7891 echo printf("%.2f", 12.115)
7892< 12.12
7893 Note that roundoff depends on the system libraries.
7894 Use |round()| when in doubt.
7895
7896 *printf-e* *printf-E*
7897 e E The Float argument is converted into a string of the
7898 form 1.234e+03 or 1.234E+03 when using 'E'. The
7899 precision specifies the number of digits after the
7900 decimal point, like with 'f'.
7901
7902 *printf-g* *printf-G*
7903 g G The Float argument is converted like with 'f' if the
7904 value is between 0.001 (inclusive) and 10000000.0
7905 (exclusive). Otherwise 'e' is used for 'g' and 'E'
7906 for 'G'. When no precision is specified superfluous
7907 zeroes and '+' signs are removed, except for the zero
7908 immediately after the decimal point. Thus 10000000.0
7909 results in 1.0e7.
7910
7911 *printf-%*
7912 % A '%' is written. No argument is converted. The
7913 complete conversion specification is "%%".
7914
7915 When a Number argument is expected a String argument is also
7916 accepted and automatically converted.
7917 When a Float or String argument is expected a Number argument
7918 is also accepted and automatically converted.
7919 Any other argument type results in an error message.
7920
7921 *E766* *E767*
7922 The number of {exprN} arguments must exactly match the number
7923 of "%" items. If there are not sufficient or too many
7924 arguments an error is given. Up to 18 arguments can be used.
7925
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007926 *printf-$*
7927 In certain languages, error and informative messages are
7928 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02007929 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007930 having a different word order, positional arguments may be
7931 used to indicate this. For instance: >
7932
h_east596a9f22023-11-21 21:24:23 +09007933 #, c-format
7934 msgid "%s returning %s"
7935 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007936<
h_east596a9f22023-11-21 21:24:23 +09007937 In this example, the sentence has its 2 string arguments
7938 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007939
h_east596a9f22023-11-21 21:24:23 +09007940 echo printf(
7941 "In The Netherlands, vim's creator's name is: %1$s %2$s",
7942 "Bram", "Moolenaar")
7943< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007944
h_east596a9f22023-11-21 21:24:23 +09007945 echo printf(
7946 "In Belgium, vim's creator's name is: %2$s %1$s",
7947 "Bram", "Moolenaar")
7948< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007949
7950 Width (and precision) can be specified using the '*' specifier.
7951 In this case, you must specify the field width position in the
7952 argument list. >
7953
h_east596a9f22023-11-21 21:24:23 +09007954 echo printf("%1$*2$.*3$d", 1, 2, 3)
7955< 001 >
7956 echo printf("%2$*3$.*1$d", 1, 2, 3)
7957< 2 >
7958 echo printf("%3$*1$.*2$d", 1, 2, 3)
7959< 03 >
7960 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
7961< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007962
7963 You can mix specifying the width and/or precision directly
7964 and via positional arguments: >
7965
h_east596a9f22023-11-21 21:24:23 +09007966 echo printf("%1$4.*2$f", 1.4142135, 6)
7967< 1.414214 >
7968 echo printf("%1$*2$.4f", 1.4142135, 6)
7969< 1.4142 >
7970 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
7971< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007972
Christ van Willegenc35fc032024-03-14 18:30:41 +01007973 You will get an overflow error |E1510|, when the field-width
7974 or precision will result in a string longer than 6400 chars.
7975
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007976 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007977 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09007978 echo printf("%s%1$s", "One", "Two")
7979< E1500: Cannot mix positional and non-positional arguments:
7980 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007981
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007982 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007983 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09007984 echo printf("%3$s%1$s", "One", "Two", "Three")
7985< E1501: format argument 2 unused in $-style format:
7986 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007987
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007988 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007989 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09007990 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
7991< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007992
7993 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09007994 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
7995< E1502: Positional argument 2 used as field width reused as
7996 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007997
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007998 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007999 When a positional argument is used, but not the correct number
8000 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09008001 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
8002< E1503: Positional argument 3 out of bounds: %1$d at width
8003 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008004
8005 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09008006 echo printf("%01$*2$.*3$d %4$d", 1, 2)
8007< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
8008 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008009
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008010 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008011 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09008012 echo printf("%1$s %2$s %1$s", "One", "Two")
8013< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008014
8015 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09008016 echo printf("%1$s %2$s %1$d", "One", "Two")
8017< E1504: Positional argument 1 type used inconsistently:
8018 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008019
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008020 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008021 Various other errors that lead to a format string being
8022 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09008023 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
8024< E1505: Invalid format specifier: %1$d at width %2$d is:
8025 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008026
Christ van Willegenea746f92023-10-05 20:48:36 +02008027 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08008028 This internal error indicates that the logic to parse a
8029 positional format argument ran into a problem that couldn't be
8030 otherwise reported. Please file a bug against Vim if you run
8031 into this, copying the exact format string and parameters that
8032 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02008033
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008034 Return type: |String|
8035
Christ van Willegenea746f92023-10-05 20:48:36 +02008036
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008037prompt_getprompt({buf}) *prompt_getprompt()*
8038 Returns the effective prompt text for buffer {buf}. {buf} can
8039 be a buffer name or number. See |prompt-buffer|.
8040
8041 If the buffer doesn't exist or isn't a prompt buffer, an empty
8042 string is returned.
8043
8044 Can also be used as a |method|: >
8045 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008046<
8047 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008048
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008049 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008050
8051
8052prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
8053 Set prompt callback for buffer {buf} to {expr}. When {expr}
8054 is an empty string the callback is removed. This has only
8055 effect if {buf} has 'buftype' set to "prompt".
8056
8057 The callback is invoked when pressing Enter. The current
8058 buffer will always be the prompt buffer. A new line for a
8059 prompt is added before invoking the callback, thus the prompt
8060 for which the callback was invoked will be in the last but one
8061 line.
8062 If the callback wants to add text to the buffer, it must
8063 insert it above the last line, since that is where the current
8064 prompt is. This can also be done asynchronously.
8065 The callback is invoked with one argument, which is the text
8066 that was entered at the prompt. This can be an empty string
8067 if the user only typed Enter.
8068 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008069 func s:TextEntered(text)
8070 if a:text == 'exit' || a:text == 'quit'
8071 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008072 " Reset 'modified' to allow the buffer to be closed.
8073 " We assume there is nothing useful to be saved.
8074 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008075 close
8076 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008077 " Do something useful with "a:text". In this example
8078 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008079 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008080 endif
8081 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008082 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008083
8084< Can also be used as a |method|: >
8085 GetBuffer()->prompt_setcallback(callback)
8086
8087< {only available when compiled with the |+channel| feature}
8088
8089prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
8090 Set a callback for buffer {buf} to {expr}. When {expr} is an
8091 empty string the callback is removed. This has only effect if
8092 {buf} has 'buftype' set to "prompt".
8093
8094 This callback will be invoked when pressing CTRL-C in Insert
8095 mode. Without setting a callback Vim will exit Insert mode,
8096 as in any buffer.
8097
8098 Can also be used as a |method|: >
8099 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008100<
8101 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008102
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008103 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008104
8105prompt_setprompt({buf}, {text}) *prompt_setprompt()*
8106 Set prompt for buffer {buf} to {text}. You most likely want
8107 {text} to end in a space.
8108 The result is only visible if {buf} has 'buftype' set to
8109 "prompt". Example: >
8110 call prompt_setprompt(bufnr(), 'command: ')
8111<
8112 Can also be used as a |method|: >
8113 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008114<
8115 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008116
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008117 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008118
8119prop_ functions are documented here: |text-prop-functions|
8120
8121pum_getpos() *pum_getpos()*
8122 If the popup menu (see |ins-completion-menu|) is not visible,
8123 returns an empty |Dictionary|, otherwise, returns a
8124 |Dictionary| with the following keys:
8125 height nr of items visible
8126 width screen cells
8127 row top screen row (0 first row)
8128 col leftmost screen column (0 first col)
8129 size total nr of items
8130 scrollbar |TRUE| if scrollbar is visible
8131
8132 The values are the same as in |v:event| during
8133 |CompleteChanged|.
8134
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008135 Return type: dict<any>
8136
8137
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008138pumvisible() *pumvisible()*
8139 Returns non-zero when the popup menu is visible, zero
8140 otherwise. See |ins-completion-menu|.
8141 This can be used to avoid some things that would remove the
8142 popup menu.
8143
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008144 Return type: |Number|
8145
8146
zeertzjq7c515282024-11-10 20:26:12 +01008147py3eval({expr} [, {locals}]) *py3eval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008148 Evaluate Python expression {expr} and return its result
8149 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008150 If a {locals} |Dictionary| is given, it defines set of local
8151 variables available in the expression. The keys are variable
8152 names and the values are the variable values. |Dictionary| and
8153 |List| values are referenced, and may be updated by the
8154 expression (as if |python-bindeval| was used).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008155 Numbers and strings are returned as they are (strings are
8156 copied though, Unicode strings are additionally converted to
8157 'encoding').
8158 Lists are represented as Vim |List| type.
8159 Dictionaries are represented as Vim |Dictionary| type with
8160 keys converted to strings.
8161 Note that in a `:def` function local variables are not visible
8162 to {expr}.
8163
8164 Can also be used as a |method|: >
8165 GetExpr()->py3eval()
Ben Jacksonea19e782024-11-06 21:50:05 +01008166 'b",".join(l)'->py3eval({'l': ['a', 'b', 'c']})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008167<
8168 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008169
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008170 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008171
8172 *E858* *E859*
zeertzjq7c515282024-11-10 20:26:12 +01008173pyeval({expr} [, {locals}]) *pyeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008174 Evaluate Python expression {expr} and return its result
8175 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008176 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008177 Numbers and strings are returned as they are (strings are
8178 copied though).
8179 Lists are represented as Vim |List| type.
8180 Dictionaries are represented as Vim |Dictionary| type,
8181 non-string keys result in error.
8182 Note that in a `:def` function local variables are not visible
8183 to {expr}.
8184
8185 Can also be used as a |method|: >
8186 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008187<
8188 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008189
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008190 {only available when compiled with the |+python| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008191
zeertzjq7c515282024-11-10 20:26:12 +01008192pyxeval({expr} [, {locals}]) *pyxeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008193 Evaluate Python expression {expr} and return its result
8194 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008195 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008196 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8197 See also: |pyeval()|, |py3eval()|
8198
8199 Can also be used as a |method|: >
h-east52e7cc22024-07-28 17:03:29 +02008200 GetExpr()->pyxeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008201<
8202 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008203
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008204 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008205 |+python3| feature}
8206
8207rand([{expr}]) *rand()* *random*
8208 Return a pseudo-random Number generated with an xoshiro128**
8209 algorithm using seed {expr}. The returned number is 32 bits,
8210 also on 64 bits systems, for consistency.
8211 {expr} can be initialized by |srand()| and will be updated by
8212 rand(). If {expr} is omitted, an internal seed value is used
8213 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008214 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008215
8216 Examples: >
8217 :echo rand()
8218 :let seed = srand()
8219 :echo rand(seed)
8220 :echo rand(seed) % 16 " random number 0 - 15
8221<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008222 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008223
8224 *E726* *E727*
8225range({expr} [, {max} [, {stride}]]) *range()*
8226 Returns a |List| with Numbers:
8227 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8228 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8229 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8230 {max}] (increasing {expr} with {stride} each time, not
8231 producing a value past {max}).
8232 When the maximum is one before the start the result is an
8233 empty list. When the maximum is more than one before the
8234 start this is an error.
8235 Examples: >
8236 range(4) " [0, 1, 2, 3]
8237 range(2, 4) " [2, 3, 4]
8238 range(2, 9, 3) " [2, 5, 8]
8239 range(2, -2, -1) " [2, 1, 0, -1, -2]
8240 range(0) " []
8241 range(2, 0) " error!
8242<
8243 Can also be used as a |method|: >
8244 GetExpr()->range()
8245<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008246 Return type: list<number>
8247
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008248
K.Takata11df3ae2022-10-19 14:02:40 +01008249readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008250 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008251 If {offset} is specified, read the file from the specified
8252 offset. If it is a negative value, it is used as an offset
8253 from the end of the file. E.g., to read the last 12 bytes: >
8254 readblob('file.bin', -12)
8255< If {size} is specified, only the specified size will be read.
8256 E.g. to read the first 100 bytes of a file: >
8257 readblob('file.bin', 0, 100)
8258< If {size} is -1 or omitted, the whole data starting from
8259 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008260 This can be also used to read the data from a character device
8261 on Unix when {size} is explicitly set. Only if the device
8262 supports seeking {offset} can be used. Otherwise it should be
8263 zero. E.g. to read 10 bytes from a serial console: >
8264 readblob('/dev/ttyS0', 0, 10)
8265< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008266 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008267 When the offset is beyond the end of the file the result is an
8268 empty blob.
8269 When trying to read more bytes than are available the result
8270 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008271 Also see |readfile()| and |writefile()|.
8272
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008273 Return type: |Blob|
8274
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008275
8276readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8277 Return a list with file and directory names in {directory}.
8278 You can also use |glob()| if you don't need to do complicated
8279 things, such as limiting the number of matches.
8280 The list will be sorted (case sensitive), see the {dict}
8281 argument below for changing the sort order.
8282
8283 When {expr} is omitted all entries are included.
8284 When {expr} is given, it is evaluated to check what to do:
8285 If {expr} results in -1 then no further entries will
8286 be handled.
8287 If {expr} results in 0 then this entry will not be
8288 added to the list.
8289 If {expr} results in 1 then this entry will be added
8290 to the list.
8291 The entries "." and ".." are always excluded.
8292 Each time {expr} is evaluated |v:val| is set to the entry name.
8293 When {expr} is a function the name is passed as the argument.
8294 For example, to get a list of files ending in ".txt": >
8295 readdir(dirname, {n -> n =~ '.txt$'})
8296< To skip hidden and backup files: >
8297 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008298< *E857*
8299 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008300 values. Currently this is used to specify if and how sorting
8301 should be performed. The dict can have the following members:
8302
8303 sort How to sort the result returned from the system.
8304 Valid values are:
8305 "none" do not sort (fastest method)
8306 "case" sort case sensitive (byte value of
8307 each character, technically, using
8308 strcmp()) (default)
8309 "icase" sort case insensitive (technically
8310 using strcasecmp())
8311 "collate" sort using the collation order
8312 of the "POSIX" or "C" |locale|
8313 (technically using strcoll())
8314 Other values are silently ignored.
8315
8316 For example, to get a list of all files in the current
8317 directory without sorting the individual entries: >
8318 readdir('.', '1', #{sort: 'none'})
8319< If you want to get a directory tree: >
8320 function! s:tree(dir)
8321 return {a:dir : map(readdir(a:dir),
8322 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008323 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008324 endfunction
8325 echo s:tree(".")
8326<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008327 Returns an empty List on error.
8328
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008329 Can also be used as a |method|: >
8330 GetDirName()->readdir()
8331<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008332 Return type: list<string> or list<any>
8333
8334
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008335readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8336 Extended version of |readdir()|.
8337 Return a list of Dictionaries with file and directory
8338 information in {directory}.
8339 This is useful if you want to get the attributes of file and
8340 directory at the same time as getting a list of a directory.
8341 This is much faster than calling |readdir()| then calling
8342 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8343 each file and directory especially on MS-Windows.
8344 The list will by default be sorted by name (case sensitive),
8345 the sorting can be changed by using the optional {dict}
8346 argument, see |readdir()|.
8347
8348 The Dictionary for file and directory information has the
8349 following items:
8350 group Group name of the entry. (Only on Unix)
8351 name Name of the entry.
8352 perm Permissions of the entry. See |getfperm()|.
8353 size Size of the entry. See |getfsize()|.
8354 time Timestamp of the entry. See |getftime()|.
8355 type Type of the entry.
8356 On Unix, almost same as |getftype()| except:
8357 Symlink to a dir "linkd"
8358 Other symlink "link"
8359 On MS-Windows:
8360 Normal file "file"
8361 Directory "dir"
8362 Junction "junction"
8363 Symlink to a dir "linkd"
8364 Other symlink "link"
8365 Other reparse point "reparse"
8366 user User name of the entry's owner. (Only on Unix)
8367 On Unix, if the entry is a symlink, the Dictionary includes
8368 the information of the target (except the "type" item).
8369 On MS-Windows, it includes the information of the symlink
8370 itself because of performance reasons.
8371
8372 When {expr} is omitted all entries are included.
8373 When {expr} is given, it is evaluated to check what to do:
8374 If {expr} results in -1 then no further entries will
8375 be handled.
8376 If {expr} results in 0 then this entry will not be
8377 added to the list.
8378 If {expr} results in 1 then this entry will be added
8379 to the list.
8380 The entries "." and ".." are always excluded.
8381 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8382 of the entry.
8383 When {expr} is a function the entry is passed as the argument.
8384 For example, to get a list of files ending in ".txt": >
8385 readdirex(dirname, {e -> e.name =~ '.txt$'})
8386<
8387 For example, to get a list of all files in the current
8388 directory without sorting the individual entries: >
8389 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008390<
8391 Can also be used as a |method|: >
8392 GetDirName()->readdirex()
8393<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008394 Return type: list<dict<any>> or list<any>
8395
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008396
8397 *readfile()*
8398readfile({fname} [, {type} [, {max}]])
8399 Read file {fname} and return a |List|, each line of the file
8400 as an item. Lines are broken at NL characters. Macintosh
8401 files separated with CR will result in a single long line
8402 (unless a NL appears somewhere).
8403 All NUL characters are replaced with a NL character.
8404 When {type} contains "b" binary mode is used:
8405 - When the last line ends in a NL an extra empty list item is
8406 added.
8407 - No CR characters are removed.
8408 Otherwise:
8409 - CR characters that appear before a NL are removed.
8410 - Whether the last line ends in a NL or not does not matter.
8411 - When 'encoding' is Unicode any UTF-8 byte order mark is
8412 removed from the text.
8413 When {max} is given this specifies the maximum number of lines
8414 to be read. Useful if you only want to check the first ten
8415 lines of a file: >
8416 :for line in readfile(fname, '', 10)
8417 : if line =~ 'Date' | echo line | endif
8418 :endfor
8419< When {max} is negative -{max} lines from the end of the file
8420 are returned, or as many as there are.
8421 When {max} is zero the result is an empty list.
8422 Note that without {max} the whole file is read into memory.
8423 Also note that there is no recognition of encoding. Read a
8424 file into a buffer if you need to.
8425 Deprecated (use |readblob()| instead): When {type} contains
8426 "B" a |Blob| is returned with the binary data of the file
8427 unmodified.
8428 When the file can't be opened an error message is given and
8429 the result is an empty list.
8430 Also see |writefile()|.
8431
8432 Can also be used as a |method|: >
8433 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008434<
8435 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008436
8437reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8438 {func} is called for every item in {object}, which can be a
8439 |String|, |List| or a |Blob|. {func} is called with two
8440 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008441 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008442
8443 {initial} is the initial result. When omitted, the first item
8444 in {object} is used and {func} is first called for the second
8445 item. If {initial} is not given and {object} is empty no
8446 result can be computed, an E998 error is given.
8447
8448 Examples: >
8449 echo reduce([1, 3, 5], { acc, val -> acc + val })
8450 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8451 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8452 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8453<
8454 Can also be used as a |method|: >
8455 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008456<
8457 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8458 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008459
8460
8461reg_executing() *reg_executing()*
8462 Returns the single letter name of the register being executed.
8463 Returns an empty string when no register is being executed.
8464 See |@|.
8465
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008466 Return type: |String|
8467
8468
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008469reg_recording() *reg_recording()*
8470 Returns the single letter name of the register being recorded.
8471 Returns an empty string when not recording. See |q|.
8472
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008473 Return type: |String|
8474
8475
8476reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008477reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008478reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008479 Return an item that represents a time value. The item is a
8480 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008481 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008482 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008483 string or |reltimefloat()| to convert to a Float. For
8484 example, to see the time spent in function Work(): >
8485 var startTime = reltime()
8486 Work()
8487 echo startTime->reltime()->reltimestr()
8488<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008489 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008490 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008491 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008492 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008493 specified in the argument.
8494 With two arguments it returns the time passed between {start}
8495 and {end}.
8496
8497 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008498 reltime(). If there is an error an empty List is returned in
8499 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008500
8501 Can also be used as a |method|: >
8502 GetStart()->reltime()
8503<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008504 Return type: list<number>
8505
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008506 {only available when compiled with the |+reltime| feature}
8507
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008508
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008509reltimefloat({time}) *reltimefloat()*
8510 Return a Float that represents the time value of {time}.
8511 Example: >
8512 let start = reltime()
8513 call MyFunction()
8514 let seconds = reltimefloat(reltime(start))
8515< See the note of reltimestr() about overhead.
8516 Also see |profiling|.
8517 If there is an error 0.0 is returned in legacy script, in Vim9
8518 script an error is given.
8519
8520 Can also be used as a |method|: >
8521 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008522<
8523 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008524
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008525 {only available when compiled with the |+reltime| feature}
8526
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008527
8528reltimestr({time}) *reltimestr()*
8529 Return a String that represents the time value of {time}.
8530 This is the number of seconds, a dot and the number of
8531 microseconds. Example: >
8532 let start = reltime()
8533 call MyFunction()
8534 echo reltimestr(reltime(start))
8535< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008536 The accuracy depends on the system. Use reltimefloat() for the
8537 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008538 Leading spaces are used to make the string align nicely. You
8539 can use split() to remove it. >
8540 echo split(reltimestr(reltime(start)))[0]
8541< Also see |profiling|.
8542 If there is an error an empty string is returned in legacy
8543 script, in Vim9 script an error is given.
8544
8545 Can also be used as a |method|: >
8546 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008547<
8548 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008549
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008550 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008551
8552 *remote_expr()* *E449*
8553remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008554 Send the {string} to {server}. The {server} argument is a
8555 string, also see |{server}|.
8556
8557 The string is sent as an expression and the result is returned
Christian Brabandt1961caf2024-10-12 11:57:12 +02008558 after evaluation. The result must be a String or a |List|
8559 other types will be converted to String. A |List| is turned
8560 into a String by joining the items with a line break in
8561 between (not at the end), like with join(expr, "\n").
Bram Moolenaar944697a2022-02-20 19:48:20 +00008562
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008563 If {idvar} is present and not empty, it is taken as the name
8564 of a variable and a {serverid} for later use with
8565 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008566
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008567 If {timeout} is given the read times out after this many
8568 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008569
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008570 See also |clientserver| |RemoteReply|.
8571 This function is not available in the |sandbox|.
8572 {only available when compiled with the |+clientserver| feature}
8573 Note: Any errors will cause a local error message to be issued
8574 and the result will be the empty string.
8575
8576 Variables will be evaluated in the global namespace,
8577 independent of a function currently being active. Except
8578 when in debug mode, then local function variables and
8579 arguments can be evaluated.
8580
8581 Examples: >
8582 :echo remote_expr("gvim", "2+2")
8583 :echo remote_expr("gvim1", "b:current_syntax")
8584<
8585 Can also be used as a |method|: >
8586 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008587<
8588 Return type: |String| or list<{type}>
8589
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008590
8591remote_foreground({server}) *remote_foreground()*
8592 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008593 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008594 This works like: >
8595 remote_expr({server}, "foreground()")
8596< Except that on Win32 systems the client does the work, to work
8597 around the problem that the OS doesn't always allow the server
8598 to bring itself to the foreground.
8599 Note: This does not restore the window if it was minimized,
8600 like foreground() does.
8601 This function is not available in the |sandbox|.
8602
8603 Can also be used as a |method|: >
8604 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008605<
8606 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008607
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008608 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008609 Win32 console version}
8610
8611
8612remote_peek({serverid} [, {retvar}]) *remote_peek()*
8613 Returns a positive number if there are available strings
8614 from {serverid}. Copies any reply string into the variable
8615 {retvar} if specified. {retvar} must be a string with the
8616 name of a variable.
8617 Returns zero if none are available.
8618 Returns -1 if something is wrong.
8619 See also |clientserver|.
8620 This function is not available in the |sandbox|.
8621 {only available when compiled with the |+clientserver| feature}
8622 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008623 :let repl = ""
8624 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008625
8626< Can also be used as a |method|: >
8627 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008628<
8629 Return type: |Number|
8630
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008631
8632remote_read({serverid}, [{timeout}]) *remote_read()*
8633 Return the oldest available reply from {serverid} and consume
8634 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008635 reply is available. Returns an empty string, if a reply is
8636 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008637 See also |clientserver|.
8638 This function is not available in the |sandbox|.
8639 {only available when compiled with the |+clientserver| feature}
8640 Example: >
8641 :echo remote_read(id)
8642
8643< Can also be used as a |method|: >
8644 ServerId()->remote_read()
8645<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008646 Return type: |String|
8647
8648
8649remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008650 Send the {string} to {server}. The {server} argument is a
8651 string, also see |{server}|.
8652
8653 The string is sent as input keys and the function returns
8654 immediately. At the Vim server the keys are not mapped
8655 |:map|.
8656
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008657 If {idvar} is present, it is taken as the name of a variable
8658 and a {serverid} for later use with remote_read() is stored
8659 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008660
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008661 See also |clientserver| |RemoteReply|.
8662 This function is not available in the |sandbox|.
8663 {only available when compiled with the |+clientserver| feature}
8664
8665 Note: Any errors will be reported in the server and may mess
8666 up the display.
8667 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008668 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008669 \ remote_read(serverid)
8670
8671 :autocmd NONE RemoteReply *
8672 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008673 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008674 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8675<
8676 Can also be used as a |method|: >
8677 ServerName()->remote_send(keys)
8678<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008679 Return type: |String|
8680
8681
8682remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008683 Become the server {name}. {name} must be a non-empty string.
8684 This fails if already running as a server, when |v:servername|
8685 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008686
8687 Can also be used as a |method|: >
8688 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008689<
8690 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008691
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008692 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008693
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008694
8695remove({list}, {idx}) *remove()*
8696remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008697 Without {end}: Remove the item at {idx} from |List| {list} and
8698 return the item.
8699 With {end}: Remove items from {idx} to {end} (inclusive) and
8700 return a |List| with these items. When {idx} points to the same
8701 item as {end} a list with one item is returned. When {end}
8702 points to an item before {idx} this is an error.
8703 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008704 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008705 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008706 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008707 :call remove(mylist, 0, 9)
8708<
8709 Use |delete()| to remove a file.
8710
8711 Can also be used as a |method|: >
8712 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008713<
8714 Return type: any, depending on {list}
8715
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008716
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008717remove({blob}, {idx})
8718remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008719 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8720 return the byte.
8721 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8722 return a |Blob| with these bytes. When {idx} points to the same
8723 byte as {end} a |Blob| with one byte is returned. When {end}
8724 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008725 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008726 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008727 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008728 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008729<
8730 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008731
8732remove({dict}, {key})
8733 Remove the entry from {dict} with key {key} and return it.
8734 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008735 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008736< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008737 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008738
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008739 Return type: any, depending on {dict}
8740
8741
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008742rename({from}, {to}) *rename()*
8743 Rename the file by the name {from} to the name {to}. This
8744 should also work to move files across file systems. The
8745 result is a Number, which is 0 if the file was renamed
8746 successfully, and non-zero when the renaming failed.
8747 NOTE: If {to} exists it is overwritten without warning.
8748 This function is not available in the |sandbox|.
8749
8750 Can also be used as a |method|: >
8751 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008752<
8753 Return type: |Number|
8754
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008755
8756repeat({expr}, {count}) *repeat()*
8757 Repeat {expr} {count} times and return the concatenated
8758 result. Example: >
8759 :let separator = repeat('-', 80)
8760< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01008761 When {expr} is a |List| or a |Blob| the result is {expr}
8762 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008763 :let longlist = repeat(['a', 'b'], 3)
8764< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
8765
8766 Can also be used as a |method|: >
8767 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008768<
8769 Return type: |String|, |Blob| or list<{type}> depending on
8770 {expr}
8771
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008772
8773resolve({filename}) *resolve()* *E655*
8774 On MS-Windows, when {filename} is a shortcut (a .lnk file),
8775 returns the path the shortcut points to in a simplified form.
8776 When {filename} is a symbolic link or junction point, return
8777 the full path to the target. If the target of junction is
8778 removed, return {filename}.
8779 On Unix, repeat resolving symbolic links in all path
8780 components of {filename} and return the simplified result.
8781 To cope with link cycles, resolving of symbolic links is
8782 stopped after 100 iterations.
8783 On other systems, return the simplified {filename}.
8784 The simplification step is done as by |simplify()|.
8785 resolve() keeps a leading path component specifying the
8786 current directory (provided the result is still a relative
8787 path name) and also keeps a trailing path separator.
8788
8789 Can also be used as a |method|: >
8790 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008791<
8792 Return type: |String|
8793
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008794
8795reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01008796 Reverse the order of items in {object}. {object} can be a
8797 |List|, a |Blob| or a |String|. For a List and a Blob the
8798 items are reversed in-place and {object} is returned.
8799 For a String a new String is returned.
8800 Returns zero if {object} is not a List, Blob or a String.
8801 If you want a List or Blob to remain unmodified make a copy
8802 first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008803 :let revlist = reverse(copy(mylist))
8804< Can also be used as a |method|: >
8805 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008806<
8807 Return type: |String|, |Blob| or list<{type}> depending on
8808 {object}
8809
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008810
8811round({expr}) *round()*
8812 Round off {expr} to the nearest integral value and return it
8813 as a |Float|. If {expr} lies halfway between two integral
8814 values, then use the larger one (away from zero).
8815 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008816 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008817 Examples: >
8818 echo round(0.456)
8819< 0.0 >
8820 echo round(4.5)
8821< 5.0 >
8822 echo round(-4.5)
8823< -5.0
8824
8825 Can also be used as a |method|: >
8826 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008827<
8828 Return type: |Float|
8829
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008830
8831rubyeval({expr}) *rubyeval()*
8832 Evaluate Ruby expression {expr} and return its result
8833 converted to Vim data structures.
8834 Numbers, floats and strings are returned as they are (strings
8835 are copied though).
8836 Arrays are represented as Vim |List| type.
8837 Hashes are represented as Vim |Dictionary| type.
8838 Other objects are represented as strings resulted from their
8839 "Object#to_s" method.
8840 Note that in a `:def` function local variables are not visible
8841 to {expr}.
8842
8843 Can also be used as a |method|: >
8844 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008845<
8846 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008847
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008848 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008849
8850screenattr({row}, {col}) *screenattr()*
8851 Like |screenchar()|, but return the attribute. This is a rather
8852 arbitrary number that can only be used to compare to the
8853 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008854 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008855
8856 Can also be used as a |method|: >
8857 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008858<
8859 Return type: |Number|
8860
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008861
8862screenchar({row}, {col}) *screenchar()*
8863 The result is a Number, which is the character at position
8864 [row, col] on the screen. This works for every possible
8865 screen position, also status lines, window separators and the
8866 command line. The top left position is row one, column one
8867 The character excludes composing characters. For double-byte
8868 encodings it may only be the first byte.
8869 This is mainly to be used for testing.
8870 Returns -1 when row or col is out of range.
8871
8872 Can also be used as a |method|: >
8873 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008874<
8875 Return type: |Number|
8876
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008877
8878screenchars({row}, {col}) *screenchars()*
8879 The result is a |List| of Numbers. The first number is the same
8880 as what |screenchar()| returns. Further numbers are
8881 composing characters on top of the base character.
8882 This is mainly to be used for testing.
8883 Returns an empty List when row or col is out of range.
8884
8885 Can also be used as a |method|: >
8886 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008887<
8888 Return type: list<number> or list<any>
8889
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008890
8891screencol() *screencol()*
8892 The result is a Number, which is the current screen column of
8893 the cursor. The leftmost column has number 1.
8894 This function is mainly used for testing.
8895
8896 Note: Always returns the current screen column, thus if used
8897 in a command (e.g. ":echo screencol()") it will return the
8898 column inside the command line, which is 1 when the command is
8899 executed. To get the cursor position in the file use one of
8900 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008901 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008902 nnoremap <silent> GG :echom screencol()<CR>
8903 nnoremap GG <Cmd>echom screencol()<CR>
8904<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008905 Return type: |Number|
8906
8907
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008908screenpos({winid}, {lnum}, {col}) *screenpos()*
8909 The result is a Dict with the screen position of the text
8910 character in window {winid} at buffer line {lnum} and column
8911 {col}. {col} is a one-based byte index.
8912 The Dict has these members:
8913 row screen row
8914 col first screen column
8915 endcol last screen column
8916 curscol cursor screen column
8917 If the specified position is not visible, all values are zero.
8918 The "endcol" value differs from "col" when the character
8919 occupies more than one screen cell. E.g. for a Tab "col" can
8920 be 1 and "endcol" can be 8.
8921 The "curscol" value is where the cursor would be placed. For
8922 a Tab it would be the same as "endcol", while for a double
8923 width character it would be the same as "col".
8924 The |conceal| feature is ignored here, the column numbers are
8925 as if 'conceallevel' is zero. You can set the cursor to the
8926 right position and use |screencol()| to get the value with
8927 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008928 If the position is in a closed fold the screen position of the
8929 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008930 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008931
8932 Can also be used as a |method|: >
8933 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008934<
8935 Return type: dict<number> or dict<any>
8936
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008937
8938screenrow() *screenrow()*
8939 The result is a Number, which is the current screen row of the
8940 cursor. The top line has number one.
8941 This function is mainly used for testing.
8942 Alternatively you can use |winline()|.
8943
8944 Note: Same restrictions as with |screencol()|.
8945
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008946 Return type: |Number|
8947
8948
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008949screenstring({row}, {col}) *screenstring()*
8950 The result is a String that contains the base character and
8951 any composing characters at position [row, col] on the screen.
8952 This is like |screenchars()| but returning a String with the
8953 characters.
8954 This is mainly to be used for testing.
8955 Returns an empty String when row or col is out of range.
8956
8957 Can also be used as a |method|: >
8958 GetRow()->screenstring(col)
8959<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008960 Return type: |String|
8961
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008962 *search()*
8963search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
8964 Search for regexp pattern {pattern}. The search starts at the
8965 cursor position (you can use |cursor()| to set it).
8966
8967 When a match has been found its line number is returned.
8968 If there is no match a 0 is returned and the cursor doesn't
8969 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01008970 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008971
8972 {flags} is a String, which can contain these character flags:
8973 'b' search Backward instead of forward
8974 'c' accept a match at the Cursor position
8975 'e' move to the End of the match
8976 'n' do Not move the cursor
8977 'p' return number of matching sub-Pattern (see below)
8978 's' Set the ' mark at the previous location of the cursor
8979 'w' Wrap around the end of the file
8980 'W' don't Wrap around the end of the file
8981 'z' start searching at the cursor column instead of zero
8982 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
8983
8984 If the 's' flag is supplied, the ' mark is set, only if the
8985 cursor is moved. The 's' flag cannot be combined with the 'n'
8986 flag.
8987
8988 'ignorecase', 'smartcase' and 'magic' are used.
8989
8990 When the 'z' flag is not given, forward searching always
8991 starts in column zero and then matches before the cursor are
8992 skipped. When the 'c' flag is present in 'cpo' the next
8993 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01008994 search starts one column after the start of the match. This
8995 matters for overlapping matches. See |cpo-c|. You can also
8996 insert "\ze" to change where the match ends, see |/\ze|.
8997
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008998 When searching backwards and the 'z' flag is given then the
8999 search starts in column zero, thus no match in the current
9000 line will be found (unless wrapping around the end of the
9001 file).
9002
9003 When the {stopline} argument is given then the search stops
9004 after searching this line. This is useful to restrict the
9005 search to a range of lines. Examples: >
9006 let match = search('(', 'b', line("w0"))
9007 let end = search('END', '', line("w$"))
9008< When {stopline} is used and it is not zero this also implies
9009 that the search does not wrap around the end of the file.
9010 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01009011 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009012 When the {timeout} argument is given the search stops when
9013 more than this many milliseconds have passed. Thus when
9014 {timeout} is 500 the search stops after half a second.
9015 The value must not be negative. A zero value is like not
9016 giving the argument.
Christian Brabandtd657d3d2024-09-10 21:55:49 +02009017
9018 Note: the timeout is only considered when searching, not
9019 while evaluating the {skip} expression.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009020 {only available when compiled with the |+reltime| feature}
9021
9022 If the {skip} expression is given it is evaluated with the
9023 cursor positioned on the start of a match. If it evaluates to
9024 non-zero this match is skipped. This can be used, for
9025 example, to skip a match in a comment or a string.
9026 {skip} can be a string, which is evaluated as an expression, a
9027 function reference or a lambda.
9028 When {skip} is omitted or empty, every match is accepted.
9029 When evaluating {skip} causes an error the search is aborted
9030 and -1 returned.
9031 *search()-sub-match*
9032 With the 'p' flag the returned value is one more than the
9033 first sub-match in \(\). One if none of them matched but the
9034 whole pattern did match.
9035 To get the column number too use |searchpos()|.
9036
9037 The cursor will be positioned at the match, unless the 'n'
9038 flag is used.
9039
9040 Example (goes over all files in the argument list): >
9041 :let n = 1
9042 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009043 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009044 : " start at the last char in the file and wrap for the
9045 : " first search to find match at start of file
9046 : normal G$
9047 : let flags = "w"
9048 : while search("foo", flags) > 0
9049 : s/foo/bar/g
9050 : let flags = "W"
9051 : endwhile
9052 : update " write the file if modified
9053 : let n = n + 1
9054 :endwhile
9055<
9056 Example for using some flags: >
9057 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
9058< This will search for the keywords "if", "else", and "endif"
9059 under or after the cursor. Because of the 'p' flag, it
9060 returns 1, 2, or 3 depending on which keyword is found, or 0
9061 if the search fails. With the cursor on the first word of the
9062 line:
9063 if (foo == 0) | let foo = foo + 1 | endif ~
9064 the function returns 1. Without the 'c' flag, the function
9065 finds the "endif" and returns 3. The same thing happens
9066 without the 'e' flag if the cursor is on the "f" of "if".
9067 The 'n' flag tells the function not to move the cursor.
9068
9069 Can also be used as a |method|: >
9070 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009071<
9072 Return type: |Number|
9073
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009074
9075searchcount([{options}]) *searchcount()*
9076 Get or update the last search count, like what is displayed
9077 without the "S" flag in 'shortmess'. This works even if
9078 'shortmess' does contain the "S" flag.
9079
9080 This returns a |Dictionary|. The dictionary is empty if the
9081 previous pattern was not set and "pattern" was not specified.
9082
9083 key type meaning ~
9084 current |Number| current position of match;
9085 0 if the cursor position is
9086 before the first match
9087 exact_match |Boolean| 1 if "current" is matched on
9088 "pos", otherwise 0
9089 total |Number| total count of matches found
9090 incomplete |Number| 0: search was fully completed
9091 1: recomputing was timed out
9092 2: max count exceeded
9093
9094 For {options} see further down.
9095
9096 To get the last search count when |n| or |N| was pressed, call
9097 this function with `recompute: 0` . This sometimes returns
9098 wrong information because |n| and |N|'s maximum count is 99.
9099 If it exceeded 99 the result must be max count + 1 (100). If
9100 you want to get correct information, specify `recompute: 1`: >
9101
9102 " result == maxcount + 1 (100) when many matches
9103 let result = searchcount(#{recompute: 0})
9104
9105 " Below returns correct result (recompute defaults
9106 " to 1)
9107 let result = searchcount()
9108<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01009109 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009110 function! LastSearchCount() abort
9111 let result = searchcount(#{recompute: 0})
9112 if empty(result)
9113 return ''
9114 endif
9115 if result.incomplete ==# 1 " timed out
9116 return printf(' /%s [?/??]', @/)
9117 elseif result.incomplete ==# 2 " max count exceeded
9118 if result.total > result.maxcount &&
9119 \ result.current > result.maxcount
9120 return printf(' /%s [>%d/>%d]', @/,
9121 \ result.current, result.total)
9122 elseif result.total > result.maxcount
9123 return printf(' /%s [%d/>%d]', @/,
9124 \ result.current, result.total)
9125 endif
9126 endif
9127 return printf(' /%s [%d/%d]', @/,
9128 \ result.current, result.total)
9129 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009130 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009131
9132 " Or if you want to show the count only when
9133 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009134 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009135 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9136<
9137 You can also update the search count, which can be useful in a
9138 |CursorMoved| or |CursorMovedI| autocommand: >
9139
9140 autocmd CursorMoved,CursorMovedI *
9141 \ let s:searchcount_timer = timer_start(
9142 \ 200, function('s:update_searchcount'))
9143 function! s:update_searchcount(timer) abort
9144 if a:timer ==# s:searchcount_timer
9145 call searchcount(#{
9146 \ recompute: 1, maxcount: 0, timeout: 100})
9147 redrawstatus
9148 endif
9149 endfunction
9150<
9151 This can also be used to count matched texts with specified
9152 pattern in the current buffer using "pattern": >
9153
9154 " Count '\<foo\>' in this buffer
9155 " (Note that it also updates search count)
9156 let result = searchcount(#{pattern: '\<foo\>'})
9157
9158 " To restore old search count by old pattern,
9159 " search again
9160 call searchcount()
9161<
9162 {options} must be a |Dictionary|. It can contain:
9163 key type meaning ~
9164 recompute |Boolean| if |TRUE|, recompute the count
9165 like |n| or |N| was executed.
9166 otherwise returns the last
9167 computed result (when |n| or
9168 |N| was used when "S" is not
9169 in 'shortmess', or this
9170 function was called).
9171 (default: |TRUE|)
9172 pattern |String| recompute if this was given
9173 and different with |@/|.
9174 this works as same as the
9175 below command is executed
9176 before calling this function >
9177 let @/ = pattern
9178< (default: |@/|)
9179 timeout |Number| 0 or negative number is no
9180 timeout. timeout milliseconds
9181 for recomputing the result
9182 (default: 0)
9183 maxcount |Number| 0 or negative number is no
9184 limit. max count of matched
9185 text while recomputing the
9186 result. if search exceeded
9187 total count, "total" value
9188 becomes `maxcount + 1`
9189 (default: 99)
9190 pos |List| `[lnum, col, off]` value
9191 when recomputing the result.
9192 this changes "current" result
9193 value. see |cursor()|,
9194 |getpos()|
9195 (default: cursor's position)
9196
9197 Can also be used as a |method|: >
9198 GetSearchOpts()->searchcount()
9199<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009200 Return type: dict<number>
9201
9202
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009203searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9204 Search for the declaration of {name}.
9205
9206 With a non-zero {global} argument it works like |gD|, find
9207 first match in the file. Otherwise it works like |gd|, find
9208 first match in the function.
9209
9210 With a non-zero {thisblock} argument matches in a {} block
9211 that ends before the cursor position are ignored. Avoids
9212 finding variable declarations only valid in another scope.
9213
9214 Moves the cursor to the found match.
9215 Returns zero for success, non-zero for failure.
9216 Example: >
9217 if searchdecl('myvar') == 0
9218 echo getline('.')
9219 endif
9220<
9221 Can also be used as a |method|: >
9222 GetName()->searchdecl()
9223<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009224 Return type: |Number|
9225
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009226 *searchpair()*
9227searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9228 [, {stopline} [, {timeout}]]]])
9229 Search for the match of a nested start-end pair. This can be
9230 used to find the "endif" that matches an "if", while other
9231 if/endif pairs in between are ignored.
9232 The search starts at the cursor. The default is to search
9233 forward, include 'b' in {flags} to search backward.
9234 If a match is found, the cursor is positioned at it and the
9235 line number is returned. If no match is found 0 or -1 is
9236 returned and the cursor doesn't move. No error message is
9237 given.
9238
9239 {start}, {middle} and {end} are patterns, see |pattern|. They
9240 must not contain \( \) pairs. Use of \%( \) is allowed. When
9241 {middle} is not empty, it is found when searching from either
9242 direction, but only when not in a nested start-end pair. A
9243 typical use is: >
9244 searchpair('\<if\>', '\<else\>', '\<endif\>')
9245< By leaving {middle} empty the "else" is skipped.
9246
9247 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9248 |search()|. Additionally:
9249 'r' Repeat until no more matches found; will find the
9250 outer pair. Implies the 'W' flag.
9251 'm' Return number of matches instead of line number with
9252 the match; will be > 1 when 'r' is used.
9253 Note: it's nearly always a good idea to use the 'W' flag, to
9254 avoid wrapping around the end of the file.
9255
9256 When a match for {start}, {middle} or {end} is found, the
9257 {skip} expression is evaluated with the cursor positioned on
9258 the start of the match. It should return non-zero if this
9259 match is to be skipped. E.g., because it is inside a comment
9260 or a string.
9261 When {skip} is omitted or empty, every match is accepted.
9262 When evaluating {skip} causes an error the search is aborted
9263 and -1 returned.
9264 {skip} can be a string, a lambda, a funcref or a partial.
9265 Anything else makes the function fail.
9266 In a `:def` function when the {skip} argument is a string
9267 constant it is compiled into instructions.
9268
9269 For {stopline} and {timeout} see |search()|.
9270
9271 The value of 'ignorecase' is used. 'magic' is ignored, the
9272 patterns are used like it's on.
9273
9274 The search starts exactly at the cursor. A match with
9275 {start}, {middle} or {end} at the next character, in the
9276 direction of searching, is the first one found. Example: >
9277 if 1
9278 if 2
9279 endif 2
9280 endif 1
9281< When starting at the "if 2", with the cursor on the "i", and
9282 searching forwards, the "endif 2" is found. When starting on
9283 the character just before the "if 2", the "endif 1" will be
9284 found. That's because the "if 2" will be found first, and
9285 then this is considered to be a nested if/endif from "if 2" to
9286 "endif 2".
9287 When searching backwards and {end} is more than one character,
9288 it may be useful to put "\zs" at the end of the pattern, so
9289 that when the cursor is inside a match with the end it finds
9290 the matching start.
9291
9292 Example, to find the "endif" command in a Vim script: >
9293
9294 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9295 \ 'getline(".") =~ "^\\s*\""')
9296
9297< The cursor must be at or after the "if" for which a match is
9298 to be found. Note that single-quote strings are used to avoid
9299 having to double the backslashes. The skip expression only
9300 catches comments at the start of a line, not after a command.
9301 Also, a word "en" or "if" halfway a line is considered a
9302 match.
9303 Another example, to search for the matching "{" of a "}": >
9304
9305 :echo searchpair('{', '', '}', 'bW')
9306
9307< This works when the cursor is at or before the "}" for which a
9308 match is to be found. To reject matches that syntax
9309 highlighting recognized as strings: >
9310
9311 :echo searchpair('{', '', '}', 'bW',
9312 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9313<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009314 Return type: |Number|
9315
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009316 *searchpairpos()*
9317searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9318 [, {stopline} [, {timeout}]]]])
9319 Same as |searchpair()|, but returns a |List| with the line and
9320 column position of the match. The first element of the |List|
9321 is the line number and the second element is the byte index of
9322 the column position of the match. If no match is found,
9323 returns [0, 0]. >
9324
9325 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9326<
9327 See |match-parens| for a bigger and more useful example.
9328
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009329 Return type: list<number>
9330
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009331 *searchpos()*
9332searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9333 Same as |search()|, but returns a |List| with the line and
9334 column position of the match. The first element of the |List|
9335 is the line number and the second element is the byte index of
9336 the column position of the match. If no match is found,
9337 returns [0, 0].
9338 Example: >
9339 :let [lnum, col] = searchpos('mypattern', 'n')
9340
9341< When the 'p' flag is given then there is an extra item with
9342 the sub-pattern match number |search()-sub-match|. Example: >
9343 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9344< In this example "submatch" is 2 when a lowercase letter is
9345 found |/\l|, 3 when an uppercase letter is found |/\u|.
9346
9347 Can also be used as a |method|: >
9348 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009349<
9350 Return type: list<number>
9351
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009352
9353server2client({clientid}, {string}) *server2client()*
9354 Send a reply string to {clientid}. The most recent {clientid}
9355 that sent a string can be retrieved with expand("<client>").
9356 {only available when compiled with the |+clientserver| feature}
9357 Returns zero for success, -1 for failure.
9358 Note:
9359 This id has to be stored before the next command can be
9360 received. I.e. before returning from the received command and
9361 before calling any commands that waits for input.
9362 See also |clientserver|.
9363 Example: >
9364 :echo server2client(expand("<client>"), "HELLO")
9365
9366< Can also be used as a |method|: >
9367 GetClientId()->server2client(string)
9368<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009369 Return type: |Number|
9370
9371
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009372serverlist() *serverlist()*
9373 Return a list of available server names, one per line.
9374 When there are no servers or the information is not available
9375 an empty string is returned. See also |clientserver|.
9376 {only available when compiled with the |+clientserver| feature}
9377 Example: >
9378 :echo serverlist()
9379<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009380 Return type: |String|
9381
9382
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009383setbufline({buf}, {lnum}, {text}) *setbufline()*
9384 Set line {lnum} to {text} in buffer {buf}. This works like
9385 |setline()| for the specified buffer.
9386
9387 This function works only for loaded buffers. First call
9388 |bufload()| if needed.
9389
9390 To insert lines use |appendbufline()|.
9391 Any text properties in {lnum} are cleared.
9392
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009393 {text} can be a string to set one line, or a List of strings
9394 to set multiple lines. If the List extends below the last
9395 line then those lines are added. If the List is empty then
9396 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009397
9398 For the use of {buf}, see |bufname()| above.
9399
9400 {lnum} is used like with |setline()|.
9401 Use "$" to refer to the last line in buffer {buf}.
9402 When {lnum} is just below the last line the {text} will be
9403 added below the last line.
9404
9405 When {buf} is not a valid buffer, the buffer is not loaded or
9406 {lnum} is not valid then 1 is returned. In |Vim9| script an
9407 error is given.
9408 On success 0 is returned.
9409
9410 Can also be used as a |method|, the base is passed as the
9411 third argument: >
9412 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009413<
9414 Return type: |Number|
9415
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009416
9417setbufvar({buf}, {varname}, {val}) *setbufvar()*
9418 Set option or local variable {varname} in buffer {buf} to
9419 {val}.
9420 This also works for a global or local window option, but it
9421 doesn't work for a global or local window variable.
9422 For a local window option the global value is unchanged.
9423 For the use of {buf}, see |bufname()| above.
9424 The {varname} argument is a string.
9425 Note that the variable name without "b:" must be used.
9426 Examples: >
9427 :call setbufvar(1, "&mod", 1)
9428 :call setbufvar("todo", "myvar", "foobar")
9429< This function is not available in the |sandbox|.
9430
9431 Can also be used as a |method|, the base is passed as the
9432 third argument: >
9433 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009434<
9435 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009436
9437
9438setcellwidths({list}) *setcellwidths()*
9439 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009440 tells Vim how wide characters are when displayed in the
9441 terminal, counted in screen cells. The values override
9442 'ambiwidth'. Example: >
9443 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009444 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009445 \ [0x2194, 0x2199, 2],
9446 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009447
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009448< The {list} argument is a List of Lists with each three
9449 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9450 {low} and {high} can be the same, in which case this refers to
9451 one character. Otherwise it is the range of characters from
9452 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009453 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009454
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009455 {width} must be either 1 or 2, indicating the character width
9456 in screen cells. *E1112*
9457 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009458 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009459
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009460 If the new value causes 'fillchars' or 'listchars' to become
9461 invalid it is rejected and an error is given.
9462
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009463 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009464 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009465
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009466< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009467 the effect for known emoji characters. Move the cursor
9468 through the text to check if the cell widths of your terminal
9469 match with what Vim knows about each emoji. If it doesn't
9470 look right you need to adjust the {list} argument.
9471
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009472 Return type: |Number|
9473
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009474
9475setcharpos({expr}, {list}) *setcharpos()*
9476 Same as |setpos()| but uses the specified column number as the
9477 character index instead of the byte index in the line.
9478
9479 Example:
9480 With the text "여보세요" in line 8: >
9481 call setcharpos('.', [0, 8, 4, 0])
9482< positions the cursor on the fourth character '요'. >
9483 call setpos('.', [0, 8, 4, 0])
9484< positions the cursor on the second character '보'.
9485
9486 Can also be used as a |method|: >
9487 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009488<
9489 Return type: |Number|
9490
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009491
9492setcharsearch({dict}) *setcharsearch()*
9493 Set the current character search information to {dict},
9494 which contains one or more of the following entries:
9495
9496 char character which will be used for a subsequent
9497 |,| or |;| command; an empty string clears the
9498 character search
9499 forward direction of character search; 1 for forward,
9500 0 for backward
9501 until type of character search; 1 for a |t| or |T|
9502 character search, 0 for an |f| or |F|
9503 character search
9504
9505 This can be useful to save/restore a user's character search
9506 from a script: >
9507 :let prevsearch = getcharsearch()
9508 :" Perform a command which clobbers user's search
9509 :call setcharsearch(prevsearch)
9510< Also see |getcharsearch()|.
9511
9512 Can also be used as a |method|: >
9513 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009514<
9515 Return type: dict<any>
9516
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009517
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009518setcmdline({str} [, {pos}]) *setcmdline()*
9519 Set the command line to {str} and set the cursor position to
9520 {pos}.
9521 If {pos} is omitted, the cursor is positioned after the text.
9522 Returns 0 when successful, 1 when not editing the command
9523 line.
9524
9525 Can also be used as a |method|: >
9526 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009527<
9528 Return type: |Number|
9529
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009530
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009531setcmdpos({pos}) *setcmdpos()*
9532 Set the cursor position in the command line to byte position
9533 {pos}. The first position is 1.
9534 Use |getcmdpos()| to obtain the current position.
9535 Only works while editing the command line, thus you must use
9536 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9537 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9538 set after the command line is set to the expression. For
9539 |c_CTRL-R_=| it is set after evaluating the expression but
9540 before inserting the resulting text.
9541 When the number is too big the cursor is put at the end of the
9542 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009543 Returns 0 when successful, 1 when not editing the command
9544 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009545
9546 Can also be used as a |method|: >
9547 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009548<
9549 Return type: |Number|
9550
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009551
9552setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9553setcursorcharpos({list})
9554 Same as |cursor()| but uses the specified column number as the
9555 character index instead of the byte index in the line.
9556
9557 Example:
9558 With the text "여보세요" in line 4: >
9559 call setcursorcharpos(4, 3)
9560< positions the cursor on the third character '세'. >
9561 call cursor(4, 3)
9562< positions the cursor on the first character '여'.
9563
9564 Can also be used as a |method|: >
9565 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009566<
9567 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009568
9569
9570setenv({name}, {val}) *setenv()*
9571 Set environment variable {name} to {val}. Example: >
9572 call setenv('HOME', '/home/myhome')
9573
9574< When {val} is |v:null| the environment variable is deleted.
9575 See also |expr-env|.
9576
9577 Can also be used as a |method|, the base is passed as the
9578 second argument: >
9579 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009580<
9581 Return type: |Number|
9582
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009583
9584setfperm({fname}, {mode}) *setfperm()* *chmod*
9585 Set the file permissions for {fname} to {mode}.
9586 {mode} must be a string with 9 characters. It is of the form
9587 "rwxrwxrwx", where each group of "rwx" flags represent, in
9588 turn, the permissions of the owner of the file, the group the
9589 file belongs to, and other users. A '-' character means the
9590 permission is off, any other character means on. Multi-byte
9591 characters are not supported.
9592
9593 For example "rw-r-----" means read-write for the user,
9594 readable by the group, not accessible by others. "xx-x-----"
9595 would do the same thing.
9596
9597 Returns non-zero for success, zero for failure.
9598
9599 Can also be used as a |method|: >
9600 GetFilename()->setfperm(mode)
9601<
9602 To read permissions see |getfperm()|.
9603
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009604 Return type: |Number|
9605
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009606
9607setline({lnum}, {text}) *setline()*
9608 Set line {lnum} of the current buffer to {text}. To insert
9609 lines use |append()|. To set lines in another buffer use
Christian Brabandt946f61c2024-06-17 13:17:58 +02009610 |setbufline()|.
h-east52e7cc22024-07-28 17:03:29 +02009611 Any text properties in {lnum} are cleared. See
9612 |text-prop-cleared|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009613
9614 {lnum} is used like with |getline()|.
9615 When {lnum} is just below the last line the {text} will be
9616 added below the last line.
9617 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009618 converted to a String. When {text} is an empty List then
9619 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009620
9621 If this succeeds, FALSE is returned. If this fails (most likely
9622 because {lnum} is invalid) TRUE is returned.
9623 In |Vim9| script an error is given if {lnum} is invalid.
9624
9625 Example: >
9626 :call setline(5, strftime("%c"))
9627
9628< When {text} is a |List| then line {lnum} and following lines
9629 will be set to the items in the list. Example: >
9630 :call setline(5, ['aaa', 'bbb', 'ccc'])
9631< This is equivalent to: >
9632 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9633 : call setline(n, l)
9634 :endfor
9635
9636< Note: The '[ and '] marks are not set.
9637
9638 Can also be used as a |method|, the base is passed as the
9639 second argument: >
9640 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009641<
9642 Return type: |Number|
9643
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009644
9645setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9646 Create or replace or add to the location list for window {nr}.
9647 {nr} can be the window number or the |window-ID|.
9648 When {nr} is zero the current window is used.
9649
9650 For a location list window, the displayed location list is
9651 modified. For an invalid window number {nr}, -1 is returned.
9652 Otherwise, same as |setqflist()|.
9653 Also see |location-list|.
9654
9655 For {action} see |setqflist-action|.
9656
9657 If the optional {what} dictionary argument is supplied, then
9658 only the items listed in {what} are set. Refer to |setqflist()|
9659 for the list of supported keys in {what}.
9660
9661 Can also be used as a |method|, the base is passed as the
9662 second argument: >
9663 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009664<
9665 Return type: |Number|
9666
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009667
9668setmatches({list} [, {win}]) *setmatches()*
9669 Restores a list of matches saved by |getmatches()| for the
9670 current window. Returns 0 if successful, otherwise -1. All
9671 current matches are cleared before the list is restored. See
9672 example for |getmatches()|.
9673 If {win} is specified, use the window with this number or
9674 window ID instead of the current window.
9675
9676 Can also be used as a |method|: >
9677 GetMatches()->setmatches()
9678<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009679 Return type: |Number|
9680
9681
9682setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009683 Set the position for String {expr}. Possible values:
9684 . the cursor
9685 'x mark x
9686
9687 {list} must be a |List| with four or five numbers:
9688 [bufnum, lnum, col, off]
9689 [bufnum, lnum, col, off, curswant]
9690
9691 "bufnum" is the buffer number. Zero can be used for the
9692 current buffer. When setting an uppercase mark "bufnum" is
9693 used for the mark position. For other marks it specifies the
9694 buffer to set the mark in. You can use the |bufnr()| function
9695 to turn a file name into a buffer number.
9696 For setting the cursor and the ' mark "bufnum" is ignored,
9697 since these are associated with a window, not a buffer.
9698 Does not change the jumplist.
9699
9700 "lnum" and "col" are the position in the buffer. The first
9701 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9702 smaller than 1 then 1 is used. To use the character count
9703 instead of the byte count, use |setcharpos()|.
9704
9705 The "off" number is only used when 'virtualedit' is set. Then
9706 it is the offset in screen columns from the start of the
9707 character. E.g., a position within a <Tab> or after the last
9708 character.
9709
9710 The "curswant" number is only used when setting the cursor
9711 position. It sets the preferred column for when moving the
9712 cursor vertically. When the "curswant" number is missing the
9713 preferred column is not set. When it is present and setting a
9714 mark position it is not used.
9715
9716 Note that for '< and '> changing the line number may result in
9717 the marks to be effectively be swapped, so that '< is always
9718 before '>.
9719
9720 Returns 0 when the position could be set, -1 otherwise.
9721 An error message is given if {expr} is invalid.
9722
9723 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9724
9725 This does not restore the preferred column for moving
9726 vertically; if you set the cursor position with this, |j| and
9727 |k| motions will jump to previous columns! Use |cursor()| to
9728 also set the preferred column. Also see the "curswant" key in
9729 |winrestview()|.
9730
9731 Can also be used as a |method|: >
9732 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009733<
9734 Return type: |Number|
9735
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009736
9737setqflist({list} [, {action} [, {what}]]) *setqflist()*
9738 Create or replace or add to the quickfix list.
9739
9740 If the optional {what} dictionary argument is supplied, then
9741 only the items listed in {what} are set. The first {list}
9742 argument is ignored. See below for the supported items in
9743 {what}.
9744 *setqflist-what*
9745 When {what} is not present, the items in {list} are used. Each
9746 item must be a dictionary. Non-dictionary items in {list} are
9747 ignored. Each dictionary item can contain the following
9748 entries:
9749
9750 bufnr buffer number; must be the number of a valid
9751 buffer
9752 filename name of a file; only used when "bufnr" is not
9753 present or it is invalid.
9754 module name of a module; if given it will be used in
9755 quickfix error window instead of the filename.
9756 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00009757 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009758 pattern search pattern used to locate the error
9759 col column number
9760 vcol when non-zero: "col" is visual column
9761 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00009762 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009763 nr error number
9764 text description of the error
9765 type single-character error type, 'E', 'W', etc.
9766 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +02009767 user_data custom data associated with the item, can be
9768 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009769
9770 The "col", "vcol", "nr", "type" and "text" entries are
9771 optional. Either "lnum" or "pattern" entry can be used to
9772 locate a matching error line.
9773 If the "filename" and "bufnr" entries are not present or
9774 neither the "lnum" or "pattern" entries are present, then the
9775 item will not be handled as an error line.
9776 If both "pattern" and "lnum" are present then "pattern" will
9777 be used.
9778 If the "valid" entry is not supplied, then the valid flag is
9779 set when "bufnr" is a valid buffer or "filename" exists.
9780 If you supply an empty {list}, the quickfix list will be
9781 cleared.
9782 Note that the list is not exactly the same as what
9783 |getqflist()| returns.
9784
9785 {action} values: *setqflist-action* *E927*
9786 'a' The items from {list} are added to the existing
9787 quickfix list. If there is no existing list, then a
9788 new list is created.
9789
9790 'r' The items from the current quickfix list are replaced
9791 with the items from {list}. This can also be used to
9792 clear the list: >
9793 :call setqflist([], 'r')
9794<
Jeremy Fleischman27fbf6e2024-10-14 20:46:27 +02009795 'u' Like 'r', but tries to preserve the current selection
9796 in the quickfix list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009797 'f' All the quickfix lists in the quickfix stack are
9798 freed.
9799
9800 If {action} is not present or is set to ' ', then a new list
9801 is created. The new quickfix list is added after the current
9802 quickfix list in the stack and all the following lists are
9803 freed. To add a new quickfix list at the end of the stack,
9804 set "nr" in {what} to "$".
9805
9806 The following items can be specified in dictionary {what}:
9807 context quickfix list context. See |quickfix-context|
9808 efm errorformat to use when parsing text from
9809 "lines". If this is not present, then the
9810 'errorformat' option value is used.
9811 See |quickfix-parse|
9812 id quickfix list identifier |quickfix-ID|
9813 idx index of the current entry in the quickfix
9814 list specified by 'id' or 'nr'. If set to '$',
9815 then the last entry in the list is set as the
9816 current entry. See |quickfix-index|
9817 items list of quickfix entries. Same as the {list}
9818 argument.
9819 lines use 'errorformat' to parse a list of lines and
9820 add the resulting entries to the quickfix list
9821 {nr} or {id}. Only a |List| value is supported.
9822 See |quickfix-parse|
9823 nr list number in the quickfix stack; zero
9824 means the current quickfix list and "$" means
9825 the last quickfix list.
9826 quickfixtextfunc
9827 function to get the text to display in the
9828 quickfix window. The value can be the name of
9829 a function or a funcref or a lambda. Refer to
9830 |quickfix-window-function| for an explanation
9831 of how to write the function and an example.
9832 title quickfix list title text. See |quickfix-title|
9833 Unsupported keys in {what} are ignored.
9834 If the "nr" item is not present, then the current quickfix list
9835 is modified. When creating a new quickfix list, "nr" can be
9836 set to a value one greater than the quickfix stack size.
9837 When modifying a quickfix list, to guarantee that the correct
9838 list is modified, "id" should be used instead of "nr" to
9839 specify the list.
9840
9841 Examples (See also |setqflist-examples|): >
9842 :call setqflist([], 'r', {'title': 'My search'})
9843 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
9844 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
9845<
9846 Returns zero for success, -1 for failure.
9847
9848 This function can be used to create a quickfix list
9849 independent of the 'errorformat' setting. Use a command like
9850 `:cc 1` to jump to the first position.
9851
9852 Can also be used as a |method|, the base is passed as the
9853 second argument: >
9854 GetErrorlist()->setqflist()
9855<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009856 Return type: |Number|
9857
9858
9859setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009860 Set the register {regname} to {value}.
9861 If {regname} is "" or "@", the unnamed register '"' is used.
9862 The {regname} argument is a string. In |Vim9-script|
9863 {regname} must be one character.
9864
9865 {value} may be any value returned by |getreg()| or
9866 |getreginfo()|, including a |List| or |Dict|.
9867 If {options} contains "a" or {regname} is upper case,
9868 then the value is appended.
9869
9870 {options} can also contain a register type specification:
9871 "c" or "v" |characterwise| mode
9872 "l" or "V" |linewise| mode
9873 "b" or "<CTRL-V>" |blockwise-visual| mode
9874 If a number immediately follows "b" or "<CTRL-V>" then this is
9875 used as the width of the selection - if it is not specified
9876 then the width of the block is set to the number of characters
9877 in the longest line (counting a <Tab> as 1 character).
9878
9879 If {options} contains no register settings, then the default
9880 is to use character mode unless {value} ends in a <NL> for
9881 string {value} and linewise mode for list {value}. Blockwise
9882 mode is never selected automatically.
9883 Returns zero for success, non-zero for failure.
9884
9885 *E883*
9886 Note: you may not use |List| containing more than one item to
9887 set search and expression registers. Lists containing no
9888 items act like empty strings.
9889
9890 Examples: >
9891 :call setreg(v:register, @*)
9892 :call setreg('*', @%, 'ac')
9893 :call setreg('a', "1\n2\n3", 'b5')
9894 :call setreg('"', { 'points_to': 'a'})
9895
9896< This example shows using the functions to save and restore a
9897 register: >
9898 :let var_a = getreginfo()
9899 :call setreg('a', var_a)
9900< or: >
9901 :let var_a = getreg('a', 1, 1)
9902 :let var_amode = getregtype('a')
9903 ....
9904 :call setreg('a', var_a, var_amode)
9905< Note: you may not reliably restore register value
9906 without using the third argument to |getreg()| as without it
9907 newlines are represented as newlines AND Nul bytes are
9908 represented as newlines as well, see |NL-used-for-Nul|.
9909
9910 You can also change the type of a register by appending
9911 nothing: >
9912 :call setreg('a', '', 'al')
9913
9914< Can also be used as a |method|, the base is passed as the
9915 second argument: >
9916 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009917<
9918 Return type: |Number|
9919
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009920
9921settabvar({tabnr}, {varname}, {val}) *settabvar()*
9922 Set tab-local variable {varname} to {val} in tab page {tabnr}.
9923 |t:var|
9924 The {varname} argument is a string.
9925 Note that autocommands are blocked, side effects may not be
9926 triggered, e.g. when setting 'filetype'.
9927 Note that the variable name without "t:" must be used.
9928 Tabs are numbered starting with one.
9929 This function is not available in the |sandbox|.
9930
9931 Can also be used as a |method|, the base is passed as the
9932 third argument: >
9933 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009934<
9935 Return type: |Number|
9936
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009937
9938settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
9939 Set option or local variable {varname} in window {winnr} to
9940 {val}.
9941 Tabs are numbered starting with one. For the current tabpage
9942 use |setwinvar()|.
9943 {winnr} can be the window number or the |window-ID|.
9944 When {winnr} is zero the current window is used.
9945 Note that autocommands are blocked, side effects may not be
9946 triggered, e.g. when setting 'filetype' or 'syntax'.
9947 This also works for a global or local buffer option, but it
9948 doesn't work for a global or local buffer variable.
9949 For a local buffer option the global value is unchanged.
9950 Note that the variable name without "w:" must be used.
9951 Examples: >
9952 :call settabwinvar(1, 1, "&list", 0)
9953 :call settabwinvar(3, 2, "myvar", "foobar")
9954< This function is not available in the |sandbox|.
9955
9956 Can also be used as a |method|, the base is passed as the
9957 fourth argument: >
9958 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009959<
9960 Return type: |Number|
9961
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009962
9963settagstack({nr}, {dict} [, {action}]) *settagstack()*
9964 Modify the tag stack of the window {nr} using {dict}.
9965 {nr} can be the window number or the |window-ID|.
9966
9967 For a list of supported items in {dict}, refer to
9968 |gettagstack()|. "curidx" takes effect before changing the tag
9969 stack.
9970 *E962*
9971 How the tag stack is modified depends on the {action}
9972 argument:
9973 - If {action} is not present or is set to 'r', then the tag
9974 stack is replaced.
9975 - If {action} is set to 'a', then new entries from {dict} are
9976 pushed (added) onto the tag stack.
9977 - If {action} is set to 't', then all the entries from the
9978 current entry in the tag stack or "curidx" in {dict} are
9979 removed and then new entries are pushed to the stack.
9980
9981 The current index is set to one after the length of the tag
9982 stack after the modification.
9983
9984 Returns zero for success, -1 for failure.
9985
9986 Examples (for more examples see |tagstack-examples|):
9987 Empty the tag stack of window 3: >
9988 call settagstack(3, {'items' : []})
9989
9990< Save and restore the tag stack: >
9991 let stack = gettagstack(1003)
9992 " do something else
9993 call settagstack(1003, stack)
9994 unlet stack
9995<
9996 Can also be used as a |method|, the base is passed as the
9997 second argument: >
9998 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009999<
10000 Return type: |Number|
10001
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010002
10003setwinvar({winnr}, {varname}, {val}) *setwinvar()*
10004 Like |settabwinvar()| for the current tab page.
10005 Examples: >
10006 :call setwinvar(1, "&list", 0)
10007 :call setwinvar(2, "myvar", "foobar")
10008
10009< Can also be used as a |method|, the base is passed as the
10010 third argument: >
10011 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010012<
10013 Return type: |Number|
10014
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010015
10016sha256({string}) *sha256()*
10017 Returns a String with 64 hex characters, which is the SHA256
10018 checksum of {string}.
10019
10020 Can also be used as a |method|: >
10021 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010022<
10023 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010024
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010025 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010026
10027shellescape({string} [, {special}]) *shellescape()*
10028 Escape {string} for use as a shell command argument.
10029 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +000010030 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010031 in single quotes and will double up all internal single
10032 quotes.
10033 On MS-Windows, when 'shellslash' is not set, it will enclose
10034 {string} in double quotes and double all double quotes within
10035 {string}.
10036 Otherwise it will enclose {string} in single quotes and
10037 replace all "'" with "'\''".
10038
Enno5faeb602024-05-15 21:54:19 +020010039 The {special} argument adds additional escaping of keywords
10040 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +090010041 number or a non-empty String (|non-zero-arg|), then special
10042 items such as "!", "%", "#" and "<cword>" (as listed in
10043 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +020010044 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010045
10046 The "!" character will be escaped (again with a |non-zero-arg|
10047 {special}) when 'shell' contains "csh" in the tail. That is
10048 because for csh and tcsh "!" is used for history replacement
10049 even when inside single quotes.
10050
10051 With a |non-zero-arg| {special} the <NL> character is also
10052 escaped. When 'shell' containing "csh" in the tail it's
10053 escaped a second time.
10054
10055 The "\" character will be escaped when 'shell' contains "fish"
10056 in the tail. That is because for fish "\" is used as an escape
10057 character inside single quotes.
10058
10059 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010060 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010061< This results in a directory listing for the file under the
10062 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010063 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010064< See also |::S|.
10065
10066 Can also be used as a |method|: >
10067 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010068<
10069 Return type: |String|
10070
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010071
10072shiftwidth([{col}]) *shiftwidth()*
10073 Returns the effective value of 'shiftwidth'. This is the
10074 'shiftwidth' value unless it is zero, in which case it is the
10075 'tabstop' value. This function was introduced with patch
10076 7.3.694 in 2012, everybody should have it by now (however it
10077 did not allow for the optional {col} argument until 8.1.542).
10078
10079 When there is one argument {col} this is used as column number
10080 for which to return the 'shiftwidth' value. This matters for the
10081 'vartabstop' feature. If the 'vartabstop' setting is enabled and
10082 no {col} argument is given, column 1 will be assumed.
10083
10084 Can also be used as a |method|: >
10085 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010086<
10087 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010088
10089sign_ functions are documented here: |sign-functions-details|
10090
10091
10092simplify({filename}) *simplify()*
10093 Simplify the file name as much as possible without changing
10094 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
10095 Unix) are not resolved. If the first path component in
10096 {filename} designates the current directory, this will be
10097 valid for the result as well. A trailing path separator is
10098 not removed either. On Unix "//path" is unchanged, but
10099 "///path" is simplified to "/path" (this follows the Posix
10100 standard).
10101 Example: >
10102 simplify("./dir/.././/file/") == "./file/"
10103< Note: The combination "dir/.." is only removed if "dir" is
10104 a searchable directory or does not exist. On Unix, it is also
10105 removed when "dir" is a symbolic link within the same
10106 directory. In order to resolve all the involved symbolic
10107 links before simplifying the path name, use |resolve()|.
10108
10109 Can also be used as a |method|: >
10110 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010111<
10112 Return type: |String|
10113
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010114
10115sin({expr}) *sin()*
10116 Return the sine of {expr}, measured in radians, as a |Float|.
10117 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010118 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010119 Examples: >
10120 :echo sin(100)
10121< -0.506366 >
10122 :echo sin(-4.01)
10123< 0.763301
10124
10125 Can also be used as a |method|: >
10126 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010127<
10128 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010129
10130
10131sinh({expr}) *sinh()*
10132 Return the hyperbolic sine of {expr} as a |Float| in the range
10133 [-inf, inf].
10134 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010135 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010136 Examples: >
10137 :echo sinh(0.5)
10138< 0.521095 >
10139 :echo sinh(-0.9)
10140< -1.026517
10141
10142 Can also be used as a |method|: >
10143 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010144<
10145 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010146
10147
10148slice({expr}, {start} [, {end}]) *slice()*
10149 Similar to using a |slice| "expr[start : end]", but "end" is
10150 used exclusive. And for a string the indexes are used as
10151 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010152 |vim9script|. Also, composing characters are treated as a
10153 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010154 When {end} is omitted the slice continues to the last item.
10155 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010156 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010157
10158 Can also be used as a |method|: >
10159 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010160<
10161 Return type: list<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010162
10163
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010164sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010165 Sort the items in {list} in-place. Returns {list}.
10166
10167 If you want a list to remain unmodified make a copy first: >
10168 :let sortedlist = sort(copy(mylist))
10169
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010170< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010171 string representation of each item to sort on. Numbers sort
10172 after Strings, |Lists| after Numbers. For sorting text in the
10173 current buffer use |:sort|.
10174
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010175 When {how} is given and it is 'i' then case is ignored.
10176 In legacy script, for backwards compatibility, the value one
10177 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010178
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010179 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010180 locale is used for ordering. Implementation details: strcoll()
10181 is used to compare strings. See |:language| check or set the
10182 collation locale. |v:collate| can also be used to check the
10183 current locale. Sorting using the locale typically ignores
10184 case. Example: >
10185 " ö is sorted similarly to o with English locale.
10186 :language collate en_US.UTF8
10187 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10188< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10189>
10190 " ö is sorted after z with Swedish locale.
10191 :language collate sv_SE.UTF8
10192 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10193< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10194 This does not work properly on Mac.
10195
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010196 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010197 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010198 strtod() function to parse numbers. Strings, Lists, Dicts and
10199 Funcrefs will be considered as being 0). Note that this won't
10200 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010201
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010202 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010203 sorted numerical. This is like 'n' but a string containing
10204 digits will be used as the number they represent.
10205
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010206 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010207 sorted numerical. All values must be a Number or a Float.
10208
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010209 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010210 is called to compare items. The function is invoked with two
10211 items as argument and must return zero if they are equal, 1 or
10212 bigger if the first one sorts after the second one, -1 or
10213 smaller if the first one sorts before the second one.
10214
10215 {dict} is for functions with the "dict" attribute. It will be
10216 used to set the local variable "self". |Dictionary-function|
10217
10218 The sort is stable, items which compare equal (as number or as
10219 string) will keep their relative position. E.g., when sorting
10220 on numbers, text strings will sort next to each other, in the
10221 same order as they were originally.
10222
10223 Can also be used as a |method|: >
10224 mylist->sort()
10225
10226< Also see |uniq()|.
10227
10228 Example: >
10229 func MyCompare(i1, i2)
10230 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10231 endfunc
10232 eval mylist->sort("MyCompare")
10233< A shorter compare version for this specific simple case, which
10234 ignores overflow: >
10235 func MyCompare(i1, i2)
10236 return a:i1 - a:i2
10237 endfunc
10238< For a simple expression you can use a lambda: >
10239 eval mylist->sort({i1, i2 -> i1 - i2})
10240<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010241 Return type: list<{type}>
10242
10243
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010244sound_clear() *sound_clear()*
10245 Stop playing all sounds.
10246
10247 On some Linux systems you may need the libcanberra-pulse
10248 package, otherwise sound may not stop.
10249
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010250 Return type: |Number|
10251
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010252 {only available when compiled with the |+sound| feature}
10253
10254 *sound_playevent()*
10255sound_playevent({name} [, {callback}])
10256 Play a sound identified by {name}. Which event names are
10257 supported depends on the system. Often the XDG sound names
10258 are used. On Ubuntu they may be found in
10259 /usr/share/sounds/freedesktop/stereo. Example: >
10260 call sound_playevent('bell')
10261< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10262 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10263 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010264 On macOS, {name} refers to files located in
10265 /System/Library/Sounds (e.g. "Tink"). It will also work for
10266 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010267
10268 When {callback} is specified it is invoked when the sound is
10269 finished. The first argument is the sound ID, the second
10270 argument is the status:
10271 0 sound was played to the end
10272 1 sound was interrupted
10273 2 error occurred after sound started
10274 Example: >
10275 func Callback(id, status)
10276 echomsg "sound " .. a:id .. " finished with " .. a:status
10277 endfunc
10278 call sound_playevent('bell', 'Callback')
10279
10280< MS-Windows: {callback} doesn't work for this function.
10281
10282 Returns the sound ID, which can be passed to `sound_stop()`.
10283 Returns zero if the sound could not be played.
10284
10285 Can also be used as a |method|: >
10286 GetSoundName()->sound_playevent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010287<
10288 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010289
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010290 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010291
10292 *sound_playfile()*
10293sound_playfile({path} [, {callback}])
10294 Like `sound_playevent()` but play sound file {path}. {path}
10295 must be a full path. On Ubuntu you may find files to play
10296 with this command: >
10297 :!find /usr/share/sounds -type f | grep -v index.theme
10298
10299< Can also be used as a |method|: >
10300 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010301<
10302 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010303
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010304 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010305
10306
10307sound_stop({id}) *sound_stop()*
10308 Stop playing sound {id}. {id} must be previously returned by
10309 `sound_playevent()` or `sound_playfile()`.
10310
10311 On some Linux systems you may need the libcanberra-pulse
10312 package, otherwise sound may not stop.
10313
10314 On MS-Windows, this does not work for event sound started by
10315 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10316
10317 Can also be used as a |method|: >
10318 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010319<
10320 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010321
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010322 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010323
10324 *soundfold()*
10325soundfold({word})
10326 Return the sound-folded equivalent of {word}. Uses the first
10327 language in 'spelllang' for the current window that supports
10328 soundfolding. 'spell' must be set. When no sound folding is
10329 possible the {word} is returned unmodified.
10330 This can be used for making spelling suggestions. Note that
10331 the method can be quite slow.
10332
10333 Can also be used as a |method|: >
10334 GetWord()->soundfold()
10335<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010336 Return type: |String|
10337
10338
10339spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010340 Without argument: The result is the badly spelled word under
10341 or after the cursor. The cursor is moved to the start of the
10342 bad word. When no bad word is found in the cursor line the
10343 result is an empty string and the cursor doesn't move.
10344
10345 With argument: The result is the first word in {sentence} that
10346 is badly spelled. If there are no spelling mistakes the
10347 result is an empty string.
10348
10349 The return value is a list with two items:
10350 - The badly spelled word or an empty string.
10351 - The type of the spelling error:
10352 "bad" spelling mistake
10353 "rare" rare word
10354 "local" word only valid in another region
10355 "caps" word should start with Capital
10356 Example: >
10357 echo spellbadword("the quik brown fox")
10358< ['quik', 'bad'] ~
10359
10360 The spelling information for the current window and the value
10361 of 'spelllang' are used.
10362
10363 Can also be used as a |method|: >
10364 GetText()->spellbadword()
10365<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010366 Return type: list<string>
10367
10368
10369spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010370 Return a |List| with spelling suggestions to replace {word}.
10371 When {max} is given up to this number of suggestions are
10372 returned. Otherwise up to 25 suggestions are returned.
10373
10374 When the {capital} argument is given and it's non-zero only
10375 suggestions with a leading capital will be given. Use this
10376 after a match with 'spellcapcheck'.
10377
10378 {word} can be a badly spelled word followed by other text.
10379 This allows for joining two words that were split. The
10380 suggestions also include the following text, thus you can
10381 replace a line.
10382
10383 {word} may also be a good word. Similar words will then be
10384 returned. {word} itself is not included in the suggestions,
10385 although it may appear capitalized.
10386
10387 The spelling information for the current window is used. The
10388 values of 'spelllang' and 'spellsuggest' are used.
10389
10390 Can also be used as a |method|: >
10391 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010392<
10393 Return type: list<string> or list<any>
10394
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010395
10396split({string} [, {pattern} [, {keepempty}]]) *split()*
10397 Make a |List| out of {string}. When {pattern} is omitted or
Shane Harperc1b39842024-07-17 19:40:40 +020010398 empty each white space separated sequence of characters
10399 becomes an item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010400 Otherwise the string is split where {pattern} matches,
10401 removing the matched characters. 'ignorecase' is not used
10402 here, add \c to ignore case. |/\c|
10403 When the first or last item is empty it is omitted, unless the
10404 {keepempty} argument is given and it's non-zero.
10405 Other empty items are kept when {pattern} matches at least one
10406 character or when {keepempty} is non-zero.
10407 Example: >
10408 :let words = split(getline('.'), '\W\+')
10409< To split a string in individual characters: >
10410 :for c in split(mystring, '\zs')
10411< If you want to keep the separator you can also use '\zs' at
10412 the end of the pattern: >
10413 :echo split('abc:def:ghi', ':\zs')
10414< ['abc:', 'def:', 'ghi'] ~
10415 Splitting a table where the first element can be empty: >
10416 :let items = split(line, ':', 1)
10417< The opposite function is |join()|.
10418
10419 Can also be used as a |method|: >
10420 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010421<
10422 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010423
10424sqrt({expr}) *sqrt()*
10425 Return the non-negative square root of Float {expr} as a
10426 |Float|.
10427 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010428 is negative the result is NaN (Not a Number). Returns 0.0 if
10429 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010430 Examples: >
10431 :echo sqrt(100)
10432< 10.0 >
10433 :echo sqrt(-4.01)
10434< nan
10435 "nan" may be different, it depends on system libraries.
10436
10437 Can also be used as a |method|: >
10438 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010439<
10440 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010441
10442
10443srand([{expr}]) *srand()*
10444 Initialize seed used by |rand()|:
10445 - If {expr} is not given, seed values are initialized by
10446 reading from /dev/urandom, if possible, or using time(NULL)
10447 a.k.a. epoch time otherwise; this only has second accuracy.
10448 - If {expr} is given it must be a Number. It is used to
10449 initialize the seed values. This is useful for testing or
10450 when a predictable sequence is intended.
10451
10452 Examples: >
10453 :let seed = srand()
10454 :let seed = srand(userinput)
10455 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010456<
10457 Return type: list<number>
10458
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010459
10460state([{what}]) *state()*
10461 Return a string which contains characters indicating the
10462 current state. Mostly useful in callbacks that want to do
10463 work that may not always be safe. Roughly this works like:
10464 - callback uses state() to check if work is safe to do.
10465 Yes: then do it right away.
10466 No: add to work queue and add a |SafeState| and/or
10467 |SafeStateAgain| autocommand (|SafeState| triggers at
10468 toplevel, |SafeStateAgain| triggers after handling
10469 messages and callbacks).
10470 - When SafeState or SafeStateAgain is triggered and executes
10471 your autocommand, check with `state()` if the work can be
10472 done now, and if yes remove it from the queue and execute.
10473 Remove the autocommand if the queue is now empty.
10474 Also see |mode()|.
10475
10476 When {what} is given only characters in this string will be
10477 added. E.g, this checks if the screen has scrolled: >
10478 if state('s') == ''
10479 " screen has not scrolled
10480<
10481 These characters indicate the state, generally indicating that
10482 something is busy:
10483 m halfway a mapping, :normal command, feedkeys() or
10484 stuffed command
10485 o operator pending, e.g. after |d|
10486 a Insert mode autocomplete active
10487 x executing an autocommand
10488 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10489 ch_readraw() when reading json
10490 S not triggering SafeState or SafeStateAgain, e.g. after
10491 |f| or a count
10492 c callback invoked, including timer (repeats for
10493 recursiveness up to "ccc")
10494 s screen has scrolled for messages
10495
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010496 Return type: |String|
10497
10498
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010499str2float({string} [, {quoted}]) *str2float()*
10500 Convert String {string} to a Float. This mostly works the
10501 same as when using a floating point number in an expression,
10502 see |floating-point-format|. But it's a bit more permissive.
10503 E.g., "1e40" is accepted, while in an expression you need to
10504 write "1.0e40". The hexadecimal form "0x123" is also
10505 accepted, but not others, like binary or octal.
10506 When {quoted} is present and non-zero then embedded single
10507 quotes before the dot are ignored, thus "1'000.0" is a
10508 thousand.
10509 Text after the number is silently ignored.
10510 The decimal point is always '.', no matter what the locale is
10511 set to. A comma ends the number: "12,345.67" is converted to
10512 12.0. You can strip out thousands separators with
10513 |substitute()|: >
10514 let f = str2float(substitute(text, ',', '', 'g'))
10515<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010516 Returns 0.0 if the conversion fails.
10517
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010518 Can also be used as a |method|: >
10519 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010520<
10521 Return type: |Float|
10522
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010523
10524str2list({string} [, {utf8}]) *str2list()*
10525 Return a list containing the number values which represent
10526 each character in String {string}. Examples: >
10527 str2list(" ") returns [32]
10528 str2list("ABC") returns [65, 66, 67]
10529< |list2str()| does the opposite.
10530
10531 When {utf8} is omitted or zero, the current 'encoding' is used.
10532 When {utf8} is TRUE, always treat the String as UTF-8
10533 characters. With UTF-8 composing characters are handled
10534 properly: >
10535 str2list("á") returns [97, 769]
10536
10537< Can also be used as a |method|: >
10538 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010539<
10540 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010541
10542
10543str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10544 Convert string {string} to a number.
10545 {base} is the conversion base, it can be 2, 8, 10 or 16.
10546 When {quoted} is present and non-zero then embedded single
10547 quotes are ignored, thus "1'000'000" is a million.
10548
10549 When {base} is omitted base 10 is used. This also means that
10550 a leading zero doesn't cause octal conversion to be used, as
10551 with the default String to Number conversion. Example: >
10552 let nr = str2nr('0123')
10553<
10554 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10555 different base the result will be zero. Similarly, when
10556 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10557 {base} is 2 a leading "0b" or "0B" is ignored.
10558 Text after the number is silently ignored.
10559
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010560 Returns 0 if {string} is empty or on error.
10561
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010562 Can also be used as a |method|: >
10563 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010564<
10565 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010566
10567
10568strcharlen({string}) *strcharlen()*
10569 The result is a Number, which is the number of characters
10570 in String {string}. Composing characters are ignored.
10571 |strchars()| can count the number of characters, counting
10572 composing characters separately.
10573
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010574 Returns 0 if {string} is empty or on error.
10575
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010576 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10577
10578 Can also be used as a |method|: >
10579 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010580<
10581 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010582
10583
10584strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10585 Like |strpart()| but using character index and length instead
10586 of byte index and length.
10587 When {skipcc} is omitted or zero, composing characters are
10588 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010589 When {skipcc} set to 1, composing characters are treated as a
10590 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010591 When a character index is used where a character does not
10592 exist it is omitted and counted as one character. For
10593 example: >
10594 strcharpart('abc', -1, 2)
10595< results in 'a'.
10596
Bram Moolenaard592deb2022-06-17 15:42:40 +010010597 Returns an empty string on error.
10598
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010599 Can also be used as a |method|: >
10600 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010601<
10602 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010603
10604
10605strchars({string} [, {skipcc}]) *strchars()*
10606 The result is a Number, which is the number of characters
10607 in String {string}.
10608 When {skipcc} is omitted or zero, composing characters are
10609 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010610 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010611 |strcharlen()| always does this.
10612
Bram Moolenaard592deb2022-06-17 15:42:40 +010010613 Returns zero on error.
10614
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010615 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10616
10617 {skipcc} is only available after 7.4.755. For backward
10618 compatibility, you can define a wrapper function: >
10619 if has("patch-7.4.755")
10620 function s:strchars(str, skipcc)
10621 return strchars(a:str, a:skipcc)
10622 endfunction
10623 else
10624 function s:strchars(str, skipcc)
10625 if a:skipcc
10626 return strlen(substitute(a:str, ".", "x", "g"))
10627 else
10628 return strchars(a:str)
10629 endif
10630 endfunction
10631 endif
10632<
10633 Can also be used as a |method|: >
10634 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010635<
10636 Return type: |Number|
10637
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010638
10639strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10640 The result is a Number, which is the number of display cells
10641 String {string} occupies on the screen when it starts at {col}
10642 (first column is zero). When {col} is omitted zero is used.
10643 Otherwise it is the screen column where to start. This
10644 matters for Tab characters.
10645 The option settings of the current window are used. This
10646 matters for anything that's displayed differently, such as
10647 'tabstop' and 'display'.
10648 When {string} contains characters with East Asian Width Class
10649 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010650 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010651 Also see |strlen()|, |strwidth()| and |strchars()|.
10652
10653 Can also be used as a |method|: >
10654 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010655<
10656 Return type: |Number|
10657
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010658
10659strftime({format} [, {time}]) *strftime()*
10660 The result is a String, which is a formatted date and time, as
10661 specified by the {format} string. The given {time} is used,
10662 or the current time if no time is given. The accepted
10663 {format} depends on your system, thus this is not portable!
10664 See the manual page of the C function strftime() for the
10665 format. The maximum length of the result is 80 characters.
10666 See also |localtime()|, |getftime()| and |strptime()|.
10667 The language can be changed with the |:language| command.
10668 Examples: >
10669 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10670 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10671 :echo strftime("%y%m%d %T") 970427 11:53:55
10672 :echo strftime("%H:%M") 11:55
10673 :echo strftime("%c", getftime("file.c"))
10674 Show mod time of file.c.
10675< Not available on all systems. To check use: >
10676 :if exists("*strftime")
10677
10678< Can also be used as a |method|: >
10679 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010680<
10681 Return type: |String|
10682
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010683
10684strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010685 Get a Number corresponding to the character at {index} in
10686 {str}. This uses a zero-based character index, not a byte
10687 index. Composing characters are considered separate
10688 characters here. Use |nr2char()| to convert the Number to a
10689 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010690 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010691 Also see |strcharpart()| and |strchars()|.
10692
10693 Can also be used as a |method|: >
10694 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010695<
10696 Return type: |Number|
10697
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010698
10699stridx({haystack}, {needle} [, {start}]) *stridx()*
10700 The result is a Number, which gives the byte index in
10701 {haystack} of the first occurrence of the String {needle}.
10702 If {start} is specified, the search starts at index {start}.
10703 This can be used to find a second match: >
10704 :let colon1 = stridx(line, ":")
10705 :let colon2 = stridx(line, ":", colon1 + 1)
10706< The search is done case-sensitive.
10707 For pattern searches use |match()|.
10708 -1 is returned if the {needle} does not occur in {haystack}.
10709 See also |strridx()|.
10710 Examples: >
10711 :echo stridx("An Example", "Example") 3
10712 :echo stridx("Starting point", "Start") 0
10713 :echo stridx("Starting point", "start") -1
10714< *strstr()* *strchr()*
10715 stridx() works similar to the C function strstr(). When used
10716 with a single character it works similar to strchr().
10717
10718 Can also be used as a |method|: >
10719 GetHaystack()->stridx(needle)
10720<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010721 Return type: |Number|
10722
10723
10724string({expr}) *string()*
10725 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010726 Float, String, Blob or a composition of them, then the result
10727 can be parsed back with |eval()|.
10728 {expr} type result ~
10729 String 'string' (single quotes are doubled)
10730 Number 123
10731 Float 123.123456 or 1.123456e8
10732 Funcref function('name')
10733 Blob 0z00112233.44556677.8899
10734 List [item, item]
10735 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000010736 Class class SomeName
10737 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010010738 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020010739 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010740
10741 When a |List| or |Dictionary| has a recursive reference it is
10742 replaced by "[...]" or "{...}". Using eval() on the result
10743 will then fail.
10744
mityu7f0bba22024-03-29 10:14:41 +010010745 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010746 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010010747 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010748
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010749 Can also be used as a |method|: >
10750 mylist->string()
10751
10752< Also see |strtrans()|.
10753
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010754 Return type: |String|
10755
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010756
10757strlen({string}) *strlen()*
10758 The result is a Number, which is the length of the String
10759 {string} in bytes.
10760 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010761 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010762 If you want to count the number of multibyte characters use
10763 |strchars()|.
10764 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
10765
10766 Can also be used as a |method|: >
10767 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010768<
10769 Return type: |Number|
10770
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010771
10772strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
10773 The result is a String, which is part of {src}, starting from
10774 byte {start}, with the byte length {len}.
10775 When {chars} is present and TRUE then {len} is the number of
10776 characters positions (composing characters are not counted
10777 separately, thus "1" means one base character and any
10778 following composing characters).
10779 To count {start} as characters instead of bytes use
10780 |strcharpart()|.
10781
10782 When bytes are selected which do not exist, this doesn't
10783 result in an error, the bytes are simply omitted.
10784 If {len} is missing, the copy continues from {start} till the
10785 end of the {src}. >
10786 strpart("abcdefg", 3, 2) == "de"
10787 strpart("abcdefg", -2, 4) == "ab"
10788 strpart("abcdefg", 5, 4) == "fg"
10789 strpart("abcdefg", 3) == "defg"
10790
10791< Note: To get the first character, {start} must be 0. For
10792 example, to get the character under the cursor: >
10793 strpart(getline("."), col(".") - 1, 1, v:true)
10794<
Bram Moolenaard592deb2022-06-17 15:42:40 +010010795 Returns an empty string on error.
10796
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010797 Can also be used as a |method|: >
10798 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010799<
10800 Return type: |String|
10801
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010802
10803strptime({format}, {timestring}) *strptime()*
10804 The result is a Number, which is a unix timestamp representing
10805 the date and time in {timestring}, which is expected to match
10806 the format specified in {format}.
10807
10808 The accepted {format} depends on your system, thus this is not
10809 portable! See the manual page of the C function strptime()
10810 for the format. Especially avoid "%c". The value of $TZ also
10811 matters.
10812
10813 If the {timestring} cannot be parsed with {format} zero is
10814 returned. If you do not know the format of {timestring} you
10815 can try different {format} values until you get a non-zero
10816 result.
10817
10818 See also |strftime()|.
10819 Examples: >
10820 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
10821< 862156163 >
10822 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
10823< Sun Apr 27 11:53:55 1997 >
10824 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
10825< Sun Apr 27 12:53:55 1997
10826
10827 Can also be used as a |method|: >
10828 GetFormat()->strptime(timestring)
10829<
10830 Not available on all systems. To check use: >
10831 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010832<
10833 Return type: |Number|
10834
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010835
10836strridx({haystack}, {needle} [, {start}]) *strridx()*
10837 The result is a Number, which gives the byte index in
10838 {haystack} of the last occurrence of the String {needle}.
10839 When {start} is specified, matches beyond this index are
10840 ignored. This can be used to find a match before a previous
10841 match: >
10842 :let lastcomma = strridx(line, ",")
10843 :let comma2 = strridx(line, ",", lastcomma - 1)
10844< The search is done case-sensitive.
10845 For pattern searches use |match()|.
10846 -1 is returned if the {needle} does not occur in {haystack}.
10847 If the {needle} is empty the length of {haystack} is returned.
10848 See also |stridx()|. Examples: >
10849 :echo strridx("an angry armadillo", "an") 3
10850< *strrchr()*
10851 When used with a single character it works similar to the C
10852 function strrchr().
10853
10854 Can also be used as a |method|: >
10855 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010856<
10857 Return type: |Number|
10858
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010859
10860strtrans({string}) *strtrans()*
10861 The result is a String, which is {string} with all unprintable
10862 characters translated into printable characters |'isprint'|.
10863 Like they are shown in a window. Example: >
10864 echo strtrans(@a)
10865< This displays a newline in register a as "^@" instead of
10866 starting a new line.
10867
Bram Moolenaard592deb2022-06-17 15:42:40 +010010868 Returns an empty string on error.
10869
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010870 Can also be used as a |method|: >
10871 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010872<
10873 Return type: |String|
10874
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010875
Christian Brabandt67672ef2023-04-24 21:09:54 +010010876strutf16len({string} [, {countcc}]) *strutf16len()*
10877 The result is a Number, which is the number of UTF-16 code
10878 units in String {string} (after converting it to UTF-16).
10879
10880 When {countcc} is TRUE, composing characters are counted
10881 separately.
10882 When {countcc} is omitted or FALSE, composing characters are
10883 ignored.
10884
10885 Returns zero on error.
10886
10887 Also see |strlen()| and |strcharlen()|.
10888 Examples: >
10889 echo strutf16len('a') returns 1
10890 echo strutf16len('©') returns 1
10891 echo strutf16len('😊') returns 2
10892 echo strutf16len('ą́') returns 1
10893 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090010894<
Christian Brabandt67672ef2023-04-24 21:09:54 +010010895 Can also be used as a |method|: >
10896 GetText()->strutf16len()
10897<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010898 Return type: |Number|
10899
10900
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010901strwidth({string}) *strwidth()*
10902 The result is a Number, which is the number of display cells
10903 String {string} occupies. A Tab character is counted as one
10904 cell, alternatively use |strdisplaywidth()|.
10905 When {string} contains characters with East Asian Width Class
10906 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010907 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010908 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
10909
10910 Can also be used as a |method|: >
10911 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010912<
10913 Return type: |Number|
10914
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010915
10916submatch({nr} [, {list}]) *submatch()* *E935*
10917 Only for an expression in a |:substitute| command or
10918 substitute() function.
10919 Returns the {nr}'th submatch of the matched text. When {nr}
10920 is 0 the whole matched text is returned.
10921 Note that a NL in the string can stand for a line break of a
10922 multi-line match or a NUL character in the text.
10923 Also see |sub-replace-expression|.
10924
10925 If {list} is present and non-zero then submatch() returns
10926 a list of strings, similar to |getline()| with two arguments.
10927 NL characters in the text represent NUL characters in the
10928 text.
10929 Only returns more than one item for |:substitute|, inside
10930 |substitute()| this list will always contain one or zero
10931 items, since there are no real line breaks.
10932
10933 When substitute() is used recursively only the submatches in
10934 the current (deepest) call can be obtained.
10935
Bram Moolenaard592deb2022-06-17 15:42:40 +010010936 Returns an empty string or list on error.
10937
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010938 Examples: >
10939 :s/\d\+/\=submatch(0) + 1/
10940 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
10941< This finds the first number in the line and adds one to it.
10942 A line break is included as a newline character.
10943
10944 Can also be used as a |method|: >
10945 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010946<
10947 Return type: |String| or list<string> depending on {list}
10948
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010949
10950substitute({string}, {pat}, {sub}, {flags}) *substitute()*
10951 The result is a String, which is a copy of {string}, in which
10952 the first match of {pat} is replaced with {sub}.
10953 When {flags} is "g", all matches of {pat} in {string} are
10954 replaced. Otherwise {flags} should be "".
10955
10956 This works like the ":substitute" command (without any flags).
10957 But the matching with {pat} is always done like the 'magic'
10958 option is set and 'cpoptions' is empty (to make scripts
10959 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
10960 if you want to ignore or match case and ignore 'ignorecase'.
10961 'smartcase' is not used. See |string-match| for how {pat} is
10962 used.
10963
10964 A "~" in {sub} is not replaced with the previous {sub}.
10965 Note that some codes in {sub} have a special meaning
10966 |sub-replace-special|. For example, to replace something with
10967 "\n" (two characters), use "\\\\n" or '\\n'.
10968
10969 When {pat} does not match in {string}, {string} is returned
10970 unmodified.
10971
10972 Example: >
10973 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
10974< This removes the last component of the 'path' option. >
10975 :echo substitute("testing", ".*", "\\U\\0", "")
10976< results in "TESTING".
10977
10978 When {sub} starts with "\=", the remainder is interpreted as
10979 an expression. See |sub-replace-expression|. Example: >
10980 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010981 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010982
10983< When {sub} is a Funcref that function is called, with one
10984 optional argument. Example: >
10985 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
10986< The optional argument is a list which contains the whole
10987 matched string and up to nine submatches, like what
10988 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010989 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010990
Bram Moolenaard592deb2022-06-17 15:42:40 +010010991< Returns an empty string on error.
10992
10993 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010994 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010995<
10996 Return type: |String|
10997
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010998
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000010999swapfilelist() *swapfilelist()*
11000 Returns a list of swap file names, like what "vim -r" shows.
11001 See the |-r| command argument. The 'directory' option is used
11002 for the directories to inspect. If you only want to get a
11003 list of swap files in the current directory then temporarily
11004 set 'directory' to a dot: >
11005 let save_dir = &directory
11006 let &directory = '.'
11007 let swapfiles = swapfilelist()
11008 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011009<
11010 Return type: list<string>
11011
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011012
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011013swapinfo({fname}) *swapinfo()*
11014 The result is a dictionary, which holds information about the
11015 swapfile {fname}. The available fields are:
11016 version Vim version
11017 user user name
11018 host host name
11019 fname original file name
11020 pid PID of the Vim process that created the swap
11021 file
11022 mtime last modification time in seconds
11023 inode Optional: INODE number of the file
11024 dirty 1 if file was modified, 0 if not
11025 Note that "user" and "host" are truncated to at most 39 bytes.
11026 In case of failure an "error" item is added with the reason:
11027 Cannot open file: file not found or in accessible
11028 Cannot read file: cannot read first block
11029 Not a swap file: does not contain correct block ID
11030 Magic number mismatch: Info in first block is invalid
11031
11032 Can also be used as a |method|: >
11033 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011034<
11035 Return type: dict<any> or dict<string>
11036
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011037
11038swapname({buf}) *swapname()*
11039 The result is the swap file path of the buffer {expr}.
11040 For the use of {buf}, see |bufname()| above.
11041 If buffer {buf} is the current buffer, the result is equal to
11042 |:swapname| (unless there is no swap file).
11043 If buffer {buf} has no swap file, returns an empty string.
11044
11045 Can also be used as a |method|: >
11046 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011047<
11048 Return type: |String|
11049
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011050
11051synID({lnum}, {col}, {trans}) *synID()*
11052 The result is a Number, which is the syntax ID at the position
11053 {lnum} and {col} in the current window.
11054 The syntax ID can be used with |synIDattr()| and
11055 |synIDtrans()| to obtain syntax information about text.
11056
11057 {col} is 1 for the leftmost column, {lnum} is 1 for the first
11058 line. 'synmaxcol' applies, in a longer line zero is returned.
11059 Note that when the position is after the last character,
11060 that's where the cursor can be in Insert mode, synID() returns
11061 zero. {lnum} is used like with |getline()|.
11062
11063 When {trans} is |TRUE|, transparent items are reduced to the
11064 item that they reveal. This is useful when wanting to know
11065 the effective color. When {trans} is |FALSE|, the transparent
11066 item is returned. This is useful when wanting to know which
11067 syntax item is effective (e.g. inside parens).
11068 Warning: This function can be very slow. Best speed is
11069 obtained by going through the file in forward direction.
11070
Bram Moolenaard592deb2022-06-17 15:42:40 +010011071 Returns zero on error.
11072
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011073 Example (echoes the name of the syntax item under the cursor): >
11074 :echo synIDattr(synID(line("."), col("."), 1), "name")
11075<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011076 Return type: |Number|
11077
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011078
11079synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
11080 The result is a String, which is the {what} attribute of
11081 syntax ID {synID}. This can be used to obtain information
11082 about a syntax item.
11083 {mode} can be "gui", "cterm" or "term", to get the attributes
11084 for that mode. When {mode} is omitted, or an invalid value is
11085 used, the attributes for the currently active highlighting are
11086 used (GUI, cterm or term).
11087 Use synIDtrans() to follow linked highlight groups.
11088 {what} result
11089 "name" the name of the syntax item
11090 "fg" foreground color (GUI: color name used to set
11091 the color, cterm: color number as a string,
11092 term: empty string)
11093 "bg" background color (as with "fg")
11094 "font" font name (only available in the GUI)
11095 |highlight-font|
11096 "sp" special color for the GUI (as with "fg")
11097 |highlight-guisp|
11098 "ul" underline color for cterm: number as a string
11099 "fg#" like "fg", but for the GUI and the GUI is
11100 running the name in "#RRGGBB" form
11101 "bg#" like "fg#" for "bg"
11102 "sp#" like "fg#" for "sp"
11103 "bold" "1" if bold
11104 "italic" "1" if italic
11105 "reverse" "1" if reverse
11106 "inverse" "1" if inverse (= reverse)
11107 "standout" "1" if standout
11108 "underline" "1" if underlined
11109 "undercurl" "1" if undercurled
11110 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010011111 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011112
Bram Moolenaard592deb2022-06-17 15:42:40 +010011113 Returns an empty string on error.
11114
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011115 Example (echoes the color of the syntax item under the
11116 cursor): >
11117 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
11118<
11119 Can also be used as a |method|: >
11120 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011121<
11122 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011123
11124
11125synIDtrans({synID}) *synIDtrans()*
11126 The result is a Number, which is the translated syntax ID of
11127 {synID}. This is the syntax group ID of what is being used to
11128 highlight the character. Highlight links given with
11129 ":highlight link" are followed.
11130
Bram Moolenaard592deb2022-06-17 15:42:40 +010011131 Returns zero on error.
11132
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011133 Can also be used as a |method|: >
11134 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011135<
11136 Return type: |Number|
11137
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011138
11139synconcealed({lnum}, {col}) *synconcealed()*
11140 The result is a |List| with currently three items:
11141 1. The first item in the list is 0 if the character at the
11142 position {lnum} and {col} is not part of a concealable
11143 region, 1 if it is. {lnum} is used like with |getline()|.
11144 2. The second item in the list is a string. If the first item
11145 is 1, the second item contains the text which will be
11146 displayed in place of the concealed text, depending on the
11147 current setting of 'conceallevel' and 'listchars'.
11148 3. The third and final item in the list is a number
11149 representing the specific syntax region matched in the
11150 line. When the character is not concealed the value is
11151 zero. This allows detection of the beginning of a new
11152 concealable region if there are two consecutive regions
11153 with the same replacement character. For an example, if
11154 the text is "123456" and both "23" and "45" are concealed
11155 and replaced by the character "X", then:
11156 call returns ~
11157 synconcealed(lnum, 1) [0, '', 0]
11158 synconcealed(lnum, 2) [1, 'X', 1]
11159 synconcealed(lnum, 3) [1, 'X', 1]
11160 synconcealed(lnum, 4) [1, 'X', 2]
11161 synconcealed(lnum, 5) [1, 'X', 2]
11162 synconcealed(lnum, 6) [0, '', 0]
11163
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011164 Note: Doesn't consider |matchadd()| highlighting items,
11165 since syntax and matching highlighting are two different
11166 mechanisms |syntax-vs-match|.
h-east52e7cc22024-07-28 17:03:29 +020011167
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011168 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011169
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011170
11171synstack({lnum}, {col}) *synstack()*
11172 Return a |List|, which is the stack of syntax items at the
11173 position {lnum} and {col} in the current window. {lnum} is
11174 used like with |getline()|. Each item in the List is an ID
11175 like what |synID()| returns.
11176 The first item in the List is the outer region, following are
11177 items contained in that one. The last one is what |synID()|
11178 returns, unless not the whole item is highlighted or it is a
11179 transparent item.
11180 This function is useful for debugging a syntax file.
11181 Example that shows the syntax stack under the cursor: >
11182 for id in synstack(line("."), col("."))
11183 echo synIDattr(id, "name")
11184 endfor
11185< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011186 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011187 character in a line and the first column in an empty line are
11188 valid positions.
11189
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011190 Return type: list<number> or list<any>
11191
11192
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011193system({expr} [, {input}]) *system()* *E677*
11194 Get the output of the shell command {expr} as a |String|. See
11195 |systemlist()| to get the output as a |List|.
11196
11197 When {input} is given and is a |String| this string is written
11198 to a file and passed as stdin to the command. The string is
11199 written as-is, you need to take care of using the correct line
11200 separators yourself.
11201 If {input} is given and is a |List| it is written to the file
11202 in a way |writefile()| does with {binary} set to "b" (i.e.
11203 with a newline between each list item with newlines inside
11204 list items converted to NULs).
11205 When {input} is given and is a number that is a valid id for
11206 an existing buffer then the content of the buffer is written
11207 to the file line by line, each line terminated by a NL and
11208 NULs characters where the text has a NL.
11209
11210 Pipes are not used, the 'shelltemp' option is not used.
11211
11212 When prepended by |:silent| the terminal will not be set to
11213 cooked mode. This is meant to be used for commands that do
11214 not need the user to type. It avoids stray characters showing
11215 up on the screen which require |CTRL-L| to remove. >
11216 :silent let f = system('ls *.vim')
11217<
11218 Note: Use |shellescape()| or |::S| with |expand()| or
11219 |fnamemodify()| to escape special characters in a command
11220 argument. Newlines in {expr} may cause the command to fail.
11221 The characters in 'shellquote' and 'shellxquote' may also
11222 cause trouble.
11223 This is not to be used for interactive commands.
11224
11225 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011226 :let files = system('ls ' .. shellescape(expand('%:h')))
11227 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011228
11229< To make the result more system-independent, the shell output
11230 is filtered to replace <CR> with <NL> for Macintosh, and
11231 <CR><NL> with <NL> for DOS-like systems.
11232 To avoid the string being truncated at a NUL, all NUL
11233 characters are replaced with SOH (0x01).
11234
11235 The command executed is constructed using several options:
11236 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11237 ({tmp} is an automatically generated file name).
11238 For Unix, braces are put around {expr} to allow for
11239 concatenated commands.
11240
11241 The command will be executed in "cooked" mode, so that a
11242 CTRL-C will interrupt the command (on Unix at least).
11243
11244 The resulting error code can be found in |v:shell_error|.
11245 This function will fail in |restricted-mode|.
11246
11247 Note that any wrong value in the options mentioned above may
11248 make the function fail. It has also been reported to fail
11249 when using a security agent application.
11250 Unlike ":!cmd" there is no automatic check for changed files.
11251 Use |:checktime| to force a check.
11252
11253 Can also be used as a |method|: >
11254 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011255<
11256 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011257
11258
11259systemlist({expr} [, {input}]) *systemlist()*
11260 Same as |system()|, but returns a |List| with lines (parts of
11261 output separated by NL) with NULs transformed into NLs. Output
11262 is the same as |readfile()| will output with {binary} argument
11263 set to "b", except that there is no extra empty item when the
11264 result ends in a NL.
11265 Note that on MS-Windows you may get trailing CR characters.
11266
11267 To see the difference between "echo hello" and "echo -n hello"
11268 use |system()| and |split()|: >
11269 echo system('echo hello')->split('\n', 1)
11270<
11271 Returns an empty string on error.
11272
11273 Can also be used as a |method|: >
11274 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011275<
11276 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011277
11278
11279tabpagebuflist([{arg}]) *tabpagebuflist()*
11280 The result is a |List|, where each item is the number of the
11281 buffer associated with each window in the current tab page.
11282 {arg} specifies the number of the tab page to be used. When
11283 omitted the current tab page is used.
11284 When {arg} is invalid the number zero is returned.
11285 To get a list of all buffers in all tabs use this: >
11286 let buflist = []
11287 for i in range(tabpagenr('$'))
11288 call extend(buflist, tabpagebuflist(i + 1))
11289 endfor
11290< Note that a buffer may appear in more than one window.
11291
11292 Can also be used as a |method|: >
11293 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011294<
11295 Return type: list<number>
11296
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011297
11298tabpagenr([{arg}]) *tabpagenr()*
11299 The result is a Number, which is the number of the current
11300 tab page. The first tab page has number 1.
11301
11302 The optional argument {arg} supports the following values:
11303 $ the number of the last tab page (the tab page
11304 count).
11305 # the number of the last accessed tab page
11306 (where |g<Tab>| goes to). if there is no
11307 previous tab page 0 is returned.
11308 The number can be used with the |:tab| command.
11309
Bram Moolenaard592deb2022-06-17 15:42:40 +010011310 Returns zero on error.
11311
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011312 Return type: |Number|
11313
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011314
11315tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11316 Like |winnr()| but for tab page {tabarg}.
11317 {tabarg} specifies the number of tab page to be used.
11318 {arg} is used like with |winnr()|:
11319 - When omitted the current window number is returned. This is
11320 the window which will be used when going to this tab page.
11321 - When "$" the number of windows is returned.
11322 - When "#" the previous window nr is returned.
11323 Useful examples: >
11324 tabpagewinnr(1) " current window of tab page 1
11325 tabpagewinnr(4, '$') " number of windows in tab page 4
11326< When {tabarg} is invalid zero is returned.
11327
11328 Can also be used as a |method|: >
11329 GetTabpage()->tabpagewinnr()
11330<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011331 Return type: |Number|
11332
11333
11334tagfiles() *tagfiles()*
11335 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011336 for the current buffer. This is the 'tags' option expanded.
11337
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011338 Return type: list<string> or list<any>
11339
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011340
11341taglist({expr} [, {filename}]) *taglist()*
11342 Returns a |List| of tags matching the regular expression {expr}.
11343
11344 If {filename} is passed it is used to prioritize the results
11345 in the same way that |:tselect| does. See |tag-priority|.
11346 {filename} should be the full path of the file.
11347
11348 Each list item is a dictionary with at least the following
11349 entries:
11350 name Name of the tag.
11351 filename Name of the file where the tag is
11352 defined. It is either relative to the
11353 current directory or a full path.
11354 cmd Ex command used to locate the tag in
11355 the file.
11356 kind Type of the tag. The value for this
11357 entry depends on the language specific
11358 kind values. Only available when
11359 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011360 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011361 static A file specific tag. Refer to
11362 |static-tag| for more information.
11363 More entries may be present, depending on the content of the
11364 tags file: access, implementation, inherits and signature.
11365 Refer to the ctags documentation for information about these
11366 fields. For C code the fields "struct", "class" and "enum"
11367 may appear, they give the name of the entity the tag is
11368 contained in.
11369
11370 The ex-command "cmd" can be either an ex search pattern, a
11371 line number or a line number followed by a byte number.
11372
11373 If there are no matching tags, then an empty list is returned.
11374
11375 To get an exact tag match, the anchors '^' and '$' should be
11376 used in {expr}. This also make the function work faster.
11377 Refer to |tag-regexp| for more information about the tag
11378 search regular expression pattern.
11379
11380 Refer to |'tags'| for information about how the tags file is
11381 located by Vim. Refer to |tags-file-format| for the format of
11382 the tags file generated by the different ctags tools.
11383
11384 Can also be used as a |method|: >
11385 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011386<
11387 Return type: list<dict<any>> or list<any>
11388
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011389
11390tan({expr}) *tan()*
11391 Return the tangent of {expr}, measured in radians, as a |Float|
11392 in the range [-inf, inf].
11393 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011394 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011395 Examples: >
11396 :echo tan(10)
11397< 0.648361 >
11398 :echo tan(-4.01)
11399< -1.181502
11400
11401 Can also be used as a |method|: >
11402 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011403<
11404 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011405
11406
11407tanh({expr}) *tanh()*
11408 Return the hyperbolic tangent of {expr} as a |Float| in the
11409 range [-1, 1].
11410 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011411 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011412 Examples: >
11413 :echo tanh(0.5)
11414< 0.462117 >
11415 :echo tanh(-1)
11416< -0.761594
11417
11418 Can also be used as a |method|: >
11419 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011420<
11421 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011422
11423
11424tempname() *tempname()* *temp-file-name*
11425 The result is a String, which is the name of a file that
11426 doesn't exist. It can be used for a temporary file. The name
11427 is different for at least 26 consecutive calls. Example: >
11428 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011429 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011430< For Unix, the file will be in a private directory |tempfile|
11431 that is recursively deleted when Vim exits, on other systems
11432 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011433 For MS-Windows forward slashes are used when the 'shellslash'
11434 option is set, or when 'shellcmdflag' starts with '-' and
11435 'shell' does not contain powershell or pwsh.
11436
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011437 Return type: |String|
11438
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011439
11440term_ functions are documented here: |terminal-function-details|
11441
11442
11443terminalprops() *terminalprops()*
11444 Returns a |Dictionary| with properties of the terminal that Vim
11445 detected from the response to |t_RV| request. See
11446 |v:termresponse| for the response itself. If |v:termresponse|
11447 is empty most values here will be 'u' for unknown.
11448 cursor_style whether sending |t_RS| works **
11449 cursor_blink_mode whether sending |t_RC| works **
11450 underline_rgb whether |t_8u| works **
11451 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011452 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011453
11454 ** value 'u' for unknown, 'y' for yes, 'n' for no
11455
11456 If the |+termresponse| feature is missing then the result is
11457 an empty dictionary.
11458
11459 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11460 current cursor style.
11461 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11462 request the cursor blink status.
11463 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11464 is not empty, Vim will detect the working of sending |t_RS|
11465 and |t_RC| on startup.
11466
11467 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11468 This avoids sending it to xterm, which would clear the colors.
11469
11470 For "mouse" the value 'u' is unknown
11471
11472 Also see:
11473 - 'ambiwidth' - detected by using |t_u7|.
11474 - |v:termstyleresp| and |v:termblinkresp| for the response to
11475 |t_RS| and |t_RC|.
11476
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011477 Return type: dict<string>
11478
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011479
11480test_ functions are documented here: |test-functions-details|
11481
11482
11483 *timer_info()*
11484timer_info([{id}])
11485 Return a list with information about timers.
11486 When {id} is given only information about this timer is
11487 returned. When timer {id} does not exist an empty list is
11488 returned.
11489 When {id} is omitted information about all timers is returned.
11490
11491 For each timer the information is stored in a |Dictionary| with
11492 these items:
11493 "id" the timer ID
11494 "time" time the timer was started with
11495 "remaining" time until the timer fires
11496 "repeat" number of times the timer will still fire;
11497 -1 means forever
11498 "callback" the callback
11499 "paused" 1 if the timer is paused, 0 otherwise
11500
11501 Can also be used as a |method|: >
11502 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011503<
11504 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011505
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011506 {only available when compiled with the |+timers| feature}
11507
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011508
11509timer_pause({timer}, {paused}) *timer_pause()*
11510 Pause or unpause a timer. A paused timer does not invoke its
11511 callback when its time expires. Unpausing a timer may cause
11512 the callback to be invoked almost immediately if enough time
11513 has passed.
11514
11515 Pausing a timer is useful to avoid the callback to be called
11516 for a short time.
11517
11518 If {paused} evaluates to a non-zero Number or a non-empty
11519 String, then the timer is paused, otherwise it is unpaused.
11520 See |non-zero-arg|.
11521
11522 Can also be used as a |method|: >
11523 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011524<
11525 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011526
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011527 {only available when compiled with the |+timers| feature}
11528
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011529
11530 *timer_start()* *timer* *timers*
11531timer_start({time}, {callback} [, {options}])
11532 Create a timer and return the timer ID.
11533
11534 {time} is the waiting time in milliseconds. This is the
11535 minimum time before invoking the callback. When the system is
11536 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011537 Zero can be used to execute the callback when Vim is back in
11538 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011539
11540 {callback} is the function to call. It can be the name of a
11541 function or a |Funcref|. It is called with one argument, which
11542 is the timer ID. The callback is only invoked when Vim is
11543 waiting for input.
11544 If you want to show a message look at |popup_notification()|
11545 to avoid interfering with what the user is doing.
11546
11547 {options} is a dictionary. Supported entries:
11548 "repeat" Number of times to repeat calling the
11549 callback. -1 means forever. When not present
11550 the callback will be called once.
11551 If the timer causes an error three times in a
11552 row the repeat is cancelled. This avoids that
11553 Vim becomes unusable because of all the error
11554 messages.
11555
Bram Moolenaard592deb2022-06-17 15:42:40 +010011556 Returns -1 on error.
11557
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011558 Example: >
11559 func MyHandler(timer)
11560 echo 'Handler called'
11561 endfunc
11562 let timer = timer_start(500, 'MyHandler',
11563 \ {'repeat': 3})
11564< This will invoke MyHandler() three times at 500 msec
11565 intervals.
11566
11567 Can also be used as a |method|: >
11568 GetMsec()->timer_start(callback)
11569
11570< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011571
11572 Return type: |Number|
11573
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011574 {only available when compiled with the |+timers| feature}
11575
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011576
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011577timer_stop({timer}) *timer_stop()*
11578 Stop a timer. The timer callback will no longer be invoked.
11579 {timer} is an ID returned by timer_start(), thus it must be a
11580 Number. If {timer} does not exist there is no error.
11581
11582 Can also be used as a |method|: >
11583 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011584<
11585 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011586
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011587 {only available when compiled with the |+timers| feature}
11588
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011589
11590timer_stopall() *timer_stopall()*
11591 Stop all timers. The timer callbacks will no longer be
11592 invoked. Useful if a timer is misbehaving. If there are no
11593 timers there is no error.
11594
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011595 Return type: |Number|
11596
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011597 {only available when compiled with the |+timers| feature}
11598
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011599
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011600tolower({expr}) *tolower()*
11601 The result is a copy of the String given, with all uppercase
11602 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011603 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011604
11605 Can also be used as a |method|: >
11606 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011607<
11608 Return type: |String|
11609
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011610
11611toupper({expr}) *toupper()*
11612 The result is a copy of the String given, with all lowercase
11613 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011614 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011615
11616 Can also be used as a |method|: >
11617 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011618<
11619 Return type: |String|
11620
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011621
11622tr({src}, {fromstr}, {tostr}) *tr()*
11623 The result is a copy of the {src} string with all characters
11624 which appear in {fromstr} replaced by the character in that
11625 position in the {tostr} string. Thus the first character in
11626 {fromstr} is translated into the first character in {tostr}
11627 and so on. Exactly like the unix "tr" command.
11628 This code also deals with multibyte characters properly.
11629
Bram Moolenaard592deb2022-06-17 15:42:40 +010011630 Returns an empty string on error.
11631
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011632 Examples: >
11633 echo tr("hello there", "ht", "HT")
11634< returns "Hello THere" >
11635 echo tr("<blob>", "<>", "{}")
11636< returns "{blob}"
11637
11638 Can also be used as a |method|: >
11639 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011640<
11641 Return type: |String|
11642
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011643
11644trim({text} [, {mask} [, {dir}]]) *trim()*
11645 Return {text} as a String where any character in {mask} is
11646 removed from the beginning and/or end of {text}.
11647
Illia Bobyr80799172023-10-17 18:00:50 +020011648 If {mask} is not given, or is an empty string, {mask} is all
11649 characters up to 0x20, which includes Tab, space, NL and CR,
11650 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011651
11652 The optional {dir} argument specifies where to remove the
11653 characters:
11654 0 remove from the beginning and end of {text}
11655 1 remove only at the beginning of {text}
11656 2 remove only at the end of {text}
11657 When omitted both ends are trimmed.
11658
11659 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011660 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011661
11662 Examples: >
11663 echo trim(" some text ")
11664< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011665 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011666< returns "RESERVE_TAIL" >
11667 echo trim("rm<Xrm<>X>rrm", "rm<>")
11668< returns "Xrm<>X" (characters in the middle are not removed) >
11669 echo trim(" vim ", " ", 2)
11670< returns " vim"
11671
11672 Can also be used as a |method|: >
11673 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011674<
11675 Return type: |String|
11676
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011677
11678trunc({expr}) *trunc()*
11679 Return the largest integral value with magnitude less than or
11680 equal to {expr} as a |Float| (truncate towards zero).
11681 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011682 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011683 Examples: >
11684 echo trunc(1.456)
11685< 1.0 >
11686 echo trunc(-5.456)
11687< -5.0 >
11688 echo trunc(4.0)
11689< 4.0
11690
11691 Can also be used as a |method|: >
11692 Compute()->trunc()
11693<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011694 Return type: |Float|
11695
11696
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011697 *type()*
11698type({expr}) The result is a Number representing the type of {expr}.
11699 Instead of using the number directly, it is better to use the
11700 v:t_ variable that has the value:
11701 Number: 0 |v:t_number|
11702 String: 1 |v:t_string|
11703 Funcref: 2 |v:t_func|
11704 List: 3 |v:t_list|
11705 Dictionary: 4 |v:t_dict|
11706 Float: 5 |v:t_float|
11707 Boolean: 6 |v:t_bool| (v:false and v:true)
11708 None: 7 |v:t_none| (v:null and v:none)
11709 Job: 8 |v:t_job|
11710 Channel: 9 |v:t_channel|
11711 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090011712 Class: 12 |v:t_class|
11713 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010011714 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011715 Enum: 15 |v:t_enum|
11716 EnumValue: 16 |v:t_enumvalue|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011717 For backward compatibility, this method can be used: >
11718 :if type(myvar) == type(0)
11719 :if type(myvar) == type("")
11720 :if type(myvar) == type(function("tr"))
11721 :if type(myvar) == type([])
11722 :if type(myvar) == type({})
11723 :if type(myvar) == type(0.0)
11724 :if type(myvar) == type(v:false)
11725 :if type(myvar) == type(v:none)
11726< To check if the v:t_ variables exist use this: >
11727 :if exists('v:t_number')
11728
11729< Can also be used as a |method|: >
11730 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011731<
11732 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011733
11734
11735typename({expr}) *typename()*
11736 Return a string representation of the type of {expr}.
11737 Example: >
11738 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000011739< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011740
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011741 Return type: |String|
11742
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011743
11744undofile({name}) *undofile()*
11745 Return the name of the undo file that would be used for a file
11746 with name {name} when writing. This uses the 'undodir'
11747 option, finding directories that exist. It does not check if
11748 the undo file exists.
11749 {name} is always expanded to the full path, since that is what
11750 is used internally.
11751 If {name} is empty undofile() returns an empty string, since a
11752 buffer without a file name will not write an undo file.
11753 Useful in combination with |:wundo| and |:rundo|.
11754 When compiled without the |+persistent_undo| option this always
11755 returns an empty string.
11756
11757 Can also be used as a |method|: >
11758 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011759<
11760 Return type: |String|
11761
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011762
Devin J. Pohly5fee1112023-04-23 20:26:59 -050011763undotree([{buf}]) *undotree()*
11764 Return the current state of the undo tree for the current
11765 buffer, or for a specific buffer if {buf} is given. The
11766 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011767 "seq_last" The highest undo sequence number used.
11768 "seq_cur" The sequence number of the current position in
11769 the undo tree. This differs from "seq_last"
11770 when some changes were undone.
11771 "time_cur" Time last used for |:earlier| and related
11772 commands. Use |strftime()| to convert to
11773 something readable.
11774 "save_last" Number of the last file write. Zero when no
11775 write yet.
11776 "save_cur" Number of the current position in the undo
11777 tree.
11778 "synced" Non-zero when the last undo block was synced.
11779 This happens when waiting from input from the
11780 user. See |undo-blocks|.
11781 "entries" A list of dictionaries with information about
11782 undo blocks.
11783
11784 The first item in the "entries" list is the oldest undo item.
11785 Each List item is a |Dictionary| with these items:
11786 "seq" Undo sequence number. Same as what appears in
11787 |:undolist|.
11788 "time" Timestamp when the change happened. Use
11789 |strftime()| to convert to something readable.
11790 "newhead" Only appears in the item that is the last one
11791 that was added. This marks the last change
11792 and where further changes will be added.
11793 "curhead" Only appears in the item that is the last one
11794 that was undone. This marks the current
11795 position in the undo tree, the block that will
11796 be used by a redo command. When nothing was
11797 undone after the last change this item will
11798 not appear anywhere.
11799 "save" Only appears on the last block before a file
11800 write. The number is the write count. The
11801 first write has number 1, the last one the
11802 "save_last" mentioned above.
11803 "alt" Alternate entry. This is again a List of undo
11804 blocks. Each item may again have an "alt"
11805 item.
11806
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011807 Return type: dict<any>
11808
11809
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011810uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
11811 Remove second and succeeding copies of repeated adjacent
11812 {list} items in-place. Returns {list}. If you want a list
11813 to remain unmodified make a copy first: >
11814 :let newlist = uniq(copy(mylist))
11815< The default compare function uses the string representation of
11816 each item. For the use of {func} and {dict} see |sort()|.
11817
Bram Moolenaard592deb2022-06-17 15:42:40 +010011818 Returns zero if {list} is not a |List|.
11819
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011820 Can also be used as a |method|: >
11821 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010011822<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011823 Return type: list<{type}>
11824
11825
Christian Brabandt67672ef2023-04-24 21:09:54 +010011826 *utf16idx()*
11827utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011828 Same as |charidx()| but returns the UTF-16 code unit index of
11829 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010011830
11831 When {charidx} is present and TRUE, {idx} is used as the
11832 character index in the String {string} instead of as the byte
11833 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010011834 An {idx} in the middle of a UTF-8 sequence is rounded
11835 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010011836
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011837 Returns -1 if the arguments are invalid or if there are less
11838 than {idx} bytes in {string}. If there are exactly {idx} bytes
11839 the length of the string in UTF-16 code units is returned.
11840
Christian Brabandt67672ef2023-04-24 21:09:54 +010011841 See |byteidx()| and |byteidxcomp()| for getting the byte index
11842 from the UTF-16 index and |charidx()| for getting the
11843 character index from the UTF-16 index.
11844 Refer to |string-offset-encoding| for more information.
11845 Examples: >
11846 echo utf16idx('a😊😊', 3) returns 2
11847 echo utf16idx('a😊😊', 7) returns 4
11848 echo utf16idx('a😊😊', 1, 0, 1) returns 2
11849 echo utf16idx('a😊😊', 2, 0, 1) returns 4
11850 echo utf16idx('aą́c', 6) returns 2
11851 echo utf16idx('aą́c', 6, 1) returns 4
11852 echo utf16idx('a😊😊', 9) returns -1
11853<
11854 Can also be used as a |method|: >
11855 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011856<
11857 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010011858
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011859
11860values({dict}) *values()*
11861 Return a |List| with all the values of {dict}. The |List| is
11862 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011863 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011864
11865 Can also be used as a |method|: >
11866 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011867<
11868 Return type: list<any>
11869
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011870
zeertzjq825cf812023-08-17 22:55:25 +020011871virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011872 The result is a Number, which is the screen column of the file
11873 position given with {expr}. That is, the last screen position
11874 occupied by the character at that position, when the screen
11875 would be of unlimited width. When there is a <Tab> at the
11876 position, the returned Number will be the column at the end of
11877 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
11878 set to 8, it returns 8. |conceal| is ignored.
11879 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011880
zeertzjq02f3eba2024-06-12 20:45:24 +020011881 For the use of {expr} see |getpos()| and |col()|.
zeertzjqd353d272024-06-13 23:00:25 +080011882 When {expr} is "$", it means the end of the cursor line, so
11883 the result is the number of cells in the cursor line plus one.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011884
11885 When 'virtualedit' is used {expr} can be [lnum, col, off],
11886 where "off" is the offset in screen columns from the start of
11887 the character. E.g., a position within a <Tab> or after the
11888 last character. When "off" is omitted zero is used. When
11889 Virtual editing is active in the current mode, a position
11890 beyond the end of the line can be returned. Also see
11891 |'virtualedit'|
11892
zeertzjq825cf812023-08-17 22:55:25 +020011893 If {list} is present and non-zero then virtcol() returns a
11894 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010011895 character.
11896
zeertzjq825cf812023-08-17 22:55:25 +020011897 With the optional {winid} argument the values are obtained for
11898 that window instead of the current window.
11899
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011900 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +020011901
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011902 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010011903 " With text "foo^Lbar" and cursor on the "^L":
11904
11905 virtcol(".") " returns 5
11906 virtcol(".", 1) " returns [4, 5]
11907 virtcol("$") " returns 9
11908
11909 " With text " there", with 't at 'h':
11910
11911 virtcol("'t") " returns 6
zeertzjq02f3eba2024-06-12 20:45:24 +020011912<
11913 The first column is 1. 0 or [0, 0] is returned for an error.
11914
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011915 A more advanced example that echoes the maximum length of
11916 all lines: >
11917 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
11918
11919< Can also be used as a |method|: >
11920 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011921<
11922 Return type: |Number|
11923
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011924
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011925virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
11926 The result is a Number, which is the byte index of the
11927 character in window {winid} at buffer line {lnum} and virtual
11928 column {col}.
11929
zeertzjqb583eda2023-10-14 11:32:28 +020011930 If buffer line {lnum} is an empty line, 0 is returned.
11931
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011932 If {col} is greater than the last virtual column in line
11933 {lnum}, then the byte index of the character at the last
11934 virtual column is returned.
11935
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020011936 For a multi-byte character, the column number of the first
11937 byte in the character is returned.
11938
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011939 The {winid} argument can be the window number or the
11940 |window-ID|. If this is zero, then the current window is used.
11941
11942 Returns -1 if the window {winid} doesn't exist or the buffer
11943 line {lnum} or virtual column {col} is invalid.
11944
11945 See also |screenpos()|, |virtcol()| and |col()|.
11946
11947 Can also be used as a |method|: >
11948 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011949<
11950 Return type: |Number|
11951
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011952
11953visualmode([{expr}]) *visualmode()*
11954 The result is a String, which describes the last Visual mode
11955 used in the current buffer. Initially it returns an empty
11956 string, but once Visual mode has been used, it returns "v",
11957 "V", or "<CTRL-V>" (a single CTRL-V character) for
11958 character-wise, line-wise, or block-wise Visual mode
11959 respectively.
11960 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011961 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011962< This enters the same Visual mode as before. It is also useful
11963 in scripts if you wish to act differently depending on the
11964 Visual mode that was used.
11965 If Visual mode is active, use |mode()| to get the Visual mode
11966 (e.g., in a |:vmap|).
11967 If {expr} is supplied and it evaluates to a non-zero Number or
11968 a non-empty String, then the Visual mode will be cleared and
11969 the old value is returned. See |non-zero-arg|.
11970
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011971 Return type: |String|
11972
11973
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011974wildmenumode() *wildmenumode()*
11975 Returns |TRUE| when the wildmenu is active and |FALSE|
11976 otherwise. See 'wildmenu' and 'wildmode'.
11977 This can be used in mappings to handle the 'wildcharm' option
11978 gracefully. (Makes only sense with |mapmode-c| mappings).
11979
11980 For example to make <c-j> work like <down> in wildmode, use: >
11981 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
11982<
Milly6c2fc372024-10-16 22:11:17 +020011983 (Note: this needs the 'wildcharm' option set appropriately).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011984
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011985 Return type: |Number|
11986
11987
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011988win_execute({id}, {command} [, {silent}]) *win_execute()*
11989 Like `execute()` but in the context of window {id}.
11990 The window will temporarily be made the current window,
11991 without triggering autocommands or changing directory. When
11992 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010011993 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011994 Example: >
11995 call win_execute(winid, 'set syntax=python')
11996< Doing the same with `setwinvar()` would not trigger
11997 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011998 *E994*
11999 Not all commands are allowed in popup windows.
12000 When window {id} does not exist then no error is given and
12001 an empty string is returned.
12002
12003 Can also be used as a |method|, the base is passed as the
12004 second argument: >
12005 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012006<
12007 Return type: |String|
12008
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012009
12010win_findbuf({bufnr}) *win_findbuf()*
12011 Returns a |List| with |window-ID|s for windows that contain
12012 buffer {bufnr}. When there is none the list is empty.
12013
12014 Can also be used as a |method|: >
12015 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012016<
12017 Return type: list<number> or list<any>
12018
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012019
12020win_getid([{win} [, {tab}]]) *win_getid()*
12021 Get the |window-ID| for the specified window.
12022 When {win} is missing use the current window.
12023 With {win} this is the window number. The top window has
12024 number 1.
12025 Without {tab} use the current tab, otherwise the tab with
12026 number {tab}. The first tab has number one.
12027 Return zero if the window cannot be found.
12028
12029 Can also be used as a |method|: >
12030 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012031<
12032 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012033
12034
12035win_gettype([{nr}]) *win_gettype()*
12036 Return the type of the window:
12037 "autocmd" autocommand window. Temporary window
12038 used to execute autocommands.
12039 "command" command-line window |cmdwin|
12040 (empty) normal window
12041 "loclist" |location-list-window|
12042 "popup" popup window |popup|
12043 "preview" preview window |preview-window|
12044 "quickfix" |quickfix-window|
12045 "unknown" window {nr} not found
12046
12047 When {nr} is omitted return the type of the current window.
12048 When {nr} is given return the type of this window by number or
12049 |window-ID|.
12050
12051 Also see the 'buftype' option. When running a terminal in a
12052 popup window then 'buftype' is "terminal" and win_gettype()
12053 returns "popup".
12054
12055 Can also be used as a |method|: >
12056 GetWinid()->win_gettype()
12057<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012058 Return type: |String|
12059
12060
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012061win_gotoid({expr}) *win_gotoid()*
12062 Go to window with ID {expr}. This may also change the current
12063 tabpage.
12064 Return TRUE if successful, FALSE if the window cannot be found.
12065
12066 Can also be used as a |method|: >
12067 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012068<
12069 Return type: |Number|
12070
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012071
12072win_id2tabwin({expr}) *win_id2tabwin()*
12073 Return a list with the tab number and window number of window
12074 with ID {expr}: [tabnr, winnr].
12075 Return [0, 0] if the window cannot be found.
12076
12077 Can also be used as a |method|: >
12078 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012079<
12080 Return type: list<number>
12081
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012082
12083win_id2win({expr}) *win_id2win()*
12084 Return the window number of window with ID {expr}.
12085 Return 0 if the window cannot be found in the current tabpage.
12086
12087 Can also be used as a |method|: >
12088 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012089<
12090 Return type: |Number|
12091
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012092
Daniel Steinbergee630312022-01-10 13:36:34 +000012093win_move_separator({nr}, {offset}) *win_move_separator()*
12094 Move window {nr}'s vertical separator (i.e., the right border)
12095 by {offset} columns, as if being dragged by the mouse. {nr}
12096 can be a window number or |window-ID|. A positive {offset}
12097 moves right and a negative {offset} moves left. Moving a
12098 window's vertical separator will change the width of the
12099 window and the width of other windows adjacent to the vertical
12100 separator. The magnitude of movement may be smaller than
12101 specified (e.g., as a consequence of maintaining
12102 'winminwidth'). Returns TRUE if the window can be found and
12103 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012104 This will fail for the rightmost window and a full-width
12105 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012106 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000012107
12108 Can also be used as a |method|: >
12109 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012110<
12111 Return type: |Number|
12112
Daniel Steinbergee630312022-01-10 13:36:34 +000012113
12114win_move_statusline({nr}, {offset}) *win_move_statusline()*
12115 Move window {nr}'s status line (i.e., the bottom border) by
12116 {offset} rows, as if being dragged by the mouse. {nr} can be a
12117 window number or |window-ID|. A positive {offset} moves down
12118 and a negative {offset} moves up. Moving a window's status
12119 line will change the height of the window and the height of
12120 other windows adjacent to the status line. The magnitude of
12121 movement may be smaller than specified (e.g., as a consequence
12122 of maintaining 'winminheight'). Returns TRUE if the window can
12123 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012124 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000012125
12126 Can also be used as a |method|: >
12127 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012128<
12129 Return type: |Number|
12130
Daniel Steinbergee630312022-01-10 13:36:34 +000012131
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012132win_screenpos({nr}) *win_screenpos()*
12133 Return the screen position of window {nr} as a list with two
12134 numbers: [row, col]. The first window always has position
12135 [1, 1], unless there is a tabline, then it is [2, 1].
12136 {nr} can be the window number or the |window-ID|. Use zero
12137 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012138 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012139
12140 Can also be used as a |method|: >
12141 GetWinid()->win_screenpos()
12142<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012143 Return type: list<number>
12144
12145
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012146win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012147 Temporarily switch to window {target}, then move window {nr}
12148 to a new split adjacent to {target}.
12149 Unlike commands such as |:split|, no new windows are created
12150 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012151
12152 Both {nr} and {target} can be window numbers or |window-ID|s.
12153 Both must be in the current tab page.
12154
12155 Returns zero for success, non-zero for failure.
12156
12157 {options} is a |Dictionary| with the following optional entries:
12158 "vertical" When TRUE, the split is created vertically,
12159 like with |:vsplit|.
12160 "rightbelow" When TRUE, the split is made below or to the
12161 right (if vertical). When FALSE, it is done
12162 above or to the left (if vertical). When not
12163 present, the values of 'splitbelow' and
12164 'splitright' are used.
12165
12166 Can also be used as a |method|: >
12167 GetWinid()->win_splitmove(target)
12168<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012169 Return type: |Number|
12170
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012171
12172 *winbufnr()*
12173winbufnr({nr}) The result is a Number, which is the number of the buffer
12174 associated with window {nr}. {nr} can be the window number or
12175 the |window-ID|.
12176 When {nr} is zero, the number of the buffer in the current
12177 window is returned.
12178 When window {nr} doesn't exist, -1 is returned.
12179 Example: >
12180 :echo "The file in the current window is " . bufname(winbufnr(0))
12181<
12182 Can also be used as a |method|: >
12183 FindWindow()->winbufnr()->bufname()
12184<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012185 Return type: |Number|
12186
12187
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012188 *wincol()*
12189wincol() The result is a Number, which is the virtual column of the
12190 cursor in the window. This is counting screen cells from the
12191 left side of the window. The leftmost column is one.
12192
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012193 Return type: |Number|
12194
12195
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012196 *windowsversion()*
12197windowsversion()
12198 The result is a String. For MS-Windows it indicates the OS
12199 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12200 Windows XP is "5.1". For non-MS-Windows systems the result is
12201 an empty string.
12202
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012203 Return type: |String|
12204
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012205winheight({nr}) *winheight()*
12206 The result is a Number, which is the height of window {nr}.
12207 {nr} can be the window number or the |window-ID|.
12208 When {nr} is zero, the height of the current window is
12209 returned. When window {nr} doesn't exist, -1 is returned.
12210 An existing window always has a height of zero or more.
12211 This excludes any window toolbar line.
12212 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012213 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012214
12215< Can also be used as a |method|: >
12216 GetWinid()->winheight()
12217<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012218 Return type: |Number|
12219
12220
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012221winlayout([{tabnr}]) *winlayout()*
12222 The result is a nested List containing the layout of windows
12223 in a tabpage.
12224
12225 Without {tabnr} use the current tabpage, otherwise the tabpage
12226 with number {tabnr}. If the tabpage {tabnr} is not found,
12227 returns an empty list.
12228
12229 For a leaf window, it returns:
12230 ['leaf', {winid}]
12231 For horizontally split windows, which form a column, it
12232 returns:
12233 ['col', [{nested list of windows}]]
12234 For vertically split windows, which form a row, it returns:
12235 ['row', [{nested list of windows}]]
12236
12237 Example: >
12238 " Only one window in the tab page
12239 :echo winlayout()
12240 ['leaf', 1000]
12241 " Two horizontally split windows
12242 :echo winlayout()
12243 ['col', [['leaf', 1000], ['leaf', 1001]]]
12244 " The second tab page, with three horizontally split
12245 " windows, with two vertically split windows in the
12246 " middle window
12247 :echo winlayout(2)
12248 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12249 ['leaf', 1001]]], ['leaf', 1000]]]
12250<
12251 Can also be used as a |method|: >
12252 GetTabnr()->winlayout()
12253<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012254 Return type: list<any>
12255
12256
12257winline() *winline()*
12258 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012259 in the window. This is counting screen lines from the top of
12260 the window. The first line is one.
12261 If the cursor was moved the view on the file will be updated
12262 first, this may cause a scroll.
12263
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012264 Return type: |Number|
12265
12266
12267winnr([{arg}]) *winnr()*
12268 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012269 window. The top window has number 1.
12270 Returns zero for a popup window.
12271
12272 The optional argument {arg} supports the following values:
12273 $ the number of the last window (the window
12274 count).
12275 # the number of the last accessed window (where
12276 |CTRL-W_p| goes to). If there is no previous
12277 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012278 returned. May refer to the current window in
12279 some cases (e.g. when evaluating 'statusline'
12280 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012281 {N}j the number of the Nth window below the
12282 current window (where |CTRL-W_j| goes to).
12283 {N}k the number of the Nth window above the current
12284 window (where |CTRL-W_k| goes to).
12285 {N}h the number of the Nth window left of the
12286 current window (where |CTRL-W_h| goes to).
12287 {N}l the number of the Nth window right of the
12288 current window (where |CTRL-W_l| goes to).
12289 The number can be used with |CTRL-W_w| and ":wincmd w"
12290 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012291 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012292 Also see |tabpagewinnr()| and |win_getid()|.
12293 Examples: >
12294 let window_count = winnr('$')
12295 let prev_window = winnr('#')
12296 let wnum = winnr('3k')
12297
12298< Can also be used as a |method|: >
12299 GetWinval()->winnr()
12300<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012301 Return type: |Number|
12302
12303
12304winrestcmd() *winrestcmd()*
12305 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012306 the current window sizes. Only works properly when no windows
12307 are opened or closed and the current window and tab page is
12308 unchanged.
12309 Example: >
12310 :let cmd = winrestcmd()
12311 :call MessWithWindowSizes()
12312 :exe cmd
12313<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012314 Return type: |String|
12315
12316
12317winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012318 Uses the |Dictionary| returned by |winsaveview()| to restore
12319 the view of the current window.
12320 Note: The {dict} does not have to contain all values, that are
12321 returned by |winsaveview()|. If values are missing, those
12322 settings won't be restored. So you can use: >
12323 :call winrestview({'curswant': 4})
12324<
12325 This will only set the curswant value (the column the cursor
12326 wants to move on vertical movements) of the cursor to column 5
12327 (yes, that is 5), while all other settings will remain the
12328 same. This is useful, if you set the cursor position manually.
12329
12330 If you have changed the values the result is unpredictable.
12331 If the window size changed the result won't be the same.
12332
12333 Can also be used as a |method|: >
12334 GetView()->winrestview()
12335<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012336 Return type: |Number|
12337
12338
12339winsaveview() *winsaveview()*
12340 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012341 the view of the current window. Use |winrestview()| to
12342 restore the view.
12343 This is useful if you have a mapping that jumps around in the
12344 buffer and you want to go back to the original view.
12345 This does not save fold information. Use the 'foldenable'
12346 option to temporarily switch off folding, so that folds are
12347 not opened when moving around. This may have side effects.
12348 The return value includes:
12349 lnum cursor line number
12350 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012351 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012352 returns)
12353 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012354 curswant column for vertical movement (Note:
12355 the first column is zero, as opposed
12356 to what |getcurpos()| returns). After
12357 |$| command it will be a very large
12358 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012359 topline first line in the window
12360 topfill filler lines, only in diff mode
12361 leftcol first column displayed; only used when
12362 'wrap' is off
12363 skipcol columns skipped
12364 Note that no option values are saved.
12365
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012366 Return type: dict<number>
12367
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012368
12369winwidth({nr}) *winwidth()*
12370 The result is a Number, which is the width of window {nr}.
12371 {nr} can be the window number or the |window-ID|.
12372 When {nr} is zero, the width of the current window is
12373 returned. When window {nr} doesn't exist, -1 is returned.
12374 An existing window always has a width of zero or more.
12375 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012376 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012377 :if winwidth(0) <= 50
12378 : 50 wincmd |
12379 :endif
12380< For getting the terminal or screen size, see the 'columns'
12381 option.
12382
12383 Can also be used as a |method|: >
12384 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012385<
12386 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012387
12388
12389wordcount() *wordcount()*
12390 The result is a dictionary of byte/chars/word statistics for
12391 the current buffer. This is the same info as provided by
12392 |g_CTRL-G|
12393 The return value includes:
12394 bytes Number of bytes in the buffer
12395 chars Number of chars in the buffer
12396 words Number of words in the buffer
12397 cursor_bytes Number of bytes before cursor position
12398 (not in Visual mode)
12399 cursor_chars Number of chars before cursor position
12400 (not in Visual mode)
12401 cursor_words Number of words before cursor position
12402 (not in Visual mode)
12403 visual_bytes Number of bytes visually selected
12404 (only in Visual mode)
12405 visual_chars Number of chars visually selected
12406 (only in Visual mode)
12407 visual_words Number of words visually selected
12408 (only in Visual mode)
12409
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012410 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012411
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012412
12413writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012414 When {object} is a |List| write it to file {fname}. Each list
12415 item is separated with a NL. Each list item must be a String
12416 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012417 All NL characters are replaced with a NUL character.
12418 Inserting CR characters needs to be done before passing {list}
12419 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012420
12421 When {object} is a |Blob| write the bytes to file {fname}
12422 unmodified, also when binary mode is not specified.
12423
12424 {flags} must be a String. These characters are recognized:
12425
12426 'b' Binary mode is used: There will not be a NL after the
12427 last list item. An empty item at the end does cause the
12428 last line in the file to end in a NL.
12429
12430 'a' Append mode is used, lines are appended to the file: >
12431 :call writefile(["foo"], "event.log", "a")
12432 :call writefile(["bar"], "event.log", "a")
12433<
12434 'D' Delete the file when the current function ends. This
12435 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012436 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012437< Fails when not in a function. Also see |:defer|.
12438
12439 's' fsync() is called after writing the file. This flushes
12440 the file to disk, if possible. This takes more time but
12441 avoids losing the file if the system crashes.
12442
12443 'S' fsync() is not called, even when 'fsync' is set.
12444
12445 When {flags} does not contain "S" or "s" then fsync() is
12446 called if the 'fsync' option is set.
12447
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012448 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012449
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012450 When the write fails -1 is returned, otherwise 0. There is an
12451 error message if the file can't be created or when writing
12452 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012453
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012454 Also see |readfile()|.
12455 To copy a file byte for byte: >
12456 :let fl = readfile("foo", "b")
12457 :call writefile(fl, "foocopy", "b")
12458
12459< Can also be used as a |method|: >
12460 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012461<
12462 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012463
12464
12465xor({expr}, {expr}) *xor()*
12466 Bitwise XOR on the two arguments. The arguments are converted
12467 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012468 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012469 Example: >
12470 :let bits = xor(bits, 0x80)
12471<
12472 Can also be used as a |method|: >
12473 :let bits = bits->xor(0x80)
12474<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012475 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012476
12477==============================================================================
124783. Feature list *feature-list*
12479
12480There are three types of features:
124811. Features that are only supported when they have been enabled when Vim
12482 was compiled |+feature-list|. Example: >
12483 :if has("cindent")
12484< *gui_running*
124852. Features that are only supported when certain conditions have been met.
12486 Example: >
12487 :if has("gui_running")
12488< *has-patch*
124893. Beyond a certain version or at a certain version and including a specific
12490 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12491 later, or it is version 7.4 and patch 248 was included. Example: >
12492 :if has("patch-7.4.248")
12493< Note that it's possible for patch 248 to be omitted even though 249 is
12494 included. Only happens when cherry-picking patches.
12495 Note that this form only works for patch 7.4.237 and later, before that
12496 you need to check for the patch and the v:version. Example (checking
12497 version 6.2.148 or later): >
12498 :if v:version > 602 || (v:version == 602 && has("patch148"))
12499
12500Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12501use: `if exists('+shellslash')`
12502
12503
12504acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012505all_builtin_terms Compiled with all builtin terminals enabled. (always
12506 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012507amiga Amiga version of Vim.
12508arabic Compiled with Arabic support |Arabic|.
12509arp Compiled with ARP support (Amiga).
12510autocmd Compiled with autocommand support. (always true)
12511autochdir Compiled with support for 'autochdir'
12512autoservername Automatically enable |clientserver|
12513balloon_eval Compiled with |balloon-eval| support.
12514balloon_multiline GUI supports multiline balloons.
12515beos BeOS version of Vim.
12516browse Compiled with |:browse| support, and browse() will
12517 work.
12518browsefilter Compiled with support for |browsefilter|.
12519bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012520builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012521byte_offset Compiled with support for 'o' in 'statusline'
12522channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012523cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012524clientserver Compiled with remote invocation support |clientserver|.
12525clipboard Compiled with 'clipboard' support.
12526clipboard_working Compiled with 'clipboard' support and it can be used.
12527cmdline_compl Compiled with |cmdline-completion| support.
12528cmdline_hist Compiled with |cmdline-history| support.
12529cmdline_info Compiled with 'showcmd' and 'ruler' support.
12530comments Compiled with |'comments'| support.
12531compatible Compiled to be very Vi compatible.
12532conpty Platform where |ConPTY| can be used.
12533cryptv Compiled with encryption support |encryption|.
12534cscope Compiled with |cscope| support.
12535cursorbind Compiled with |'cursorbind'| (always true)
12536debug Compiled with "DEBUG" defined.
12537dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012538dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012539dialog_gui Compiled with GUI dialog support.
12540diff Compiled with |vimdiff| and 'diff' support.
12541digraphs Compiled with support for digraphs.
12542directx Compiled with support for DirectX and 'renderoptions'.
12543dnd Compiled with support for the "~ register |quote_~|.
12544drop_file Compiled with |drop_file| support.
12545ebcdic Compiled on a machine with ebcdic character set.
12546emacs_tags Compiled with support for Emacs tags.
12547eval Compiled with expression evaluation support. Always
12548 true, of course!
12549ex_extra |+ex_extra| (always true)
12550extra_search Compiled with support for |'incsearch'| and
12551 |'hlsearch'|
12552farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012553file_in_path Compiled with support for |gf| and |<cfile>| (always
12554 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012555filterpipe When 'shelltemp' is off pipes are used for shell
12556 read/write/filter commands
12557find_in_path Compiled with support for include file searches
12558 |+find_in_path|.
12559float Compiled with support for |Float|.
12560fname_case Case in file names matters (for Amiga and MS-Windows
12561 this is not present).
12562folding Compiled with |folding| support.
12563footer Compiled with GUI footer support. |gui-footer|
12564fork Compiled to use fork()/exec() instead of system().
12565gettext Compiled with message translation |multi-lang|
12566gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012567gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012568gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12569gui_gtk Compiled with GTK+ GUI (any version).
12570gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12571gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12572gui_haiku Compiled with Haiku GUI.
12573gui_mac Compiled with Macintosh GUI.
12574gui_motif Compiled with Motif GUI.
12575gui_photon Compiled with Photon GUI.
12576gui_running Vim is running in the GUI, or it will start soon.
12577gui_win32 Compiled with MS-Windows Win32 GUI.
12578gui_win32s idem, and Win32s system being used (Windows 3.1)
12579haiku Haiku version of Vim.
12580hangul_input Compiled with Hangul input support. |hangul|
12581hpux HP-UX version of Vim.
12582iconv Can use iconv() for conversion.
12583insert_expand Compiled with support for CTRL-X expansion commands in
12584 Insert mode. (always true)
12585job Compiled with support for |channel| and |job|
12586ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012587jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012588keymap Compiled with 'keymap' support.
12589lambda Compiled with |lambda| support.
12590langmap Compiled with 'langmap' support.
12591libcall Compiled with |libcall()| support.
12592linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12593 'breakindent' support.
12594linux Linux version of Vim.
12595lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012596 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012597listcmds Compiled with commands for the buffer list |:files|
12598 and the argument list |arglist|.
12599localmap Compiled with local mappings and abbr. |:map-local|
12600lua Compiled with Lua interface |Lua|.
12601mac Any Macintosh version of Vim cf. osx
12602macunix Synonym for osxdarwin
12603menu Compiled with support for |:menu|.
12604mksession Compiled with support for |:mksession|.
12605modify_fname Compiled with file name modifiers. |filename-modifiers|
12606 (always true)
12607mouse Compiled with support for mouse.
12608mouse_dec Compiled with support for Dec terminal mouse.
12609mouse_gpm Compiled with support for gpm (Linux console mouse)
12610mouse_gpm_enabled GPM mouse is working
12611mouse_netterm Compiled with support for netterm mouse.
12612mouse_pterm Compiled with support for qnx pterm mouse.
12613mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12614mouse_sgr Compiled with support for sgr mouse.
12615mouse_urxvt Compiled with support for urxvt mouse.
12616mouse_xterm Compiled with support for xterm mouse.
12617mouseshape Compiled with support for 'mouseshape'.
12618multi_byte Compiled with support for 'encoding' (always true)
12619multi_byte_encoding 'encoding' is set to a multibyte encoding.
12620multi_byte_ime Compiled with support for IME input method.
12621multi_lang Compiled with support for multiple languages.
12622mzscheme Compiled with MzScheme interface |mzscheme|.
12623nanotime Compiled with sub-second time stamp checks.
12624netbeans_enabled Compiled with support for |netbeans| and connected.
12625netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012626num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012627ole Compiled with OLE automation support for Win32.
12628osx Compiled for macOS cf. mac
12629osxdarwin Compiled for macOS, with |mac-darwin-feature|
12630packages Compiled with |packages| support.
12631path_extra Compiled with up/downwards search in 'path' and 'tags'
12632perl Compiled with Perl interface.
12633persistent_undo Compiled with support for persistent undo history.
12634postscript Compiled with PostScript file printing.
12635printer Compiled with |:hardcopy| support.
12636profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012637prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012638python Python 2.x interface available. |has-python|
12639python_compiled Compiled with Python 2.x interface. |has-python|
12640python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12641python3 Python 3.x interface available. |has-python|
12642python3_compiled Compiled with Python 3.x interface. |has-python|
12643python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012644python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012645pythonx Python 2.x and/or 3.x interface available. |python_x|
12646qnx QNX version of Vim.
12647quickfix Compiled with |quickfix| support.
12648reltime Compiled with |reltime()| support.
12649rightleft Compiled with 'rightleft' support.
12650ruby Compiled with Ruby interface |ruby|.
12651scrollbind Compiled with 'scrollbind' support. (always true)
12652showcmd Compiled with 'showcmd' support.
12653signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012654smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012655sodium Compiled with libsodium for better crypt support
12656sound Compiled with sound support, e.g. `sound_playevent()`
12657spell Compiled with spell checking support |spell|.
12658startuptime Compiled with |--startuptime| support.
12659statusline Compiled with support for 'statusline', 'rulerformat'
12660 and special formats of 'titlestring' and 'iconstring'.
12661sun SunOS version of Vim.
12662sun_workshop Support for Sun |workshop| has been removed.
12663syntax Compiled with syntax highlighting support |syntax|.
12664syntax_items There are active syntax highlighting items for the
12665 current buffer.
12666system Compiled to use system() instead of fork()/exec().
12667tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012668 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012669tag_old_static Support for old static tags was removed, see
12670 |tag-old-static|.
12671tcl Compiled with Tcl interface.
12672termguicolors Compiled with true color in terminal support.
12673terminal Compiled with |terminal| support.
12674terminfo Compiled with terminfo instead of termcap.
12675termresponse Compiled with support for |t_RV| and |v:termresponse|.
12676textobjects Compiled with support for |text-objects|.
12677textprop Compiled with support for |text-properties|.
12678tgetent Compiled with tgetent support, able to use a termcap
12679 or terminfo file.
12680timers Compiled with |timer_start()| support.
12681title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012682 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012683toolbar Compiled with support for |gui-toolbar|.
12684ttyin input is a terminal (tty)
12685ttyout output is a terminal (tty)
12686unix Unix version of Vim. *+unix*
12687unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
12688user_commands User-defined commands. (always true)
12689vartabs Compiled with variable tabstop support |'vartabstop'|.
12690vcon Win32: Virtual console support is working, can use
12691 'termguicolors'. Also see |+vtp|.
12692vertsplit Compiled with vertically split windows |:vsplit|.
12693 (always true)
12694vim_starting True while initial source'ing takes place. |startup|
12695 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000012696vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012697viminfo Compiled with viminfo support.
12698vimscript-1 Compiled Vim script version 1 support
12699vimscript-2 Compiled Vim script version 2 support
12700vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010012701vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012702virtualedit Compiled with 'virtualedit' option. (always true)
12703visual Compiled with Visual mode. (always true)
12704visualextra Compiled with extra Visual mode commands. (always
12705 true) |blockwise-operators|.
12706vms VMS version of Vim.
12707vreplace Compiled with |gR| and |gr| commands. (always true)
12708vtp Compiled for vcon support |+vtp| (check vcon to find
12709 out if it works in the current console).
12710wildignore Compiled with 'wildignore' option.
12711wildmenu Compiled with 'wildmenu' option.
12712win16 old version for MS-Windows 3.1 (always false)
12713win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
12714 64 bits)
12715win32unix Win32 version of Vim, using Unix files (Cygwin)
12716win64 Win64 version of Vim (MS-Windows 64 bit).
12717win95 Win32 version for MS-Windows 95/98/ME (always false)
12718winaltkeys Compiled with 'winaltkeys' option.
12719windows Compiled with support for more than one window.
12720 (always true)
12721writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020012722xattr Compiled with extended attributes support |xattr|
12723 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012724xfontset Compiled with X fontset support |xfontset|.
12725xim Compiled with X input method support |xim|.
12726xpm Compiled with pixmap support.
12727xpm_w32 Compiled with pixmap support for Win32. (Only for
12728 backward compatibility. Use "xpm" instead.)
12729xsmp Compiled with X session management support.
12730xsmp_interact Compiled with interactive X session management support.
12731xterm_clipboard Compiled with support for xterm clipboard.
12732xterm_save Compiled with support for saving and restoring the
12733 xterm screen.
12734x11 Compiled with X11 support.
12735
12736
12737==============================================================================
127384. Matching a pattern in a String *string-match*
12739
12740This is common between several functions. A regexp pattern as explained at
12741|pattern| is normally used to find a match in the buffer lines. When a
12742pattern is used to find a match in a String, almost everything works in the
12743same way. The difference is that a String is handled like it is one line.
12744When it contains a "\n" character, this is not seen as a line break for the
12745pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
12746>
12747 :let a = "aaaa\nxxxx"
12748 :echo matchstr(a, "..\n..")
12749 aa
12750 xx
12751 :echo matchstr(a, "a.x")
12752 a
12753 x
12754
12755Don't forget that "^" will only match at the first character of the String and
12756"$" at the last character of the string. They don't match after or before a
12757"\n".
12758
12759 vim:tw=78:ts=8:noet:ft=help:norl: