blob: 880dfcd78506432301025ceb9a46167d35c0d500 [file] [log] [blame]
Ruslan Russkikh0407d622024-10-08 22:21:05 +02001*builtin.txt* For Vim version 9.1. Last change: 2024 Oct 08
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7Builtin functions *builtin-functions*
8
Bram Moolenaarf269eab2022-10-03 18:04:35 +01009Note: Expression evaluation can be disabled at compile time, the builtin
10functions are not available then. See |+eval| and |no-eval-feature|.
11
12For functions grouped by what they are used for see |function-list|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000013
141. Overview |builtin-function-list|
152. Details |builtin-function-details|
163. Feature list |feature-list|
174. Matching a pattern in a String |string-match|
18
19==============================================================================
201. Overview *builtin-function-list*
21
22Use CTRL-] on the function name to jump to the full explanation.
23
24USAGE RESULT DESCRIPTION ~
25
26abs({expr}) Float or Number absolute value of {expr}
27acos({expr}) Float arc cosine of {expr}
28add({object}, {item}) List/Blob append {item} to {object}
29and({expr}, {expr}) Number bitwise AND
30append({lnum}, {text}) Number append {text} below line {lnum}
erraelf0837ba2024-06-24 12:27:01 -070031appendbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000032 Number append {text} below line {lnum}
erraelf0837ba2024-06-24 12:27:01 -070033 in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000034argc([{winid}]) Number number of files in the argument list
35argidx() Number current index in the argument list
36arglistid([{winnr} [, {tabnr}]]) Number argument list id
37argv({nr} [, {winid}]) String {nr} entry of the argument list
38argv([-1, {winid}]) List the argument list
39asin({expr}) Float arc sine of {expr}
40assert_beeps({cmd}) Number assert {cmd} causes a beep
41assert_equal({exp}, {act} [, {msg}])
42 Number assert {exp} is equal to {act}
43assert_equalfile({fname-one}, {fname-two} [, {msg}])
44 Number assert file contents are equal
45assert_exception({error} [, {msg}])
46 Number assert {error} is in v:exception
47assert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]])
48 Number assert {cmd} fails
49assert_false({actual} [, {msg}])
50 Number assert {actual} is false
51assert_inrange({lower}, {upper}, {actual} [, {msg}])
52 Number assert {actual} is inside the range
53assert_match({pat}, {text} [, {msg}])
54 Number assert {pat} matches {text}
55assert_nobeep({cmd}) Number assert {cmd} does not cause a beep
56assert_notequal({exp}, {act} [, {msg}])
57 Number assert {exp} is not equal {act}
58assert_notmatch({pat}, {text} [, {msg}])
59 Number assert {pat} not matches {text}
60assert_report({msg}) Number report a test failure
61assert_true({actual} [, {msg}]) Number assert {actual} is true
62atan({expr}) Float arc tangent of {expr}
63atan2({expr1}, {expr2}) Float arc tangent of {expr1} / {expr2}
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +010064autocmd_add({acmds}) Bool add a list of autocmds and groups
65autocmd_delete({acmds}) Bool delete a list of autocmds and groups
66autocmd_get([{opts}]) List return a list of autocmds
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000067balloon_gettext() String current text in the balloon
68balloon_show({expr}) none show {expr} inside the balloon
69balloon_split({msg}) List split {msg} as used for a balloon
Christ van Willegence0ef912024-06-20 23:41:59 +020070bindtextdomain({package}, {path})
Christ van Willegen8252ef12024-07-11 21:36:21 +020071 Bool bind text domain to specified path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000072blob2list({blob}) List convert {blob} into a list of numbers
73browse({save}, {title}, {initdir}, {default})
74 String put up a file requester
75browsedir({title}, {initdir}) String put up a directory requester
76bufadd({name}) Number add a buffer to the buffer list
77bufexists({buf}) Number |TRUE| if buffer {buf} exists
78buflisted({buf}) Number |TRUE| if buffer {buf} is listed
79bufload({buf}) Number load buffer {buf} if not loaded yet
80bufloaded({buf}) Number |TRUE| if buffer {buf} is loaded
81bufname([{buf}]) String Name of the buffer {buf}
82bufnr([{buf} [, {create}]]) Number Number of the buffer {buf}
83bufwinid({buf}) Number window ID of buffer {buf}
84bufwinnr({buf}) Number window number of buffer {buf}
85byte2line({byte}) Number line number at byte count {byte}
Christian Brabandt67672ef2023-04-24 21:09:54 +010086byteidx({expr}, {nr} [, {utf16}])
87 Number byte index of {nr}'th char in {expr}
88byteidxcomp({expr}, {nr} [, {utf16}])
89 Number byte index of {nr}'th char in {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000090call({func}, {arglist} [, {dict}])
91 any call {func} with arguments {arglist}
92ceil({expr}) Float round {expr} up
93ch_canread({handle}) Number check if there is something to read
94ch_close({handle}) none close {handle}
95ch_close_in({handle}) none close in part of {handle}
96ch_evalexpr({handle}, {expr} [, {options}])
97 any evaluate {expr} on JSON {handle}
98ch_evalraw({handle}, {string} [, {options}])
99 any evaluate {string} on raw {handle}
100ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
101ch_getjob({channel}) Job get the Job of {channel}
102ch_info({handle}) String info about channel {handle}
103ch_log({msg} [, {handle}]) none write {msg} in the channel log file
104ch_logfile({fname} [, {mode}]) none start logging channel activity
105ch_open({address} [, {options}])
106 Channel open a channel to {address}
107ch_read({handle} [, {options}]) String read from {handle}
108ch_readblob({handle} [, {options}])
109 Blob read Blob from {handle}
110ch_readraw({handle} [, {options}])
111 String read raw from {handle}
112ch_sendexpr({handle}, {expr} [, {options}])
113 any send {expr} over JSON {handle}
114ch_sendraw({handle}, {expr} [, {options}])
115 any send {expr} over raw {handle}
116ch_setoptions({handle}, {options})
117 none set options for {handle}
118ch_status({handle} [, {options}])
119 String status of channel {handle}
120changenr() Number current change number
121char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr}
122charclass({string}) Number character class of {string}
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000123charcol({expr} [, {winid}]) Number column number of cursor or mark
Christian Brabandt67672ef2023-04-24 21:09:54 +0100124charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000125 Number char index of byte {idx} in {string}
126chdir({dir}) String change current working directory
127cindent({lnum}) Number C indent for line {lnum}
128clearmatches([{win}]) none clear all matches
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000129col({expr} [, {winid}]) Number column byte index of cursor or mark
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000130complete({startcol}, {matches}) none set Insert mode completion
131complete_add({expr}) Number add completion match
132complete_check() Number check for key typed during completion
133complete_info([{what}]) Dict get current completion information
134confirm({msg} [, {choices} [, {default} [, {type}]]])
135 Number number of choice picked by user
136copy({expr}) any make a shallow copy of {expr}
137cos({expr}) Float cosine of {expr}
138cosh({expr}) Float hyperbolic cosine of {expr}
139count({comp}, {expr} [, {ic} [, {start}]])
140 Number count how many {expr} are in {comp}
141cscope_connection([{num}, {dbpath} [, {prepend}]])
142 Number checks existence of cscope connection
143cursor({lnum}, {col} [, {off}])
144 Number move cursor to {lnum}, {col}, {off}
145cursor({list}) Number move cursor to position in {list}
146debugbreak({pid}) Number interrupt process being debugged
147deepcopy({expr} [, {noref}]) any make a full copy of {expr}
148delete({fname} [, {flags}]) Number delete the file or directory {fname}
149deletebufline({buf}, {first} [, {last}])
150 Number delete lines from buffer {buf}
151did_filetype() Number |TRUE| if FileType autocmd event used
Yegappan Lakshmananfa378352024-02-01 22:05:27 +0100152diff({fromlist}, {tolist} [, {options}])
153 List diff two Lists of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000154diff_filler({lnum}) Number diff filler lines about {lnum}
155diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
156digraph_get({chars}) String get the |digraph| of {chars}
157digraph_getlist([{listall}]) List get all |digraph|s
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200158digraph_set({chars}, {digraph}) Bool register |digraph|
159digraph_setlist({digraphlist}) Bool register multiple |digraph|s
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000160echoraw({expr}) none output {expr} as-is
161empty({expr}) Number |TRUE| if {expr} is empty
162environ() Dict return environment variables
Sean Dewarb0efa492023-07-08 10:35:19 +0100163err_teapot([{expr}]) none give E418, or E503 if {expr} is |TRUE|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000164escape({string}, {chars}) String escape {chars} in {string} with '\'
165eval({string}) any evaluate {string} into its value
166eventhandler() Number |TRUE| if inside an event handler
167executable({expr}) Number 1 if executable {expr} exists
168execute({command}) String execute {command} and get the output
169exepath({expr}) String full path of the command {expr}
170exists({expr}) Number |TRUE| if {expr} exists
171exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
172exp({expr}) Float exponential of {expr}
173expand({expr} [, {nosuf} [, {list}]])
174 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100175expandcmd({string} [, {options}])
176 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000177extend({expr1}, {expr2} [, {expr3}])
178 List/Dict insert items of {expr2} into {expr1}
179extendnew({expr1}, {expr2} [, {expr3}])
180 List/Dict like |extend()| but creates a new
181 List or Dictionary
182feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
Shougo Matsushita60c87432024-06-03 22:59:27 +0200183filecopy({from}, {to}) Number |TRUE| if copying file {from} to {to}
184 worked
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000185filereadable({file}) Number |TRUE| if {file} is a readable file
186filewritable({file}) Number |TRUE| if {file} is a writable file
187filter({expr1}, {expr2}) List/Dict/Blob/String
188 remove items from {expr1} where
189 {expr2} is 0
190finddir({name} [, {path} [, {count}]])
191 String find directory {name} in {path}
192findfile({name} [, {path} [, {count}]])
193 String find file {name} in {path}
194flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
195flattennew({list} [, {maxdepth}])
196 List flatten a copy of {list}
197float2nr({expr}) Number convert Float {expr} to a Number
198floor({expr}) Float round {expr} down
199fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
200fnameescape({fname}) String escape special characters in {fname}
201fnamemodify({fname}, {mods}) String modify file name
202foldclosed({lnum}) Number first line of fold at {lnum} if closed
203foldclosedend({lnum}) Number last line of fold at {lnum} if closed
204foldlevel({lnum}) Number fold level at {lnum}
205foldtext() String line displayed for closed fold
206foldtextresult({lnum}) String text for closed fold at {lnum}
Ernie Raele79e2072024-01-13 11:47:33 +0100207foreach({expr1}, {expr2}) List/Dict/Blob/String
208 for each item in {expr1} call {expr2}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000209foreground() Number bring the Vim window to the foreground
Bram Moolenaaraa534142022-09-15 21:46:02 +0100210fullcommand({name} [, {vim9}]) String get full command from {name}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000211funcref({name} [, {arglist}] [, {dict}])
212 Funcref reference to function {name}
213function({name} [, {arglist}] [, {dict}])
214 Funcref named reference to function {name}
215garbagecollect([{atexit}]) none free memory, breaking cyclic references
216get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
217get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
218get({func}, {what}) any get property of funcref/partial {func}
219getbufinfo([{buf}]) List information about buffers
220getbufline({buf}, {lnum} [, {end}])
221 List lines {lnum} to {end} of buffer {buf}
Bram Moolenaarce30ccc2022-11-21 19:57:04 +0000222getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000223getbufvar({buf}, {varname} [, {def}])
224 any variable {varname} in buffer {buf}
Kota Kato66bb9ae2023-01-17 18:31:56 +0000225getcellwidths() List get character cell width overrides
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000226getchangelist([{buf}]) List list of change list items
Doug Kearns9cd9e752024-04-07 17:42:17 +0200227getchar([{expr}]) Number or String
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000228 get one character from the user
229getcharmod() Number modifiers for the last typed character
230getcharpos({expr}) List position of cursor, mark, etc.
231getcharsearch() Dict last character search
Doug Kearns9cd9e752024-04-07 17:42:17 +0200232getcharstr([{expr}]) String get one character from the user
Ruslan Russkikh0407d622024-10-08 22:21:05 +0200233getcmdcomplpat() String return the completion pattern of the
234 current command-line completion
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100235getcmdcompltype() String return the type of the current
236 command-line completion
Shougo Matsushita69084282024-09-23 20:34:47 +0200237getcmdline() String return the current command-line input
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000238getcmdpos() Number return cursor position in command-line
Shougo Matsushita69084282024-09-23 20:34:47 +0200239getcmdprompt() String return the current command-line prompt
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100240getcmdscreenpos() Number return cursor screen position in
241 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000242getcmdtype() String return current command-line type
243getcmdwintype() String return current command-line window type
244getcompletion({pat}, {type} [, {filtered}])
245 List list of cmdline completion matches
246getcurpos([{winnr}]) List position of the cursor
247getcursorcharpos([{winnr}]) List character position of the cursor
248getcwd([{winnr} [, {tabnr}]]) String get the current working directory
249getenv({name}) String return environment variable
250getfontname([{name}]) String name of font being used
251getfperm({fname}) String file permissions of file {fname}
252getfsize({fname}) Number size in bytes of file {fname}
253getftime({fname}) Number last modification time of file
254getftype({fname}) String description of type of file {fname}
255getimstatus() Number |TRUE| if the IME status is active
256getjumplist([{winnr} [, {tabnr}]])
257 List list of jump list items
258getline({lnum}) String line {lnum} of current buffer
259getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
260getloclist({nr}) List list of location list items
261getloclist({nr}, {what}) Dict get specific location list properties
262getmarklist([{buf}]) List list of global/local marks
263getmatches([{win}]) List list of current matches
264getmousepos() Dict last known mouse position
Bram Moolenaar24dc19c2022-11-14 19:49:15 +0000265getmouseshape() String current mouse shape name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000266getpid() Number process ID of Vim
267getpos({expr}) List position of cursor, mark, etc.
268getqflist() List list of quickfix items
269getqflist({what}) Dict get specific quickfix list properties
270getreg([{regname} [, 1 [, {list}]]])
271 String or List contents of a register
272getreginfo([{regname}]) Dict information about a register
Shougo Matsushita19b71882024-02-28 22:48:12 +0100273getregion({pos1}, {pos2} [, {opts}])
Shougo Matsushita3f905ab2024-02-21 00:02:45 +0100274 List get the text from {pos1} to {pos2}
Shougo Matsushitab4757e62024-05-07 20:49:24 +0200275getregionpos({pos1}, {pos2} [, {opts}])
276 List get a list of positions for a region
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000277getregtype([{regname}]) String type of a register
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +0100278getscriptinfo([{opts}]) List list of sourced scripts
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000279gettabinfo([{expr}]) List list of tab pages
280gettabvar({nr}, {varname} [, {def}])
281 any variable {varname} in tab {nr} or {def}
282gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
283 any {name} in {winnr} in tab page {tabnr}
284gettagstack([{nr}]) Dict get the tag stack of window {nr}
h-east52e7cc22024-07-28 17:03:29 +0200285gettext({text} [, {package}]) String lookup translation of {text}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000286getwininfo([{winid}]) List list of info about each window
Bram Moolenaar938ae282023-02-20 20:44:55 +0000287getwinpos([{timeout}]) List X and Y coord in pixels of Vim window
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000288getwinposx() Number X coord in pixels of the Vim window
289getwinposy() Number Y coord in pixels of the Vim window
290getwinvar({nr}, {varname} [, {def}])
291 any variable {varname} in window {nr}
292glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
293 any expand file wildcards in {expr}
294glob2regpat({expr}) String convert a glob pat into a search pat
295globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
296 String do glob({expr}) for all dirs in {path}
297has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
298has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
299haslocaldir([{winnr} [, {tabnr}]])
300 Number |TRUE| if the window executed |:lcd|
301 or |:tcd|
302hasmapto({what} [, {mode} [, {abbr}]])
303 Number |TRUE| if mapping to {what} exists
304histadd({history}, {item}) Number add an item to a history
305histdel({history} [, {item}]) Number remove an item from a history
306histget({history} [, {index}]) String get the item {index} from a history
307histnr({history}) Number highest index of a history
308hlID({name}) Number syntax ID of highlight group {name}
309hlexists({name}) Number |TRUE| if highlight group {name} exists
310hlget([{name} [, {resolve}]]) List get highlight group attributes
311hlset({list}) Number set highlight group attributes
312hostname() String name of the machine Vim is running on
313iconv({expr}, {from}, {to}) String convert encoding of {expr}
Ernie Rael05124252024-07-11 22:10:45 +0200314id({item}) String get unique identity string of item
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000315indent({lnum}) Number indent of line {lnum}
316index({object}, {expr} [, {start} [, {ic}]])
317 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100318indexof({object}, {expr} [, {opts}]])
319 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000320input({prompt} [, {text} [, {completion}]])
321 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100322inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000323 String like input() but in a GUI dialog
324inputlist({textlist}) Number let the user pick from a choice list
325inputrestore() Number restore typeahead
326inputsave() Number save and clear typeahead
327inputsecret({prompt} [, {text}]) String like input() but hiding the text
328insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
LemonBoyafe04662023-08-23 21:08:11 +0200329instanceof({object}, {class}) Number |TRUE| if {object} is an instance of {class}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000330interrupt() none interrupt script execution
331invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100332isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000333isdirectory({directory}) Number |TRUE| if {directory} is a directory
334isinf({expr}) Number determine if {expr} is infinity value
335 (positive or negative)
336islocked({expr}) Number |TRUE| if {expr} is locked
337isnan({expr}) Number |TRUE| if {expr} is NaN
338items({dict}) List key-value pairs in {dict}
339job_getchannel({job}) Channel get the channel handle for {job}
340job_info([{job}]) Dict get information about {job}
341job_setoptions({job}, {options}) none set options for {job}
342job_start({command} [, {options}])
343 Job start a job
344job_status({job}) String get the status of {job}
345job_stop({job} [, {how}]) Number stop {job}
346join({list} [, {sep}]) String join {list} items into one String
347js_decode({string}) any decode JS style JSON
348js_encode({expr}) String encode JS style JSON
349json_decode({string}) any decode JSON
350json_encode({expr}) String encode JSON
351keys({dict}) List keys in {dict}
zeertzjqcdc83932022-09-12 13:38:41 +0100352keytrans({string}) String translate internal keycodes to a form
353 that can be used by |:map|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000354len({expr}) Number the length of {expr}
355libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
356libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
357line({expr} [, {winid}]) Number line nr of cursor, last line or mark
358line2byte({lnum}) Number byte count of line {lnum}
359lispindent({lnum}) Number Lisp indent for line {lnum}
360list2blob({list}) Blob turn {list} of numbers into a Blob
361list2str({list} [, {utf8}]) String turn {list} of numbers into a String
362listener_add({callback} [, {buf}])
363 Number add a callback to listen to changes
364listener_flush([{buf}]) none invoke listener callbacks
365listener_remove({id}) none remove a listener callback
366localtime() Number current time
367log({expr}) Float natural logarithm (base e) of {expr}
368log10({expr}) Float logarithm of Float {expr} to base 10
369luaeval({expr} [, {expr}]) any evaluate |Lua| expression
370map({expr1}, {expr2}) List/Dict/Blob/String
371 change each item in {expr1} to {expr2}
372maparg({name} [, {mode} [, {abbr} [, {dict}]]])
373 String or Dict
374 rhs of mapping {name} in mode {mode}
375mapcheck({name} [, {mode} [, {abbr}]])
376 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100377maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000378mapnew({expr1}, {expr2}) List/Dict/Blob/String
379 like |map()| but creates a new List or
380 Dictionary
381mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
382match({expr}, {pat} [, {start} [, {count}]])
383 Number position where {pat} matches in {expr}
384matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
385 Number highlight {pattern} with {group}
386matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
387 Number highlight positions with {group}
388matcharg({nr}) List arguments of |:match|
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100389matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict})
390 List all the {pat} matches in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000391matchdelete({id} [, {win}]) Number delete match identified by {id}
392matchend({expr}, {pat} [, {start} [, {count}]])
393 Number position where {pat} ends in {expr}
394matchfuzzy({list}, {str} [, {dict}])
395 List fuzzy match {str} in {list}
396matchfuzzypos({list}, {str} [, {dict}])
397 List fuzzy match {str} in {list}
398matchlist({expr}, {pat} [, {start} [, {count}]])
399 List match and submatches of {pat} in {expr}
400matchstr({expr}, {pat} [, {start} [, {count}]])
401 String {count}'th match of {pat} in {expr}
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100402matchstrlist({list}, {pat} [, {dict})
403 List all the {pat} matches in {list}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000404matchstrpos({expr}, {pat} [, {start} [, {count}]])
405 List {count}'th match of {pat} in {expr}
406max({expr}) Number maximum value of items in {expr}
407menu_info({name} [, {mode}]) Dict get menu item information
408min({expr}) Number minimum value of items in {expr}
Bram Moolenaar938ae282023-02-20 20:44:55 +0000409mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000410 Number create directory {name}
Doug Kearns9cd9e752024-04-07 17:42:17 +0200411mode([{expr}]) String current editing mode
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000412mzeval({expr}) any evaluate |MzScheme| expression
413nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
414nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
415or({expr}, {expr}) Number bitwise OR
416pathshorten({expr} [, {len}]) String shorten directory names in a path
417perleval({expr}) any evaluate |Perl| expression
418popup_atcursor({what}, {options}) Number create popup window near the cursor
419popup_beval({what}, {options}) Number create popup window for 'ballooneval'
420popup_clear() none close all popup windows
421popup_close({id} [, {result}]) none close popup window {id}
422popup_create({what}, {options}) Number create a popup window
423popup_dialog({what}, {options}) Number create a popup window used as a dialog
424popup_filter_menu({id}, {key}) Number filter for a menu popup window
425popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100426popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000427popup_findinfo() Number get window ID of info popup window
428popup_findpreview() Number get window ID of preview popup window
429popup_getoptions({id}) Dict get options of popup window {id}
430popup_getpos({id}) Dict get position of popup window {id}
431popup_hide({id}) none hide popup menu {id}
432popup_list() List get a list of window IDs of all popups
433popup_locate({row}, {col}) Number get window ID of popup at position
434popup_menu({what}, {options}) Number create a popup window used as a menu
435popup_move({id}, {options}) none set position of popup window {id}
436popup_notification({what}, {options})
437 Number create a notification popup window
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200438popup_setbuf({id}, {buf}) Bool set the buffer for the popup window {id}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000439popup_setoptions({id}, {options})
440 none set options for popup window {id}
441popup_settext({id}, {text}) none set the text of popup window {id}
442popup_show({id}) none unhide popup window {id}
443pow({x}, {y}) Float {x} to the power of {y}
444prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
445printf({fmt}, {expr1}...) String format text
446prompt_getprompt({buf}) String get prompt text
447prompt_setcallback({buf}, {expr}) none set prompt callback function
448prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
449prompt_setprompt({buf}, {text}) none set prompt text
450prop_add({lnum}, {col}, {props}) none add one text property
451prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
452 none add multiple text properties
453prop_clear({lnum} [, {lnum-end} [, {props}]])
454 none remove all text properties
455prop_find({props} [, {direction}])
456 Dict search for a text property
457prop_list({lnum} [, {props}]) List text properties in {lnum}
458prop_remove({props} [, {lnum} [, {lnum-end}]])
459 Number remove a text property
460prop_type_add({name}, {props}) none define a new property type
461prop_type_change({name}, {props})
462 none change an existing property type
463prop_type_delete({name} [, {props}])
464 none delete a property type
465prop_type_get({name} [, {props}])
466 Dict get property type values
467prop_type_list([{props}]) List get list of property types
468pum_getpos() Dict position and size of pum if visible
469pumvisible() Number whether popup menu is visible
470py3eval({expr}) any evaluate |python3| expression
471pyeval({expr}) any evaluate |Python| expression
472pyxeval({expr}) any evaluate |python_x| expression
473rand([{expr}]) Number get pseudo-random number
474range({expr} [, {max} [, {stride}]])
475 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100476readblob({fname} [, {offset} [, {size}]])
477 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000478readdir({dir} [, {expr} [, {dict}]])
479 List file names in {dir} selected by {expr}
480readdirex({dir} [, {expr} [, {dict}]])
481 List file info in {dir} selected by {expr}
482readfile({fname} [, {type} [, {max}]])
483 List get list of lines from file {fname}
484reduce({object}, {func} [, {initial}])
485 any reduce {object} using {func}
486reg_executing() String get the executing register name
487reg_recording() String get the recording register name
488reltime([{start} [, {end}]]) List get time value
489reltimefloat({time}) Float turn the time value into a Float
490reltimestr({time}) String turn time value into a String
491remote_expr({server}, {string} [, {idvar} [, {timeout}]])
492 String send expression
493remote_foreground({server}) Number bring Vim server to the foreground
494remote_peek({serverid} [, {retvar}])
495 Number check for reply string
496remote_read({serverid} [, {timeout}])
497 String read reply string
498remote_send({server}, {string} [, {idvar}])
499 String send key sequence
500remote_startserver({name}) none become server {name}
501remove({list}, {idx} [, {end}]) any/List
502 remove items {idx}-{end} from {list}
503remove({blob}, {idx} [, {end}]) Number/Blob
504 remove bytes {idx}-{end} from {blob}
505remove({dict}, {key}) any remove entry {key} from {dict}
506rename({from}, {to}) Number rename (move) file from {from} to {to}
Bakudankun375141e2022-09-09 18:46:47 +0100507repeat({expr}, {count}) List/Blob/String
508 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000509resolve({filename}) String get filename a shortcut points to
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +0100510reverse({obj}) List/Blob/String
511 reverse {obj}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000512round({expr}) Float round off {expr}
513rubyeval({expr}) any evaluate |Ruby| expression
514screenattr({row}, {col}) Number attribute at screen position
515screenchar({row}, {col}) Number character at screen position
516screenchars({row}, {col}) List List of characters at screen position
517screencol() Number current cursor column
518screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
519screenrow() Number current cursor row
520screenstring({row}, {col}) String characters at screen position
521search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
522 Number search for {pattern}
523searchcount([{options}]) Dict get or update search stats
524searchdecl({name} [, {global} [, {thisblock}]])
525 Number search for variable declaration
526searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
527 Number search for other end of start/end pair
528searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
529 List search for other end of start/end pair
530searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
531 List search for {pattern}
532server2client({clientid}, {string})
533 Number send reply string
534serverlist() String get a list of available servers
erraelf0837ba2024-06-24 12:27:01 -0700535setbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000536 Number set line {lnum} to {text} in buffer
erraelf0837ba2024-06-24 12:27:01 -0700537 {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000538setbufvar({buf}, {varname}, {val})
539 none set {varname} in buffer {buf} to {val}
540setcellwidths({list}) none set character cell width overrides
541setcharpos({expr}, {list}) Number set the {expr} position to {list}
542setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100543setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000544setcmdpos({pos}) Number set cursor position in command-line
545setcursorcharpos({list}) Number move cursor to position in {list}
546setenv({name}, {val}) none set environment variable
547setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
548setline({lnum}, {line}) Number set line {lnum} to {line}
549setloclist({nr}, {list} [, {action}])
550 Number modify location list using {list}
551setloclist({nr}, {list}, {action}, {what})
552 Number modify specific location list props
553setmatches({list} [, {win}]) Number restore a list of matches
554setpos({expr}, {list}) Number set the {expr} position to {list}
555setqflist({list} [, {action}]) Number modify quickfix list using {list}
556setqflist({list}, {action}, {what})
557 Number modify specific quickfix list props
558setreg({n}, {v} [, {opt}]) Number set register to value and type
559settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
560settabwinvar({tabnr}, {winnr}, {varname}, {val})
561 none set {varname} in window {winnr} in tab
562 page {tabnr} to {val}
563settagstack({nr}, {dict} [, {action}])
564 Number modify tag stack using {dict}
565setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
566sha256({string}) String SHA256 checksum of {string}
567shellescape({string} [, {special}])
568 String escape {string} for use as shell
569 command argument
570shiftwidth([{col}]) Number effective value of 'shiftwidth'
571sign_define({name} [, {dict}]) Number define or update a sign
572sign_define({list}) List define or update a list of signs
573sign_getdefined([{name}]) List get a list of defined signs
574sign_getplaced([{buf} [, {dict}]])
575 List get a list of placed signs
576sign_jump({id}, {group}, {buf})
577 Number jump to a sign
578sign_place({id}, {group}, {name}, {buf} [, {dict}])
579 Number place a sign
580sign_placelist({list}) List place a list of signs
581sign_undefine([{name}]) Number undefine a sign
582sign_undefine({list}) List undefine a list of signs
583sign_unplace({group} [, {dict}])
584 Number unplace a sign
585sign_unplacelist({list}) List unplace a list of signs
586simplify({filename}) String simplify filename as much as possible
587sin({expr}) Float sine of {expr}
588sinh({expr}) Float hyperbolic sine of {expr}
589slice({expr}, {start} [, {end}]) String, List or Blob
590 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000591sort({list} [, {how} [, {dict}]])
592 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000593sound_clear() none stop playing all sounds
594sound_playevent({name} [, {callback}])
595 Number play an event sound
596sound_playfile({path} [, {callback}])
597 Number play sound file {path}
598sound_stop({id}) none stop playing sound {id}
599soundfold({word}) String sound-fold {word}
600spellbadword() String badly spelled word at cursor
601spellsuggest({word} [, {max} [, {capital}]])
602 List spelling suggestions
603split({expr} [, {pat} [, {keepempty}]])
604 List make |List| from {pat} separated {expr}
605sqrt({expr}) Float square root of {expr}
606srand([{expr}]) List get seed for |rand()|
607state([{what}]) String current state of Vim
608str2float({expr} [, {quoted}]) Float convert String to Float
609str2list({expr} [, {utf8}]) List convert each character of {expr} to
610 ASCII/UTF-8 value
611str2nr({expr} [, {base} [, {quoted}]])
612 Number convert String to Number
613strcharlen({expr}) Number character length of the String {expr}
614strcharpart({str}, {start} [, {len} [, {skipcc}]])
615 String {len} characters of {str} at
616 character {start}
617strchars({expr} [, {skipcc}]) Number character count of the String {expr}
618strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
619strftime({format} [, {time}]) String format time with a specified format
620strgetchar({str}, {index}) Number get char {index} from {str}
621stridx({haystack}, {needle} [, {start}])
622 Number index of {needle} in {haystack}
623string({expr}) String String representation of {expr} value
624strlen({expr}) Number length of the String {expr}
625strpart({str}, {start} [, {len} [, {chars}]])
626 String {len} bytes/chars of {str} at
627 byte {start}
628strptime({format}, {timestring})
629 Number Convert {timestring} to unix timestamp
630strridx({haystack}, {needle} [, {start}])
631 Number last index of {needle} in {haystack}
632strtrans({expr}) String translate string to make it printable
Christian Brabandt67672ef2023-04-24 21:09:54 +0100633strutf16len({string} [, {countcc}])
634 Number number of UTF-16 code units in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000635strwidth({expr}) Number display cell length of the String {expr}
636submatch({nr} [, {list}]) String or List
637 specific match in ":s" or substitute()
638substitute({expr}, {pat}, {sub}, {flags})
639 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000640swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000641swapinfo({fname}) Dict information about swap file {fname}
642swapname({buf}) String swap file of buffer {buf}
643synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
644synIDattr({synID}, {what} [, {mode}])
645 String attribute {what} of syntax ID {synID}
646synIDtrans({synID}) Number translated syntax ID of {synID}
647synconcealed({lnum}, {col}) List info about concealing
648synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
649system({expr} [, {input}]) String output of shell command/filter {expr}
650systemlist({expr} [, {input}]) List output of shell command/filter {expr}
651tabpagebuflist([{arg}]) List list of buffer numbers in tab page
652tabpagenr([{arg}]) Number number of current or last tab page
653tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
654tagfiles() List tags files used
655taglist({expr} [, {filename}]) List list of tags matching {expr}
656tan({expr}) Float tangent of {expr}
657tanh({expr}) Float hyperbolic tangent of {expr}
658tempname() String name for a temporary file
659term_dumpdiff({filename}, {filename} [, {options}])
660 Number display difference between two dumps
661term_dumpload({filename} [, {options}])
662 Number displaying a screen dump
663term_dumpwrite({buf}, {filename} [, {options}])
664 none dump terminal window contents
665term_getaltscreen({buf}) Number get the alternate screen flag
666term_getansicolors({buf}) List get ANSI palette in GUI color mode
667term_getattr({attr}, {what}) Number get the value of attribute {what}
668term_getcursor({buf}) List get the cursor position of a terminal
669term_getjob({buf}) Job get the job associated with a terminal
670term_getline({buf}, {row}) String get a line of text from a terminal
671term_getscrolled({buf}) Number get the scroll count of a terminal
672term_getsize({buf}) List get the size of a terminal
673term_getstatus({buf}) String get the status of a terminal
674term_gettitle({buf}) String get the title of a terminal
675term_gettty({buf}, [{input}]) String get the tty name of a terminal
676term_list() List get the list of terminal buffers
677term_scrape({buf}, {row}) List get row of a terminal screen
678term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
679term_setansicolors({buf}, {colors})
680 none set ANSI palette in GUI color mode
681term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
682term_setkill({buf}, {how}) none set signal to stop job in terminal
683term_setrestore({buf}, {command}) none set command to restore terminal
684term_setsize({buf}, {rows}, {cols})
685 none set the size of a terminal
686term_start({cmd} [, {options}]) Number open a terminal window and run a job
687term_wait({buf} [, {time}]) Number wait for screen to be updated
688terminalprops() Dict properties of the terminal
689test_alloc_fail({id}, {countdown}, {repeat})
690 none make memory allocation fail
691test_autochdir() none enable 'autochdir' during startup
692test_feedinput({string}) none add key sequence to input buffer
693test_garbagecollect_now() none free memory right now for testing
694test_garbagecollect_soon() none free memory soon for testing
695test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000696test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000697test_ignore_error({expr}) none ignore a specific error
Christopher Plewright20b795e2022-12-20 20:01:58 +0000698test_mswin_event({event}, {args})
699 bool generate MS-Windows event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000700test_null_blob() Blob null value for testing
701test_null_channel() Channel null value for testing
702test_null_dict() Dict null value for testing
703test_null_function() Funcref null value for testing
704test_null_job() Job null value for testing
705test_null_list() List null value for testing
706test_null_partial() Funcref null value for testing
707test_null_string() String null value for testing
708test_option_not_set({name}) none reset flag indicating option was set
709test_override({expr}, {val}) none test with Vim internal overrides
710test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000711test_setmouse({row}, {col}) none set the mouse position for testing
712test_settime({expr}) none set current time for testing
Doug Kearns9cd9e752024-04-07 17:42:17 +0200713test_srand_seed([{seed}]) none set seed for testing srand()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000714test_unknown() any unknown value for testing
715test_void() any void value for testing
716timer_info([{id}]) List information about timers
717timer_pause({id}, {pause}) none pause or unpause a timer
718timer_start({time}, {callback} [, {options}])
719 Number create a timer
720timer_stop({timer}) none stop a timer
721timer_stopall() none stop all timers
722tolower({expr}) String the String {expr} switched to lowercase
723toupper({expr}) String the String {expr} switched to uppercase
724tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
725 to chars in {tostr}
726trim({text} [, {mask} [, {dir}]])
727 String trim characters in {mask} from {text}
728trunc({expr}) Float truncate Float {expr}
729type({expr}) Number type of value {expr}
730typename({expr}) String representation of the type of {expr}
731undofile({name}) String undo file name for {name}
Devin J. Pohly5fee1112023-04-23 20:26:59 -0500732undotree([{buf}]) List undo file tree for buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000733uniq({list} [, {func} [, {dict}]])
734 List remove adjacent duplicates from a list
Christian Brabandt67672ef2023-04-24 21:09:54 +0100735utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
736 Number UTF-16 index of byte {idx} in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000737values({dict}) List values in {dict}
zeertzjq825cf812023-08-17 22:55:25 +0200738virtcol({expr} [, {list} [, {winid}])
739 Number or List
LemonBoy0f7a3e12022-05-26 12:10:37 +0100740 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100741virtcol2col({winid}, {lnum}, {col})
742 Number byte index of a character on screen
Doug Kearns9cd9e752024-04-07 17:42:17 +0200743visualmode([{expr}]) String last visual mode used
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000744wildmenumode() Number whether 'wildmenu' mode is active
745win_execute({id}, {command} [, {silent}])
746 String execute {command} in window {id}
747win_findbuf({bufnr}) List find windows containing {bufnr}
748win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
749win_gettype([{nr}]) String type of window {nr}
750win_gotoid({expr}) Number go to window with ID {expr}
751win_id2tabwin({expr}) List get tab and window nr from window ID
752win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000753win_move_separator({nr}) Number move window vertical separator
754win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000755win_screenpos({nr}) List get screen position of window {nr}
756win_splitmove({nr}, {target} [, {options}])
757 Number move window {nr} to split of {target}
758winbufnr({nr}) Number buffer number of window {nr}
759wincol() Number window column of the cursor
760windowsversion() String MS-Windows OS version
761winheight({nr}) Number height of window {nr}
762winlayout([{tabnr}]) List layout of windows in tab {tabnr}
763winline() Number window line of the cursor
764winnr([{expr}]) Number number of current window
765winrestcmd() String returns command to restore window sizes
766winrestview({dict}) none restore view of current window
767winsaveview() Dict save view of current window
768winwidth({nr}) Number width of window {nr}
769wordcount() Dict get byte/char/word statistics
770writefile({object}, {fname} [, {flags}])
771 Number write |Blob| or |List| of lines to file
772xor({expr}, {expr}) Number bitwise XOR
773
774==============================================================================
7752. Details *builtin-function-details*
776
777Not all functions are here, some have been moved to a help file covering the
778specific functionality.
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200779Return type specifies the type for |Vim9-script|, see |vim9-types|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000780
781abs({expr}) *abs()*
782 Return the absolute value of {expr}. When {expr} evaluates to
783 a |Float| abs() returns a |Float|. When {expr} can be
784 converted to a |Number| abs() returns a |Number|. Otherwise
785 abs() gives an error message and returns -1.
786 Examples: >
787 echo abs(1.456)
788< 1.456 >
789 echo abs(-5.456)
790< 5.456 >
791 echo abs(-4)
792< 4
793
794 Can also be used as a |method|: >
795 Compute()->abs()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200796<
797 Return type: |Number| or |Float| depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000798
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000799
800acos({expr}) *acos()*
801 Return the arc cosine of {expr} measured in radians, as a
802 |Float| in the range of [0, pi].
803 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100804 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000805 Examples: >
806 :echo acos(0)
807< 1.570796 >
808 :echo acos(-0.5)
809< 2.094395
810
811 Can also be used as a |method|: >
812 Compute()->acos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200813<
814 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000815
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000816
817add({object}, {expr}) *add()*
818 Append the item {expr} to |List| or |Blob| {object}. Returns
819 the resulting |List| or |Blob|. Examples: >
820 :let alist = add([1, 2, 3], item)
821 :call add(mylist, "woodstock")
822< Note that when {expr} is a |List| it is appended as a single
823 item. Use |extend()| to concatenate |Lists|.
824 When {object} is a |Blob| then {expr} must be a number.
825 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100826 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000827
828 Can also be used as a |method|: >
829 mylist->add(val1)->add(val2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200830<
831 Return type: list<{type}> (depending on the given |List|) or
832 |Blob|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000833
834
835and({expr}, {expr}) *and()*
836 Bitwise AND on the two arguments. The arguments are converted
837 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100838 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000839 Example: >
840 :let flag = and(bits, 0x80)
841< Can also be used as a |method|: >
842 :let flag = bits->and(0x80)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200843<
844 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000845
846
847append({lnum}, {text}) *append()*
848 When {text} is a |List|: Append each item of the |List| as a
849 text line below line {lnum} in the current buffer.
850 Otherwise append {text} as one text line below line {lnum} in
851 the current buffer.
852 Any type of item is accepted and converted to a String.
853 {lnum} can be zero to insert a line before the first one.
854 {lnum} is used like with |getline()|.
855 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000856 0 for success. When {text} is an empty list zero is returned,
857 no matter the value of {lnum}.
858 In |Vim9| script an invalid argument or negative number
859 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000860 :let failed = append(line('$'), "# THE END")
861 :let failed = append(0, ["Chapter 1", "the beginning"])
862
863< Can also be used as a |method| after a List, the base is
864 passed as the second argument: >
865 mylist->append(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200866<
867 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000868
869
870appendbufline({buf}, {lnum}, {text}) *appendbufline()*
871 Like |append()| but append the text in buffer {buf}.
872
873 This function works only for loaded buffers. First call
874 |bufload()| if needed.
875
876 For the use of {buf}, see |bufname()|.
877
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000878 {lnum} is the line number to append below. Note that using
879 |line()| would use the current buffer, not the one appending
880 to. Use "$" to append at the end of the buffer. Other string
881 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000882
883 On success 0 is returned, on failure 1 is returned.
884 In |Vim9| script an error is given for an invalid {lnum}.
885
886 If {buf} is not a valid buffer or {lnum} is not valid, an
887 error message is given. Example: >
888 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000889< However, when {text} is an empty list then no error is given
890 for an invalid {lnum}, since {lnum} isn't actually used.
891
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000892 Can also be used as a |method| after a List, the base is
893 passed as the second argument: >
894 mylist->appendbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200895<
896 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000897
898
899argc([{winid}]) *argc()*
900 The result is the number of files in the argument list. See
901 |arglist|.
902 If {winid} is not supplied, the argument list of the current
903 window is used.
904 If {winid} is -1, the global argument list is used.
905 Otherwise {winid} specifies the window of which the argument
906 list is used: either the window number or the window ID.
907 Returns -1 if the {winid} argument is invalid.
908
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200909 Return type: |Number|
910
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000911 *argidx()*
912argidx() The result is the current index in the argument list. 0 is
913 the first file. argc() - 1 is the last one. See |arglist|.
914
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200915 Return type: |Number|
916
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000917 *arglistid()*
918arglistid([{winnr} [, {tabnr}]])
919 Return the argument list ID. This is a number which
920 identifies the argument list being used. Zero is used for the
921 global argument list. See |arglist|.
922 Returns -1 if the arguments are invalid.
923
924 Without arguments use the current window.
925 With {winnr} only use this window in the current tab page.
926 With {winnr} and {tabnr} use the window in the specified tab
927 page.
928 {winnr} can be the window number or the |window-ID|.
929
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200930 Return type: |Number|
931
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000932 *argv()*
933argv([{nr} [, {winid}]])
934 The result is the {nr}th file in the argument list. See
935 |arglist|. "argv(0)" is the first one. Example: >
936 :let i = 0
937 :while i < argc()
938 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000939 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000940 : let i = i + 1
941 :endwhile
942< Without the {nr} argument, or when {nr} is -1, a |List| with
943 the whole |arglist| is returned.
944
945 The {winid} argument specifies the window ID, see |argc()|.
946 For the Vim command line arguments see |v:argv|.
947
Bram Moolenaar016188f2022-06-06 20:52:59 +0100948 Returns an empty string if {nr}th argument is not present in
949 the argument list. Returns an empty List if the {winid}
950 argument is invalid.
951
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200952 Return type: |String|
953
954
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000955asin({expr}) *asin()*
956 Return the arc sine of {expr} measured in radians, as a |Float|
957 in the range of [-pi/2, pi/2].
958 {expr} must evaluate to a |Float| or a |Number| in the range
959 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100960 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
961 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000962 Examples: >
963 :echo asin(0.8)
964< 0.927295 >
965 :echo asin(-0.5)
966< -0.523599
967
968 Can also be used as a |method|: >
969 Compute()->asin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200970<
971 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000972
973assert_ functions are documented here: |assert-functions-details|
974
975
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000976atan({expr}) *atan()*
977 Return the principal value of the arc tangent of {expr}, in
978 the range [-pi/2, +pi/2] radians, as a |Float|.
979 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100980 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000981 Examples: >
982 :echo atan(100)
983< 1.560797 >
984 :echo atan(-4.01)
985< -1.326405
986
987 Can also be used as a |method|: >
988 Compute()->atan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200989<
990 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000991
992
993atan2({expr1}, {expr2}) *atan2()*
994 Return the arc tangent of {expr1} / {expr2}, measured in
995 radians, as a |Float| in the range [-pi, pi].
996 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100997 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
998 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000999 Examples: >
1000 :echo atan2(-1, 1)
1001< -0.785398 >
1002 :echo atan2(1, -1)
1003< 2.356194
1004
1005 Can also be used as a |method|: >
1006 Compute()->atan2(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001007<
1008 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001009
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001010
1011autocmd_add({acmds}) *autocmd_add()*
1012 Adds a List of autocmds and autocmd groups.
1013
1014 The {acmds} argument is a List where each item is a Dict with
1015 the following optional items:
1016 bufnr buffer number to add a buffer-local autocmd.
1017 If this item is specified, then the "pattern"
1018 item is ignored.
1019 cmd Ex command to execute for this autocmd event
1020 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001021 This can be either a String with a single
1022 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001023 group autocmd group name. Refer to |autocmd-groups|.
1024 If this group doesn't exist then it is
1025 created. If not specified or empty, then the
1026 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001027 nested boolean flag, set to v:true to add a nested
1028 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +01001029 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001030 which executes only once. Refer to
1031 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001032 pattern autocmd pattern string. Refer to
1033 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001034 present, then this item is ignored. This can
1035 be a String with a single pattern or a List of
1036 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001037 replace boolean flag, set to v:true to remove all the
1038 commands associated with the specified autocmd
1039 event and group and add the {cmd}. This is
1040 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +01001041 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001042
1043 Returns v:true on success and v:false on failure.
1044 Examples: >
1045 " Create a buffer-local autocmd for buffer 5
1046 let acmd = {}
1047 let acmd.group = 'MyGroup'
1048 let acmd.event = 'BufEnter'
1049 let acmd.bufnr = 5
1050 let acmd.cmd = 'call BufEnterFunc()'
1051 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00001052<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001053 Can also be used as a |method|: >
1054 GetAutocmdList()->autocmd_add()
1055<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001056 Return type: |vim9-boolean|
1057
1058
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001059autocmd_delete({acmds}) *autocmd_delete()*
1060 Deletes a List of autocmds and autocmd groups.
1061
1062 The {acmds} argument is a List where each item is a Dict with
1063 the following optional items:
1064 bufnr buffer number to delete a buffer-local autocmd.
1065 If this item is specified, then the "pattern"
1066 item is ignored.
1067 cmd Ex command for this autocmd event
1068 event autocmd event name. Refer to |autocmd-events|.
1069 If '*' then all the autocmd events in this
1070 group are deleted.
1071 group autocmd group name. Refer to |autocmd-groups|.
1072 If not specified or empty, then the default
1073 group is used.
1074 nested set to v:true for a nested autocmd.
1075 Refer to |autocmd-nested|.
1076 once set to v:true for an autocmd which executes
1077 only once. Refer to |autocmd-once|.
1078 pattern autocmd pattern string. Refer to
1079 |autocmd-patterns|. If "bufnr" item is
1080 present, then this item is ignored.
1081
1082 If only {group} is specified in a {acmds} entry and {event},
1083 {pattern} and {cmd} are not specified, then that autocmd group
1084 is deleted.
1085
Bram Moolenaar016188f2022-06-06 20:52:59 +01001086 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001087 Examples: >
1088 " :autocmd! BufLeave *.vim
1089 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1090 call autocmd_delete([acmd]})
1091 " :autocmd! MyGroup1 BufLeave
1092 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1093 call autocmd_delete([acmd])
1094 " :autocmd! MyGroup2 BufEnter *.c
1095 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1096 \ pattern: '*.c'}
1097 " :autocmd! MyGroup2 * *.c
1098 let acmd = #{group: 'MyGroup2', event: '*',
1099 \ pattern: '*.c'}
1100 call autocmd_delete([acmd])
1101 " :autocmd! MyGroup3
1102 let acmd = #{group: 'MyGroup3'}
1103 call autocmd_delete([acmd])
1104<
1105 Can also be used as a |method|: >
1106 GetAutocmdList()->autocmd_delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001107<
1108 Return type: |vim9-boolean|
1109
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001110
1111autocmd_get([{opts}]) *autocmd_get()*
1112 Returns a |List| of autocmds. If {opts} is not supplied, then
1113 returns the autocmds for all the events in all the groups.
1114
1115 The optional {opts} Dict argument supports the following
1116 items:
1117 group Autocmd group name. If specified, returns only
1118 the autocmds defined in this group. If the
1119 specified group doesn't exist, results in an
1120 error message. If set to an empty string,
1121 then the default autocmd group is used.
1122 event Autocmd event name. If specified, returns only
1123 the autocmds defined for this event. If set
1124 to "*", then returns autocmds for all the
1125 events. If the specified event doesn't exist,
1126 results in an error message.
1127 pattern Autocmd pattern. If specified, returns only
1128 the autocmds defined for this pattern.
1129 A combination of the above three times can be supplied in
1130 {opts}.
1131
1132 Each Dict in the returned List contains the following items:
1133 bufnr For buffer-local autocmds, buffer number where
1134 the autocmd is defined.
1135 cmd Command executed for this autocmd.
1136 event Autocmd event name.
1137 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001138 nested Boolean flag, set to v:true for a nested
1139 autocmd. See |autocmd-nested|.
1140 once Boolean flag, set to v:true, if the autocmd
1141 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001142 pattern Autocmd pattern. For a buffer-local
1143 autocmd, this will be of the form "<buffer=n>".
1144 If there are multiple commands for an autocmd event in a
1145 group, then separate items are returned for each command.
1146
Bram Moolenaar016188f2022-06-06 20:52:59 +01001147 Returns an empty List if an autocmd with the specified group
1148 or event or pattern is not found.
1149
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001150 Examples: >
1151 " :autocmd MyGroup
1152 echo autocmd_get(#{group: 'Mygroup'})
1153 " :autocmd G BufUnload
1154 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1155 " :autocmd G * *.ts
1156 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1157 echo autocmd_get(acmd)
1158 " :autocmd Syntax
1159 echo autocmd_get(#{event: 'Syntax'})
1160 " :autocmd G BufEnter *.ts
1161 let acmd = #{group: 'G', event: 'BufEnter',
1162 \ pattern: '*.ts'}
1163 echo autocmd_get(acmd)
1164<
1165 Can also be used as a |method|: >
1166 Getopts()->autocmd_get()
1167<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001168 Return type: list<dict<any>>
1169
1170
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001171balloon_gettext() *balloon_gettext()*
1172 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001173 not used for the List. Returns an empty string if balloon
1174 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001175
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001176 Return type: |String|
1177
1178
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001179balloon_show({expr}) *balloon_show()*
1180 Show {expr} inside the balloon. For the GUI {expr} is used as
1181 a string. For a terminal {expr} can be a list, which contains
1182 the lines of the balloon. If {expr} is not a list it will be
1183 split with |balloon_split()|.
1184 If {expr} is an empty string any existing balloon is removed.
1185
1186 Example: >
1187 func GetBalloonContent()
1188 " ... initiate getting the content
1189 return ''
1190 endfunc
1191 set balloonexpr=GetBalloonContent()
1192
1193 func BalloonCallback(result)
1194 call balloon_show(a:result)
1195 endfunc
1196< Can also be used as a |method|: >
1197 GetText()->balloon_show()
1198<
1199 The intended use is that fetching the content of the balloon
1200 is initiated from 'balloonexpr'. It will invoke an
1201 asynchronous method, in which a callback invokes
1202 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001203 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001204
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001205 When showing a balloon is not possible then nothing happens,
1206 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001207 {only available when compiled with the |+balloon_eval| or
1208 |+balloon_eval_term| feature}
1209
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001210 Return type: |Number|
1211
1212
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001213balloon_split({msg}) *balloon_split()*
1214 Split String {msg} into lines to be displayed in a balloon.
1215 The splits are made for the current window size and optimize
1216 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001217 Returns a |List| with the split lines. Returns an empty List
1218 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001219 Can also be used as a |method|: >
1220 GetText()->balloon_split()->balloon_show()
1221
1222< {only available when compiled with the |+balloon_eval_term|
1223 feature}
1224
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001225 Return type: list<any> or list<string>
1226
Christ van Willegence0ef912024-06-20 23:41:59 +02001227bindtextdomain({package}, {path}) *bindtextdomain()*
1228 Bind a specific {package} to a {path} so that the
1229 |gettext()| function can be used to get language-specific
1230 translations for a package. {path} is the directory name
h-east52e7cc22024-07-28 17:03:29 +02001231 for the translations. See |package-translation|.
Christ van Willegence0ef912024-06-20 23:41:59 +02001232
Christ van Willegen8252ef12024-07-11 21:36:21 +02001233 Returns v:true on success and v:false on failure (out of
1234 memory).
1235
1236 Return type: |vim9-boolean|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001237
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001238blob2list({blob}) *blob2list()*
1239 Return a List containing the number value of each byte in Blob
1240 {blob}. Examples: >
1241 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1242 blob2list(0z) returns []
1243< Returns an empty List on error. |list2blob()| does the
1244 opposite.
1245
1246 Can also be used as a |method|: >
1247 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001248<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001249 Return type: list<any> or list<number>
1250
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001251 *browse()*
1252browse({save}, {title}, {initdir}, {default})
1253 Put up a file requester. This only works when "has("browse")"
1254 returns |TRUE| (only in some GUI versions).
1255 The input fields are:
1256 {save} when |TRUE|, select file to write
1257 {title} title for the requester
1258 {initdir} directory to start browsing in
1259 {default} default file name
1260 An empty string is returned when the "Cancel" button is hit,
1261 something went wrong, or browsing is not possible.
1262
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001263 Return type: |String|
1264
1265
1266browsedir({title}, {initdir}) *browsedir()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001267 Put up a directory requester. This only works when
1268 "has("browse")" returns |TRUE| (only in some GUI versions).
1269 On systems where a directory browser is not supported a file
1270 browser is used. In that case: select a file in the directory
1271 to be used.
1272 The input fields are:
1273 {title} title for the requester
1274 {initdir} directory to start browsing in
1275 When the "Cancel" button is hit, something went wrong, or
1276 browsing is not possible, an empty string is returned.
1277
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001278 Return type: |String|
1279
1280
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001281bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001282 Add a buffer to the buffer list with name {name} (must be a
1283 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001284 If a buffer for file {name} already exists, return that buffer
1285 number. Otherwise return the buffer number of the newly
1286 created buffer. When {name} is an empty string then a new
1287 buffer is always created.
1288 The buffer will not have 'buflisted' set and not be loaded
1289 yet. To add some text to the buffer use this: >
1290 let bufnr = bufadd('someName')
1291 call bufload(bufnr)
1292 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001293< Returns 0 on error.
1294 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001295 let bufnr = 'somename'->bufadd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001296<
1297 Return type: |Number|
1298
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001299
1300bufexists({buf}) *bufexists()*
1301 The result is a Number, which is |TRUE| if a buffer called
1302 {buf} exists.
1303 If the {buf} argument is a number, buffer numbers are used.
1304 Number zero is the alternate buffer for the current window.
1305
1306 If the {buf} argument is a string it must match a buffer name
1307 exactly. The name can be:
1308 - Relative to the current directory.
1309 - A full path.
1310 - The name of a buffer with 'buftype' set to "nofile".
1311 - A URL name.
1312 Unlisted buffers will be found.
1313 Note that help files are listed by their short name in the
1314 output of |:buffers|, but bufexists() requires using their
1315 long name to be able to find them.
1316 bufexists() may report a buffer exists, but to use the name
1317 with a |:buffer| command you may need to use |expand()|. Esp
1318 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1319 Use "bufexists(0)" to test for the existence of an alternate
1320 file name.
1321
1322 Can also be used as a |method|: >
1323 let exists = 'somename'->bufexists()
1324<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001325 Return type: |Number|
1326
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001327 Obsolete name: buffer_exists(). *buffer_exists()*
1328
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001329
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001330buflisted({buf}) *buflisted()*
1331 The result is a Number, which is |TRUE| if a buffer called
1332 {buf} exists and is listed (has the 'buflisted' option set).
1333 The {buf} argument is used like with |bufexists()|.
1334
1335 Can also be used as a |method|: >
1336 let listed = 'somename'->buflisted()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001337<
1338 Return type: |Number|
1339
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001340
1341bufload({buf}) *bufload()*
1342 Ensure the buffer {buf} is loaded. When the buffer name
1343 refers to an existing file then the file is read. Otherwise
1344 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001345 then there is no change. If the buffer is not related to a
Daniel Steinbergc2bd2052023-08-09 12:10:59 -04001346 file then no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001347 If there is an existing swap file for the file of the buffer,
1348 there will be no dialog, the buffer will be loaded anyway.
1349 The {buf} argument is used like with |bufexists()|.
1350
1351 Can also be used as a |method|: >
1352 eval 'somename'->bufload()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001353<
1354 Return type: |Number|
1355
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001356
1357bufloaded({buf}) *bufloaded()*
1358 The result is a Number, which is |TRUE| if a buffer called
1359 {buf} exists and is loaded (shown in a window or hidden).
1360 The {buf} argument is used like with |bufexists()|.
1361
1362 Can also be used as a |method|: >
1363 let loaded = 'somename'->bufloaded()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001364<
1365 Return type: |Number|
1366
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001367
1368bufname([{buf}]) *bufname()*
1369 The result is the name of a buffer. Mostly as it is displayed
1370 by the `:ls` command, but not using special names such as
1371 "[No Name]".
1372 If {buf} is omitted the current buffer is used.
1373 If {buf} is a Number, that buffer number's name is given.
1374 Number zero is the alternate buffer for the current window.
1375 If {buf} is a String, it is used as a |file-pattern| to match
1376 with the buffer names. This is always done like 'magic' is
1377 set and 'cpoptions' is empty. When there is more than one
1378 match an empty string is returned.
1379 "" or "%" can be used for the current buffer, "#" for the
1380 alternate buffer.
1381 A full match is preferred, otherwise a match at the start, end
1382 or middle of the buffer name is accepted. If you only want a
1383 full match then put "^" at the start and "$" at the end of the
1384 pattern.
1385 Listed buffers are found first. If there is a single match
1386 with a listed buffer, that one is returned. Next unlisted
1387 buffers are searched for.
1388 If the {buf} is a String, but you want to use it as a buffer
1389 number, force it to be a Number by adding zero to it: >
1390 :echo bufname("3" + 0)
1391< Can also be used as a |method|: >
1392 echo bufnr->bufname()
1393
1394< If the buffer doesn't exist, or doesn't have a name, an empty
1395 string is returned. >
1396 bufname("#") alternate buffer name
1397 bufname(3) name of buffer 3
1398 bufname("%") name of current buffer
1399 bufname("file2") name of buffer where "file2" matches.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001400<
1401 Return type: |String|
1402 *buffer_name()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001403 Obsolete name: buffer_name().
1404
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001405
1406bufnr([{buf} [, {create}]]) *bufnr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001407 The result is the number of a buffer, as it is displayed by
1408 the `:ls` command. For the use of {buf}, see |bufname()|
1409 above.
1410
1411 If the buffer doesn't exist, -1 is returned. Or, if the
1412 {create} argument is present and TRUE, a new, unlisted,
1413 buffer is created and its number is returned. Example: >
1414 let newbuf = bufnr('Scratch001', 1)
1415< Using an empty name uses the current buffer. To create a new
1416 buffer with an empty name use |bufadd()|.
1417
1418 bufnr("$") is the last buffer: >
1419 :let last_buffer = bufnr("$")
1420< The result is a Number, which is the highest buffer number
1421 of existing buffers. Note that not all buffers with a smaller
1422 number necessarily exist, because ":bwipeout" may have removed
1423 them. Use bufexists() to test for the existence of a buffer.
1424
1425 Can also be used as a |method|: >
1426 echo bufref->bufnr()
1427<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001428 Return type: |Number|
1429
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001430 Obsolete name: buffer_number(). *buffer_number()*
1431 *last_buffer_nr()*
1432 Obsolete name for bufnr("$"): last_buffer_nr().
1433
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001434
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001435bufwinid({buf}) *bufwinid()*
1436 The result is a Number, which is the |window-ID| of the first
1437 window associated with buffer {buf}. For the use of {buf},
1438 see |bufname()| above. If buffer {buf} doesn't exist or
1439 there is no such window, -1 is returned. Example: >
1440
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001441 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001442<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001443 Only deals with the current tab page. See |win_findbuf()| for
1444 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001445
1446 Can also be used as a |method|: >
1447 FindBuffer()->bufwinid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001448<
1449 Return type: |Number|
1450
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001451
1452bufwinnr({buf}) *bufwinnr()*
1453 Like |bufwinid()| but return the window number instead of the
1454 |window-ID|.
1455 If buffer {buf} doesn't exist or there is no such window, -1
1456 is returned. Example: >
1457
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001458 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001459
1460< The number can be used with |CTRL-W_w| and ":wincmd w"
1461 |:wincmd|.
1462
1463 Can also be used as a |method|: >
1464 FindBuffer()->bufwinnr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001465<
1466 Return type: |Number|
1467
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001468
1469byte2line({byte}) *byte2line()*
1470 Return the line number that contains the character at byte
1471 count {byte} in the current buffer. This includes the
1472 end-of-line character, depending on the 'fileformat' option
1473 for the current buffer. The first character has byte count
1474 one.
1475 Also see |line2byte()|, |go| and |:goto|.
1476
Bram Moolenaar016188f2022-06-06 20:52:59 +01001477 Returns -1 if the {byte} value is invalid.
1478
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001479 Can also be used as a |method|: >
1480 GetOffset()->byte2line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001481<
1482 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001483
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001484 {not available when compiled without the |+byte_offset|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001485 feature}
1486
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001487
Christian Brabandt67672ef2023-04-24 21:09:54 +01001488byteidx({expr}, {nr} [, {utf16}]) *byteidx()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001489 Return byte index of the {nr}'th character in the String
1490 {expr}. Use zero for the first character, it then returns
1491 zero.
1492 If there are no multibyte characters the returned value is
1493 equal to {nr}.
1494 Composing characters are not counted separately, their byte
1495 length is added to the preceding base character. See
1496 |byteidxcomp()| below for counting composing characters
1497 separately.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001498 When {utf16} is present and TRUE, {nr} is used as the UTF-16
1499 index in the String {expr} instead of as the character index.
1500 The UTF-16 index is the index in the string when it is encoded
1501 with 16-bit words. If the specified UTF-16 index is in the
1502 middle of a character (e.g. in a 4-byte character), then the
1503 byte index of the first byte in the character is returned.
1504 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001505 Example : >
1506 echo matchstr(str, ".", byteidx(str, 3))
1507< will display the fourth character. Another way to do the
1508 same: >
1509 let s = strpart(str, byteidx(str, 3))
1510 echo strpart(s, 0, byteidx(s, 1))
1511< Also see |strgetchar()| and |strcharpart()|.
1512
1513 If there are less than {nr} characters -1 is returned.
1514 If there are exactly {nr} characters the length of the string
1515 in bytes is returned.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001516 See |charidx()| and |utf16idx()| for getting the character and
1517 UTF-16 index respectively from the byte index.
1518 Examples: >
1519 echo byteidx('a😊😊', 2) returns 5
1520 echo byteidx('a😊😊', 2, 1) returns 1
1521 echo byteidx('a😊😊', 3, 1) returns 5
1522<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001523 Can also be used as a |method|: >
1524 GetName()->byteidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001525<
1526 Return type: |Number|
1527
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001528
Christian Brabandt67672ef2023-04-24 21:09:54 +01001529byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001530 Like byteidx(), except that a composing character is counted
1531 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001532 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001533 echo byteidx(s, 1)
1534 echo byteidxcomp(s, 1)
1535 echo byteidxcomp(s, 2)
1536< The first and third echo result in 3 ('e' plus composing
1537 character is 3 bytes), the second echo results in 1 ('e' is
1538 one byte).
1539 Only works differently from byteidx() when 'encoding' is set
1540 to a Unicode encoding.
1541
1542 Can also be used as a |method|: >
1543 GetName()->byteidxcomp(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001544<
1545 Return type: |Number|
1546
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001547
1548call({func}, {arglist} [, {dict}]) *call()* *E699*
1549 Call function {func} with the items in |List| {arglist} as
1550 arguments.
1551 {func} can either be a |Funcref| or the name of a function.
1552 a:firstline and a:lastline are set to the cursor line.
1553 Returns the return value of the called function.
1554 {dict} is for functions with the "dict" attribute. It will be
1555 used to set the local variable "self". |Dictionary-function|
1556
1557 Can also be used as a |method|: >
1558 GetFunc()->call([arg, arg], dict)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001559<
1560 Return type: any, depending on {func}
1561
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001562
1563ceil({expr}) *ceil()*
1564 Return the smallest integral value greater than or equal to
1565 {expr} as a |Float| (round up).
1566 {expr} must evaluate to a |Float| or a |Number|.
1567 Examples: >
1568 echo ceil(1.456)
1569< 2.0 >
1570 echo ceil(-5.456)
1571< -5.0 >
1572 echo ceil(4.0)
1573< 4.0
1574
Bram Moolenaar016188f2022-06-06 20:52:59 +01001575 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1576
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001577 Can also be used as a |method|: >
1578 Compute()->ceil()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001579<
1580 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001581
1582
1583ch_ functions are documented here: |channel-functions-details|
1584
1585
1586changenr() *changenr()*
1587 Return the number of the most recent change. This is the same
1588 number as what is displayed with |:undolist| and can be used
1589 with the |:undo| command.
1590 When a change was made it is the number of that change. After
1591 redo it is the number of the redone change. After undo it is
1592 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001593 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001594
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001595 Return type: |Number|
1596
1597
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001598char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001599 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001600 Examples: >
1601 char2nr(" ") returns 32
1602 char2nr("ABC") returns 65
1603< When {utf8} is omitted or zero, the current 'encoding' is used.
1604 Example for "utf-8": >
1605 char2nr("á") returns 225
1606 char2nr("á"[0]) returns 195
1607< When {utf8} is TRUE, always treat as UTF-8 characters.
1608 A combining character is a separate character.
1609 |nr2char()| does the opposite.
1610 To turn a string into a list of character numbers: >
1611 let str = "ABC"
1612 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1613< Result: [65, 66, 67]
1614
Bram Moolenaar016188f2022-06-06 20:52:59 +01001615 Returns 0 if {string} is not a |String|.
1616
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001617 Can also be used as a |method|: >
1618 GetChar()->char2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001619<
1620 Return type: |Number|
1621
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001622
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001623charclass({string}) *charclass()*
1624 Return the character class of the first character in {string}.
1625 The character class is one of:
1626 0 blank
1627 1 punctuation
1628 2 word character
1629 3 emoji
1630 other specific Unicode class
1631 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001632 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001633
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001634 Return type: |Number|
1635
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001636
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001637charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001638 Same as |col()| but returns the character index of the column
1639 position given with {expr} instead of the byte position.
1640
1641 Example:
1642 With the cursor on '세' in line 5 with text "여보세요": >
1643 charcol('.') returns 3
1644 col('.') returns 7
1645
1646< Can also be used as a |method|: >
1647 GetPos()->col()
1648<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001649 Return type: |Number|
1650
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001651 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001652charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001653 Return the character index of the byte at {idx} in {string}.
1654 The index of the first character is zero.
1655 If there are no multibyte characters the returned value is
1656 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001657
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001658 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001659 are not counted separately, their byte length is added to the
1660 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001661 When {countcc} is |TRUE|, then composing characters are
1662 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001663
1664 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1665 index in the String {expr} instead of as the byte index.
1666
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001667 Returns -1 if the arguments are invalid or if there are less
1668 than {idx} bytes. If there are exactly {idx} bytes the length
1669 of the string in characters is returned.
1670
1671 An error is given and -1 is returned if the first argument is
1672 not a string, the second argument is not a number or when the
1673 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001674
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001675 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001676 from the character index and |utf16idx()| for getting the
1677 UTF-16 index from the character index.
1678 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001679 Examples: >
1680 echo charidx('áb́ć', 3) returns 1
1681 echo charidx('áb́ć', 6, 1) returns 4
1682 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001683 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001684<
1685 Can also be used as a |method|: >
1686 GetName()->charidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001687<
1688 Return type: |Number|
1689
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001690
1691chdir({dir}) *chdir()*
1692 Change the current working directory to {dir}. The scope of
1693 the directory change depends on the directory of the current
1694 window:
1695 - If the current window has a window-local directory
1696 (|:lcd|), then changes the window local directory.
1697 - Otherwise, if the current tabpage has a local
1698 directory (|:tcd|) then changes the tabpage local
1699 directory.
1700 - Otherwise, changes the global directory.
1701 {dir} must be a String.
1702 If successful, returns the previous working directory. Pass
1703 this to another chdir() to restore the directory.
1704 On failure, returns an empty string.
1705
1706 Example: >
1707 let save_dir = chdir(newdir)
1708 if save_dir != ""
1709 " ... do some work
1710 call chdir(save_dir)
1711 endif
1712
1713< Can also be used as a |method|: >
1714 GetDir()->chdir()
1715<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001716 Return type: |String|
1717
1718
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001719cindent({lnum}) *cindent()*
1720 Get the amount of indent for line {lnum} according the C
1721 indenting rules, as with 'cindent'.
1722 The indent is counted in spaces, the value of 'tabstop' is
1723 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001724 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001725 See |C-indenting|.
1726
1727 Can also be used as a |method|: >
1728 GetLnum()->cindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001729<
1730 Return type: |Number|
1731
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001732
1733clearmatches([{win}]) *clearmatches()*
1734 Clears all matches previously defined for the current window
1735 by |matchadd()| and the |:match| commands.
1736 If {win} is specified, use the window with this number or
1737 window ID instead of the current window.
1738
1739 Can also be used as a |method|: >
1740 GetWin()->clearmatches()
1741<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001742 Return type: |Number|
1743
1744
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001745col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001746 The result is a Number, which is the byte index of the column
zeertzjq02f3eba2024-06-12 20:45:24 +02001747 position given with {expr}.
1748 For accepted positions see |getpos()|.
zeertzjqd353d272024-06-13 23:00:25 +08001749 When {expr} is "$", it means the end of the cursor line, so
1750 the result is the number of bytes in the cursor line plus one.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001751 Additionally {expr} can be [lnum, col]: a |List| with the line
1752 and column number. Most useful when the column is "$", to get
1753 the last column of a specific line. When "lnum" or "col" is
1754 out of range then col() returns zero.
zeertzjq02f3eba2024-06-12 20:45:24 +02001755
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001756 With the optional {winid} argument the values are obtained for
1757 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02001758
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001759 To get the line number use |line()|. To get both use
1760 |getpos()|.
1761 For the screen column position use |virtcol()|. For the
1762 character position use |charcol()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02001763
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001764 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +02001765
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001766 Examples: >
1767 col(".") column of cursor
1768 col("$") length of cursor line plus one
1769 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001770 col("'" .. markname) column of mark markname
zeertzjq02f3eba2024-06-12 20:45:24 +02001771<
1772 The first column is 1. Returns 0 if {expr} is invalid or when
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001773 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001774 For an uppercase mark the column may actually be in another
1775 buffer.
1776 For the cursor position, when 'virtualedit' is active, the
1777 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001778 line. Also, when using a <Cmd> mapping the cursor isn't
1779 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001780 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001781
1782< Can also be used as a |method|: >
1783 GetPos()->col()
1784<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001785 Return type: |Number|
1786
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001787
1788complete({startcol}, {matches}) *complete()* *E785*
1789 Set the matches for Insert mode completion.
1790 Can only be used in Insert mode. You need to use a mapping
1791 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1792 or with an expression mapping.
1793 {startcol} is the byte offset in the line where the completed
1794 text start. The text up to the cursor is the original text
1795 that will be replaced by the matches. Use col('.') for an
1796 empty string. "col('.') - 1" will replace one character by a
1797 match.
1798 {matches} must be a |List|. Each |List| item is one match.
1799 See |complete-items| for the kind of items that are possible.
1800 "longest" in 'completeopt' is ignored.
1801 Note that the after calling this function you need to avoid
1802 inserting anything that would cause completion to stop.
1803 The match can be selected with CTRL-N and CTRL-P as usual with
1804 Insert mode completion. The popup menu will appear if
1805 specified, see |ins-completion-menu|.
1806 Example: >
1807 inoremap <F5> <C-R>=ListMonths()<CR>
1808
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001809 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001810 call complete(col('.'), ['January', 'February', 'March',
1811 \ 'April', 'May', 'June', 'July', 'August', 'September',
1812 \ 'October', 'November', 'December'])
1813 return ''
1814 endfunc
1815< This isn't very useful, but it shows how it works. Note that
1816 an empty string is returned to avoid a zero being inserted.
1817
1818 Can also be used as a |method|, the base is passed as the
1819 second argument: >
1820 GetMatches()->complete(col('.'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001821<
1822 Return type: |Number|
1823
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001824
1825complete_add({expr}) *complete_add()*
1826 Add {expr} to the list of matches. Only to be used by the
1827 function specified with the 'completefunc' option.
1828 Returns 0 for failure (empty string or out of memory),
1829 1 when the match was added, 2 when the match was already in
1830 the list.
1831 See |complete-functions| for an explanation of {expr}. It is
1832 the same as one item in the list that 'omnifunc' would return.
1833
1834 Can also be used as a |method|: >
1835 GetMoreMatches()->complete_add()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001836<
1837 Return type: |Number|
1838
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001839
1840complete_check() *complete_check()*
1841 Check for a key typed while looking for completion matches.
1842 This is to be used when looking for matches takes some time.
1843 Returns |TRUE| when searching for matches is to be aborted,
1844 zero otherwise.
1845 Only to be used by the function specified with the
1846 'completefunc' option.
1847
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001848 Return type: |Number|
1849
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001850
1851complete_info([{what}]) *complete_info()*
1852 Returns a |Dictionary| with information about Insert mode
1853 completion. See |ins-completion|.
1854 The items are:
1855 mode Current completion mode name string.
1856 See |complete_info_mode| for the values.
1857 pum_visible |TRUE| if popup menu is visible.
1858 See |pumvisible()|.
1859 items List of completion matches. Each item is a
1860 dictionary containing the entries "word",
1861 "abbr", "menu", "kind", "info" and "user_data".
1862 See |complete-items|.
1863 selected Selected item index. First index is zero.
1864 Index is -1 if no item is selected (showing
1865 typed text only, or the last completion after
1866 no item is selected when using the <Up> or
1867 <Down> keys)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01001868 inserted Inserted string. [NOT IMPLEMENTED YET]
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001869
1870 *complete_info_mode*
1871 mode values are:
1872 "" Not in completion mode
1873 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1874 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1875 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1876 |i_CTRL-X_CTRL-Y|
1877 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1878 "files" File names |i_CTRL-X_CTRL-F|
1879 "tags" Tags |i_CTRL-X_CTRL-]|
1880 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1881 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1882 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1883 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1884 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1885 "function" User defined completion |i_CTRL-X_CTRL-U|
1886 "omni" Omni completion |i_CTRL-X_CTRL-O|
1887 "spell" Spelling suggestions |i_CTRL-X_s|
1888 "eval" |complete()| completion
1889 "unknown" Other internal modes
1890
1891 If the optional {what} list argument is supplied, then only
1892 the items listed in {what} are returned. Unsupported items in
1893 {what} are silently ignored.
1894
1895 To get the position and size of the popup menu, see
1896 |pum_getpos()|. It's also available in |v:event| during the
1897 |CompleteChanged| event.
1898
Bram Moolenaar016188f2022-06-06 20:52:59 +01001899 Returns an empty |Dictionary| on error.
1900
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001901 Examples: >
1902 " Get all items
1903 call complete_info()
1904 " Get only 'mode'
1905 call complete_info(['mode'])
1906 " Get only 'mode' and 'pum_visible'
1907 call complete_info(['mode', 'pum_visible'])
1908
1909< Can also be used as a |method|: >
1910 GetItems()->complete_info()
1911<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001912 Return type: dict<any>
1913
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001914 *confirm()*
1915confirm({msg} [, {choices} [, {default} [, {type}]]])
1916 confirm() offers the user a dialog, from which a choice can be
1917 made. It returns the number of the choice. For the first
1918 choice this is 1.
1919 Note: confirm() is only supported when compiled with dialog
glepnirdf461152024-04-04 22:23:29 +02001920 support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001921
1922 {msg} is displayed in a |dialog| with {choices} as the
1923 alternatives. When {choices} is missing or empty, "&OK" is
1924 used (and translated).
1925 {msg} is a String, use '\n' to include a newline. Only on
1926 some systems the string is wrapped when it doesn't fit.
1927
1928 {choices} is a String, with the individual choices separated
1929 by '\n', e.g. >
1930 confirm("Save changes?", "&Yes\n&No\n&Cancel")
1931< The letter after the '&' is the shortcut key for that choice.
1932 Thus you can type 'c' to select "Cancel". The shortcut does
1933 not need to be the first letter: >
1934 confirm("file has been modified", "&Save\nSave &All")
1935< For the console, the first letter of each choice is used as
1936 the default shortcut key. Case is ignored.
1937
1938 The optional {default} argument is the number of the choice
1939 that is made if the user hits <CR>. Use 1 to make the first
1940 choice the default one. Use 0 to not set a default. If
1941 {default} is omitted, 1 is used.
1942
1943 The optional {type} String argument gives the type of dialog.
1944 This is only used for the icon of the GTK, Mac, Motif and
1945 Win32 GUI. It can be one of these values: "Error",
1946 "Question", "Info", "Warning" or "Generic". Only the first
1947 character is relevant. When {type} is omitted, "Generic" is
1948 used.
1949
1950 If the user aborts the dialog by pressing <Esc>, CTRL-C,
1951 or another valid interrupt key, confirm() returns 0.
1952
1953 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01001954 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001955 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01001956 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001957 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001958 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001959 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001960 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001961 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01001962 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001963< In a GUI dialog, buttons are used. The layout of the buttons
1964 depends on the 'v' flag in 'guioptions'. If it is included,
1965 the buttons are always put vertically. Otherwise, confirm()
1966 tries to put the buttons in one horizontal line. If they
1967 don't fit, a vertical layout is used anyway. For some systems
1968 the horizontal layout is always used.
1969
1970 Can also be used as a |method|in: >
1971 BuildMessage()->confirm("&Yes\n&No")
1972<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001973 Return type: |Number|
1974
1975
1976copy({expr}) *copy()*
1977 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001978 different from using {expr} directly.
1979 When {expr} is a |List| a shallow copy is created. This means
1980 that the original |List| can be changed without changing the
1981 copy, and vice versa. But the items are identical, thus
1982 changing an item changes the contents of both |Lists|.
1983 A |Dictionary| is copied in a similar way as a |List|.
1984 Also see |deepcopy()|.
1985 Can also be used as a |method|: >
1986 mylist->copy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001987<
1988 Return type: any, depending on {expr}
1989
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001990
1991cos({expr}) *cos()*
1992 Return the cosine of {expr}, measured in radians, as a |Float|.
1993 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001994 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001995 Examples: >
1996 :echo cos(100)
1997< 0.862319 >
1998 :echo cos(-4.01)
1999< -0.646043
2000
2001 Can also be used as a |method|: >
2002 Compute()->cos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002003<
2004 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002005
2006
2007cosh({expr}) *cosh()*
2008 Return the hyperbolic cosine of {expr} as a |Float| in the range
2009 [1, inf].
2010 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002011 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002012 Examples: >
2013 :echo cosh(0.5)
2014< 1.127626 >
2015 :echo cosh(-0.5)
2016< -1.127626
2017
2018 Can also be used as a |method|: >
2019 Compute()->cosh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002020<
2021 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002022
2023
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07002024count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002025 Return the number of times an item with value {expr} appears
2026 in |String|, |List| or |Dictionary| {comp}.
2027
2028 If {start} is given then start with the item with this index.
2029 {start} can only be used with a |List|.
2030
2031 When {ic} is given and it's |TRUE| then case is ignored.
2032
2033 When {comp} is a string then the number of not overlapping
2034 occurrences of {expr} is returned. Zero is returned when
2035 {expr} is an empty string.
2036
2037 Can also be used as a |method|: >
2038 mylist->count(val)
2039<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002040 Return type: |Number|
2041
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002042 *cscope_connection()*
2043cscope_connection([{num} , {dbpath} [, {prepend}]])
2044 Checks for the existence of a |cscope| connection. If no
2045 parameters are specified, then the function returns:
2046 0, if cscope was not available (not compiled in), or
2047 if there are no cscope connections;
2048 1, if there is at least one cscope connection.
2049
2050 If parameters are specified, then the value of {num}
2051 determines how existence of a cscope connection is checked:
2052
2053 {num} Description of existence check
2054 ----- ------------------------------
2055 0 Same as no parameters (e.g., "cscope_connection()").
2056 1 Ignore {prepend}, and use partial string matches for
2057 {dbpath}.
2058 2 Ignore {prepend}, and use exact string matches for
2059 {dbpath}.
2060 3 Use {prepend}, use partial string matches for both
2061 {dbpath} and {prepend}.
2062 4 Use {prepend}, use exact string matches for both
2063 {dbpath} and {prepend}.
2064
2065 Note: All string comparisons are case sensitive!
2066
2067 Examples. Suppose we had the following (from ":cs show"): >
2068
2069 # pid database name prepend path
2070 0 27664 cscope.out /usr/local
2071<
2072 Invocation Return Val ~
2073 ---------- ---------- >
2074 cscope_connection() 1
2075 cscope_connection(1, "out") 1
2076 cscope_connection(2, "out") 0
2077 cscope_connection(3, "out") 0
2078 cscope_connection(3, "out", "local") 1
2079 cscope_connection(4, "out") 0
2080 cscope_connection(4, "out", "local") 0
2081 cscope_connection(4, "cscope.out", "/usr/local") 1
2082<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002083 Return type: |Number|
2084
2085
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002086cursor({lnum}, {col} [, {off}]) *cursor()*
2087cursor({list})
2088 Positions the cursor at the column (byte count) {col} in the
2089 line {lnum}. The first column is one.
2090
2091 When there is one argument {list} this is used as a |List|
2092 with two, three or four item:
2093 [{lnum}, {col}]
2094 [{lnum}, {col}, {off}]
2095 [{lnum}, {col}, {off}, {curswant}]
2096 This is like the return value of |getpos()| or |getcurpos()|,
2097 but without the first item.
2098
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01002099 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002100 |setcursorcharpos()|.
2101
2102 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01002103 {lnum} is used like with |getline()|, except that if {lnum} is
2104 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002105 If {lnum} is greater than the number of lines in the buffer,
2106 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002107 If {col} is greater than the number of bytes in the line,
2108 the cursor will be positioned at the last character in the
2109 line.
2110 If {col} is zero, the cursor will stay in the current column.
2111 If {curswant} is given it is used to set the preferred column
2112 for vertical movement. Otherwise {col} is used.
2113
2114 When 'virtualedit' is used {off} specifies the offset in
2115 screen columns from the start of the character. E.g., a
2116 position within a <Tab> or after the last character.
2117 Returns 0 when the position could be set, -1 otherwise.
2118
2119 Can also be used as a |method|: >
2120 GetCursorPos()->cursor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002121<
2122 Return type: |Number|
2123
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002124
2125debugbreak({pid}) *debugbreak()*
2126 Specifically used to interrupt a program being debugged. It
2127 will cause process {pid} to get a SIGTRAP. Behavior for other
2128 processes is undefined. See |terminal-debugger|.
2129 {only available on MS-Windows}
2130
Bram Moolenaar016188f2022-06-06 20:52:59 +01002131 Returns |TRUE| if successfully interrupted the program.
2132 Otherwise returns |FALSE|.
2133
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002134 Can also be used as a |method|: >
2135 GetPid()->debugbreak()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002136<
2137 Return type: |Number|
2138
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002139
2140deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
2141 Make a copy of {expr}. For Numbers and Strings this isn't
2142 different from using {expr} directly.
2143 When {expr} is a |List| a full copy is created. This means
2144 that the original |List| can be changed without changing the
2145 copy, and vice versa. When an item is a |List| or
2146 |Dictionary|, a copy for it is made, recursively. Thus
2147 changing an item in the copy does not change the contents of
2148 the original |List|.
2149 A |Dictionary| is copied in a similar way as a |List|.
2150
2151 When {noref} is omitted or zero a contained |List| or
2152 |Dictionary| is only copied once. All references point to
2153 this single copy. With {noref} set to 1 every occurrence of a
2154 |List| or |Dictionary| results in a new copy. This also means
2155 that a cyclic reference causes deepcopy() to fail.
2156 *E724*
2157 Nesting is possible up to 100 levels. When there is an item
2158 that refers back to a higher level making a deep copy with
2159 {noref} set to 1 will fail.
2160 Also see |copy()|.
2161
2162 Can also be used as a |method|: >
2163 GetObject()->deepcopy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002164<
2165 Return type: any, depending on {expr}
2166
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002167
2168delete({fname} [, {flags}]) *delete()*
2169 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002170 name {fname}.
2171
2172 This also works when {fname} is a symbolic link. The symbolic
2173 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002174
2175 When {flags} is "d": Deletes the directory by the name
2176 {fname}. This fails when directory {fname} is not empty.
2177
2178 When {flags} is "rf": Deletes the directory by the name
2179 {fname} and everything in it, recursively. BE CAREFUL!
2180 Note: on MS-Windows it is not possible to delete a directory
2181 that is being used.
2182
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002183 The result is a Number, which is 0/false if the delete
2184 operation was successful and -1/true when the deletion failed
2185 or partly failed.
2186
2187 Use |remove()| to delete an item from a |List|.
2188 To delete a line from the buffer use |:delete| or
2189 |deletebufline()|.
2190
2191 Can also be used as a |method|: >
2192 GetName()->delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002193<
2194 Return type: |Number|
2195
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002196
2197deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2198 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2199 If {last} is omitted then delete line {first} only.
2200 On success 0 is returned, on failure 1 is returned.
2201
2202 This function works only for loaded buffers. First call
2203 |bufload()| if needed.
2204
2205 For the use of {buf}, see |bufname()| above.
2206
2207 {first} and {last} are used like with |getline()|. Note that
2208 when using |line()| this refers to the current buffer. Use "$"
2209 to refer to the last line in buffer {buf}.
2210
2211 Can also be used as a |method|: >
2212 GetBuffer()->deletebufline(1)
2213<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002214 Return type: |Number|
2215
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002216 *did_filetype()*
2217did_filetype() Returns |TRUE| when autocommands are being executed and the
2218 FileType event has been triggered at least once. Can be used
2219 to avoid triggering the FileType event again in the scripts
2220 that detect the file type. |FileType|
2221 Returns |FALSE| when `:setf FALLBACK` was used.
2222 When editing another file, the counter is reset, thus this
2223 really checks if the FileType event has been triggered for the
2224 current buffer. This allows an autocommand that starts
2225 editing another buffer to set 'filetype' and load a syntax
2226 file.
2227
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002228 Return type: |Number|
2229
2230
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002231diff({fromlist}, {tolist} [, {options}]) *diff()*
2232 Returns a String or a List containing the diff between the
2233 strings in {fromlist} and {tolist}. Uses the Vim internal
2234 diff library to compute the diff.
2235
2236 *E106*
2237 The optional "output" item in {options} specifies the returned
2238 diff format. The following values are supported:
2239 indices Return a List of the starting and ending
2240 indices and a count of the strings in each
2241 diff hunk.
2242 unified Return the unified diff output as a String.
2243 This is the default.
2244
2245 If the "output" item in {options} is "indices", then a List is
2246 returned. Each List item contains a Dict with the following
2247 items for each diff hunk:
2248 from_idx start index in {fromlist} for this diff hunk.
2249 from_count number of strings in {fromlist} that are
2250 added/removed/modified in this diff hunk.
2251 to_idx start index in {tolist} for this diff hunk.
2252 to_count number of strings in {tolist} that are
2253 added/removed/modified in this diff hunk.
2254
2255 The {options} Dict argument also specifies diff options
2256 (similar to 'diffopt') and supports the following items:
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002257 algorithm Dict specifying the diff algorithm to
2258 use. Supported boolean items are
2259 "myers", "minimal", "patience" and
2260 "histogram".
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002261 context diff context length. Default is 0.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002262 iblank ignore changes where lines are all
2263 blank.
2264 icase ignore changes in case of text.
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002265 indent-heuristic use the indent heuristic for the
2266 internal diff library.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002267 iwhite ignore changes in amount of white
2268 space.
2269 iwhiteall ignore all white space changes.
2270 iwhiteeol ignore white space changes at end of
2271 line.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002272 For more information about these options, refer to 'diffopt'.
2273
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002274 To compute the unified diff, all the items in {fromlist} are
2275 concatenated into a string using a newline separator and the
2276 same for {tolist}. The unified diff output uses line numbers.
2277
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002278 Returns an empty List or String if {fromlist} and {tolist} are
2279 identical.
2280
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002281 Examples: >
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002282 :echo diff(['abc'], ['xxx'])
2283 @@ -1 +1 @@
2284 -abc
2285 +xxx
2286
2287 :echo diff(['abc'], ['xxx'], {'output': 'indices'})
2288 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}]
2289 :echo diff(readfile('oldfile'), readfile('newfile'))
2290 :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$'))
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002291<
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002292 For more examples, refer to |diff-func-examples|
2293
2294 Can also be used as a |method|: >
2295 GetFromList->diff(to_list)
2296<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002297 Return type: |String| or list<dict<number>> or list<any>
2298 depending on {options}
2299
2300
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002301diff_filler({lnum}) *diff_filler()*
2302 Returns the number of filler lines above line {lnum}.
2303 These are the lines that were inserted at this point in
2304 another diff'ed window. These filler lines are shown in the
2305 display but don't exist in the buffer.
2306 {lnum} is used like with |getline()|. Thus "." is the current
2307 line, "'m" mark m, etc.
2308 Returns 0 if the current window is not in diff mode.
2309
2310 Can also be used as a |method|: >
2311 GetLnum()->diff_filler()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002312<
2313 Return type: |Number|
2314
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002315
2316diff_hlID({lnum}, {col}) *diff_hlID()*
2317 Returns the highlight ID for diff mode at line {lnum} column
2318 {col} (byte index). When the current line does not have a
2319 diff change zero is returned.
2320 {lnum} is used like with |getline()|. Thus "." is the current
2321 line, "'m" mark m, etc.
2322 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2323 line.
2324 The highlight ID can be used with |synIDattr()| to obtain
2325 syntax information about the highlighting.
2326
2327 Can also be used as a |method|: >
2328 GetLnum()->diff_hlID(col)
2329<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002330 Return type: |Number|
2331
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002332
2333digraph_get({chars}) *digraph_get()* *E1214*
2334 Return the digraph of {chars}. This should be a string with
2335 exactly two characters. If {chars} are not just two
2336 characters, or the digraph of {chars} does not exist, an error
2337 is given and an empty string is returned.
2338
2339 The character will be converted from Unicode to 'encoding'
2340 when needed. This does require the conversion to be
2341 available, it might fail.
2342
2343 Also see |digraph_getlist()|.
2344
2345 Examples: >
2346 " Get a built-in digraph
2347 :echo digraph_get('00') " Returns '∞'
2348
2349 " Get a user-defined digraph
2350 :call digraph_set('aa', 'あ')
2351 :echo digraph_get('aa') " Returns 'あ'
2352<
2353 Can also be used as a |method|: >
2354 GetChars()->digraph_get()
2355<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002356 Return type: |String|
2357
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002358 This function works only when compiled with the |+digraphs|
2359 feature. If this feature is disabled, this function will
2360 display an error message.
2361
2362
2363digraph_getlist([{listall}]) *digraph_getlist()*
2364 Return a list of digraphs. If the {listall} argument is given
2365 and it is TRUE, return all digraphs, including the default
2366 digraphs. Otherwise, return only user-defined digraphs.
2367
2368 The characters will be converted from Unicode to 'encoding'
2369 when needed. This does require the conservation to be
2370 available, it might fail.
2371
2372 Also see |digraph_get()|.
2373
2374 Examples: >
2375 " Get user-defined digraphs
2376 :echo digraph_getlist()
2377
2378 " Get all the digraphs, including default digraphs
2379 :echo digraph_getlist(1)
2380<
2381 Can also be used as a |method|: >
2382 GetNumber()->digraph_getlist()
2383<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002384 Return type: list<list<string>>
2385
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002386 This function works only when compiled with the |+digraphs|
2387 feature. If this feature is disabled, this function will
2388 display an error message.
2389
2390
Bram Moolenaara2baa732022-02-04 16:09:54 +00002391digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002392 Add digraph {chars} to the list. {chars} must be a string
2393 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002394 encoded character. *E1215*
2395 Be careful, composing characters are NOT ignored. This
2396 function is similar to |:digraphs| command, but useful to add
2397 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002398
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002399 The function returns v:true if |digraph| is registered. If
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002400 this fails an error message is given and v:false is returned.
2401
2402 If you want to define multiple digraphs at once, you can use
2403 |digraph_setlist()|.
2404
2405 Example: >
2406 call digraph_set(' ', 'あ')
2407<
2408 Can be used as a |method|: >
2409 GetString()->digraph_set('あ')
2410<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002411 Return type: |vim9-boolean|
2412
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002413 This function works only when compiled with the |+digraphs|
2414 feature. If this feature is disabled, this function will
2415 display an error message.
2416
2417
2418digraph_setlist({digraphlist}) *digraph_setlist()*
2419 Similar to |digraph_set()| but this function can add multiple
2420 digraphs at once. {digraphlist} is a list composed of lists,
2421 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002422 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002423 Example: >
2424 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2425<
2426 It is similar to the following: >
2427 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2428 call digraph_set(chars, digraph)
2429 endfor
2430< Except that the function returns after the first error,
2431 following digraphs will not be added.
2432
2433 Can be used as a |method|: >
2434 GetList()->digraph_setlist()
2435<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002436 Return type: |vim9-boolean|
2437
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002438 This function works only when compiled with the |+digraphs|
2439 feature. If this feature is disabled, this function will
2440 display an error message.
2441
2442
2443echoraw({string}) *echoraw()*
2444 Output {string} as-is, including unprintable characters.
2445 This can be used to output a terminal code. For example, to
2446 disable modifyOtherKeys: >
2447 call echoraw(&t_TE)
2448< and to enable it again: >
2449 call echoraw(&t_TI)
2450< Use with care, you can mess up the terminal this way.
2451
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002452 Return type: |Number|
2453
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002454
2455empty({expr}) *empty()*
2456 Return the Number 1 if {expr} is empty, zero otherwise.
2457 - A |List| or |Dictionary| is empty when it does not have any
2458 items.
2459 - A |String| is empty when its length is zero.
2460 - A |Number| and |Float| are empty when their value is zero.
2461 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2462 - A |Job| is empty when it failed to start.
2463 - A |Channel| is empty when it is closed.
2464 - A |Blob| is empty when its length is zero.
mityu7f0bba22024-03-29 10:14:41 +01002465 - An |Object| is empty, when the empty() method in the object
2466 (if present) returns true. |object-empty()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002467
2468 For a long |List| this is much faster than comparing the
2469 length with zero.
2470
2471 Can also be used as a |method|: >
2472 mylist->empty()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002473<
2474 Return type: |Number|
2475
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002476
2477environ() *environ()*
2478 Return all of environment variables as dictionary. You can
2479 check if an environment variable exists like this: >
2480 :echo has_key(environ(), 'HOME')
2481< Note that the variable name may be CamelCase; to ignore case
2482 use this: >
2483 :echo index(keys(environ()), 'HOME', 0, 1) != -1
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002484<
2485 Return type: dict<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002486
Bram Moolenaar416bd912023-07-07 23:19:18 +01002487
2488err_teapot([{expr}]) *err_teapot()*
2489 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002490 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002491 If {expr} is present and it is TRUE error 503 is given,
2492 indicating that coffee is temporarily not available.
2493 If {expr} is present it must be a String.
2494
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002495 Return type: |Number|
2496
Bram Moolenaar416bd912023-07-07 23:19:18 +01002497
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002498escape({string}, {chars}) *escape()*
2499 Escape the characters in {chars} that occur in {string} with a
2500 backslash. Example: >
2501 :echo escape('c:\program files\vim', ' \')
2502< results in: >
2503 c:\\program\ files\\vim
2504< Also see |shellescape()| and |fnameescape()|.
2505
2506 Can also be used as a |method|: >
2507 GetText()->escape(' \')
2508<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002509 Return type: |String|
2510
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002511 *eval()*
2512eval({string}) Evaluate {string} and return the result. Especially useful to
2513 turn the result of |string()| back into the original value.
2514 This works for Numbers, Floats, Strings, Blobs and composites
2515 of them. Also works for |Funcref|s that refer to existing
Aliaksei Budavei95740222024-04-04 23:05:33 +03002516 functions. In |Vim9| script, it can be used to obtain |enum|
2517 values from their fully qualified names.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002518
2519 Can also be used as a |method|: >
2520 argv->join()->eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002521<
2522 Return type: any, depending on {string}
2523
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002524
2525eventhandler() *eventhandler()*
2526 Returns 1 when inside an event handler. That is that Vim got
2527 interrupted while waiting for the user to type a character,
2528 e.g., when dropping a file on Vim. This means interactive
2529 commands cannot be used. Otherwise zero is returned.
2530
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002531 Return type: |Number|
2532
2533
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002534executable({expr}) *executable()*
2535 This function checks if an executable with the name {expr}
2536 exists. {expr} must be the name of the program without any
2537 arguments.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002538
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002539 executable() uses the value of $PATH and/or the normal
zeertzjq0cc5dce2024-08-08 21:12:15 +02002540 searchpath for programs.
2541 *PATHEXT*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002542 On MS-Windows the ".exe", ".bat", etc. can optionally be
2543 included. Then the extensions in $PATHEXT are tried. Thus if
2544 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2545 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2546 by itself can be used in $PATHEXT to try using the name
2547 without an extension. When 'shell' looks like a Unix shell,
2548 then the name is also tried without adding an extension.
2549 On MS-Windows it only checks if the file exists and is not a
2550 directory, not if it's really executable.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002551 On MS-Windows an executable in the same directory as the Vim
2552 executable is always found. Since this directory is added to
2553 $PATH it should also work to execute it |win32-PATH|.
2554 *NoDefaultCurrentDirectoryInExePath*
2555 On MS-Windows an executable in Vim's current working directory
2556 is also normally found, but this can be disabled by setting
2557 the $NoDefaultCurrentDirectoryInExePath environment variable.
2558
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002559 The result is a Number:
2560 1 exists
2561 0 does not exist
2562 -1 not implemented on this system
2563 |exepath()| can be used to get the full path of an executable.
2564
2565 Can also be used as a |method|: >
2566 GetCommand()->executable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002567<
2568 Return type: |Number|
2569
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002570
2571execute({command} [, {silent}]) *execute()*
2572 Execute an Ex command or commands and return the output as a
2573 string.
2574 {command} can be a string or a List. In case of a List the
2575 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002576 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002577 redir => var
2578 {command}
2579 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002580< Except that line continuation in {command} is not recognized.
2581
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002582 The optional {silent} argument can have these values:
2583 "" no `:silent` used
2584 "silent" `:silent` used
2585 "silent!" `:silent!` used
2586 The default is "silent". Note that with "silent!", unlike
2587 `:redir`, error messages are dropped. When using an external
2588 command the screen may be messed up, use `system()` instead.
2589 *E930*
2590 It is not possible to use `:redir` anywhere in {command}.
2591
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002592 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002593 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002594
2595< To execute a command in another window than the current one
2596 use `win_execute()`.
2597
2598 When used recursively the output of the recursive call is not
2599 included in the output of the higher level call.
2600
2601 Can also be used as a |method|: >
2602 GetCommand()->execute()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002603<
Marius Gedminasc98bfb92024-06-19 19:59:23 +02002604 Return type: |String|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002605
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002606
2607exepath({expr}) *exepath()*
2608 If {expr} is an executable and is either an absolute path, a
2609 relative path or found in $PATH, return the full path.
2610 Note that the current directory is used when {expr} starts
2611 with "./", which may be a problem for Vim: >
2612 echo exepath(v:progpath)
2613< If {expr} cannot be found in $PATH or is not executable then
2614 an empty string is returned.
2615
2616 Can also be used as a |method|: >
2617 GetCommand()->exepath()
2618<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002619 Return type: |String|
2620
2621
2622exists({expr}) *exists()*
2623 The result is a Number, which is |TRUE| if {expr} is defined,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002624 zero otherwise.
2625
2626 Note: In a compiled |:def| function the evaluation is done at
2627 runtime. Use `exists_compiled()` to evaluate the expression
2628 at compile time.
2629
2630 For checking for a supported feature use |has()|.
2631 For checking if a file exists use |filereadable()|.
2632
2633 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002634 varname internal variable (see
2635 dict.key |internal-variables|). Also works
2636 list[i] for |curly-braces-names|, |Dictionary|
Yegappan Lakshmanana2ebb6e2024-02-25 08:40:10 +01002637 import.Func entries, |List| items, class and
2638 class.Func object methods, imported items, etc.
2639 object.Func Does not work for local variables in a
2640 class.varname compiled `:def` function.
2641 object.varname Also works for a function in |Vim9|
Bram Moolenaar944697a2022-02-20 19:48:20 +00002642 script, since it can be used as a
2643 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002644 Beware that evaluating an index may
2645 cause an error message for an invalid
2646 expression. E.g.: >
2647 :let l = [1, 2, 3]
2648 :echo exists("l[5]")
2649< 0 >
2650 :echo exists("l[xx]")
2651< E121: Undefined variable: xx
2652 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002653 &option-name Vim option (only checks if it exists,
2654 not if it really works)
2655 +option-name Vim option that works.
2656 $ENVNAME environment variable (could also be
2657 done by comparing with an empty
2658 string)
2659 *funcname built-in function (see |functions|)
2660 or user defined function (see
2661 |user-functions|) that is implemented.
2662 Also works for a variable that is a
2663 Funcref.
2664 ?funcname built-in function that could be
2665 implemented; to be used to check if
2666 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002667 :cmdname Ex command: built-in command, user
2668 command or command modifier |:command|.
2669 Returns:
2670 1 for match with start of a command
2671 2 full match with a command
2672 3 matches several user commands
2673 To check for a supported command
2674 always check the return value to be 2.
2675 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002676 :3match The |:3match| command (but you
2677 probably should not use it, it is
2678 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002679 #event autocommand defined for this event
2680 #event#pattern autocommand defined for this event and
2681 pattern (the pattern is taken
2682 literally and compared to the
2683 autocommand patterns character by
2684 character)
2685 #group autocommand group exists
2686 #group#event autocommand defined for this group and
2687 event.
2688 #group#event#pattern
2689 autocommand defined for this group,
2690 event and pattern.
2691 ##event autocommand for this event is
2692 supported.
2693
2694 Examples: >
2695 exists("&shortname")
2696 exists("$HOSTNAME")
2697 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002698 exists("*s:MyFunc") " only for legacy script
2699 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002700 exists("bufcount")
2701 exists(":Make")
2702 exists("#CursorHold")
2703 exists("#BufReadPre#*.gz")
2704 exists("#filetypeindent")
2705 exists("#filetypeindent#FileType")
2706 exists("#filetypeindent#FileType#*")
2707 exists("##ColorScheme")
2708< There must be no space between the symbol (&/$/*/#) and the
2709 name.
2710 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002711 a few cases this is ignored. That may become stricter in the
2712 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002713 Working example: >
2714 exists(":make")
2715< NOT working example: >
2716 exists(":make install")
2717
2718< Note that the argument must be a string, not the name of the
2719 variable itself. For example: >
2720 exists(bufcount)
2721< This doesn't check for existence of the "bufcount" variable,
2722 but gets the value of "bufcount", and checks if that exists.
2723
2724 Can also be used as a |method|: >
2725 Varname()->exists()
2726<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002727 Return type: |String|
2728
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002729
2730exists_compiled({expr}) *exists_compiled()*
2731 Like `exists()` but evaluated at compile time. This is useful
2732 to skip a block where a function is used that would otherwise
2733 give an error: >
2734 if exists_compiled('*ThatFunction')
2735 ThatFunction('works')
2736 endif
2737< If `exists()` were used then a compilation error would be
2738 given if ThatFunction() is not defined.
2739
2740 {expr} must be a literal string. *E1232*
2741 Can only be used in a |:def| function. *E1233*
2742 This does not work to check for arguments or local variables.
2743
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002744 Return type: |String|
2745
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002746
2747exp({expr}) *exp()*
2748 Return the exponential of {expr} as a |Float| in the range
2749 [0, inf].
2750 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002751 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002752 Examples: >
2753 :echo exp(2)
2754< 7.389056 >
2755 :echo exp(-1)
2756< 0.367879
2757
2758 Can also be used as a |method|: >
2759 Compute()->exp()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002760<
2761 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002762
2763
2764expand({string} [, {nosuf} [, {list}]]) *expand()*
2765 Expand wildcards and the following special keywords in
2766 {string}. 'wildignorecase' applies.
2767
2768 If {list} is given and it is |TRUE|, a List will be returned.
2769 Otherwise the result is a String and when there are several
2770 matches, they are separated by <NL> characters. [Note: in
2771 version 5.0 a space was used, which caused problems when a
2772 file name contains a space]
2773
2774 If the expansion fails, the result is an empty string. A name
2775 for a non-existing file is not included, unless {string} does
2776 not start with '%', '#' or '<', see below.
2777
Christian Brabandtec9c3262024-02-21 20:40:05 +01002778 For a |:terminal| window '%' expands to a '!' followed by
h-east53753f62024-05-05 18:42:31 +02002779 the command or shell that is run. |terminal-bufname|
Christian Brabandtec9c3262024-02-21 20:40:05 +01002780
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002781 When {string} starts with '%', '#' or '<', the expansion is
2782 done like for the |cmdline-special| variables with their
2783 associated modifiers. Here is a short overview:
2784
2785 % current file name
2786 # alternate file name
2787 #n alternate file name n
2788 <cfile> file name under the cursor
2789 <afile> autocmd file name
2790 <abuf> autocmd buffer number (as a String!)
2791 <amatch> autocmd matched name
2792 <cexpr> C expression under the cursor
2793 <sfile> sourced script file or function name
2794 <slnum> sourced script line number or function
2795 line number
2796 <sflnum> script file line number, also when in
2797 a function
2798 <SID> "<SNR>123_" where "123" is the
2799 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002800 <script> sourced script file, or script file
2801 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002802 <stack> call stack
2803 <cword> word under the cursor
2804 <cWORD> WORD under the cursor
2805 <client> the {clientid} of the last received
2806 message |server2client()|
2807 Modifiers:
2808 :p expand to full path
2809 :h head (last path component removed)
2810 :t tail (last path component only)
2811 :r root (one extension removed)
2812 :e extension only
2813
2814 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002815 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002816< Note that when expanding a string that starts with '%', '#' or
2817 '<', any following text is ignored. This does NOT work: >
2818 :let doesntwork = expand("%:h.bak")
2819< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002820 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002821< Also note that expanding "<cfile>" and others only returns the
2822 referenced file name without further expansion. If "<cfile>"
2823 is "~/.cshrc", you need to do another expand() to have the
2824 "~/" expanded into the path of the home directory: >
2825 :echo expand(expand("<cfile>"))
2826<
2827 There cannot be white space between the variables and the
2828 following modifier. The |fnamemodify()| function can be used
2829 to modify normal file names.
2830
2831 When using '%' or '#', and the current or alternate file name
2832 is not defined, an empty string is used. Using "%:p" in a
2833 buffer with no name, results in the current directory, with a
2834 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002835 When 'verbose' is set then expanding '%', '#' and <> items
2836 will result in an error message if the argument cannot be
2837 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002838
2839 When {string} does not start with '%', '#' or '<', it is
2840 expanded like a file name is expanded on the command line.
2841 'suffixes' and 'wildignore' are used, unless the optional
2842 {nosuf} argument is given and it is |TRUE|.
2843 Names for non-existing files are included. The "**" item can
2844 be used to search in a directory tree. For example, to find
2845 all "README" files in the current directory and below: >
2846 :echo expand("**/README")
2847<
2848 expand() can also be used to expand variables and environment
2849 variables that are only known in a shell. But this can be
2850 slow, because a shell may be used to do the expansion. See
2851 |expr-env-expand|.
2852 The expanded variable is still handled like a list of file
2853 names. When an environment variable cannot be expanded, it is
2854 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2855 "$FOOBAR".
2856
2857 See |glob()| for finding existing files. See |system()| for
2858 getting the raw output of an external command.
2859
2860 Can also be used as a |method|: >
2861 Getpattern()->expand()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002862<
2863 Return type: |String| or list<string> depending on {list}
2864
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002865
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002866expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002867 Expand special items in String {string} like what is done for
2868 an Ex command such as `:edit`. This expands special keywords,
2869 like with |expand()|, and environment variables, anywhere in
2870 {string}. "~user" and "~/path" are only expanded at the
2871 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002872
2873 The following items are supported in the {options} Dict
2874 argument:
2875 errmsg If set to TRUE, error messages are displayed
2876 if an error is encountered during expansion.
2877 By default, error messages are not displayed.
2878
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002879 Returns the expanded string. If an error is encountered
2880 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002881
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002882 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002883 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002884 make /path/runtime/doc/builtin.o
2885 :echo expandcmd('make %<.o', {'errmsg': v:true})
2886<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002887 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002888 GetCommand()->expandcmd()
2889<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002890 Return type: |String| or list<string> depending on {list}
2891
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002892extend({expr1}, {expr2} [, {expr3}]) *extend()*
2893 {expr1} and {expr2} must be both |Lists| or both
2894 |Dictionaries|.
2895
2896 If they are |Lists|: Append {expr2} to {expr1}.
2897 If {expr3} is given insert the items of {expr2} before the
2898 item with index {expr3} in {expr1}. When {expr3} is zero
2899 insert before the first item. When {expr3} is equal to
2900 len({expr1}) then {expr2} is appended.
2901 Examples: >
2902 :echo sort(extend(mylist, [7, 5]))
2903 :call extend(mylist, [2, 3], 1)
2904< When {expr1} is the same List as {expr2} then the number of
2905 items copied is equal to the original length of the List.
2906 E.g., when {expr3} is 1 you get N new copies of the first item
2907 (where N is the original length of the List).
2908 Use |add()| to concatenate one item to a list. To concatenate
2909 two lists into a new list use the + operator: >
2910 :let newlist = [1, 2, 3] + [4, 5]
2911<
2912 If they are |Dictionaries|:
2913 Add all entries from {expr2} to {expr1}.
2914 If a key exists in both {expr1} and {expr2} then {expr3} is
2915 used to decide what to do:
2916 {expr3} = "keep": keep the value of {expr1}
2917 {expr3} = "force": use the value of {expr2}
2918 {expr3} = "error": give an error message *E737*
2919 When {expr3} is omitted then "force" is assumed.
2920
2921 {expr1} is changed when {expr2} is not empty. If necessary
2922 make a copy of {expr1} first.
2923 {expr2} remains unchanged.
2924 When {expr1} is locked and {expr2} is not empty the operation
2925 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002926 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002927
2928 Can also be used as a |method|: >
2929 mylist->extend(otherlist)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002930<
2931 Return type: list<{type}> or dict<{type}> depending on {expr1}
2932 and {expr2}, in case of error: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002933
2934
2935extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
2936 Like |extend()| but instead of adding items to {expr1} a new
2937 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00002938 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002939
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002940 Return type: list<{type}> or dict<{type}> depending on {expr1}
2941 and {expr2}, in case of error: |Number|
2942
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002943
2944feedkeys({string} [, {mode}]) *feedkeys()*
2945 Characters in {string} are queued for processing as if they
2946 come from a mapping or were typed by the user.
2947
2948 By default the string is added to the end of the typeahead
2949 buffer, thus if a mapping is still being executed the
2950 characters come after them. Use the 'i' flag to insert before
2951 other characters, they will be executed next, before any
2952 characters from a mapping.
2953
2954 The function does not wait for processing of keys contained in
2955 {string}.
2956
2957 To include special keys into {string}, use double-quotes
2958 and "\..." notation |expr-quote|. For example,
2959 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
2960 feedkeys('\<CR>') pushes 5 characters.
2961 A special code that might be useful is <Ignore>, it exits the
2962 wait for a character without doing anything. *<Ignore>*
2963
2964 {mode} is a String, which can contain these character flags:
2965 'm' Remap keys. This is default. If {mode} is absent,
2966 keys are remapped.
2967 'n' Do not remap keys.
2968 't' Handle keys as if typed; otherwise they are handled as
2969 if coming from a mapping. This matters for undo,
2970 opening folds, etc.
2971 'L' Lowlevel input. Only works for Unix or when using the
2972 GUI. Keys are used as if they were coming from the
2973 terminal. Other flags are not used. *E980*
2974 When a CTRL-C interrupts and 't' is included it sets
2975 the internal "got_int" flag.
2976 'i' Insert the string instead of appending (see above).
2977 'x' Execute commands until typeahead is empty. This is
2978 similar to using ":normal!". You can call feedkeys()
2979 several times without 'x' and then one time with 'x'
2980 (possibly with an empty {string}) to execute all the
2981 typeahead. Note that when Vim ends in Insert mode it
2982 will behave as if <Esc> is typed, to avoid getting
2983 stuck, waiting for a character to be typed before the
2984 script continues.
2985 Note that if you manage to call feedkeys() while
2986 executing commands, thus calling it recursively, then
2987 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00002988 'c' Remove any script context when executing, so that
2989 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01002990 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01002991 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002992 '!' When used with 'x' will not end Insert mode. Can be
2993 used in a test when a timer is set to exit Insert mode
2994 a little later. Useful for testing CursorHoldI.
2995
2996 Return value is always 0.
2997
2998 Can also be used as a |method|: >
2999 GetInput()->feedkeys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003000<
3001 Return type: |String| or list<string> depending on {list}
3002
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003003
Shougo Matsushita60c87432024-06-03 22:59:27 +02003004filecopy({from}, {to}) *filecopy()*
3005 Copy the file pointed to by the name {from} to {to}. The
3006 result is a Number, which is |TRUE| if the file was copied
3007 successfully, and |FALSE| when it failed.
3008 If a file with name {to} already exists, it will fail.
3009 Note that it does not handle directories (yet).
3010
3011 This function is not available in the |sandbox|.
3012
3013 Can also be used as a |method|: >
3014 GetOldName()->filecopy(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003015<
3016 Return type: |Number|
3017
Shougo Matsushita60c87432024-06-03 22:59:27 +02003018
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003019filereadable({file}) *filereadable()*
3020 The result is a Number, which is |TRUE| when a file with the
3021 name {file} exists, and can be read. If {file} doesn't exist,
3022 or is a directory, the result is |FALSE|. {file} is any
3023 expression, which is used as a String.
3024 If you don't care about the file being readable you can use
3025 |glob()|.
3026 {file} is used as-is, you may want to expand wildcards first: >
3027 echo filereadable('~/.vimrc')
3028 0
3029 echo filereadable(expand('~/.vimrc'))
3030 1
3031
3032< Can also be used as a |method|: >
3033 GetName()->filereadable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003034<
3035 Return type: |Number|
3036
3037 *file_readable()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003038 Obsolete name: file_readable().
3039
3040
3041filewritable({file}) *filewritable()*
3042 The result is a Number, which is 1 when a file with the
3043 name {file} exists, and can be written. If {file} doesn't
3044 exist, or is not writable, the result is 0. If {file} is a
3045 directory, and we can write to it, the result is 2.
3046
3047 Can also be used as a |method|: >
3048 GetName()->filewritable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003049<
3050 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003051
3052
3053filter({expr1}, {expr2}) *filter()*
3054 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3055 For each item in {expr1} evaluate {expr2} and when the result
3056 is zero or false remove the item from the |List| or
3057 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003058 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003059
3060 {expr2} must be a |string| or |Funcref|.
3061
3062 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3063 of the current item. For a |Dictionary| |v:key| has the key
3064 of the current item and for a |List| |v:key| has the index of
3065 the current item. For a |Blob| |v:key| has the index of the
3066 current byte. For a |String| |v:key| has the index of the
3067 current character.
3068 Examples: >
3069 call filter(mylist, 'v:val !~ "OLD"')
3070< Removes the items where "OLD" appears. >
3071 call filter(mydict, 'v:key >= 8')
3072< Removes the items with a key below 8. >
3073 call filter(var, 0)
3074< Removes all the items, thus clears the |List| or |Dictionary|.
3075
3076 Note that {expr2} is the result of expression and is then
3077 used as an expression again. Often it is good to use a
3078 |literal-string| to avoid having to double backslashes.
3079
3080 If {expr2} is a |Funcref| it must take two arguments:
3081 1. the key or the index of the current item.
3082 2. the value of the current item.
3083 The function must return |TRUE| if the item should be kept.
3084 Example that keeps the odd items of a list: >
3085 func Odd(idx, val)
3086 return a:idx % 2 == 1
3087 endfunc
3088 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003089< It is shorter when using a |lambda|. In |Vim9| syntax: >
3090 call filter(myList, (idx, val) => idx * val <= 42)
3091< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003092 call filter(myList, {idx, val -> idx * val <= 42})
3093< If you do not use "val" you can leave it out: >
3094 call filter(myList, {idx -> idx % 2 == 1})
3095<
3096 In |Vim9| script the result must be true, false, zero or one.
3097 Other values will result in a type error.
3098
3099 For a |List| and a |Dictionary| the operation is done
3100 in-place. If you want it to remain unmodified make a copy
3101 first: >
3102 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
3103
3104< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00003105 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003106 When an error is encountered while evaluating {expr2} no
3107 further items in {expr1} are processed.
3108 When {expr2} is a Funcref errors inside a function are ignored,
3109 unless it was defined with the "abort" flag.
3110
3111 Can also be used as a |method|: >
3112 mylist->filter(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003113<
3114 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
3115 depending on {expr1}
3116
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003117
3118finddir({name} [, {path} [, {count}]]) *finddir()*
3119 Find directory {name} in {path}. Supports both downwards and
3120 upwards recursive directory searches. See |file-searching|
3121 for the syntax of {path}.
3122
3123 Returns the path of the first found match. When the found
3124 directory is below the current directory a relative path is
3125 returned. Otherwise a full path is returned.
3126 If {path} is omitted or empty then 'path' is used.
3127
3128 If the optional {count} is given, find {count}'s occurrence of
3129 {name} in {path} instead of the first one.
3130 When {count} is negative return all the matches in a |List|.
3131
Bram Moolenaar016188f2022-06-06 20:52:59 +01003132 Returns an empty string if the directory is not found.
3133
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003134 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003135
3136 Can also be used as a |method|: >
3137 GetName()->finddir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003138<
3139 Return type: |String|
3140
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003141
3142findfile({name} [, {path} [, {count}]]) *findfile()*
3143 Just like |finddir()|, but find a file instead of a directory.
3144 Uses 'suffixesadd'.
3145 Example: >
3146 :echo findfile("tags.vim", ".;")
3147< Searches from the directory of the current file upwards until
3148 it finds the file "tags.vim".
3149
3150 Can also be used as a |method|: >
3151 GetName()->findfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003152<
3153 Return type: |String|
3154
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003155
3156flatten({list} [, {maxdepth}]) *flatten()*
3157 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
3158 the result is a |List| without nesting, as if {maxdepth} is
3159 a very large number.
3160 The {list} is changed in place, use |flattennew()| if you do
3161 not want that.
3162 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00003163 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003164 *E900*
3165 {maxdepth} means how deep in nested lists changes are made.
3166 {list} is not modified when {maxdepth} is 0.
3167 {maxdepth} must be positive number.
3168
3169 If there is an error the number zero is returned.
3170
3171 Example: >
3172 :echo flatten([1, [2, [3, 4]], 5])
3173< [1, 2, 3, 4, 5] >
3174 :echo flatten([1, [2, [3, 4]], 5], 1)
3175< [1, 2, [3, 4], 5]
3176
3177 Can also be used as a |method|: >
3178 mylist->flatten()
3179<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003180 Return type: list<{type}>
3181
3182
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003183flattennew({list} [, {maxdepth}]) *flattennew()*
3184 Like |flatten()| but first make a copy of {list}.
3185
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003186 Return type: list<{type}>
3187
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003188
3189float2nr({expr}) *float2nr()*
3190 Convert {expr} to a Number by omitting the part after the
3191 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00003192 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003193 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003194 When the value of {expr} is out of range for a |Number| the
3195 result is truncated to 0x7fffffff or -0x7fffffff (or when
3196 64-bit Number support is enabled, 0x7fffffffffffffff or
3197 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
3198 64-bit Number support is enabled, -0x8000000000000000).
3199 Examples: >
3200 echo float2nr(3.95)
3201< 3 >
3202 echo float2nr(-23.45)
3203< -23 >
3204 echo float2nr(1.0e100)
3205< 2147483647 (or 9223372036854775807) >
3206 echo float2nr(-1.0e150)
3207< -2147483647 (or -9223372036854775807) >
3208 echo float2nr(1.0e-100)
3209< 0
3210
3211 Can also be used as a |method|: >
3212 Compute()->float2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003213<
3214 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003215
3216
3217floor({expr}) *floor()*
3218 Return the largest integral value less than or equal to
3219 {expr} as a |Float| (round down).
3220 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003221 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003222 Examples: >
3223 echo floor(1.856)
3224< 1.0 >
3225 echo floor(-5.456)
3226< -6.0 >
3227 echo floor(4.0)
3228< 4.0
3229
3230 Can also be used as a |method|: >
3231 Compute()->floor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003232<
3233 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003234
3235
3236fmod({expr1}, {expr2}) *fmod()*
3237 Return the remainder of {expr1} / {expr2}, even if the
3238 division is not representable. Returns {expr1} - i * {expr2}
3239 for some integer i such that if {expr2} is non-zero, the
3240 result has the same sign as {expr1} and magnitude less than
3241 the magnitude of {expr2}. If {expr2} is zero, the value
3242 returned is zero. The value returned is a |Float|.
3243 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003244 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
3245 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003246 Examples: >
3247 :echo fmod(12.33, 1.22)
3248< 0.13 >
3249 :echo fmod(-12.33, 1.22)
3250< -0.13
3251
3252 Can also be used as a |method|: >
3253 Compute()->fmod(1.22)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003254<
3255 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003256
3257
3258fnameescape({string}) *fnameescape()*
3259 Escape {string} for use as file name command argument. All
3260 characters that have a special meaning, such as '%' and '|'
3261 are escaped with a backslash.
3262 For most systems the characters escaped are
3263 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3264 appears in a filename, it depends on the value of 'isfname'.
3265 A leading '+' and '>' is also escaped (special after |:edit|
3266 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01003267 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003268 Example: >
3269 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003270 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003271< results in executing: >
3272 edit \+some\ str\%nge\|name
3273<
3274 Can also be used as a |method|: >
3275 GetName()->fnameescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003276<
3277 Return type: |String|
3278
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003279
3280fnamemodify({fname}, {mods}) *fnamemodify()*
3281 Modify file name {fname} according to {mods}. {mods} is a
3282 string of characters like it is used for file names on the
3283 command line. See |filename-modifiers|.
3284 Example: >
3285 :echo fnamemodify("main.c", ":p:h")
3286< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01003287 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01003288< If {mods} is empty or an unsupported modifier is used then
3289 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01003290 When {fname} is empty then with {mods} ":h" returns ".", so
3291 that `:cd` can be used with it. This is different from
3292 expand('%:h') without a buffer name, which returns an empty
3293 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003294 Note: Environment variables don't work in {fname}, use
3295 |expand()| first then.
3296
3297 Can also be used as a |method|: >
3298 GetName()->fnamemodify(':p:h')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003299<
3300 Return type: |String|
3301
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003302
3303foldclosed({lnum}) *foldclosed()*
3304 The result is a Number. If the line {lnum} is in a closed
3305 fold, the result is the number of the first line in that fold.
3306 If the line {lnum} is not in a closed fold, -1 is returned.
3307 {lnum} is used like with |getline()|. Thus "." is the current
3308 line, "'m" mark m, etc.
3309
3310 Can also be used as a |method|: >
3311 GetLnum()->foldclosed()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003312<
3313 Return type: |Number|
3314
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003315
3316foldclosedend({lnum}) *foldclosedend()*
3317 The result is a Number. If the line {lnum} is in a closed
3318 fold, the result is the number of the last line in that fold.
3319 If the line {lnum} is not in a closed fold, -1 is returned.
3320 {lnum} is used like with |getline()|. Thus "." is the current
3321 line, "'m" mark m, etc.
3322
3323 Can also be used as a |method|: >
3324 GetLnum()->foldclosedend()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003325<
3326 Return type: |Number|
3327
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003328
3329foldlevel({lnum}) *foldlevel()*
3330 The result is a Number, which is the foldlevel of line {lnum}
3331 in the current buffer. For nested folds the deepest level is
3332 returned. If there is no fold at line {lnum}, zero is
3333 returned. It doesn't matter if the folds are open or closed.
3334 When used while updating folds (from 'foldexpr') -1 is
3335 returned for lines where folds are still to be updated and the
3336 foldlevel is unknown. As a special case the level of the
3337 previous line is usually available.
3338 {lnum} is used like with |getline()|. Thus "." is the current
3339 line, "'m" mark m, etc.
3340
3341 Can also be used as a |method|: >
3342 GetLnum()->foldlevel()
3343<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003344 Return type: |Number|
3345
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003346 *foldtext()*
3347foldtext() Returns a String, to be displayed for a closed fold. This is
3348 the default function used for the 'foldtext' option and should
3349 only be called from evaluating 'foldtext'. It uses the
3350 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3351 The returned string looks like this: >
3352 +-- 45 lines: abcdef
3353< The number of leading dashes depends on the foldlevel. The
3354 "45" is the number of lines in the fold. "abcdef" is the text
3355 in the first non-blank line of the fold. Leading white space,
3356 "//" or "/*" and the text from the 'foldmarker' and
3357 'commentstring' options is removed.
3358 When used to draw the actual foldtext, the rest of the line
3359 will be filled with the fold char from the 'fillchars'
3360 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003361 Returns an empty string when there is no fold.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003362
3363 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003364 {not available when compiled without the |+folding| feature}
3365
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003366
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003367foldtextresult({lnum}) *foldtextresult()*
3368 Returns the text that is displayed for the closed fold at line
3369 {lnum}. Evaluates 'foldtext' in the appropriate context.
3370 When there is no closed fold at {lnum} an empty string is
3371 returned.
3372 {lnum} is used like with |getline()|. Thus "." is the current
3373 line, "'m" mark m, etc.
3374 Useful when exporting folded text, e.g., to HTML.
3375 {not available when compiled without the |+folding| feature}
3376
3377
3378 Can also be used as a |method|: >
3379 GetLnum()->foldtextresult()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003380<
3381 Return type: |String|
3382
Ernie Raele79e2072024-01-13 11:47:33 +01003383
3384foreach({expr1}, {expr2}) *foreach()*
3385 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3386 For each item in {expr1} execute {expr2}. {expr1} is not
erraelc92b8be2024-01-14 10:11:07 -08003387 modified; its values may be, as with |:lockvar| 1. |E741|
Ernie Raele79e2072024-01-13 11:47:33 +01003388 See |map()| and |filter()| to modify {expr1}.
3389
3390 {expr2} must be a |string| or |Funcref|.
3391
3392 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3393 of the current item. For a |Dictionary| |v:key| has the key
3394 of the current item and for a |List| |v:key| has the index of
3395 the current item. For a |Blob| |v:key| has the index of the
3396 current byte. For a |String| |v:key| has the index of the
3397 current character.
3398 Examples: >
3399 call foreach(mylist, 'used[v:val] = true')
3400< This records the items that are in the {expr1} list.
3401
3402 Note that {expr2} is the result of expression and is then used
3403 as a command. Often it is good to use a |literal-string| to
3404 avoid having to double backslashes.
3405
3406 If {expr2} is a |Funcref| it must take two arguments:
3407 1. the key or the index of the current item.
3408 2. the value of the current item.
3409 With a legacy script lambda you don't get an error if it only
3410 accepts one argument, but with a Vim9 lambda you get "E1106:
3411 One argument too many", the number of arguments must match.
3412 If the function returns a value, it is ignored.
3413
3414 Returns {expr1} in all cases.
3415 When an error is encountered while executing {expr2} no
3416 further items in {expr1} are processed.
3417 When {expr2} is a Funcref errors inside a function are ignored,
3418 unless it was defined with the "abort" flag.
3419
3420 Can also be used as a |method|: >
3421 mylist->foreach(expr2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003422<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003423 Return type: |String|, |Blob| list<{type}> or dict<{type}>
3424 depending on {expr1}
3425
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003426 *foreground()*
3427foreground() Move the Vim window to the foreground. Useful when sent from
3428 a client to a Vim server. |remote_send()|
3429 On Win32 systems this might not work, the OS does not always
3430 allow a window to bring itself to the foreground. Use
3431 |remote_foreground()| instead.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003432
3433 Return type: |Number|
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003434 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003435 Win32 console version}
3436
Bram Moolenaaraa534142022-09-15 21:46:02 +01003437fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003438 Get the full command name from a short abbreviated command
3439 name; see |20.2| for details on command abbreviations.
3440
3441 The string argument {name} may start with a `:` and can
3442 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003443 Returns an empty string if a command doesn't exist, if it's
3444 ambiguous (for user-defined commands) or cannot be shortened
3445 this way. |vim9-no-shorten|
3446
3447 Without the {vim9} argument uses the current script version.
3448 If {vim9} is present and FALSE then legacy script rules are
3449 used. When {vim9} is present and TRUE then Vim9 rules are
3450 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003451
3452 For example `fullcommand('s')`, `fullcommand('sub')`,
3453 `fullcommand(':%substitute')` all return "substitute".
3454
3455 Can also be used as a |method|: >
3456 GetName()->fullcommand()
3457<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003458 Return type: |String|
3459
3460
3461funcref({name} [, {arglist}] [, {dict}]) *funcref()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003462 Just like |function()|, but the returned Funcref will lookup
3463 the function by reference, not by name. This matters when the
3464 function {name} is redefined later.
3465
3466 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003467 It only works for an autoloaded function if it has already
3468 been loaded (to avoid mistakenly loading the autoload script
3469 when only intending to use the function name, use |function()|
3470 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003471 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003472
3473 Can also be used as a |method|: >
3474 GetFuncname()->funcref([arg])
3475<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003476 Return type: func(...): any or |Number| on error
3477
Dominique Pellee764d1b2023-03-12 21:20:59 +00003478 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003479function({name} [, {arglist}] [, {dict}])
3480 Return a |Funcref| variable that refers to function {name}.
3481 {name} can be the name of a user defined function or an
3482 internal function.
3483
3484 {name} can also be a Funcref or a partial. When it is a
3485 partial the dict stored in it will be used and the {dict}
3486 argument is not allowed. E.g.: >
3487 let FuncWithArg = function(dict.Func, [arg])
3488 let Broken = function(dict.Func, [arg], dict)
3489<
3490 When using the Funcref the function will be found by {name},
3491 also when it was redefined later. Use |funcref()| to keep the
3492 same function.
3493
3494 When {arglist} or {dict} is present this creates a partial.
3495 That means the argument list and/or the dictionary is stored in
3496 the Funcref and will be used when the Funcref is called.
3497
3498 The arguments are passed to the function in front of other
3499 arguments, but after any argument from |method|. Example: >
3500 func Callback(arg1, arg2, name)
3501 ...
3502 let Partial = function('Callback', ['one', 'two'])
3503 ...
3504 call Partial('name')
3505< Invokes the function as with: >
3506 call Callback('one', 'two', 'name')
3507
3508< With a |method|: >
3509 func Callback(one, two, three)
3510 ...
3511 let Partial = function('Callback', ['two'])
3512 ...
3513 eval 'one'->Partial('three')
3514< Invokes the function as with: >
3515 call Callback('one', 'two', 'three')
3516
3517< The function() call can be nested to add more arguments to the
3518 Funcref. The extra arguments are appended to the list of
3519 arguments. Example: >
3520 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003521 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003522 let Func = function('Callback', ['one'])
3523 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003524 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003525 call Func2('name')
3526< Invokes the function as with: >
3527 call Callback('one', 'two', 'name')
3528
3529< The Dictionary is only useful when calling a "dict" function.
3530 In that case the {dict} is passed in as "self". Example: >
3531 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003532 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003533 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003534 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003535 let context = {"name": "example"}
3536 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003537 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003538 call Func() " will echo: called for example
3539< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003540 arguments, these two are equivalent, if Callback() is defined
3541 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003542 let Func = function('Callback', context)
3543 let Func = context.Callback
3544
3545< The argument list and the Dictionary can be combined: >
3546 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003547 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003548 let context = {"name": "example"}
3549 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003550 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003551 call Func(500)
3552< Invokes the function as with: >
3553 call context.Callback('one', 500)
3554<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003555 Returns 0 on error.
3556
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003557 Can also be used as a |method|: >
3558 GetFuncname()->function([arg])
3559
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003560<
3561 Return type: func(...): any or |Number| on error
3562
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003563
3564garbagecollect([{atexit}]) *garbagecollect()*
3565 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3566 that have circular references.
3567
3568 There is hardly ever a need to invoke this function, as it is
3569 automatically done when Vim runs out of memory or is waiting
3570 for the user to press a key after 'updatetime'. Items without
3571 circular references are always freed when they become unused.
3572 This is useful if you have deleted a very big |List| and/or
3573 |Dictionary| with circular references in a script that runs
3574 for a long time.
3575
3576 When the optional {atexit} argument is one, garbage
3577 collection will also be done when exiting Vim, if it wasn't
3578 done before. This is useful when checking for memory leaks.
3579
3580 The garbage collection is not done immediately but only when
3581 it's safe to perform. This is when waiting for the user to
3582 type a character. To force garbage collection immediately use
3583 |test_garbagecollect_now()|.
3584
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003585 Return type: |String|
3586
3587
LemonBoy48b7d052024-07-09 18:24:59 +02003588get({list}, {idx} [, {default}]) *get()* *get()-list*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003589 Get item {idx} from |List| {list}. When this item is not
3590 available return {default}. Return zero when {default} is
3591 omitted.
3592 Preferably used as a |method|: >
3593 mylist->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003594<
3595 Return type: any, depending on {list}
3596
LemonBoy48b7d052024-07-09 18:24:59 +02003597get({blob}, {idx} [, {default}]) *get()-blob*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003598 Get byte {idx} from |Blob| {blob}. When this byte is not
3599 available return {default}. Return -1 when {default} is
3600 omitted.
3601 Preferably used as a |method|: >
3602 myblob->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003603<
3604 Return type: |Number|
3605
LemonBoy48b7d052024-07-09 18:24:59 +02003606get({dict}, {key} [, {default}]) *get()-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003607 Get item with key {key} from |Dictionary| {dict}. When this
3608 item is not available return {default}. Return zero when
3609 {default} is omitted. Useful example: >
3610 let val = get(g:, 'var_name', 'default')
3611< This gets the value of g:var_name if it exists, and uses
3612 'default' when it does not exist.
3613 Preferably used as a |method|: >
3614 mydict->get(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003615<
h-east84ac2122024-06-17 18:12:30 +02003616 Return type: any, depending on {dict}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003617
LemonBoy48b7d052024-07-09 18:24:59 +02003618get({func}, {what}) *get()-func*
3619 Get item {what} from |Funcref| {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003620 {what} are:
LemonBoy48b7d052024-07-09 18:24:59 +02003621 "name" The function name
3622 "func" The function
3623 "dict" The dictionary
3624 "args" The list with arguments
3625 "arity" A dictionary with information about the number of
3626 arguments accepted by the function (minus the
3627 {arglist}) with the following fields:
3628 required the number of positional arguments
3629 optional the number of optional arguments,
3630 in addition to the required ones
3631 varargs |TRUE| if the function accepts a
3632 variable number of arguments |...|
3633
3634 Note: There is no error, if the {arglist} of
3635 the Funcref contains more arguments than the
3636 Funcref expects, it's not validated.
3637
Bram Moolenaar016188f2022-06-06 20:52:59 +01003638 Returns zero on error.
LemonBoy48b7d052024-07-09 18:24:59 +02003639
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003640 Preferably used as a |method|: >
3641 myfunc->get(what)
3642<
LemonBoy48b7d052024-07-09 18:24:59 +02003643 Return type: any, depending on {func} and {what}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003644
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003645 *getbufinfo()*
3646getbufinfo([{buf}])
3647getbufinfo([{dict}])
3648 Get information about buffers as a List of Dictionaries.
3649
3650 Without an argument information about all the buffers is
3651 returned.
3652
3653 When the argument is a |Dictionary| only the buffers matching
3654 the specified criteria are returned. The following keys can
3655 be specified in {dict}:
3656 buflisted include only listed buffers.
3657 bufloaded include only loaded buffers.
3658 bufmodified include only modified buffers.
3659
3660 Otherwise, {buf} specifies a particular buffer to return
3661 information for. For the use of {buf}, see |bufname()|
3662 above. If the buffer is found the returned List has one item.
3663 Otherwise the result is an empty list.
3664
3665 Each returned List item is a dictionary with the following
3666 entries:
3667 bufnr Buffer number.
3668 changed TRUE if the buffer is modified.
3669 changedtick Number of changes made to the buffer.
Sean Dewar1fb41032023-08-16 17:15:05 +01003670 command TRUE if the buffer belongs to the
3671 command-line window |cmdwin|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003672 hidden TRUE if the buffer is hidden.
3673 lastused Timestamp in seconds, like
3674 |localtime()|, when the buffer was
3675 last used.
3676 {only with the |+viminfo| feature}
3677 listed TRUE if the buffer is listed.
3678 lnum Line number used for the buffer when
3679 opened in the current window.
3680 Only valid if the buffer has been
3681 displayed in the window in the past.
3682 If you want the line number of the
3683 last known cursor position in a given
3684 window, use |line()|: >
3685 :echo line('.', {winid})
3686<
3687 linecount Number of lines in the buffer (only
3688 valid when loaded)
3689 loaded TRUE if the buffer is loaded.
3690 name Full path to the file in the buffer.
3691 signs List of signs placed in the buffer.
3692 Each list item is a dictionary with
3693 the following fields:
3694 id sign identifier
3695 lnum line number
3696 name sign name
3697 variables A reference to the dictionary with
3698 buffer-local variables.
3699 windows List of |window-ID|s that display this
3700 buffer
3701 popups List of popup |window-ID|s that
3702 display this buffer
3703
3704 Examples: >
3705 for buf in getbufinfo()
3706 echo buf.name
3707 endfor
3708 for buf in getbufinfo({'buflisted':1})
3709 if buf.changed
3710 ....
3711 endif
3712 endfor
3713<
3714 To get buffer-local options use: >
3715 getbufvar({bufnr}, '&option_name')
3716<
3717 Can also be used as a |method|: >
3718 GetBufnr()->getbufinfo()
3719<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003720 Return type: list<dict<any>>
3721
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003722
3723 *getbufline()*
3724getbufline({buf}, {lnum} [, {end}])
3725 Return a |List| with the lines starting from {lnum} to {end}
3726 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003727 |List| with only the line {lnum} is returned. See
3728 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003729
3730 For the use of {buf}, see |bufname()| above.
3731
3732 For {lnum} and {end} "$" can be used for the last line of the
3733 buffer. Otherwise a number must be used.
3734
3735 When {lnum} is smaller than 1 or bigger than the number of
3736 lines in the buffer, an empty |List| is returned.
3737
3738 When {end} is greater than the number of lines in the buffer,
3739 it is treated as {end} is set to the number of lines in the
3740 buffer. When {end} is before {lnum} an empty |List| is
3741 returned.
3742
3743 This function works only for loaded buffers. For unloaded and
3744 non-existing buffers, an empty |List| is returned.
3745
3746 Example: >
3747 :let lines = getbufline(bufnr("myfile"), 1, "$")
3748
3749< Can also be used as a |method|: >
3750 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003751<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003752 Return type: list<string>
3753
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003754 *getbufoneline()*
3755getbufoneline({buf}, {lnum})
3756 Just like `getbufline()` but only get one line and return it
3757 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003758
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003759 Return type: |String|
3760
3761
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003762getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3763 The result is the value of option or local buffer variable
3764 {varname} in buffer {buf}. Note that the name without "b:"
3765 must be used.
3766 The {varname} argument is a string.
3767 When {varname} is empty returns a |Dictionary| with all the
3768 buffer-local variables.
3769 When {varname} is equal to "&" returns a |Dictionary| with all
3770 the buffer-local options.
3771 Otherwise, when {varname} starts with "&" returns the value of
3772 a buffer-local option.
3773 This also works for a global or buffer-local option, but it
3774 doesn't work for a global variable, window-local variable or
3775 window-local option.
3776 For the use of {buf}, see |bufname()| above.
3777 When the buffer or variable doesn't exist {def} or an empty
3778 string is returned, there is no error message.
3779 Examples: >
3780 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003781 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003782
3783< Can also be used as a |method|: >
3784 GetBufnr()->getbufvar(varname)
3785<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003786 Return type: any, depending on {varname}
3787
3788
Kota Kato66bb9ae2023-01-17 18:31:56 +00003789getcellwidths() *getcellwidths()*
3790 Returns a |List| of cell widths of character ranges overridden
3791 by |setcellwidths()|. The format is equal to the argument of
3792 |setcellwidths()|. If no character ranges have their cell
3793 widths overridden, an empty List is returned.
h-east84ac2122024-06-17 18:12:30 +02003794
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003795 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003796
3797
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003798getchangelist([{buf}]) *getchangelist()*
3799 Returns the |changelist| for the buffer {buf}. For the use
3800 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3801 exist, an empty list is returned.
3802
3803 The returned list contains two entries: a list with the change
3804 locations and the current position in the list. Each
3805 entry in the change list is a dictionary with the following
3806 entries:
3807 col column number
3808 coladd column offset for 'virtualedit'
3809 lnum line number
3810 If buffer {buf} is the current buffer, then the current
3811 position refers to the position in the list. For other
3812 buffers, it is set to the length of the list.
3813
3814 Can also be used as a |method|: >
3815 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003816<
3817 Return type: list<any>
3818
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003819
Doug Kearns9cd9e752024-04-07 17:42:17 +02003820getchar([{expr}]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003821 Get a single character from the user or input stream.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003822 If {expr} is omitted, wait until a character is available.
3823 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003824 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003825 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003826 not consumed. Return zero if no character available.
3827 If you prefer always getting a string use |getcharstr()|.
3828
Doug Kearns9cd9e752024-04-07 17:42:17 +02003829 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003830 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003831 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003832 Otherwise a String is returned with the encoded character.
3833 For a special key it's a String with a sequence of bytes
3834 starting with 0x80 (decimal: 128). This is the same value as
3835 the String "\<Key>", e.g., "\<Left>". The returned value is
3836 also a String when a modifier (shift, control, alt) was used
3837 that is not included in the character.
3838
Doug Kearns9cd9e752024-04-07 17:42:17 +02003839 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003840 while Vim waits to see if this is the start of an escape
3841 sequence.
3842
Doug Kearns9cd9e752024-04-07 17:42:17 +02003843 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003844 one-byte character it is the character itself as a number.
3845 Use nr2char() to convert it to a String.
3846
3847 Use getcharmod() to obtain any additional modifiers.
3848
3849 When the user clicks a mouse button, the mouse event will be
3850 returned. The position can then be found in |v:mouse_col|,
3851 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3852 |getmousepos()| can also be used. Mouse move events will be
3853 ignored.
3854 This example positions the mouse as it would normally happen: >
3855 let c = getchar()
3856 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003857 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003858 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003859 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003860 endif
3861<
3862 When using bracketed paste only the first character is
3863 returned, the rest of the pasted text is dropped.
3864 |xterm-bracketed-paste|.
3865
3866 There is no prompt, you will somehow have to make clear to the
3867 user that a character has to be typed. The screen is not
3868 redrawn, e.g. when resizing the window. When using a popup
3869 window it should work better with a |popup-filter|.
3870
3871 There is no mapping for the character.
3872 Key codes are replaced, thus when the user presses the <Del>
3873 key you get the code for the <Del> key, not the raw character
3874 sequence. Examples: >
3875 getchar() == "\<Del>"
3876 getchar() == "\<S-Left>"
3877< This example redefines "f" to ignore case: >
3878 :nmap f :call FindChar()<CR>
3879 :function FindChar()
3880 : let c = nr2char(getchar())
3881 : while col('.') < col('$') - 1
3882 : normal l
3883 : if getline('.')[col('.') - 1] ==? c
3884 : break
3885 : endif
3886 : endwhile
3887 :endfunction
3888<
3889 You may also receive synthetic characters, such as
3890 |<CursorHold>|. Often you will want to ignore this and get
3891 another character: >
3892 :function GetKey()
3893 : let c = getchar()
3894 : while c == "\<CursorHold>"
3895 : let c = getchar()
3896 : endwhile
3897 : return c
3898 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003899<
3900 Return type: |Number| or |String|
3901
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003902
3903getcharmod() *getcharmod()*
3904 The result is a Number which is the state of the modifiers for
3905 the last obtained character with getchar() or in another way.
3906 These values are added together:
3907 2 shift
3908 4 control
3909 8 alt (meta)
3910 16 meta (when it's different from ALT)
3911 32 mouse double click
3912 64 mouse triple click
3913 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01003914 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003915 Only the modifiers that have not been included in the
3916 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01003917 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003918
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003919 Return type: |Number|
3920
3921
3922getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003923 Get the position for String {expr}. Same as |getpos()| but the
3924 column number in the returned List is a character index
3925 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00003926 If |getpos()| returns a very large column number, equal to
3927 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003928 of the last character.
3929
3930 Example:
3931 With the cursor on '세' in line 5 with text "여보세요": >
3932 getcharpos('.') returns [0, 5, 3, 0]
3933 getpos('.') returns [0, 5, 7, 0]
3934<
3935 Can also be used as a |method|: >
3936 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003937<
3938 Return type: list<number>
3939
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003940
3941getcharsearch() *getcharsearch()*
3942 Return the current character search information as a {dict}
3943 with the following entries:
3944
3945 char character previously used for a character
3946 search (|t|, |f|, |T|, or |F|); empty string
3947 if no character search has been performed
3948 forward direction of character search; 1 for forward,
3949 0 for backward
3950 until type of character search; 1 for a |t| or |T|
3951 character search, 0 for an |f| or |F|
3952 character search
3953
3954 This can be useful to always have |;| and |,| search
3955 forward/backward regardless of the direction of the previous
3956 character search: >
3957 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
3958 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
3959< Also see |setcharsearch()|.
3960
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003961 Return type: dict<any>
3962
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003963
Doug Kearns9cd9e752024-04-07 17:42:17 +02003964getcharstr([{expr}]) *getcharstr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003965 Get a single character from the user or input stream as a
3966 string.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003967 If {expr} is omitted, wait until a character is available.
3968 If {expr} is 0 or false, only get a character when one is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003969 available. Return an empty string otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003970 If {expr} is 1 or true, only check if a character is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003971 available, it is not consumed. Return an empty string
3972 if no character is available.
3973 Otherwise this works like |getchar()|, except that a number
3974 result is converted to a string.
3975
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003976 Return type: |String|
3977
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003978getcmdcomplpat() *getcmdcomplpat()*
3979 Return completion pattern of the current command-line.
3980 Only works when the command line is being edited, thus
3981 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
3982 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
3983 |getcmdprompt()|, |getcmdcompltype()| and |setcmdline()|.
3984 Returns an empty string when completion is not defined.
3985
3986 Return type: |String|
3987
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003988
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003989getcmdcompltype() *getcmdcompltype()*
3990 Return the type of the current command-line completion.
3991 Only works when the command line is being edited, thus
3992 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01003993 See |:command-completion| for the return string.
Shougo Matsushita69084282024-09-23 20:34:47 +02003994 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003995 |getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003996 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003997
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003998 Return type: |String|
3999
4000
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004001getcmdline() *getcmdline()*
Shougo Matsushita69084282024-09-23 20:34:47 +02004002 Return the current command-line input. Only works when the
4003 command line is being edited, thus requires use of
4004 |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004005 Example: >
4006 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita69084282024-09-23 20:34:47 +02004007< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()|,
4008 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004009 Returns an empty string when entering a password or using
4010 |inputsecret()|.
4011
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004012 Return type: |String|
4013
4014
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004015getcmdpos() *getcmdpos()*
4016 Return the position of the cursor in the command line as a
4017 byte count. The first column is 1.
4018 Only works when editing the command line, thus requires use of
4019 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4020 Returns 0 otherwise.
Shougo Matsushita69084282024-09-23 20:34:47 +02004021 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4022 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004023
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004024 Return type: |Number|
4025
4026
Shougo Matsushita69084282024-09-23 20:34:47 +02004027getcmdprompt() *getcmdprompt()*
4028 Return the current command-line prompt when using functions
4029 like |input()| or |confirm()|.
4030 Only works when the command line is being edited, thus
4031 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4032 Also see |getcmdtype()|, |getcmdline()|, |getcmdpos()|,
4033 |setcmdpos()| and |setcmdline()|.
4034
4035 Return type: |String|
4036
4037
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004038getcmdscreenpos() *getcmdscreenpos()*
4039 Return the screen position of the cursor in the command line
4040 as a byte count. The first column is 1.
4041 Instead of |getcmdpos()|, it adds the prompt position.
4042 Only works when editing the command line, thus requires use of
4043 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4044 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004045 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
4046 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004047
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004048 Return type: |Number|
4049
4050
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004051getcmdtype() *getcmdtype()*
4052 Return the current command-line type. Possible return values
4053 are:
4054 : normal Ex command
4055 > debug mode command |debug-mode|
4056 / forward search command
4057 ? backward search command
4058 @ |input()| command
4059 - |:insert| or |:append| command
4060 = |i_CTRL-R_=|
4061 Only works when editing the command line, thus requires use of
4062 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4063 Returns an empty string otherwise.
4064 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4065
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004066 Return type: |String|
4067
4068
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004069getcmdwintype() *getcmdwintype()*
4070 Return the current |command-line-window| type. Possible return
4071 values are the same as |getcmdtype()|. Returns an empty string
4072 when not in the command-line window.
4073
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004074 Return type: |String|
4075
4076
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004077getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4078 Return a list of command-line completion matches. The String
4079 {type} argument specifies what for. The following completion
4080 types are supported:
4081
4082 arglist file names in argument list
4083 augroup autocmd groups
4084 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004085 behave |:behave| suboptions
4086 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004087 color color schemes
4088 command Ex command
4089 cmdline |cmdline-completion| result
4090 compiler compilers
4091 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004092 custom,{func} custom completion, defined via {func}
4093 customlist,{func} custom completion, defined via {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004094 diff_buffer |:diffget| and |:diffput| completion
4095 dir directory names
LemonBoya20bf692024-07-11 22:35:53 +02004096 dir_in_path directory names in |'cdpath'|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004097 environment environment variable names
4098 event autocommand events
4099 expression Vim expression
4100 file file and directory names
4101 file_in_path file and directory names in |'path'|
4102 filetype filetype names |'filetype'|
4103 function function name
4104 help help subjects
4105 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004106 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004107 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004108 locale locale names (as output of locale -a)
4109 mapclear buffer argument
4110 mapping mapping name
4111 menu menus
4112 messages |:messages| suboptions
4113 option options
4114 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004115 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004116 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004117 shellcmd Shell command
4118 sign |:sign| suboptions
4119 syntax syntax file names |'syntax'|
4120 syntime |:syntime| suboptions
4121 tag tags
4122 tag_listfiles tags, file names
4123 user user names
4124 var user variables
4125
4126 If {pat} is an empty string, then all the matches are
4127 returned. Otherwise only items matching {pat} are returned.
4128 See |wildcards| for the use of special characters in {pat}.
4129
4130 If the optional {filtered} flag is set to 1, then 'wildignore'
4131 is applied to filter the results. Otherwise all the matches
4132 are returned. The 'wildignorecase' option always applies.
4133
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004134 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4135 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004136 regular expression matching is used. Thus this function
4137 follows the user preference, what happens on the command line.
4138 If you do not want this you can make 'wildoptions' empty
4139 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004140
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004141 If {type} is "cmdline", then the |cmdline-completion| result is
4142 returned. For example, to complete the possible values after
4143 a ":call" command: >
4144 echo getcompletion('call ', 'cmdline')
4145<
4146 If there are no matches, an empty list is returned. An
4147 invalid value for {type} produces an error.
4148
4149 Can also be used as a |method|: >
4150 GetPattern()->getcompletion('color')
4151<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004152 Return type: list<string>
4153
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004154 *getcurpos()*
4155getcurpos([{winid}])
4156 Get the position of the cursor. This is like getpos('.'), but
4157 includes an extra "curswant" item in the list:
4158 [0, lnum, col, off, curswant] ~
4159 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004160 cursor vertically. After |$| command it will be a very large
4161 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004162 |getpos()|.
4163 The first "bufnum" item is always zero. The byte position of
4164 the cursor is returned in 'col'. To get the character
4165 position, use |getcursorcharpos()|.
4166
4167 The optional {winid} argument can specify the window. It can
4168 be the window number or the |window-ID|. The last known
4169 cursor position is returned, this may be invalid for the
4170 current value of the buffer if it is not the current window.
4171 If {winid} is invalid a list with zeroes is returned.
4172
4173 This can be used to save and restore the cursor position: >
4174 let save_cursor = getcurpos()
4175 MoveTheCursorAround
4176 call setpos('.', save_cursor)
4177< Note that this only works within the window. See
4178 |winrestview()| for restoring more state.
4179
4180 Can also be used as a |method|: >
4181 GetWinid()->getcurpos()
4182<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004183 Return type: list<number>
4184
4185
4186getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004187 Same as |getcurpos()| but the column number in the returned
4188 List is a character index instead of a byte index.
4189
4190 Example:
4191 With the cursor on '보' in line 3 with text "여보세요": >
4192 getcursorcharpos() returns [0, 3, 2, 0, 3]
4193 getcurpos() returns [0, 3, 4, 0, 3]
4194<
4195 Can also be used as a |method|: >
4196 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004197<
4198 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004199
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004200
4201getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004202 The result is a String, which is the name of the current
4203 working directory. 'autochdir' is ignored.
4204
4205 With {winnr} return the local current directory of this window
4206 in the current tab page. {winnr} can be the window number or
4207 the |window-ID|.
4208 If {winnr} is -1 return the name of the global working
4209 directory. See also |haslocaldir()|.
4210
4211 With {winnr} and {tabnr} return the local current directory of
4212 the window in the specified tab page. If {winnr} is -1 return
4213 the working directory of the tabpage.
4214 If {winnr} is zero use the current window, if {tabnr} is zero
4215 use the current tabpage.
4216 Without any arguments, return the actual working directory of
4217 the current window.
4218 Return an empty string if the arguments are invalid.
4219
4220 Examples: >
4221 " Get the working directory of the current window
4222 :echo getcwd()
4223 :echo getcwd(0)
4224 :echo getcwd(0, 0)
4225 " Get the working directory of window 3 in tabpage 2
4226 :echo getcwd(3, 2)
4227 " Get the global working directory
4228 :echo getcwd(-1)
4229 " Get the working directory of tabpage 3
4230 :echo getcwd(-1, 3)
4231 " Get the working directory of current tabpage
4232 :echo getcwd(-1, 0)
4233
4234< Can also be used as a |method|: >
4235 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004236<
4237 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004238
4239getenv({name}) *getenv()*
4240 Return the value of environment variable {name}. The {name}
4241 argument is a string, without a leading '$'. Example: >
4242 myHome = getenv('HOME')
4243
4244< When the variable does not exist |v:null| is returned. That
4245 is different from a variable set to an empty string, although
4246 some systems interpret the empty value as the variable being
4247 deleted. See also |expr-env|.
4248
4249 Can also be used as a |method|: >
4250 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004251<
4252 Return type: |String| or |Number|
4253
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004254
4255getfontname([{name}]) *getfontname()*
4256 Without an argument returns the name of the normal font being
4257 used. Like what is used for the Normal highlight group
4258 |hl-Normal|.
4259 With an argument a check is done whether String {name} is a
4260 valid font name. If not then an empty string is returned.
4261 Otherwise the actual font name is returned, or {name} if the
4262 GUI does not support obtaining the real name.
4263 Only works when the GUI is running, thus not in your vimrc or
4264 gvimrc file. Use the |GUIEnter| autocommand to use this
4265 function just after the GUI has started.
4266 Note that the GTK GUI accepts any font name, thus checking for
4267 a valid name does not work.
4268
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004269 Return type: |String|
4270
4271
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004272getfperm({fname}) *getfperm()*
4273 The result is a String, which is the read, write, and execute
4274 permissions of the given file {fname}.
4275 If {fname} does not exist or its directory cannot be read, an
4276 empty string is returned.
4277 The result is of the form "rwxrwxrwx", where each group of
4278 "rwx" flags represent, in turn, the permissions of the owner
4279 of the file, the group the file belongs to, and other users.
4280 If a user does not have a given permission the flag for this
4281 is replaced with the string "-". Examples: >
4282 :echo getfperm("/etc/passwd")
4283 :echo getfperm(expand("~/.vimrc"))
4284< This will hopefully (from a security point of view) display
4285 the string "rw-r--r--" or even "rw-------".
4286
4287 Can also be used as a |method|: >
4288 GetFilename()->getfperm()
4289<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004290 Return type: |String|
4291
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004292 For setting permissions use |setfperm()|.
4293
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004294
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004295getfsize({fname}) *getfsize()*
4296 The result is a Number, which is the size in bytes of the
4297 given file {fname}.
4298 If {fname} is a directory, 0 is returned.
4299 If the file {fname} can't be found, -1 is returned.
4300 If the size of {fname} is too big to fit in a Number then -2
4301 is returned.
4302
4303 Can also be used as a |method|: >
4304 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004305<
4306 Return type: |Number|
4307
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004308
4309getftime({fname}) *getftime()*
4310 The result is a Number, which is the last modification time of
4311 the given file {fname}. The value is measured as seconds
4312 since 1st Jan 1970, and may be passed to strftime(). See also
4313 |localtime()| and |strftime()|.
4314 If the file {fname} can't be found -1 is returned.
4315
4316 Can also be used as a |method|: >
4317 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004318<
4319 Return type: |Number|
4320
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004321
4322getftype({fname}) *getftype()*
4323 The result is a String, which is a description of the kind of
4324 file of the given file {fname}.
4325 If {fname} does not exist an empty string is returned.
4326 Here is a table over different kinds of files and their
4327 results:
4328 Normal file "file"
4329 Directory "dir"
4330 Symbolic link "link"
4331 Block device "bdev"
4332 Character device "cdev"
4333 Socket "socket"
4334 FIFO "fifo"
4335 All other "other"
4336 Example: >
4337 getftype("/home")
4338< Note that a type such as "link" will only be returned on
4339 systems that support it. On some systems only "dir" and
4340 "file" are returned. On MS-Windows a symbolic link to a
4341 directory returns "dir" instead of "link".
4342
4343 Can also be used as a |method|: >
4344 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004345<
4346 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004347
4348getimstatus() *getimstatus()*
4349 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004350 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004351 See 'imstatusfunc'.
4352
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004353 Return type: |Number|
4354
4355
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004356getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4357 Returns the |jumplist| for the specified window.
4358
4359 Without arguments use the current window.
4360 With {winnr} only use this window in the current tab page.
4361 {winnr} can also be a |window-ID|.
4362 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004363 page. If {winnr} or {tabnr} is invalid, an empty list is
4364 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004365
4366 The returned list contains two entries: a list with the jump
4367 locations and the last used jump position number in the list.
4368 Each entry in the jump location list is a dictionary with
4369 the following entries:
4370 bufnr buffer number
4371 col column number
4372 coladd column offset for 'virtualedit'
4373 filename filename if available
4374 lnum line number
4375
4376 Can also be used as a |method|: >
4377 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004378<
4379 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004380
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004381 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004382getline({lnum} [, {end}])
4383 Without {end} the result is a String, which is line {lnum}
4384 from the current buffer. Example: >
4385 getline(1)
4386< When {lnum} is a String that doesn't start with a
4387 digit, |line()| is called to translate the String into a Number.
4388 To get the line under the cursor: >
4389 getline(".")
4390< When {lnum} is a number smaller than 1 or bigger than the
4391 number of lines in the buffer, an empty string is returned.
4392
4393 When {end} is given the result is a |List| where each item is
4394 a line from the current buffer in the range {lnum} to {end},
4395 including line {end}.
4396 {end} is used in the same way as {lnum}.
4397 Non-existing lines are silently omitted.
4398 When {end} is before {lnum} an empty |List| is returned.
4399 Example: >
4400 :let start = line('.')
4401 :let end = search("^$") - 1
4402 :let lines = getline(start, end)
4403
4404< Can also be used as a |method|: >
4405 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004406<
4407 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004408
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004409 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004410 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004411
4412getloclist({nr} [, {what}]) *getloclist()*
4413 Returns a |List| with all the entries in the location list for
4414 window {nr}. {nr} can be the window number or the |window-ID|.
4415 When {nr} is zero the current window is used.
4416
4417 For a location list window, the displayed location list is
4418 returned. For an invalid window number {nr}, an empty list is
4419 returned. Otherwise, same as |getqflist()|.
4420
4421 If the optional {what} dictionary argument is supplied, then
4422 returns the items listed in {what} as a dictionary. Refer to
4423 |getqflist()| for the supported items in {what}.
4424
4425 In addition to the items supported by |getqflist()| in {what},
4426 the following item is supported by |getloclist()|:
4427
4428 filewinid id of the window used to display files
4429 from the location list. This field is
4430 applicable only when called from a
4431 location list window. See
4432 |location-list-file-window| for more
4433 details.
4434
4435 Returns a |Dictionary| with default values if there is no
4436 location list for the window {nr}.
4437 Returns an empty Dictionary if window {nr} does not exist.
4438
4439 Examples (See also |getqflist-examples|): >
4440 :echo getloclist(3, {'all': 0})
4441 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004442<
4443 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004444
4445
4446getmarklist([{buf}]) *getmarklist()*
4447 Without the {buf} argument returns a |List| with information
4448 about all the global marks. |mark|
4449
4450 If the optional {buf} argument is specified, returns the
4451 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004452 see |bufname()|. If {buf} is invalid, an empty list is
4453 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004454
4455 Each item in the returned List is a |Dict| with the following:
4456 mark name of the mark prefixed by "'"
4457 pos a |List| with the position of the mark:
4458 [bufnum, lnum, col, off]
4459 Refer to |getpos()| for more information.
4460 file file name
4461
4462 Refer to |getpos()| for getting information about a specific
4463 mark.
4464
4465 Can also be used as a |method|: >
4466 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004467<
4468 Return type: list<dict<any>> or list<any>
4469
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004470
4471getmatches([{win}]) *getmatches()*
4472 Returns a |List| with all matches previously defined for the
4473 current window by |matchadd()| and the |:match| commands.
4474 |getmatches()| is useful in combination with |setmatches()|,
4475 as |setmatches()| can restore a list of matches saved by
4476 |getmatches()|.
4477 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004478 window ID instead of the current window. If {win} is invalid,
4479 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004480 Example: >
4481 :echo getmatches()
4482< [{'group': 'MyGroup1', 'pattern': 'TODO',
4483 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4484 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4485 :let m = getmatches()
4486 :call clearmatches()
4487 :echo getmatches()
4488< [] >
4489 :call setmatches(m)
4490 :echo getmatches()
4491< [{'group': 'MyGroup1', 'pattern': 'TODO',
4492 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4493 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4494 :unlet m
4495<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004496 Return type: list<dict<any>> or list<any>
4497
4498
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004499getmousepos() *getmousepos()*
4500 Returns a |Dictionary| with the last known position of the
4501 mouse. This can be used in a mapping for a mouse click or in
4502 a filter of a popup window. The items are:
4503 screenrow screen row
4504 screencol screen column
4505 winid Window ID of the click
4506 winrow row inside "winid"
4507 wincol column inside "winid"
4508 line text line inside "winid"
4509 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004510 coladd offset (in screen columns) from the
4511 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004512 All numbers are 1-based.
4513
4514 If not over a window, e.g. when in the command line, then only
4515 "screenrow" and "screencol" are valid, the others are zero.
4516
4517 When on the status line below a window or the vertical
4518 separator right of a window, the "line" and "column" values
4519 are zero.
4520
4521 When the position is after the text then "column" is the
4522 length of the text in bytes plus one.
4523
4524 If the mouse is over a popup window then that window is used.
4525
4526 When using |getchar()| the Vim variables |v:mouse_lnum|,
4527 |v:mouse_col| and |v:mouse_winid| also provide these values.
4528
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004529 Return type: dict<number>
4530
4531
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004532getmouseshape() *getmouseshape()*
4533 Returns the name of the currently showing mouse pointer.
4534 When the |+mouseshape| feature is not supported or the shape
4535 is unknown an empty string is returned.
4536 This function is mainly intended for testing.
4537
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004538 Return type: |String|
4539
4540
4541getpid() *getpid()*
4542 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004543 On Unix and MS-Windows this is a unique number, until Vim
4544 exits.
4545
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004546 Return type: |Number|
4547
4548
4549getpos({expr}) *getpos()*
zeertzjq02f3eba2024-06-12 20:45:24 +02004550 Get the position for String {expr}.
4551 The accepted values for {expr} are: *E1209*
4552 . The cursor position.
4553 $ The last line in the current buffer.
4554 'x Position of mark x (if the mark is not set, 0 is
zeertzjqd353d272024-06-13 23:00:25 +08004555 returned for all values).
zeertzjq02f3eba2024-06-12 20:45:24 +02004556 w0 First line visible in current window (one if the
4557 display isn't updated, e.g. in silent Ex mode).
4558 w$ Last line visible in current window (this is one
4559 less than "w0" if no lines are visible).
4560 v When not in Visual mode, returns the cursor
4561 position. In Visual mode, returns the other end
4562 of the Visual area. A good way to think about
4563 this is that in Visual mode "v" and "." complement
4564 each other. While "." refers to the cursor
4565 position, "v" refers to where |v_o| would move the
4566 cursor. As a result, you can use "v" and "."
4567 together to work on all of a selection in
4568 characterwise Visual mode. If the cursor is at
4569 the end of a characterwise Visual area, "v" refers
4570 to the start of the same Visual area. And if the
4571 cursor is at the start of a characterwise Visual
4572 area, "v" refers to the end of the same Visual
4573 area. "v" differs from |'<| and |'>| in that it's
4574 updated right away.
4575 Note that a mark in another file can be used. The line number
4576 then applies to another buffer.
4577
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004578 The result is a |List| with four numbers:
4579 [bufnum, lnum, col, off]
4580 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4581 is the buffer number of the mark.
4582 "lnum" and "col" are the position in the buffer. The first
4583 column is 1.
4584 The "off" number is zero, unless 'virtualedit' is used. Then
4585 it is the offset in screen columns from the start of the
4586 character. E.g., a position within a <Tab> or after the last
4587 character.
zeertzjq02f3eba2024-06-12 20:45:24 +02004588
4589 For getting the cursor position see |getcurpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004590 The column number in the returned List is the byte position
4591 within the line. To get the character position in the line,
4592 use |getcharpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02004593
4594 Note that for '< and '> Visual mode matters: when it is "V"
4595 (visual line mode) the column of '< is zero and the column of
4596 '> is a large number equal to |v:maxcol|.
naohiro ono56200ee2022-01-01 14:59:44 +00004597 A very large column number equal to |v:maxcol| can be returned,
4598 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004599 If {expr} is invalid, returns a list with all zeros.
zeertzjq02f3eba2024-06-12 20:45:24 +02004600
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004601 This can be used to save and restore the position of a mark: >
4602 let save_a_mark = getpos("'a")
4603 ...
4604 call setpos("'a", save_a_mark)
zeertzjqd353d272024-06-13 23:00:25 +08004605<
4606 Also see |getcharpos()|, |getcurpos()| and |setpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004607
4608 Can also be used as a |method|: >
4609 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004610<
4611 Return type: list<number>
4612
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004613
4614getqflist([{what}]) *getqflist()*
4615 Returns a |List| with all the current quickfix errors. Each
4616 list item is a dictionary with these entries:
4617 bufnr number of buffer that has the file name, use
4618 bufname() to get the name
4619 module module name
4620 lnum line number in the buffer (first line is 1)
4621 end_lnum
4622 end of line number if the item is multiline
4623 col column number (first column is 1)
4624 end_col end of column number if the item has range
4625 vcol |TRUE|: "col" is visual column
4626 |FALSE|: "col" is byte index
4627 nr error number
h-east84ac2122024-06-17 18:12:30 +02004628 pattern search pattern used to locate the error
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004629 text description of the error
4630 type type of the error, 'E', '1', etc.
4631 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004632 user_data
4633 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004634 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004635
4636 When there is no error list or it's empty, an empty list is
4637 returned. Quickfix list entries with a non-existing buffer
4638 number are returned with "bufnr" set to zero (Note: some
4639 functions accept buffer number zero for the alternate buffer,
4640 you may need to explicitly check for zero).
4641
4642 Useful application: Find pattern matches in multiple files and
4643 do something with them: >
4644 :vimgrep /theword/jg *.c
4645 :for d in getqflist()
4646 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4647 :endfor
4648<
4649 If the optional {what} dictionary argument is supplied, then
4650 returns only the items listed in {what} as a dictionary. The
4651 following string items are supported in {what}:
4652 changedtick get the total number of changes made
4653 to the list |quickfix-changedtick|
4654 context get the |quickfix-context|
4655 efm errorformat to use when parsing "lines". If
4656 not present, then the 'errorformat' option
4657 value is used.
4658 id get information for the quickfix list with
4659 |quickfix-ID|; zero means the id for the
4660 current list or the list specified by "nr"
4661 idx get information for the quickfix entry at this
4662 index in the list specified by 'id' or 'nr'.
4663 If set to zero, then uses the current entry.
4664 See |quickfix-index|
4665 items quickfix list entries
4666 lines parse a list of lines using 'efm' and return
4667 the resulting entries. Only a |List| type is
4668 accepted. The current quickfix list is not
4669 modified. See |quickfix-parse|.
4670 nr get information for this quickfix list; zero
4671 means the current quickfix list and "$" means
4672 the last quickfix list
4673 qfbufnr number of the buffer displayed in the quickfix
4674 window. Returns 0 if the quickfix buffer is
4675 not present. See |quickfix-buffer|.
4676 size number of entries in the quickfix list
4677 title get the list title |quickfix-title|
4678 winid get the quickfix |window-ID|
4679 all all of the above quickfix properties
4680 Non-string items in {what} are ignored. To get the value of a
4681 particular item, set it to zero.
4682 If "nr" is not present then the current quickfix list is used.
4683 If both "nr" and a non-zero "id" are specified, then the list
4684 specified by "id" is used.
4685 To get the number of lists in the quickfix stack, set "nr" to
4686 "$" in {what}. The "nr" value in the returned dictionary
4687 contains the quickfix stack size.
4688 When "lines" is specified, all the other items except "efm"
4689 are ignored. The returned dictionary contains the entry
4690 "items" with the list of entries.
4691
4692 The returned dictionary contains the following entries:
4693 changedtick total number of changes made to the
4694 list |quickfix-changedtick|
4695 context quickfix list context. See |quickfix-context|
4696 If not present, set to "".
4697 id quickfix list ID |quickfix-ID|. If not
4698 present, set to 0.
4699 idx index of the quickfix entry in the list. If not
4700 present, set to 0.
4701 items quickfix list entries. If not present, set to
4702 an empty list.
4703 nr quickfix list number. If not present, set to 0
4704 qfbufnr number of the buffer displayed in the quickfix
4705 window. If not present, set to 0.
4706 size number of entries in the quickfix list. If not
4707 present, set to 0.
4708 title quickfix list title text. If not present, set
4709 to "".
4710 winid quickfix |window-ID|. If not present, set to 0
4711
4712 Examples (See also |getqflist-examples|): >
4713 :echo getqflist({'all': 1})
4714 :echo getqflist({'nr': 2, 'title': 1})
4715 :echo getqflist({'lines' : ["F1:10:L10"]})
4716<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004717 Return type: list<dict<any>> or list<any>
4718
4719
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004720getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4721 The result is a String, which is the contents of register
4722 {regname}. Example: >
4723 :let cliptext = getreg('*')
4724< When register {regname} was not set the result is an empty
4725 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004726 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004727
4728 getreg('=') returns the last evaluated value of the expression
4729 register. (For use in maps.)
4730 getreg('=', 1) returns the expression itself, so that it can
4731 be restored with |setreg()|. For other registers the extra
4732 argument is ignored, thus you can always give it.
4733
4734 If {list} is present and |TRUE|, the result type is changed
4735 to |List|. Each list item is one text line. Use it if you care
4736 about zero bytes possibly present inside register: without
4737 third argument both NLs and zero bytes are represented as NLs
4738 (see |NL-used-for-Nul|).
4739 When the register was not set an empty list is returned.
4740
4741 If {regname} is "", the unnamed register '"' is used.
4742 If {regname} is not specified, |v:register| is used.
4743 In |Vim9-script| {regname} must be one character.
4744
4745 Can also be used as a |method|: >
4746 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004747<
4748 Return type: |String|
4749
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004750
4751getreginfo([{regname}]) *getreginfo()*
4752 Returns detailed information about register {regname} as a
4753 Dictionary with the following entries:
4754 regcontents List of lines contained in register
4755 {regname}, like
4756 |getreg|({regname}, 1, 1).
4757 regtype the type of register {regname}, as in
4758 |getregtype()|.
4759 isunnamed Boolean flag, v:true if this register
4760 is currently pointed to by the unnamed
4761 register.
4762 points_to for the unnamed register, gives the
4763 single letter name of the register
4764 currently pointed to (see |quotequote|).
4765 For example, after deleting a line
4766 with `dd`, this field will be "1",
4767 which is the register that got the
4768 deleted text.
4769
4770 The {regname} argument is a string. If {regname} is invalid
4771 or not set, an empty Dictionary will be returned.
4772 If {regname} is "" or "@", the unnamed register '"' is used.
4773 If {regname} is not specified, |v:register| is used.
4774 The returned Dictionary can be passed to |setreg()|.
4775 In |Vim9-script| {regname} must be one character.
4776
4777 Can also be used as a |method|: >
4778 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004779<
4780 Return type: dict<any>
4781
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004782
Shougo Matsushita19b71882024-02-28 22:48:12 +01004783getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004784 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01004785 buffer.
4786
4787 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004788 See |getpos()| for the format of the list. It's possible
4789 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01004790 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01004791
4792 The optional argument {opts} is a Dict and supports the
4793 following items:
4794
zeertzjqafc22952024-05-24 19:07:12 +02004795 type Specify the region's selection type.
4796 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02004797 except that the width can be omitted
4798 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02004799 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01004800
zeertzjq87410ab2024-03-02 06:00:23 +08004801 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02004802 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08004803 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01004804
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004805 You can get the last selection type by |visualmode()|.
4806 If Visual mode is active, use |mode()| to get the Visual mode
4807 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08004808 This function is useful to get text starting and ending in
4809 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004810
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004811 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004812 Note that:
4813 - Order of {pos1} and {pos2} doesn't matter, it will always
4814 return content from the upper left position to the lower
4815 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08004816 - If 'virtualedit' is enabled and the region is past the end
4817 of the lines, resulting lines are padded with spaces.
4818 - If the region is blockwise and it starts or ends in the
4819 middle of a multi-cell character, it is not included but
4820 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004821 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01004822 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004823 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01004824 - It is evaluated in current window context, which makes a
4825 difference if the buffer is displayed in a window with
4826 different 'virtualedit' or 'list' values.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004827
4828 Examples: >
4829 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01004830 \ <Cmd>echow getregion(
4831 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004832<
4833 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01004834 getpos('.')->getregion(getpos("'a"))
zeertzjqd4d12072024-07-16 20:34:16 +02004835<
4836 Return type: list<string>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004837
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004838<
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004839getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
4840 Same as |getregion()|, but returns a list of positions
4841 describing the buffer text segments bound by {pos1} and
4842 {pos2}.
4843 The segments are a pair of positions for every line: >
4844 [[{start_pos}, {end_pos}], ...]
4845<
4846 The position is a |List| with four numbers:
4847 [bufnum, lnum, col, off]
4848 "bufnum" is the buffer number.
4849 "lnum" and "col" are the position in the buffer. The first
4850 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02004851 If the "off" number of a starting position is non-zero, it is
4852 the offset in screen columns from the start of the character.
4853 E.g., a position within a <Tab> or after the last character.
4854 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02004855 the offset of the character's first cell not included in the
4856 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004857
zeertzjq2b09de92024-05-24 07:48:51 +02004858 Apart from the options supported by |getregion()|, {opts} also
4859 supports the following:
4860
4861 eol If |TRUE|, indicate positions beyond
4862 the end of a line with "col" values
4863 one more than the length of the line.
4864 If |FALSE|, positions are limited
4865 within their lines, and if a line is
4866 empty or the selection is entirely
4867 beyond the end of a line, a "col"
4868 value of 0 is used for both positions.
4869 (default: |FALSE|)
4870
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004871 Can also be used as a |method|: >
4872 getpos('.')->getregionpos(getpos("'a"))
4873<
zeertzjqd4d12072024-07-16 20:34:16 +02004874 Return type: list<list<list<number>>>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004875
4876
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004877getregtype([{regname}]) *getregtype()*
4878 The result is a String, which is type of register {regname}.
4879 The value will be one of:
4880 "v" for |characterwise| text
4881 "V" for |linewise| text
4882 "<CTRL-V>{width}" for |blockwise-visual| text
4883 "" for an empty or unknown register
4884 <CTRL-V> is one character with value 0x16.
4885 The {regname} argument is a string. If {regname} is "", the
4886 unnamed register '"' is used. If {regname} is not specified,
4887 |v:register| is used.
4888 In |Vim9-script| {regname} must be one character.
4889
4890 Can also be used as a |method|: >
4891 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004892<
4893 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004894
Bram Moolenaar71badf92023-04-22 22:40:14 +01004895getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004896 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01004897 scripts in the order they were sourced, like what
4898 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004899
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004900 The optional Dict argument {opts} supports the following
4901 optional items:
4902 name Script name match pattern. If specified,
4903 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01004904 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004905 "name" are returned.
4906 sid Script ID |<SID>|. If specified, only
4907 information about the script with ID "sid" is
4908 returned and "name" is ignored.
4909
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004910 Each item in the returned List is a |Dict| with the following
4911 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004912 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01004913 `import autoload` but was not actually sourced
4914 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004915 functions List of script-local function names defined in
4916 the script. Present only when a particular
4917 script is specified using the "sid" item in
4918 {opts}.
4919 name Vim script file name.
4920 sid Script ID |<SID>|.
4921 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01004922 this script name links to, if any, otherwise
4923 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004924 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00004925 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004926 specified using the "sid" item in {opts}.
4927 Note that this is a copy, the value of
4928 script-local variables cannot be changed using
4929 this dictionary.
h_east59858792023-10-25 22:47:05 +09004930 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01004931
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004932 Examples: >
4933 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08004934 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004935<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004936 Return type: list<dict<any>>
4937
4938
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004939gettabinfo([{tabnr}]) *gettabinfo()*
4940 If {tabnr} is not specified, then information about all the
4941 tab pages is returned as a |List|. Each List item is a
4942 |Dictionary|. Otherwise, {tabnr} specifies the tab page
4943 number and information about that one is returned. If the tab
4944 page does not exist an empty List is returned.
4945
4946 Each List item is a |Dictionary| with the following entries:
4947 tabnr tab page number.
4948 variables a reference to the dictionary with
4949 tabpage-local variables
4950 windows List of |window-ID|s in the tab page.
4951
4952 Can also be used as a |method|: >
4953 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004954<
4955 Return type: list<dict<any>>
4956
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004957
4958gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
4959 Get the value of a tab-local variable {varname} in tab page
4960 {tabnr}. |t:var|
4961 Tabs are numbered starting with one.
4962 The {varname} argument is a string. When {varname} is empty a
4963 dictionary with all tab-local variables is returned.
4964 Note that the name without "t:" must be used.
4965 When the tab or variable doesn't exist {def} or an empty
4966 string is returned, there is no error message.
4967
4968 Can also be used as a |method|: >
4969 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004970<
4971 Return type: any, depending on {varname}
4972
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004973
4974gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
4975 Get the value of window-local variable {varname} in window
4976 {winnr} in tab page {tabnr}.
4977 The {varname} argument is a string. When {varname} is empty a
4978 dictionary with all window-local variables is returned.
4979 When {varname} is equal to "&" get the values of all
4980 window-local options in a |Dictionary|.
4981 Otherwise, when {varname} starts with "&" get the value of a
4982 window-local option.
4983 Note that {varname} must be the name without "w:".
4984 Tabs are numbered starting with one. For the current tabpage
4985 use |getwinvar()|.
4986 {winnr} can be the window number or the |window-ID|.
4987 When {winnr} is zero the current window is used.
4988 This also works for a global option, buffer-local option and
4989 window-local option, but it doesn't work for a global variable
4990 or buffer-local variable.
4991 When the tab, window or variable doesn't exist {def} or an
4992 empty string is returned, there is no error message.
4993 Examples: >
4994 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004995 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004996<
4997 To obtain all window-local variables use: >
4998 gettabwinvar({tabnr}, {winnr}, '&')
4999
5000< Can also be used as a |method|: >
5001 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005002<
5003 Return type: any, depending on {varname}
5004
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005005
5006gettagstack([{winnr}]) *gettagstack()*
5007 The result is a Dict, which is the tag stack of window {winnr}.
5008 {winnr} can be the window number or the |window-ID|.
5009 When {winnr} is not specified, the current window is used.
5010 When window {winnr} doesn't exist, an empty Dict is returned.
5011
5012 The returned dictionary contains the following entries:
5013 curidx Current index in the stack. When at
5014 top of the stack, set to (length + 1).
5015 Index of bottom of the stack is 1.
5016 items List of items in the stack. Each item
5017 is a dictionary containing the
5018 entries described below.
5019 length Number of entries in the stack.
5020
5021 Each item in the stack is a dictionary with the following
5022 entries:
5023 bufnr buffer number of the current jump
5024 from cursor position before the tag jump.
5025 See |getpos()| for the format of the
5026 returned list.
5027 matchnr current matching tag number. Used when
5028 multiple matching tags are found for a
5029 name.
5030 tagname name of the tag
5031
5032 See |tagstack| for more information about the tag stack.
5033
5034 Can also be used as a |method|: >
5035 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005036<
5037 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005038
5039
Christ van Willegence0ef912024-06-20 23:41:59 +02005040gettext({text} [, {package}]) *gettext()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005041 Translate String {text} if possible.
RestorerZ96509102024-07-11 21:14:15 +02005042 This is intended for use in Vim scripts. When generating
5043 message translations the {text} is extracted by `xgettext`,
5044 the translator can add translated messages into the .po file
5045 and Vim will lookup the translation when gettext() is called.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005046 For {text} double quoted strings are preferred, because
RestorerZ96509102024-07-11 21:14:15 +02005047 `xgettext` does not support single quoted escaped text.
5048
Christ van Willegence0ef912024-06-20 23:41:59 +02005049 When the {package} is specified, the translation is looked up
RestorerZ96509102024-07-11 21:14:15 +02005050 for that specific package. This is mainly required for
5051 third-party Vim scripts. You need to specify a path to the
5052 translations with the |bindtextdomain()| function before
5053 using the gettext() function.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005054
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005055 Return type: |String|
5056
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005057
5058getwininfo([{winid}]) *getwininfo()*
5059 Returns information about windows as a |List| with Dictionaries.
5060
5061 If {winid} is given Information about the window with that ID
5062 is returned, as a |List| with one item. If the window does not
5063 exist the result is an empty list.
5064
5065 Without {winid} information about all the windows in all the
5066 tab pages is returned.
5067
5068 Each List item is a |Dictionary| with the following entries:
5069 botline last complete displayed buffer line
5070 bufnr number of buffer in the window
5071 height window height (excluding winbar)
5072 loclist 1 if showing a location list
5073 {only with the +quickfix feature}
5074 quickfix 1 if quickfix or location list window
5075 {only with the +quickfix feature}
5076 terminal 1 if a terminal window
5077 {only with the +terminal feature}
5078 tabnr tab page number
5079 topline first displayed buffer line
5080 variables a reference to the dictionary with
5081 window-local variables
5082 width window width
5083 winbar 1 if the window has a toolbar, 0
5084 otherwise
5085 wincol leftmost screen column of the window;
5086 "col" from |win_screenpos()|
5087 textoff number of columns occupied by any
5088 'foldcolumn', 'signcolumn' and line
5089 number in front of the text
5090 winid |window-ID|
5091 winnr window number
5092 winrow topmost screen line of the window;
5093 "row" from |win_screenpos()|
5094
5095 Can also be used as a |method|: >
5096 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005097<
5098 Return type: list<dict<any>>
5099
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005100
5101getwinpos([{timeout}]) *getwinpos()*
5102 The result is a |List| with two numbers, the result of
5103 |getwinposx()| and |getwinposy()| combined:
5104 [x-pos, y-pos]
5105 {timeout} can be used to specify how long to wait in msec for
5106 a response from the terminal. When omitted 100 msec is used.
5107 Use a longer time for a remote terminal.
5108 When using a value less than 10 and no response is received
5109 within that time, a previously reported position is returned,
5110 if available. This can be used to poll for the position and
5111 do some work in the meantime: >
5112 while 1
5113 let res = getwinpos(1)
5114 if res[0] >= 0
5115 break
5116 endif
5117 " Do some work here
5118 endwhile
5119<
5120
5121 Can also be used as a |method|: >
5122 GetTimeout()->getwinpos()
5123<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005124 Return type: list<number>
5125
5126
5127getwinposx() *getwinposx()*
5128 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005129 the left hand side of the GUI Vim window. Also works for an
5130 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005131 The result will be -1 if the information is not available
5132 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005133 The value can be used with `:winpos`.
5134
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005135 Return type: |Number|
5136
5137
5138getwinposy() *getwinposy()*
5139 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005140 the top of the GUI Vim window. Also works for an xterm (uses
5141 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005142 The result will be -1 if the information is not available
5143 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005144 The value can be used with `:winpos`.
5145
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005146 Return type: |Number|
5147
5148
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005149getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5150 Like |gettabwinvar()| for the current tabpage.
5151 Examples: >
5152 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005153 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005154
5155< Can also be used as a |method|: >
5156 GetWinnr()->getwinvar(varname)
5157<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005158 Return type: any, depending on {varname}
5159
5160
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005161glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5162 Expand the file wildcards in {expr}. See |wildcards| for the
5163 use of special characters.
5164
5165 Unless the optional {nosuf} argument is given and is |TRUE|,
5166 the 'suffixes' and 'wildignore' options apply: Names matching
5167 one of the patterns in 'wildignore' will be skipped and
5168 'suffixes' affect the ordering of matches.
5169 'wildignorecase' always applies.
5170
5171 When {list} is present and it is |TRUE| the result is a |List|
5172 with all matching files. The advantage of using a List is,
5173 you also get filenames containing newlines correctly.
5174 Otherwise the result is a String and when there are several
5175 matches, they are separated by <NL> characters.
5176
5177 If the expansion fails, the result is an empty String or List.
5178
5179 You can also use |readdir()| if you need to do complicated
5180 things, such as limiting the number of matches.
5181
5182 A name for a non-existing file is not included. A symbolic
5183 link is only included if it points to an existing file.
5184 However, when the {alllinks} argument is present and it is
5185 |TRUE| then all symbolic links are included.
5186
5187 For most systems backticks can be used to get files names from
5188 any external command. Example: >
5189 :let tagfiles = glob("`find . -name tags -print`")
5190 :let &tags = substitute(tagfiles, "\n", ",", "g")
5191< The result of the program inside the backticks should be one
5192 item per line. Spaces inside an item are allowed.
5193
5194 See |expand()| for expanding special Vim variables. See
5195 |system()| for getting the raw output of an external command.
5196
5197 Can also be used as a |method|: >
5198 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005199<
5200 Return type: |String| or list<string> or list<any> depending
5201 on {list}
5202
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005203
5204glob2regpat({string}) *glob2regpat()*
5205 Convert a file pattern, as used by glob(), into a search
5206 pattern. The result can be used to match with a string that
5207 is a file name. E.g. >
5208 if filename =~ glob2regpat('Make*.mak')
5209< This is equivalent to: >
5210 if filename =~ '^Make.*\.mak$'
5211< When {string} is an empty string the result is "^$", match an
5212 empty string.
5213 Note that the result depends on the system. On MS-Windows
5214 a backslash usually means a path separator.
5215
5216 Can also be used as a |method|: >
5217 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005218<
5219 Return type: |String|
5220
5221 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005222globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5223 Perform glob() for String {expr} on all directories in {path}
5224 and concatenate the results. Example: >
5225 :echo globpath(&rtp, "syntax/c.vim")
5226<
5227 {path} is a comma-separated list of directory names. Each
5228 directory name is prepended to {expr} and expanded like with
5229 |glob()|. A path separator is inserted when needed.
5230 To add a comma inside a directory name escape it with a
5231 backslash. Note that on MS-Windows a directory may have a
5232 trailing backslash, remove it if you put a comma after it.
5233 If the expansion fails for one of the directories, there is no
5234 error message.
5235
5236 Unless the optional {nosuf} argument is given and is |TRUE|,
5237 the 'suffixes' and 'wildignore' options apply: Names matching
5238 one of the patterns in 'wildignore' will be skipped and
5239 'suffixes' affect the ordering of matches.
5240
5241 When {list} is present and it is |TRUE| the result is a |List|
5242 with all matching files. The advantage of using a List is, you
5243 also get filenames containing newlines correctly. Otherwise
5244 the result is a String and when there are several matches,
5245 they are separated by <NL> characters. Example: >
5246 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5247<
5248 {alllinks} is used as with |glob()|.
5249
5250 The "**" item can be used to search in a directory tree.
5251 For example, to find all "README.txt" files in the directories
5252 in 'runtimepath' and below: >
5253 :echo globpath(&rtp, "**/README.txt")
5254< Upwards search and limiting the depth of "**" is not
5255 supported, thus using 'path' will not always work properly.
5256
5257 Can also be used as a |method|, the base is passed as the
5258 second argument: >
5259 GetExpr()->globpath(&rtp)
5260<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005261 Return type: |String| or list<string> or list<any> depending
5262 on {list}
5263
5264
5265has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005266 When {check} is omitted or is zero: The result is a Number,
5267 which is 1 if the feature {feature} is supported, zero
5268 otherwise. The {feature} argument is a string, case is
5269 ignored. See |feature-list| below.
5270
5271 When {check} is present and not zero: The result is a Number,
5272 which is 1 if the feature {feature} could ever be supported,
5273 zero otherwise. This is useful to check for a typo in
5274 {feature} and to detect dead code. Keep in mind that an older
5275 Vim version will not know about a feature added later and
5276 features that have been abandoned will not be known by the
5277 current Vim version.
5278
5279 Also see |exists()| and |exists_compiled()|.
5280
5281 Note that to skip code that has a syntax error when the
5282 feature is not available, Vim may skip the rest of the line
5283 and miss a following `endif`. Therefore put the `endif` on a
5284 separate line: >
5285 if has('feature')
5286 let x = this->breaks->without->the->feature
5287 endif
5288< If the `endif` would be moved to the second line as "| endif" it
5289 would not be found.
5290
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005291 Return type: |Number|
5292
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005293
5294has_key({dict}, {key}) *has_key()*
5295 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005296 has an entry with key {key}. FALSE otherwise.
5297 The {key} argument is a string. In |Vim9| script a number is
5298 also accepted (and converted to a string) but no other types.
5299 In legacy script the usual automatic conversion to string is
5300 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005301
5302 Can also be used as a |method|: >
5303 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005304<
5305 Return type: |Number|
5306
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005307
5308haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5309 The result is a Number:
5310 1 when the window has set a local directory via |:lcd|
5311 2 when the tab-page has set a local directory via |:tcd|
5312 0 otherwise.
5313
5314 Without arguments use the current window.
5315 With {winnr} use this window in the current tab page.
5316 With {winnr} and {tabnr} use the window in the specified tab
5317 page.
5318 {winnr} can be the window number or the |window-ID|.
5319 If {winnr} is -1 it is ignored and only the tabpage is used.
5320 Return 0 if the arguments are invalid.
5321 Examples: >
5322 if haslocaldir() == 1
5323 " window local directory case
5324 elseif haslocaldir() == 2
5325 " tab-local directory case
5326 else
5327 " global directory case
5328 endif
5329
5330 " current window
5331 :echo haslocaldir()
5332 :echo haslocaldir(0)
5333 :echo haslocaldir(0, 0)
5334 " window n in current tab page
5335 :echo haslocaldir(n)
5336 :echo haslocaldir(n, 0)
5337 " window n in tab page m
5338 :echo haslocaldir(n, m)
5339 " tab page m
5340 :echo haslocaldir(-1, m)
5341<
5342 Can also be used as a |method|: >
5343 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005344<
5345 Return type: |Number|
5346
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005347
5348hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5349 The result is a Number, which is TRUE if there is a mapping
5350 that contains {what} in somewhere in the rhs (what it is
5351 mapped to) and this mapping exists in one of the modes
5352 indicated by {mode}.
5353 The arguments {what} and {mode} are strings.
5354 When {abbr} is there and it is |TRUE| use abbreviations
5355 instead of mappings. Don't forget to specify Insert and/or
5356 Command-line mode.
5357 Both the global mappings and the mappings local to the current
5358 buffer are checked for a match.
5359 If no matching mapping is found FALSE is returned.
5360 The following characters are recognized in {mode}:
5361 n Normal mode
5362 v Visual and Select mode
5363 x Visual mode
5364 s Select mode
5365 o Operator-pending mode
5366 i Insert mode
5367 l Language-Argument ("r", "f", "t", etc.)
5368 c Command-line mode
5369 When {mode} is omitted, "nvo" is used.
5370
5371 This function is useful to check if a mapping already exists
5372 to a function in a Vim script. Example: >
5373 :if !hasmapto('\ABCdoit')
5374 : map <Leader>d \ABCdoit
5375 :endif
5376< This installs the mapping to "\ABCdoit" only if there isn't
5377 already a mapping to "\ABCdoit".
5378
5379 Can also be used as a |method|: >
5380 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005381<
5382 Return type: |Number|
5383
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005384
5385histadd({history}, {item}) *histadd()*
5386 Add the String {item} to the history {history} which can be
5387 one of: *hist-names*
5388 "cmd" or ":" command line history
5389 "search" or "/" search pattern history
5390 "expr" or "=" typed expression history
5391 "input" or "@" input line history
5392 "debug" or ">" debug command history
5393 empty the current or last used history
5394 The {history} string does not need to be the whole name, one
5395 character is sufficient.
5396 If {item} does already exist in the history, it will be
5397 shifted to become the newest entry.
5398 The result is a Number: TRUE if the operation was successful,
5399 otherwise FALSE is returned.
5400
5401 Example: >
5402 :call histadd("input", strftime("%Y %b %d"))
5403 :let date=input("Enter date: ")
5404< This function is not available in the |sandbox|.
5405
5406 Can also be used as a |method|, the base is passed as the
5407 second argument: >
5408 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005409<
5410 Return type: |Number|
5411
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005412
5413histdel({history} [, {item}]) *histdel()*
5414 Clear {history}, i.e. delete all its entries. See |hist-names|
5415 for the possible values of {history}.
5416
5417 If the parameter {item} evaluates to a String, it is used as a
5418 regular expression. All entries matching that expression will
5419 be removed from the history (if there are any).
5420 Upper/lowercase must match, unless "\c" is used |/\c|.
5421 If {item} evaluates to a Number, it will be interpreted as
5422 an index, see |:history-indexing|. The respective entry will
5423 be removed if it exists.
5424
5425 The result is TRUE for a successful operation, otherwise FALSE
5426 is returned.
5427
5428 Examples:
5429 Clear expression register history: >
5430 :call histdel("expr")
5431<
5432 Remove all entries starting with "*" from the search history: >
5433 :call histdel("/", '^\*')
5434<
5435 The following three are equivalent: >
5436 :call histdel("search", histnr("search"))
5437 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005438 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005439<
5440 To delete the last search pattern and use the last-but-one for
5441 the "n" command and 'hlsearch': >
5442 :call histdel("search", -1)
5443 :let @/ = histget("search", -1)
5444<
5445 Can also be used as a |method|: >
5446 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005447<
5448 Return type: |Number|
5449
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005450
5451histget({history} [, {index}]) *histget()*
5452 The result is a String, the entry with Number {index} from
5453 {history}. See |hist-names| for the possible values of
5454 {history}, and |:history-indexing| for {index}. If there is
5455 no such entry, an empty String is returned. When {index} is
5456 omitted, the most recent item from the history is used.
5457
5458 Examples:
5459 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005460 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005461
5462< Define an Ex command ":H {num}" that supports re-execution of
5463 the {num}th entry from the output of |:history|. >
5464 :command -nargs=1 H execute histget("cmd", 0+<args>)
5465<
5466 Can also be used as a |method|: >
5467 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005468<
5469 Return type: |String|
5470
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005471
5472histnr({history}) *histnr()*
5473 The result is the Number of the current entry in {history}.
5474 See |hist-names| for the possible values of {history}.
5475 If an error occurred, -1 is returned.
5476
5477 Example: >
5478 :let inp_index = histnr("expr")
5479
5480< Can also be used as a |method|: >
5481 GetHistory()->histnr()
5482<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005483 Return type: |Number|
5484
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005485hlexists({name}) *hlexists()*
5486 The result is a Number, which is TRUE if a highlight group
5487 called {name} exists. This is when the group has been
5488 defined in some way. Not necessarily when highlighting has
5489 been defined for it, it may also have been used for a syntax
5490 item.
5491 *highlight_exists()*
5492 Obsolete name: highlight_exists().
5493
5494 Can also be used as a |method|: >
5495 GetName()->hlexists()
5496<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005497 Return type: |Number|
5498
5499
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005500hlget([{name} [, {resolve}]]) *hlget()*
5501 Returns a List of all the highlight group attributes. If the
5502 optional {name} is specified, then returns a List with only
5503 the attributes of the specified highlight group. Returns an
5504 empty List if the highlight group {name} is not present.
5505
5506 If the optional {resolve} argument is set to v:true and the
5507 highlight group {name} is linked to another group, then the
5508 link is resolved recursively and the attributes of the
5509 resolved highlight group are returned.
5510
5511 Each entry in the returned List is a Dictionary with the
5512 following items:
5513 cleared boolean flag, set to v:true if the highlight
5514 group attributes are cleared or not yet
5515 specified. See |highlight-clear|.
5516 cterm cterm attributes. See |highlight-cterm|.
5517 ctermbg cterm background color.
5518 See |highlight-ctermbg|.
5519 ctermfg cterm foreground color.
5520 See |highlight-ctermfg|.
5521 ctermul cterm underline color. See |highlight-ctermul|.
5522 default boolean flag, set to v:true if the highlight
5523 group link is a default link. See
5524 |highlight-default|.
5525 font highlight group font. See |highlight-font|.
5526 gui gui attributes. See |highlight-gui|.
5527 guibg gui background color. See |highlight-guibg|.
5528 guifg gui foreground color. See |highlight-guifg|.
5529 guisp gui special color. See |highlight-guisp|.
5530 id highlight group ID.
5531 linksto linked highlight group name.
5532 See |:highlight-link|.
5533 name highlight group name. See |group-name|.
5534 start start terminal keycode. See |highlight-start|.
5535 stop stop terminal keycode. See |highlight-stop|.
5536 term term attributes. See |highlight-term|.
5537
5538 The 'term', 'cterm' and 'gui' items in the above Dictionary
5539 have a dictionary value with the following optional boolean
5540 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5541 'reverse', 'inverse' and 'strikethrough'.
5542
5543 Example(s): >
5544 :echo hlget()
5545 :echo hlget('ModeMsg')
5546 :echo hlget('Number', v:true)
5547<
5548 Can also be used as a |method|: >
5549 GetName()->hlget()
5550<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005551 Return type: list<dict<any>>
5552
5553
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005554hlset({list}) *hlset()*
5555 Creates or modifies the attributes of a List of highlight
5556 groups. Each item in {list} is a dictionary containing the
5557 attributes of a highlight group. See |hlget()| for the list of
5558 supported items in this dictionary.
5559
5560 In addition to the items described in |hlget()|, the following
5561 additional items are supported in the dictionary:
5562
5563 force boolean flag to force the creation of
5564 a link for an existing highlight group
5565 with attributes.
5566
5567 The highlight group is identified using the 'name' item and
5568 the 'id' item (if supplied) is ignored. If a highlight group
5569 with a specified name doesn't exist, then it is created.
5570 Otherwise the attributes of an existing highlight group are
5571 modified.
5572
5573 If an empty dictionary value is used for the 'term' or 'cterm'
5574 or 'gui' entries, then the corresponding attributes are
5575 cleared. If the 'cleared' item is set to v:true, then all the
5576 attributes of the highlight group are cleared.
5577
5578 The 'linksto' item can be used to link a highlight group to
5579 another highlight group. See |:highlight-link|.
5580
5581 Returns zero for success, -1 for failure.
5582
5583 Example(s): >
5584 " add bold attribute to the Visual highlight group
5585 :call hlset([#{name: 'Visual',
5586 \ term: #{reverse: 1 , bold: 1}}])
5587 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5588 :let l = hlget()
5589 :call hlset(l)
5590 " clear the Search highlight group
5591 :call hlset([#{name: 'Search', cleared: v:true}])
5592 " clear the 'term' attributes for a highlight group
5593 :call hlset([#{name: 'Title', term: {}}])
5594 " create the MyHlg group linking it to DiffAdd
5595 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5596 " remove the MyHlg group link
5597 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5598 " clear the attributes and a link
5599 :call hlset([#{name: 'MyHlg', cleared: v:true,
5600 \ linksto: 'NONE'}])
5601<
5602 Can also be used as a |method|: >
5603 GetAttrList()->hlset()
5604<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005605 Return type: |Number|
5606
5607hlID({name}) *hlID()*
5608 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005609 with name {name}. When the highlight group doesn't exist,
5610 zero is returned.
5611 This can be used to retrieve information about the highlight
5612 group. For example, to get the background color of the
5613 "Comment" group: >
5614 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5615< *highlightID()*
5616 Obsolete name: highlightID().
5617
5618 Can also be used as a |method|: >
5619 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005620<
5621 Return type: |Number|
5622
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005623
5624hostname() *hostname()*
5625 The result is a String, which is the name of the machine on
5626 which Vim is currently running. Machine names greater than
5627 256 characters long are truncated.
5628
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005629 Return type: |String|
5630
5631
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005632iconv({string}, {from}, {to}) *iconv()*
5633 The result is a String, which is the text {string} converted
5634 from encoding {from} to encoding {to}.
5635 When the conversion completely fails an empty string is
5636 returned. When some characters could not be converted they
5637 are replaced with "?".
5638 The encoding names are whatever the iconv() library function
5639 can accept, see ":!man 3 iconv".
5640 Most conversions require Vim to be compiled with the |+iconv|
5641 feature. Otherwise only UTF-8 to latin1 conversion and back
5642 can be done.
5643 This can be used to display messages with special characters,
5644 no matter what 'encoding' is set to. Write the message in
5645 UTF-8 and use: >
5646 echo iconv(utf8_str, "utf-8", &enc)
5647< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5648 from/to UCS-2 is automatically changed to use UTF-8. You
5649 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5650
5651 Can also be used as a |method|: >
5652 GetText()->iconv('latin1', 'utf-8')
5653<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005654 Return type: |String|
5655
5656
Ernie Raelc8e158b2024-07-09 18:39:52 +02005657id({item}) *id()*
5658 The result is a unique String associated with the {item} and
5659 not with the {item}'s contents. It is only valid while the
5660 {item} exists and is referenced. It is valid only in the
5661 instance of vim that produces the result. The whole idea is
5662 that `id({item})` does not change if the contents of {item}
5663 changes. This is useful as a `key` for creating an identity
5664 dictionary, rather than one based on equals.
5665
5666 This operation does not reference {item} and there is no
5667 function to convert the `id` to the {item}. It may be useful to
5668 have a map of `id` to {item}. The following >
5669 var referenceMap: dict<any>
5670 var id = item->id()
5671 referenceMap[id] = item
5672< prevents {item} from being garbage collected and provides a
5673 way to get the {item} from the `id`.
5674
5675 {item} may be a List, Dictionary, Object, Job, Channel or
5676 Blob. If the item is not a permitted type, or it is a null
5677 value, then an empty String is returned.
5678
5679 Can also be used as a |method|: >
5680 GetItem()->id()
5681<
5682 Return type: |String|
5683
5684
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005685indent({lnum}) *indent()*
5686 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005687 current buffer. The indent is counted in spaces, the value
5688 of 'tabstop' is relevant. {lnum} is used just like in
5689 |getline()|.
5690 When {lnum} is invalid -1 is returned. In |Vim9| script an
5691 error is given.
5692
5693 Can also be used as a |method|: >
5694 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005695<
5696 Return type: |Number|
5697
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005698
5699index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005700 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005701 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005702
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005703 If {object} is a |List| return the lowest index where the item
5704 has a value equal to {expr}. There is no automatic
5705 conversion, so the String "4" is different from the Number 4.
5706 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005707 of 'ignorecase' is not used here, case matters as indicated by
5708 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005709
5710 If {object} is |Blob| return the lowest index where the byte
5711 value is equal to {expr}.
5712
5713 If {start} is given then start looking at the item with index
5714 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005715
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005716 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5717 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005718
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005719 -1 is returned when {expr} is not found in {object}.
5720 Example: >
5721 :let idx = index(words, "the")
5722 :if index(numbers, 123) >= 0
5723
5724< Can also be used as a |method|: >
5725 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005726<
5727 Return type: |Number|
5728
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005729
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005730indexof({object}, {expr} [, {opts}]) *indexof()*
5731 Returns the index of an item in {object} where {expr} is
5732 v:true. {object} must be a |List| or a |Blob|.
5733
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005734 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005735 List until the expression is v:true and return the index of
5736 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005737
5738 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005739 Blob until the expression is v:true and return the index of
5740 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005741
5742 {expr} must be a |string| or |Funcref|.
5743
5744 If {expr} is a |string|: If {object} is a |List|, inside
5745 {expr} |v:key| has the index of the current List item and
5746 |v:val| has the value of the item. If {object} is a |Blob|,
5747 inside {expr} |v:key| has the index of the current byte and
5748 |v:val| has the byte value.
5749
5750 If {expr} is a |Funcref| it must take two arguments:
5751 1. the key or the index of the current item.
5752 2. the value of the current item.
5753 The function must return |TRUE| if the item is found and the
5754 search should stop.
5755
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005756 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005757 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005758 startidx start evaluating {expr} at the item with this
5759 index; may be negative for an item relative to
5760 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005761 Returns -1 when {expr} evaluates to v:false for all the items.
5762 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005763 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
5764 :echo indexof(l, "v:val.n == 20")
5765 :echo indexof(l, {i, v -> v.n == 30})
5766 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005767
5768< Can also be used as a |method|: >
5769 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005770<
5771 Return type: |Number|
5772
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005773
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005774input({prompt} [, {text} [, {completion}]]) *input()*
5775 The result is a String, which is whatever the user typed on
5776 the command-line. The {prompt} argument is either a prompt
5777 string, or a blank string (for no prompt). A '\n' can be used
5778 in the prompt to start a new line.
5779 The highlighting set with |:echohl| is used for the prompt.
5780 The input is entered just like a command-line, with the same
5781 editing commands and mappings. There is a separate history
5782 for lines typed for input().
5783 Example: >
5784 :if input("Coffee or beer? ") == "beer"
5785 : echo "Cheers!"
5786 :endif
5787<
5788 If the optional {text} argument is present and not empty, this
5789 is used for the default reply, as if the user typed this.
5790 Example: >
5791 :let color = input("Color? ", "white")
5792
5793< The optional {completion} argument specifies the type of
5794 completion supported for the input. Without it completion is
5795 not performed. The supported completion types are the same as
5796 that can be supplied to a user-defined command using the
5797 "-complete=" argument. Refer to |:command-completion| for
5798 more information. Example: >
5799 let fname = input("File: ", "", "file")
5800<
5801 NOTE: This function must not be used in a startup file, for
5802 the versions that only run in GUI mode (e.g., the Win32 GUI).
5803 Note: When input() is called from within a mapping it will
5804 consume remaining characters from that mapping, because a
5805 mapping is handled like the characters were typed.
5806 Use |inputsave()| before input() and |inputrestore()|
5807 after input() to avoid that. Another solution is to avoid
5808 that further characters follow in the mapping, e.g., by using
5809 |:execute| or |:normal|.
5810
5811 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005812 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005813 :function GetFoo()
5814 : call inputsave()
5815 : let g:Foo = input("enter search pattern: ")
5816 : call inputrestore()
5817 :endfunction
5818
5819< Can also be used as a |method|: >
5820 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005821<
5822 Return type: |String|
5823
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005824
5825inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
5826 Like |input()|, but when the GUI is running and text dialogs
5827 are supported, a dialog window pops up to input the text.
5828 Example: >
5829 :let n = inputdialog("value for shiftwidth", shiftwidth())
5830 :if n != ""
5831 : let &sw = n
5832 :endif
5833< When the dialog is cancelled {cancelreturn} is returned. When
5834 omitted an empty string is returned.
5835 Hitting <Enter> works like pressing the OK button. Hitting
5836 <Esc> works like pressing the Cancel button.
5837 NOTE: Command-line completion is not supported.
5838
5839 Can also be used as a |method|: >
5840 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005841<
5842 Return type: |String|
5843
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005844
5845inputlist({textlist}) *inputlist()*
5846 {textlist} must be a |List| of strings. This |List| is
5847 displayed, one string per line. The user will be prompted to
5848 enter a number, which is returned.
5849 The user can also select an item by clicking on it with the
5850 mouse, if the mouse is enabled in the command line ('mouse' is
5851 "a" or includes "c"). For the first string 0 is returned.
5852 When clicking above the first item a negative number is
5853 returned. When clicking on the prompt one more than the
5854 length of {textlist} is returned.
5855 Make sure {textlist} has less than 'lines' entries, otherwise
5856 it won't work. It's a good idea to put the entry number at
5857 the start of the string. And put a prompt in the first item.
5858 Example: >
5859 let color = inputlist(['Select color:', '1. red',
5860 \ '2. green', '3. blue'])
5861
5862< Can also be used as a |method|: >
5863 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005864<
5865 Return type: |Number|
5866
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005867
5868inputrestore() *inputrestore()*
5869 Restore typeahead that was saved with a previous |inputsave()|.
5870 Should be called the same number of times inputsave() is
5871 called. Calling it more often is harmless though.
5872 Returns TRUE when there is nothing to restore, FALSE otherwise.
5873
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005874 Return type: |Number|
5875
5876
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005877inputsave() *inputsave()*
5878 Preserve typeahead (also from mappings) and clear it, so that
5879 a following prompt gets input from the user. Should be
5880 followed by a matching inputrestore() after the prompt. Can
5881 be used several times, in which case there must be just as
5882 many inputrestore() calls.
5883 Returns TRUE when out of memory, FALSE otherwise.
5884
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005885 Return type: |Number|
5886
5887
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005888inputsecret({prompt} [, {text}]) *inputsecret()*
5889 This function acts much like the |input()| function with but
5890 two exceptions:
5891 a) the user's response will be displayed as a sequence of
5892 asterisks ("*") thereby keeping the entry secret, and
5893 b) the user's response will not be recorded on the input
5894 |history| stack.
5895 The result is a String, which is whatever the user actually
5896 typed on the command-line in response to the issued prompt.
5897 NOTE: Command-line completion is not supported.
5898
5899 Can also be used as a |method|: >
5900 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005901<
5902 Return type: |String|
5903
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005904
5905insert({object}, {item} [, {idx}]) *insert()*
5906 When {object} is a |List| or a |Blob| insert {item} at the start
5907 of it.
5908
5909 If {idx} is specified insert {item} before the item with index
5910 {idx}. If {idx} is zero it goes before the first item, just
5911 like omitting {idx}. A negative {idx} is also possible, see
5912 |list-index|. -1 inserts just before the last item.
5913
5914 Returns the resulting |List| or |Blob|. Examples: >
5915 :let mylist = insert([2, 3, 5], 1)
5916 :call insert(mylist, 4, -1)
5917 :call insert(mylist, 6, len(mylist))
5918< The last example can be done simpler with |add()|.
5919 Note that when {item} is a |List| it is inserted as a single
5920 item. Use |extend()| to concatenate |Lists|.
5921
5922 Can also be used as a |method|: >
5923 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005924<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005925 Return type: |Number|
5926
5927
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005928 *instanceof()* *E614* *E616* *E693*
5929instanceof({object}, {class})
5930 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01005931 argument is a direct or indirect instance of a |Class|,
5932 |Interface|, or class |:type| alias specified by {class}.
5933 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005934 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02005935 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01005936 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02005937
5938< Can also be used as a |method|: >
5939 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005940<
5941 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02005942
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005943interrupt() *interrupt()*
5944 Interrupt script execution. It works more or less like the
5945 user typing CTRL-C, most commands won't execute and control
5946 returns to the user. This is useful to abort execution
5947 from lower down, e.g. in an autocommand. Example: >
5948 :function s:check_typoname(file)
5949 : if fnamemodify(a:file, ':t') == '['
5950 : echomsg 'Maybe typo'
5951 : call interrupt()
5952 : endif
5953 :endfunction
5954 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005955<
5956 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005957
5958invert({expr}) *invert()*
5959 Bitwise invert. The argument is converted to a number. A
5960 List, Dict or Float argument causes an error. Example: >
5961 :let bits = invert(bits)
5962< Can also be used as a |method|: >
5963 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005964<
5965 Return type: |Number|
5966
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005967
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005968isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01005969 The result is a Number, which is |TRUE| when {path} is an
5970 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005971 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01005972 On MS-Windows, it is considered absolute when it starts with an
5973 optional drive prefix and is followed by a '\' or '/'. UNC paths
5974 are always absolute.
5975 Example: >
5976 echo isabsolutepath('/usr/share/') " 1
5977 echo isabsolutepath('./foobar') " 0
5978 echo isabsolutepath('C:\Windows') " 1
5979 echo isabsolutepath('foobar') " 0
5980 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005981<
LemonBoydca1d402022-04-28 15:26:33 +01005982 Can also be used as a |method|: >
5983 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005984<
5985 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01005986
5987
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005988isdirectory({directory}) *isdirectory()*
5989 The result is a Number, which is |TRUE| when a directory
5990 with the name {directory} exists. If {directory} doesn't
5991 exist, or isn't a directory, the result is |FALSE|. {directory}
5992 is any expression, which is used as a String.
5993
5994 Can also be used as a |method|: >
5995 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005996<
5997 Return type: |Number|
5998
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005999
6000isinf({expr}) *isinf()*
6001 Return 1 if {expr} is a positive infinity, or -1 a negative
6002 infinity, otherwise 0. >
6003 :echo isinf(1.0 / 0.0)
6004< 1 >
6005 :echo isinf(-1.0 / 0.0)
6006< -1
6007
6008 Can also be used as a |method|: >
6009 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006010<
6011 Return type: |Number|
6012
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006013
6014islocked({expr}) *islocked()* *E786*
6015 The result is a Number, which is |TRUE| when {expr} is the
6016 name of a locked variable.
6017 The string argument {expr} must be the name of a variable,
6018 |List| item or |Dictionary| entry, not the variable itself!
6019 Example: >
6020 :let alist = [0, ['a', 'b'], 2, 3]
6021 :lockvar 1 alist
6022 :echo islocked('alist') " 1
6023 :echo islocked('alist[1]') " 0
6024
Bram Moolenaar9da17d72022-02-09 21:50:44 +00006025< When {expr} is a variable that does not exist -1 is returned.
6026 If {expr} uses a range, list or dict index that is out of
6027 range or does not exist you get an error message. Use
6028 |exists()| to check for existence.
6029 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006030
6031 Can also be used as a |method|: >
6032 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006033<
6034 Return type: |Number|
6035
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006036
6037isnan({expr}) *isnan()*
6038 Return |TRUE| if {expr} is a float with value NaN. >
6039 echo isnan(0.0 / 0.0)
6040< 1
6041
6042 Can also be used as a |method|: >
6043 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006044<
6045 Return type: |Number|
6046
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006047
6048items({dict}) *items()*
6049 Return a |List| with all the key-value pairs of {dict}. Each
6050 |List| item is a list with two items: the key of a {dict}
6051 entry and the value of this entry. The |List| is in arbitrary
6052 order. Also see |keys()| and |values()|.
6053 Example: >
6054 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006055 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006056 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006057<
6058 A List or a String argument is also supported. In these
6059 cases, items() returns a List with the index and the value at
6060 the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006061
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006062 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006063 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006064<
6065 Return type: list<list<any>> or list<any>
6066
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006067
6068job_ functions are documented here: |job-functions-details|
6069
6070
6071join({list} [, {sep}]) *join()*
6072 Join the items in {list} together into one String.
6073 When {sep} is specified it is put in between the items. If
6074 {sep} is omitted a single space is used.
6075 Note that {sep} is not added at the end. You might want to
6076 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006077 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006078< String items are used as-is. |Lists| and |Dictionaries| are
6079 converted into a string like with |string()|.
6080 The opposite function is |split()|.
6081
6082 Can also be used as a |method|: >
6083 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006084<
6085 Return type: |String|
6086
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006087
6088js_decode({string}) *js_decode()*
6089 This is similar to |json_decode()| with these differences:
6090 - Object key names do not have to be in quotes.
6091 - Strings can be in single quotes.
6092 - Empty items in an array (between two commas) are allowed and
6093 result in v:none items.
6094
6095 Can also be used as a |method|: >
6096 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006097<
6098 Return type: any, depending on {varname}
6099
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006100
6101js_encode({expr}) *js_encode()*
6102 This is similar to |json_encode()| with these differences:
6103 - Object key names are not in quotes.
6104 - v:none items in an array result in an empty item between
6105 commas.
6106 For example, the Vim object:
6107 [1,v:none,{"one":1},v:none] ~
6108 Will be encoded as:
6109 [1,,{one:1},,] ~
6110 While json_encode() would produce:
6111 [1,null,{"one":1},null] ~
6112 This encoding is valid for JavaScript. It is more efficient
6113 than JSON, especially when using an array with optional items.
6114
6115 Can also be used as a |method|: >
6116 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006117<
6118 Return type: |String|
6119
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006120
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006121json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006122 This parses a JSON formatted string and returns the equivalent
6123 in Vim values. See |json_encode()| for the relation between
6124 JSON and Vim values.
6125 The decoding is permissive:
6126 - A trailing comma in an array and object is ignored, e.g.
6127 "[1, 2, ]" is the same as "[1, 2]".
6128 - Integer keys are accepted in objects, e.g. {1:2} is the
6129 same as {"1":2}.
6130 - More floating point numbers are recognized, e.g. "1." for
6131 "1.0", or "001.2" for "1.2". Special floating point values
6132 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6133 are accepted.
6134 - Leading zeroes in integer numbers are ignored, e.g. "012"
6135 for "12" or "-012" for "-12".
6136 - Capitalization is ignored in literal names null, true or
6137 false, e.g. "NULL" for "null", "True" for "true".
6138 - Control characters U+0000 through U+001F which are not
6139 escaped in strings are accepted, e.g. " " (tab
6140 character in string) for "\t".
6141 - An empty JSON expression or made of only spaces is accepted
6142 and results in v:none.
6143 - Backslash in an invalid 2-character sequence escape is
6144 ignored, e.g. "\a" is decoded as "a".
6145 - A correct surrogate pair in JSON strings should normally be
6146 a 12 character sequence such as "\uD834\uDD1E", but
6147 json_decode() silently accepts truncated surrogate pairs
6148 such as "\uD834" or "\uD834\u"
6149 *E938*
6150 A duplicate key in an object, valid in rfc7159, is not
6151 accepted by json_decode() as the result must be a valid Vim
6152 type, e.g. this fails: {"a":"b", "a":"c"}
6153
6154 Can also be used as a |method|: >
6155 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006156<
6157 Return type: any, depending on {varname}
6158
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006159
6160json_encode({expr}) *json_encode()*
6161 Encode {expr} as JSON and return this as a string.
6162 The encoding is specified in:
6163 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006164 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006165 |Number| decimal number
6166 |Float| floating point number
6167 Float nan "NaN"
6168 Float inf "Infinity"
6169 Float -inf "-Infinity"
6170 |String| in double quotes (possibly null)
6171 |Funcref| not possible, error
6172 |List| as an array (possibly null); when
6173 used recursively: []
6174 |Dict| as an object (possibly null); when
6175 used recursively: {}
6176 |Blob| as an array of the individual bytes
6177 v:false "false"
6178 v:true "true"
6179 v:none "null"
6180 v:null "null"
6181 Note that NaN and Infinity are passed on as values. This is
6182 missing in the JSON standard, but several implementations do
6183 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006184 If a string contains an illegal character then the replacement
6185 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006186
6187 Can also be used as a |method|: >
6188 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006189<
6190 Return type: |String|
6191
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006192
6193keys({dict}) *keys()*
6194 Return a |List| with all the keys of {dict}. The |List| is in
6195 arbitrary order. Also see |items()| and |values()|.
6196
6197 Can also be used as a |method|: >
6198 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006199<
6200 Return type: list<string>
6201
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006202
zeertzjqcdc83932022-09-12 13:38:41 +01006203keytrans({string}) *keytrans()*
6204 Turn the internal byte representation of keys into a form that
6205 can be used for |:map|. E.g. >
6206 :let xx = "\<C-Home>"
6207 :echo keytrans(xx)
6208< <C-Home>
6209
6210 Can also be used as a |method|: >
6211 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006212<
6213 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006214
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006215
6216len({expr}) *len()* *E701*
6217 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006218 When {expr} is a String or a Number the length in bytes is
6219 used, as with |strlen()|.
6220 When {expr} is a |List| the number of items in the |List| is
6221 returned.
6222 When {expr} is a |Blob| the number of bytes is returned.
6223 When {expr} is a |Dictionary| the number of entries in the
6224 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006225 When {expr} is an |Object|, invokes the len() method in the
6226 object (if present) to get the length (|object-len()|).
6227 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006228
6229 Can also be used as a |method|: >
6230 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006231<
6232 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006233
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006234
6235 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006236libcall({libname}, {funcname}, {argument})
6237 Call function {funcname} in the run-time library {libname}
6238 with single argument {argument}.
6239 This is useful to call functions in a library that you
6240 especially made to be used with Vim. Since only one argument
6241 is possible, calling standard library functions is rather
6242 limited.
6243 The result is the String returned by the function. If the
6244 function returns NULL, this will appear as an empty string ""
6245 to Vim.
6246 If the function returns a number, use libcallnr()!
6247 If {argument} is a number, it is passed to the function as an
6248 int; if {argument} is a string, it is passed as a
6249 null-terminated string.
6250 This function will fail in |restricted-mode|.
6251
6252 libcall() allows you to write your own 'plug-in' extensions to
6253 Vim without having to recompile the program. It is NOT a
6254 means to call system functions! If you try to do so Vim will
6255 very probably crash.
6256
6257 For Win32, the functions you write must be placed in a DLL
6258 and use the normal C calling convention (NOT Pascal which is
6259 used in Windows System DLLs). The function must take exactly
6260 one parameter, either a character pointer or a long integer,
6261 and must return a character pointer or NULL. The character
6262 pointer returned must point to memory that will remain valid
6263 after the function has returned (e.g. in static data in the
6264 DLL). If it points to allocated memory, that memory will
6265 leak away. Using a static buffer in the function should work,
6266 it's then freed when the DLL is unloaded.
6267
6268 WARNING: If the function returns a non-valid pointer, Vim may
6269 crash! This also happens if the function returns a number,
6270 because Vim thinks it's a pointer.
6271 For Win32 systems, {libname} should be the filename of the DLL
6272 without the ".DLL" suffix. A full path is only required if
6273 the DLL is not in the usual places.
6274 For Unix: When compiling your own plugins, remember that the
6275 object code must be compiled as position-independent ('PIC').
6276 {only in Win32 and some Unix versions, when the |+libcall|
6277 feature is present}
6278 Examples: >
6279 :echo libcall("libc.so", "getenv", "HOME")
6280
6281< Can also be used as a |method|, the base is passed as the
6282 third argument: >
6283 GetValue()->libcall("libc.so", "getenv")
6284<
6285 *libcallnr()*
6286libcallnr({libname}, {funcname}, {argument})
6287 Just like |libcall()|, but used for a function that returns an
6288 int instead of a string.
6289 {only in Win32 on some Unix versions, when the |+libcall|
6290 feature is present}
6291 Examples: >
6292 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6293 :call libcallnr("libc.so", "printf", "Hello World!\n")
6294 :call libcallnr("libc.so", "sleep", 10)
6295<
6296 Can also be used as a |method|, the base is passed as the
6297 third argument: >
6298 GetValue()->libcallnr("libc.so", "printf")
6299<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006300 Return type: |String|
6301
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006302
6303line({expr} [, {winid}]) *line()*
6304 The result is a Number, which is the line number of the file
6305 position given with {expr}. The {expr} argument is a string.
zeertzjq02f3eba2024-06-12 20:45:24 +02006306 See |getpos()| for accepted positions.
6307
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006308 To get the column number use |col()|. To get both use
6309 |getpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02006310
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006311 With the optional {winid} argument the values are obtained for
6312 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02006313
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006314 Returns 0 for invalid values of {expr} and {winid}.
zeertzjq02f3eba2024-06-12 20:45:24 +02006315
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006316 Examples: >
6317 line(".") line number of the cursor
6318 line(".", winid) idem, in window "winid"
6319 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006320 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006321<
6322 To jump to the last known position when opening a file see
6323 |last-position-jump|.
6324
6325 Can also be used as a |method|: >
6326 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006327<
6328 Return type: |Number|
6329
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006330
6331line2byte({lnum}) *line2byte()*
6332 Return the byte count from the start of the buffer for line
6333 {lnum}. This includes the end-of-line character, depending on
6334 the 'fileformat' option for the current buffer. The first
6335 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6336 This can also be used to get the byte count for the line just
6337 below the last line: >
6338 line2byte(line("$") + 1)
6339< This is the buffer size plus one. If 'fileencoding' is empty
6340 it is the file size plus one. {lnum} is used like with
6341 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6342 feature has been disabled at compile time, -1 is returned.
6343 Also see |byte2line()|, |go| and |:goto|.
6344
6345 Can also be used as a |method|: >
6346 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006347<
6348 Return type: |Number|
6349
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006350
6351lispindent({lnum}) *lispindent()*
6352 Get the amount of indent for line {lnum} according the lisp
6353 indenting rules, as with 'lisp'.
6354 The indent is counted in spaces, the value of 'tabstop' is
6355 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006356 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006357 error is given.
6358
6359 Can also be used as a |method|: >
6360 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006361<
6362 Return type: |Number|
6363
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006364
6365list2blob({list}) *list2blob()*
6366 Return a Blob concatenating all the number values in {list}.
6367 Examples: >
6368 list2blob([1, 2, 3, 4]) returns 0z01020304
6369 list2blob([]) returns 0z
6370< Returns an empty Blob on error. If one of the numbers is
6371 negative or more than 255 error *E1239* is given.
6372
6373 |blob2list()| does the opposite.
6374
6375 Can also be used as a |method|: >
6376 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006377<
6378 Return type: |Blob|
6379
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006380
6381list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006382 Convert each number in {list} to a character string and
6383 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006384 list2str([32]) returns " "
6385 list2str([65, 66, 67]) returns "ABC"
6386< The same can be done (slowly) with: >
6387 join(map(list, {nr, val -> nr2char(val)}), '')
6388< |str2list()| does the opposite.
6389
6390 When {utf8} is omitted or zero, the current 'encoding' is used.
6391 When {utf8} is TRUE, always return UTF-8 characters.
6392 With UTF-8 composing characters work as expected: >
6393 list2str([97, 769]) returns "á"
6394<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006395 Returns an empty string on error.
6396
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006397 Can also be used as a |method|: >
6398 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006399<
6400 Return type: |String|
6401
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006402
6403listener_add({callback} [, {buf}]) *listener_add()*
6404 Add a callback function that will be invoked when changes have
6405 been made to buffer {buf}.
6406 {buf} refers to a buffer name or number. For the accepted
6407 values, see |bufname()|. When {buf} is omitted the current
6408 buffer is used.
6409 Returns a unique ID that can be passed to |listener_remove()|.
6410
6411 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006412 bufnr the buffer that was changed
6413 start first changed line number
6414 end first line number below the change
6415 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006416 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006417 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006418
6419 Example: >
6420 func Listener(bufnr, start, end, added, changes)
6421 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6422 endfunc
6423 call listener_add('Listener', bufnr)
6424
Bram Moolenaar944697a2022-02-20 19:48:20 +00006425< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006426 dictionary with these entries:
6427 lnum the first line number of the change
6428 end the first line below the change
6429 added number of lines added; negative if lines were
6430 deleted
6431 col first column in "lnum" that was affected by
6432 the change; one if unknown or the whole line
6433 was affected; this is a byte index, first
6434 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006435 When lines are inserted (not when a line is split, e.g. by
6436 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006437 lnum line above which the new line is added
6438 end equal to "lnum"
6439 added number of lines inserted
6440 col 1
6441 When lines are deleted the values are:
6442 lnum the first deleted line
6443 end the line below the first deleted line, before
6444 the deletion was done
6445 added negative, number of lines deleted
6446 col 1
6447 When lines are changed:
6448 lnum the first changed line
6449 end the line below the last changed line
6450 added 0
6451 col first column with a change or 1
6452
6453 The entries are in the order the changes were made, thus the
6454 most recent change is at the end. The line numbers are valid
6455 when the callback is invoked, but later changes may make them
6456 invalid, thus keeping a copy for later might not work.
6457
6458 The {callback} is invoked just before the screen is updated,
6459 when |listener_flush()| is called or when a change is being
6460 made that changes the line count in a way it causes a line
6461 number in the list of changes to become invalid.
6462
6463 The {callback} is invoked with the text locked, see
6464 |textlock|. If you do need to make changes to the buffer, use
6465 a timer to do this later |timer_start()|.
6466
6467 The {callback} is not invoked when the buffer is first loaded.
6468 Use the |BufReadPost| autocmd event to handle the initial text
6469 of a buffer.
6470 The {callback} is also not invoked when the buffer is
6471 unloaded, use the |BufUnload| autocmd event for that.
6472
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006473 Returns zero if {callback} or {buf} is invalid.
6474
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006475 Can also be used as a |method|, the base is passed as the
6476 second argument: >
6477 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006478<
6479 Return type: |Number|
6480
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006481
6482listener_flush([{buf}]) *listener_flush()*
6483 Invoke listener callbacks for buffer {buf}. If there are no
6484 pending changes then no callbacks are invoked.
6485
6486 {buf} refers to a buffer name or number. For the accepted
6487 values, see |bufname()|. When {buf} is omitted the current
6488 buffer is used.
6489
6490 Can also be used as a |method|: >
6491 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006492<
6493 Return type: |Number|
6494
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006495
6496listener_remove({id}) *listener_remove()*
6497 Remove a listener previously added with listener_add().
6498 Returns FALSE when {id} could not be found, TRUE when {id} was
6499 removed.
6500
6501 Can also be used as a |method|: >
6502 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006503<
6504 Return type: |Number|
6505
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006506
6507localtime() *localtime()*
6508 Return the current time, measured as seconds since 1st Jan
6509 1970. See also |strftime()|, |strptime()| and |getftime()|.
6510
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006511 Return type: |Number|
6512
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006513
6514log({expr}) *log()*
6515 Return the natural logarithm (base e) of {expr} as a |Float|.
6516 {expr} must evaluate to a |Float| or a |Number| in the range
6517 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006518 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006519 Examples: >
6520 :echo log(10)
6521< 2.302585 >
6522 :echo log(exp(5))
6523< 5.0
6524
6525 Can also be used as a |method|: >
6526 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006527<
6528 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006529
6530
6531log10({expr}) *log10()*
6532 Return the logarithm of Float {expr} to base 10 as a |Float|.
6533 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006534 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006535 Examples: >
6536 :echo log10(1000)
6537< 3.0 >
6538 :echo log10(0.01)
6539< -2.0
6540
6541 Can also be used as a |method|: >
6542 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006543<
6544 Return type: |Float|
6545
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006546
6547luaeval({expr} [, {expr}]) *luaeval()*
6548 Evaluate Lua expression {expr} and return its result converted
6549 to Vim data structures. Second {expr} may hold additional
6550 argument accessible as _A inside first {expr}.
6551 Strings are returned as they are.
6552 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006553 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006554 Dictionaries and lists obtained by vim.eval() are returned
6555 as-is.
6556 Other objects are returned as zero without any errors.
6557 See |lua-luaeval| for more details.
6558 Note that in a `:def` function local variables are not visible
6559 to {expr}.
6560
6561 Can also be used as a |method|: >
6562 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006563<
6564 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006565
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006566 {only available when compiled with the |+lua| feature}
6567
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006568
6569map({expr1}, {expr2}) *map()*
6570 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006571 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006572 item in {expr1} with the result of evaluating {expr2}.
6573 For a |Blob| each byte is replaced.
6574 For a |String|, each character, including composing
6575 characters, is replaced.
6576 If the item type changes you may want to use |mapnew()| to
6577 create a new List or Dictionary. This is required when using
6578 Vim9 script.
6579
6580 {expr2} must be a |String| or |Funcref|.
6581
6582 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6583 of the current item. For a |Dictionary| |v:key| has the key
6584 of the current item and for a |List| |v:key| has the index of
6585 the current item. For a |Blob| |v:key| has the index of the
6586 current byte. For a |String| |v:key| has the index of the
6587 current character.
6588 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006589 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006590< This puts "> " before and " <" after each item in "mylist".
6591
6592 Note that {expr2} is the result of an expression and is then
6593 used as an expression again. Often it is good to use a
6594 |literal-string| to avoid having to double backslashes. You
6595 still have to double ' quotes
6596
6597 If {expr2} is a |Funcref| it is called with two arguments:
6598 1. The key or the index of the current item.
6599 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006600 With a legacy script lambda you don't get an error if it only
6601 accepts one argument, but with a Vim9 lambda you get "E1106:
6602 One argument too many", the number of arguments must match.
6603
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006604 The function must return the new value of the item. Example
6605 that changes each value by "key-value": >
6606 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006607 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006608 endfunc
6609 call map(myDict, function('KeyValue'))
6610< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006611 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006612< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006613 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006614< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006615 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006616<
6617 The operation is done in-place for a |List| and |Dictionary|.
6618 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006619 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006620
6621< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6622 or a new |Blob| or |String|.
6623 When an error is encountered while evaluating {expr2} no
6624 further items in {expr1} are processed.
6625 When {expr2} is a Funcref errors inside a function are ignored,
6626 unless it was defined with the "abort" flag.
6627
6628 Can also be used as a |method|: >
6629 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006630<
6631 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6632 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006633
6634
6635maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6636 When {dict} is omitted or zero: Return the rhs of mapping
6637 {name} in mode {mode}. The returned String has special
6638 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006639 listing. When {dict} is TRUE a dictionary is returned, see
6640 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006641
6642 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006643 returned if {dict} is FALSE, otherwise returns an empty Dict.
6644 When the mapping for {name} is empty, then "<Nop>" is
6645 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006646
6647 The {name} can have special key names, like in the ":map"
6648 command.
6649
6650 {mode} can be one of these strings:
6651 "n" Normal
6652 "v" Visual (including Select)
6653 "o" Operator-pending
6654 "i" Insert
6655 "c" Cmd-line
6656 "s" Select
6657 "x" Visual
6658 "l" langmap |language-mapping|
6659 "t" Terminal-Job
6660 "" Normal, Visual and Operator-pending
6661 When {mode} is omitted, the modes for "" are used.
6662
6663 When {abbr} is there and it is |TRUE| use abbreviations
6664 instead of mappings.
6665
6666 When {dict} is there and it is |TRUE| return a dictionary
6667 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006668 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006669 "lhs" The {lhs} of the mapping as it would be typed
6670 "lhsraw" The {lhs} of the mapping as raw bytes
6671 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6672 form, only present when it differs from "lhsraw"
6673 "rhs" The {rhs} of the mapping as typed.
6674 "silent" 1 for a |:map-silent| mapping, else 0.
6675 "noremap" 1 if the {rhs} of the mapping is not remappable.
6676 "script" 1 if mapping was defined with <script>.
6677 "expr" 1 for an expression mapping (|:map-<expr>|).
6678 "buffer" 1 for a buffer local mapping (|:map-local|).
6679 "mode" Modes for which the mapping is defined. In
6680 addition to the modes mentioned above, these
6681 characters will be used:
6682 " " Normal, Visual and Operator-pending
6683 "!" Insert and Commandline mode
6684 (|mapmode-ic|)
6685 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006686 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006687 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006688 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006689 "lnum" The line number in "sid", zero if unknown.
6690 "nowait" Do not wait for other, longer mappings.
6691 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006692 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006693 "mode_bits" Vim's internal binary representation of "mode".
6694 |mapset()| ignores this; only "mode" is used.
6695 See |maplist()| for usage examples. The values
6696 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006697
6698 The dictionary can be used to restore a mapping with
6699 |mapset()|.
6700
6701 The mappings local to the current buffer are checked first,
6702 then the global mappings.
6703 This function can be used to map a key even when it's already
6704 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006705 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006706
6707< Can also be used as a |method|: >
6708 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006709<
6710 Return type: |String| or dict<any> depending on {dict}
6711
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006712
6713mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6714 Check if there is a mapping that matches with {name} in mode
6715 {mode}. See |maparg()| for {mode} and special names in
6716 {name}.
6717 When {abbr} is there and it is |TRUE| use abbreviations
6718 instead of mappings.
6719 A match happens with a mapping that starts with {name} and
6720 with a mapping which is equal to the start of {name}.
6721
6722 matches mapping "a" "ab" "abc" ~
6723 mapcheck("a") yes yes yes
6724 mapcheck("abc") yes yes yes
6725 mapcheck("ax") yes no no
6726 mapcheck("b") no no no
6727
6728 The difference with maparg() is that mapcheck() finds a
6729 mapping that matches with {name}, while maparg() only finds a
6730 mapping for {name} exactly.
6731 When there is no mapping that starts with {name}, an empty
6732 String is returned. If there is one, the RHS of that mapping
6733 is returned. If there are several mappings that start with
6734 {name}, the RHS of one of them is returned. This will be
6735 "<Nop>" if the RHS is empty.
6736 The mappings local to the current buffer are checked first,
6737 then the global mappings.
6738 This function can be used to check if a mapping can be added
6739 without being ambiguous. Example: >
6740 :if mapcheck("_vv") == ""
6741 : map _vv :set guifont=7x13<CR>
6742 :endif
6743< This avoids adding the "_vv" mapping when there already is a
6744 mapping for "_v" or for "_vvv".
6745
6746 Can also be used as a |method|: >
6747 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006748<
6749 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006750
6751
Ernie Rael09661202022-04-25 14:40:44 +01006752maplist([{abbr}]) *maplist()*
6753 Returns a |List| of all mappings. Each List item is a |Dict|,
6754 the same as what is returned by |maparg()|, see
6755 |mapping-dict|. When {abbr} is there and it is |TRUE| use
6756 abbreviations instead of mappings.
6757
6758 Example to show all mappings with 'MultiMatch' in rhs: >
6759 vim9script
6760 echo maplist()->filter(
6761 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01006762< It can be tricky to find mappings for particular |:map-modes|.
6763 |mapping-dict|'s "mode_bits" can simplify this. For example,
6764 the mode_bits for Normal, Insert or Command-line modes are
6765 0x19. To find all the mappings available in those modes you
6766 can do: >
6767 vim9script
6768 var saved_maps = []
6769 for m in maplist()
6770 if and(m.mode_bits, 0x19) != 0
6771 saved_maps->add(m)
6772 endif
6773 endfor
6774 echo saved_maps->mapnew((_, m) => m.lhs)
6775< The values of the mode_bits are defined in Vim's src/vim.h
6776 file and they can be discovered at runtime using
6777 |:map-commands| and "maplist()". Example: >
6778 vim9script
6779 omap xyzzy <Nop>
6780 var op_bit = maplist()->filter(
6781 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
6782 ounmap xyzzy
6783 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006784<
6785 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01006786
6787
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006788mapnew({expr1}, {expr2}) *mapnew()*
6789 Like |map()| but instead of replacing items in {expr1} a new
6790 List or Dictionary is created and returned. {expr1} remains
6791 unchanged. Items can still be changed by {expr2}, if you
6792 don't want that use |deepcopy()| first.
6793
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006794 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6795 depending on {expr1}
6796
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006797
6798mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01006799mapset({dict})
6800 Restore a mapping from a dictionary, possibly returned by
6801 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
6802 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006803 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01006804 feature allows copying mappings from one buffer to another.
6805 The dict.mode value may restore a single mapping that covers
6806 more than one mode, like with mode values of '!', ' ', 'nox',
6807 or 'v'. *E1276*
6808
6809 In the first form, {mode} and {abbr} should be the same as
6810 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006811 {mode} is used to define the mode in which the mapping is set,
6812 not the "mode" entry in {dict}.
6813 Example for saving and restoring a mapping: >
6814 let save_map = maparg('K', 'n', 0, 1)
6815 nnoremap K somethingelse
6816 ...
6817 call mapset('n', 0, save_map)
6818< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01006819 e.g. with `:map!`, you need to save/restore the mapping for
6820 all of them, when they might differ.
6821
6822 In the second form, with {dict} as the only argument, mode
6823 and abbr are taken from the dict.
6824 Example: >
6825 vim9script
6826 var save_maps = maplist()->filter(
6827 (_, m) => m.lhs == 'K')
6828 nnoremap K somethingelse
6829 cnoremap K somethingelse2
6830 # ...
6831 unmap K
6832 for d in save_maps
6833 mapset(d)
6834 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006835<
6836 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006837
6838
6839match({expr}, {pat} [, {start} [, {count}]]) *match()*
6840 When {expr} is a |List| then this returns the index of the
6841 first item where {pat} matches. Each item is used as a
6842 String, |Lists| and |Dictionaries| are used as echoed.
6843
6844 Otherwise, {expr} is used as a String. The result is a
6845 Number, which gives the index (byte offset) in {expr} where
6846 {pat} matches.
6847
6848 A match at the first character or |List| item returns zero.
6849 If there is no match -1 is returned.
6850
6851 For getting submatches see |matchlist()|.
6852 Example: >
6853 :echo match("testing", "ing") " results in 4
6854 :echo match([1, 'x'], '\a') " results in 1
6855< See |string-match| for how {pat} is used.
6856 *strpbrk()*
6857 Vim doesn't have a strpbrk() function. But you can do: >
6858 :let sepidx = match(line, '[.,;: \t]')
6859< *strcasestr()*
6860 Vim doesn't have a strcasestr() function. But you can add
6861 "\c" to the pattern to ignore case: >
6862 :let idx = match(haystack, '\cneedle')
6863<
6864 If {start} is given, the search starts from byte index
6865 {start} in a String or item {start} in a |List|.
6866 The result, however, is still the index counted from the
6867 first character/item. Example: >
6868 :echo match("testing", "ing", 2)
6869< result is again "4". >
6870 :echo match("testing", "ing", 4)
6871< result is again "4". >
6872 :echo match("testing", "t", 2)
6873< result is "3".
6874 For a String, if {start} > 0 then it is like the string starts
6875 {start} bytes later, thus "^" will match at {start}. Except
6876 when {count} is given, then it's like matches before the
6877 {start} byte are ignored (this is a bit complicated to keep it
6878 backwards compatible).
6879 For a String, if {start} < 0, it will be set to 0. For a list
6880 the index is counted from the end.
6881 If {start} is out of range ({start} > strlen({expr}) for a
6882 String or {start} > len({expr}) for a |List|) -1 is returned.
6883
6884 When {count} is given use the {count}'th match. When a match
6885 is found in a String the search for the next one starts one
6886 character further. Thus this example results in 1: >
6887 echo match("testing", "..", 0, 2)
6888< In a |List| the search continues in the next item.
6889 Note that when {count} is added the way {start} works changes,
6890 see above.
6891
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01006892 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006893 See |pattern| for the patterns that are accepted.
6894 The 'ignorecase' option is used to set the ignore-caseness of
6895 the pattern. 'smartcase' is NOT used. The matching is always
6896 done like 'magic' is set and 'cpoptions' is empty.
6897 Note that a match at the start is preferred, thus when the
6898 pattern is using "*" (any number of matches) it tends to find
6899 zero matches at the start instead of a number of matches
6900 further down in the text.
6901
6902 Can also be used as a |method|: >
6903 GetText()->match('word')
6904 GetList()->match('word')
6905<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006906 Return type: |Number|
6907
6908
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006909 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006910matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
6911 Defines a pattern to be highlighted in the current window (a
6912 "match"). It will be highlighted with {group}. Returns an
6913 identification number (ID), which can be used to delete the
6914 match using |matchdelete()|. The ID is bound to the window.
6915 Matching is case sensitive and magic, unless case sensitivity
6916 or magicness are explicitly overridden in {pattern}. The
6917 'magic', 'smartcase' and 'ignorecase' options are not used.
6918 The "Conceal" value is special, it causes the match to be
6919 concealed.
6920
6921 The optional {priority} argument assigns a priority to the
6922 match. A match with a high priority will have its
6923 highlighting overrule that of a match with a lower priority.
6924 A priority is specified as an integer (negative numbers are no
6925 exception). If the {priority} argument is not specified, the
6926 default priority is 10. The priority of 'hlsearch' is zero,
6927 hence all matches with a priority greater than zero will
6928 overrule it. Syntax highlighting (see 'syntax') is a separate
6929 mechanism, and regardless of the chosen priority a match will
6930 always overrule syntax highlighting.
6931
6932 The optional {id} argument allows the request for a specific
6933 match ID. If a specified ID is already taken, an error
6934 message will appear and the match will not be added. An ID
6935 is specified as a positive integer (zero excluded). IDs 1, 2
6936 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01006937 respectively. 3 is reserved for use by the |matchparen|
6938 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01006939 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01006940 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006941
6942 The optional {dict} argument allows for further custom
6943 values. Currently this is used to specify a match specific
6944 conceal character that will be shown for |hl-Conceal|
6945 highlighted matches. The dict can have the following members:
6946
6947 conceal Special character to show instead of the
6948 match (only for |hl-Conceal| highlighted
6949 matches, see |:syn-cchar|)
6950 window Instead of the current window use the
6951 window with this number or window ID.
6952
6953 The number of matches is not limited, as it is the case with
6954 the |:match| commands.
6955
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006956 Returns -1 on error.
6957
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006958 Example: >
6959 :highlight MyGroup ctermbg=green guibg=green
6960 :let m = matchadd("MyGroup", "TODO")
6961< Deletion of the pattern: >
6962 :call matchdelete(m)
6963
6964< A list of matches defined by |matchadd()| and |:match| are
6965 available from |getmatches()|. All matches can be deleted in
6966 one operation by |clearmatches()|.
6967
6968 Can also be used as a |method|: >
6969 GetGroup()->matchadd('TODO')
6970<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006971 Return type: |Number|
6972
6973
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006974 *matchaddpos()*
6975matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
6976 Same as |matchadd()|, but requires a list of positions {pos}
6977 instead of a pattern. This command is faster than |matchadd()|
Shane Harperc1b39842024-07-17 19:40:40 +02006978 because it does not handle regular expressions and it sets
6979 buffer line boundaries to redraw screen. It is supposed to be
6980 used when fast match additions and deletions are required, for
6981 example to highlight matching parentheses.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006982
6983 {pos} is a list of positions. Each position can be one of
6984 these:
6985 - A number. This whole line will be highlighted. The first
6986 line has number 1.
6987 - A list with one number, e.g., [23]. The whole line with this
6988 number will be highlighted.
6989 - A list with two numbers, e.g., [23, 11]. The first number is
6990 the line number, the second one is the column number (first
6991 column is 1, the value must correspond to the byte index as
6992 |col()| would return). The character at this position will
6993 be highlighted.
6994 - A list with three numbers, e.g., [23, 11, 3]. As above, but
6995 the third number gives the length of the highlight in bytes.
6996
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006997 Returns -1 on error.
6998
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006999 Example: >
7000 :highlight MyGroup ctermbg=green guibg=green
7001 :let m = matchaddpos("MyGroup", [[23, 24], 34])
7002< Deletion of the pattern: >
7003 :call matchdelete(m)
7004
7005< Matches added by |matchaddpos()| are returned by
7006 |getmatches()|.
7007
7008 Can also be used as a |method|: >
7009 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007010<
7011 Return type: |Number|
7012
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007013
7014matcharg({nr}) *matcharg()*
7015 Selects the {nr} match item, as set with a |:match|,
7016 |:2match| or |:3match| command.
7017 Return a |List| with two elements:
7018 The name of the highlight group used
7019 The pattern used.
7020 When {nr} is not 1, 2 or 3 returns an empty |List|.
7021 When there is no match item set returns ['', ''].
7022 This is useful to save and restore a |:match|.
7023 Highlighting matches using the |:match| commands are limited
7024 to three matches. |matchadd()| does not have this limitation.
7025
7026 Can also be used as a |method|: >
7027 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007028<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007029 Return type: list<string>
7030
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007031 *matchbufline()*
7032matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
7033 Returns the |List| of matches in lines from {lnum} to {end} in
7034 buffer {buf} where {pat} matches.
7035
7036 {lnum} and {end} can either be a line number or the string "$"
7037 to refer to the last line in {buf}.
7038
7039 The {dict} argument supports following items:
7040 submatches include submatch information (|/\(|)
7041
7042 For each match, a |Dict| with the following items is returned:
7043 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007044 lnum line number where there is a match
7045 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007046 Note that there can be multiple matches in a single line.
7047
7048 This function works only for loaded buffers. First call
7049 |bufload()| if needed.
7050
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007051 See |match-pattern| for information about the effect of some
7052 option settings on the pattern.
7053
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007054 When {buf} is not a valid buffer, the buffer is not loaded or
7055 {lnum} or {end} is not valid then an error is given and an
7056 empty |List| is returned.
7057
7058 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007059 " Assuming line 3 in buffer 5 contains "a"
7060 :echo matchbufline(5, '\<\k\+\>', 3, 3)
7061 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
7062 " Assuming line 4 in buffer 10 contains "tik tok"
7063 :echo matchbufline(10, '\<\k\+\>', 1, 4)
7064 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007065<
7066 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007067 "\1", "\2", etc. are also returned. Example: >
7068 " Assuming line 2 in buffer 2 contains "acd"
7069 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007070 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007071 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007072< The "submatches" List always contains 9 items. If a submatch
7073 is not found, then an empty string is returned for that
7074 submatch.
7075
7076 Can also be used as a |method|: >
7077 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007078<
7079 Return type: list<dict<any>> or list<any>
7080
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007081
7082matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
7083 Deletes a match with ID {id} previously defined by |matchadd()|
7084 or one of the |:match| commands. Returns 0 if successful,
7085 otherwise -1. See example for |matchadd()|. All matches can
7086 be deleted in one operation by |clearmatches()|.
7087 If {win} is specified, use the window with this number or
7088 window ID instead of the current window.
7089
7090 Can also be used as a |method|: >
7091 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007092<
7093 Return type: |Number|
7094
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007095
7096matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
7097 Same as |match()|, but return the index of first character
7098 after the match. Example: >
7099 :echo matchend("testing", "ing")
7100< results in "7".
7101 *strspn()* *strcspn()*
7102 Vim doesn't have a strspn() or strcspn() function, but you can
7103 do it with matchend(): >
7104 :let span = matchend(line, '[a-zA-Z]')
7105 :let span = matchend(line, '[^a-zA-Z]')
7106< Except that -1 is returned when there are no matches.
7107
7108 The {start}, if given, has the same meaning as for |match()|. >
7109 :echo matchend("testing", "ing", 2)
7110< results in "7". >
7111 :echo matchend("testing", "ing", 5)
7112< result is "-1".
7113 When {expr} is a |List| the result is equal to |match()|.
7114
7115 Can also be used as a |method|: >
7116 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007117<
7118 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007119
7120
7121matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7122 If {list} is a list of strings, then returns a |List| with all
7123 the strings in {list} that fuzzy match {str}. The strings in
7124 the returned list are sorted based on the matching score.
7125
7126 The optional {dict} argument always supports the following
7127 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007128 matchseq When this item is present return only matches
7129 that contain the characters in {str} in the
7130 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007131 limit Maximum number of matches in {list} to be
7132 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007133
7134 If {list} is a list of dictionaries, then the optional {dict}
7135 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007136 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007137 {str}. The value of this item should be a
7138 string.
7139 text_cb |Funcref| that will be called for every item
7140 in {list} to get the text for fuzzy matching.
7141 This should accept a dictionary item as the
7142 argument and return the text for that item to
7143 use for fuzzy matching.
7144
7145 {str} is treated as a literal string and regular expression
7146 matching is NOT supported. The maximum supported {str} length
7147 is 256.
7148
7149 When {str} has multiple words each separated by white space,
7150 then the list of strings that have all the words is returned.
7151
7152 If there are no matching strings or there is an error, then an
7153 empty list is returned. If length of {str} is greater than
7154 256, then returns an empty list.
7155
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007156 When {limit} is given, matchfuzzy() will find up to this
7157 number of matches in {list} and return them in sorted order.
7158
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007159 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007160 matching strings.
7161
7162 Example: >
7163 :echo matchfuzzy(["clay", "crow"], "cay")
7164< results in ["clay"]. >
7165 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7166< results in a list of buffer names fuzzy matching "ndl". >
7167 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7168< results in a list of buffer information dicts with buffer
7169 names fuzzy matching "ndl". >
7170 :echo getbufinfo()->matchfuzzy("spl",
7171 \ {'text_cb' : {v -> v.name}})
7172< results in a list of buffer information dicts with buffer
7173 names fuzzy matching "spl". >
7174 :echo v:oldfiles->matchfuzzy("test")
7175< results in a list of file names fuzzy matching "test". >
7176 :let l = readfile("buffer.c")->matchfuzzy("str")
7177< results in a list of lines in "buffer.c" fuzzy matching "str". >
7178 :echo ['one two', 'two one']->matchfuzzy('two one')
7179< results in ['two one', 'one two']. >
7180 :echo ['one two', 'two one']->matchfuzzy('two one',
7181 \ {'matchseq': 1})
7182< results in ['two one'].
7183
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007184 Return type: list<string> or list<any>
7185
7186
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007187matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7188 Same as |matchfuzzy()|, but returns the list of matched
7189 strings, the list of character positions where characters
7190 in {str} matches and a list of matching scores. You can
7191 use |byteidx()| to convert a character position to a byte
7192 position.
7193
7194 If {str} matches multiple times in a string, then only the
7195 positions for the best match is returned.
7196
7197 If there are no matching strings or there is an error, then a
7198 list with three empty list items is returned.
7199
7200 Example: >
7201 :echo matchfuzzypos(['testing'], 'tsg')
7202< results in [['testing'], [[0, 2, 6]], [99]] >
7203 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7204< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7205 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7206< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7207
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007208 Return type: list<list<any>>
7209
7210
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007211matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7212 Same as |match()|, but return a |List|. The first item in the
7213 list is the matched string, same as what matchstr() would
7214 return. Following items are submatches, like "\1", "\2", etc.
7215 in |:substitute|. When an optional submatch didn't match an
7216 empty string is used. Example: >
7217 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7218< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7219 When there is no match an empty list is returned.
7220
7221 You can pass in a List, but that is not very useful.
7222
7223 Can also be used as a |method|: >
7224 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007225<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007226 Return type: list<string> or list<any>
7227
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007228 *matchstrlist()*
7229matchstrlist({list}, {pat} [, {dict}])
7230 Returns the |List| of matches in {list} where {pat} matches.
7231 {list} is a |List| of strings. {pat} is matched against each
7232 string in {list}.
7233
7234 The {dict} argument supports following items:
7235 submatches include submatch information (|/\(|)
7236
7237 For each match, a |Dict| with the following items is returned:
7238 byteidx starting byte index of the match.
7239 idx index in {list} of the match.
7240 text matched string
7241 submatches a List of submatches. Present only if
7242 "submatches" is set to v:true in {dict}.
7243
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007244 See |match-pattern| for information about the effect of some
7245 option settings on the pattern.
7246
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007247 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007248 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7249 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7250 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7251 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007252<
7253 If "submatches" is present and is v:true, then submatches like
7254 "\1", "\2", etc. are also returned. Example: >
7255 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7256 \ #{submatches: v:true})
7257 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7258< The "submatches" List always contains 9 items. If a submatch
7259 is not found, then an empty string is returned for that
7260 submatch.
7261
7262 Can also be used as a |method|: >
7263 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007264<
7265 Return type: list<dict<any>> or list<any>
7266
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007267
7268matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7269 Same as |match()|, but return the matched string. Example: >
7270 :echo matchstr("testing", "ing")
7271< results in "ing".
7272 When there is no match "" is returned.
7273 The {start}, if given, has the same meaning as for |match()|. >
7274 :echo matchstr("testing", "ing", 2)
7275< results in "ing". >
7276 :echo matchstr("testing", "ing", 5)
7277< result is "".
7278 When {expr} is a |List| then the matching item is returned.
7279 The type isn't changed, it's not necessarily a String.
7280
7281 Can also be used as a |method|: >
7282 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007283<
7284 Return type: |String|
7285
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007286
7287matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7288 Same as |matchstr()|, but return the matched string, the start
7289 position and the end position of the match. Example: >
7290 :echo matchstrpos("testing", "ing")
7291< results in ["ing", 4, 7].
7292 When there is no match ["", -1, -1] is returned.
7293 The {start}, if given, has the same meaning as for |match()|. >
7294 :echo matchstrpos("testing", "ing", 2)
7295< results in ["ing", 4, 7]. >
7296 :echo matchstrpos("testing", "ing", 5)
7297< result is ["", -1, -1].
7298 When {expr} is a |List| then the matching item, the index
7299 of first item where {pat} matches, the start position and the
7300 end position of the match are returned. >
7301 :echo matchstrpos([1, '__x'], '\a')
7302< result is ["x", 1, 2, 3].
7303 The type isn't changed, it's not necessarily a String.
7304
7305 Can also be used as a |method|: >
7306 GetText()->matchstrpos('word')
7307<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007308 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007309
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007310
7311max({expr}) *max()*
7312 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007313 echo max([apples, pears, oranges])
7314
7315< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7316 it returns the maximum of all values in the Dictionary.
7317 If {expr} is neither a List nor a Dictionary, or one of the
7318 items in {expr} cannot be used as a Number this results in
7319 an error. An empty |List| or |Dictionary| results in zero.
7320
7321 Can also be used as a |method|: >
7322 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007323<
7324 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007325
7326
7327menu_info({name} [, {mode}]) *menu_info()*
7328 Return information about the specified menu {name} in
7329 mode {mode}. The menu name should be specified without the
7330 shortcut character ('&'). If {name} is "", then the top-level
7331 menu names are returned.
7332
7333 {mode} can be one of these strings:
7334 "n" Normal
7335 "v" Visual (including Select)
7336 "o" Operator-pending
7337 "i" Insert
7338 "c" Cmd-line
7339 "s" Select
7340 "x" Visual
7341 "t" Terminal-Job
7342 "" Normal, Visual and Operator-pending
7343 "!" Insert and Cmd-line
7344 When {mode} is omitted, the modes for "" are used.
7345
7346 Returns a |Dictionary| containing the following items:
7347 accel menu item accelerator text |menu-text|
7348 display display name (name without '&')
7349 enabled v:true if this menu item is enabled
7350 Refer to |:menu-enable|
7351 icon name of the icon file (for toolbar)
7352 |toolbar-icon|
7353 iconidx index of a built-in icon
7354 modes modes for which the menu is defined. In
7355 addition to the modes mentioned above, these
7356 characters will be used:
7357 " " Normal, Visual and Operator-pending
7358 name menu item name.
7359 noremenu v:true if the {rhs} of the menu item is not
7360 remappable else v:false.
7361 priority menu order priority |menu-priority|
7362 rhs right-hand-side of the menu item. The returned
7363 string has special characters translated like
7364 in the output of the ":menu" command listing.
7365 When the {rhs} of a menu item is empty, then
7366 "<Nop>" is returned.
7367 script v:true if script-local remapping of {rhs} is
7368 allowed else v:false. See |:menu-script|.
7369 shortcut shortcut key (character after '&' in
7370 the menu name) |menu-shortcut|
7371 silent v:true if the menu item is created
7372 with <silent> argument |:menu-silent|
7373 submenus |List| containing the names of
7374 all the submenus. Present only if the menu
7375 item has submenus.
7376
7377 Returns an empty dictionary if the menu item is not found.
7378
7379 Examples: >
7380 :echo menu_info('Edit.Cut')
7381 :echo menu_info('File.Save', 'n')
7382
7383 " Display the entire menu hierarchy in a buffer
7384 func ShowMenu(name, pfx)
7385 let m = menu_info(a:name)
7386 call append(line('$'), a:pfx .. m.display)
7387 for child in m->get('submenus', [])
7388 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7389 \ a:pfx .. ' ')
7390 endfor
7391 endfunc
7392 new
7393 for topmenu in menu_info('').submenus
7394 call ShowMenu(topmenu, '')
7395 endfor
7396<
7397 Can also be used as a |method|: >
7398 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007399<
7400 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007401
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007402min({expr}) *min()*
7403 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007404 echo min([apples, pears, oranges])
7405
7406< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7407 it returns the minimum of all values in the Dictionary.
7408 If {expr} is neither a List nor a Dictionary, or one of the
7409 items in {expr} cannot be used as a Number this results in
7410 an error. An empty |List| or |Dictionary| results in zero.
7411
7412 Can also be used as a |method|: >
7413 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007414<
7415 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007416
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007417
7418mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007419 Create directory {name}.
7420
Bram Moolenaar938ae282023-02-20 20:44:55 +00007421 When {flags} is present it must be a string. An empty string
7422 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007423
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007424 {flags} can contain these character flags:
7425 "p" intermediate directories will be created as necessary
7426 "D" {name} will be deleted at the end of the current
Christian Brabandtc509c002024-06-14 20:22:05 +02007427 function, but not recursively |:defer|
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007428 "R" {name} will be deleted recursively at the end of the
Christian Brabandtc509c002024-06-14 20:22:05 +02007429 current function |:defer|
Bram Moolenaar938ae282023-02-20 20:44:55 +00007430
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007431 Note that when {name} has more than one part and "p" is used
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007432 some directories may already exist. Only the first one that
7433 is created and what it contains is scheduled to be deleted.
7434 E.g. when using: >
7435 call mkdir('subdir/tmp/autoload', 'pR')
7436< and "subdir" already exists then "subdir/tmp" will be
7437 scheduled for deletion, like with: >
7438 defer delete('subdir/tmp', 'rf')
7439< Note that if scheduling the defer fails the directory is not
7440 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007441
7442 If {prot} is given it is used to set the protection bits of
7443 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7444 the user, readable for others). Use 0o700 to make it
7445 unreadable for others. This is only used for the last part of
7446 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
7447 created with 0o755.
7448 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007449 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007450
7451< This function is not available in the |sandbox|.
7452
7453 There is no error if the directory already exists and the "p"
7454 flag is passed (since patch 8.0.1708). However, without the
7455 "p" option the call will fail.
7456
7457 The function result is a Number, which is TRUE if the call was
7458 successful or FALSE if the directory creation failed or partly
7459 failed.
7460
7461 Not available on all systems. To check use: >
7462 :if exists("*mkdir")
7463
7464< Can also be used as a |method|: >
7465 GetName()->mkdir()
7466<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007467 Return type: |Number|
7468
7469
7470mode([{expr}]) *mode()*
7471 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007472 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007473 a non-empty String (|non-zero-arg|), then the full mode is
7474 returned, otherwise only the first letter is returned.
7475 Also see |state()|.
7476
7477 n Normal
7478 no Operator-pending
7479 nov Operator-pending (forced characterwise |o_v|)
7480 noV Operator-pending (forced linewise |o_V|)
7481 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7482 CTRL-V is one character
7483 niI Normal using |i_CTRL-O| in |Insert-mode|
7484 niR Normal using |i_CTRL-O| in |Replace-mode|
7485 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7486 nt Terminal-Normal (insert goes to Terminal-Job mode)
7487 v Visual by character
7488 vs Visual by character using |v_CTRL-O| in Select mode
7489 V Visual by line
7490 Vs Visual by line using |v_CTRL-O| in Select mode
7491 CTRL-V Visual blockwise
7492 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7493 s Select by character
7494 S Select by line
7495 CTRL-S Select blockwise
7496 i Insert
7497 ic Insert mode completion |compl-generic|
7498 ix Insert mode |i_CTRL-X| completion
7499 R Replace |R|
7500 Rc Replace mode completion |compl-generic|
7501 Rx Replace mode |i_CTRL-X| completion
7502 Rv Virtual Replace |gR|
7503 Rvc Virtual Replace mode completion |compl-generic|
7504 Rvx Virtual Replace mode |i_CTRL-X| completion
7505 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007506 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007507 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007508 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007509 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007510 ce Normal Ex mode |Q|
7511 r Hit-enter prompt
7512 rm The -- more -- prompt
7513 r? A |:confirm| query of some sort
7514 ! Shell or external command is executing
7515 t Terminal-Job mode: keys go to the job
7516
7517 This is useful in the 'statusline' option or when used
7518 with |remote_expr()| In most other places it always returns
7519 "c" or "n".
7520 Note that in the future more modes and more specific modes may
7521 be added. It's better not to compare the whole string but only
7522 the leading character(s).
7523 Also see |visualmode()|.
7524
7525 Can also be used as a |method|: >
7526 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007527<
7528 Return type: |String|
7529
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007530
7531mzeval({expr}) *mzeval()*
7532 Evaluate MzScheme expression {expr} and return its result
7533 converted to Vim data structures.
7534 Numbers and strings are returned as they are.
7535 Pairs (including lists and improper lists) and vectors are
7536 returned as Vim |Lists|.
7537 Hash tables are represented as Vim |Dictionary| type with keys
7538 converted to strings.
7539 All other types are converted to string with display function.
7540 Examples: >
7541 :mz (define l (list 1 2 3))
7542 :mz (define h (make-hash)) (hash-set! h "list" l)
7543 :echo mzeval("l")
7544 :echo mzeval("h")
7545<
7546 Note that in a `:def` function local variables are not visible
7547 to {expr}.
7548
7549 Can also be used as a |method|: >
7550 GetExpr()->mzeval()
7551<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007552 Return type: any, depending on {expr}
7553
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007554 {only available when compiled with the |+mzscheme| feature}
7555
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007556
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007557nextnonblank({lnum}) *nextnonblank()*
7558 Return the line number of the first line at or below {lnum}
7559 that is not blank. Example: >
7560 if getline(nextnonblank(1)) =~ "Java"
7561< When {lnum} is invalid or there is no non-blank line at or
7562 below it, zero is returned.
7563 {lnum} is used like with |getline()|.
7564 See also |prevnonblank()|.
7565
7566 Can also be used as a |method|: >
7567 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007568<
7569 Return type: |Number|
7570
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007571
7572nr2char({expr} [, {utf8}]) *nr2char()*
7573 Return a string with a single character, which has the number
7574 value {expr}. Examples: >
7575 nr2char(64) returns "@"
7576 nr2char(32) returns " "
7577< When {utf8} is omitted or zero, the current 'encoding' is used.
7578 Example for "utf-8": >
7579 nr2char(300) returns I with bow character
7580< When {utf8} is TRUE, always return UTF-8 characters.
7581 Note that a NUL character in the file is specified with
7582 nr2char(10), because NULs are represented with newline
7583 characters. nr2char(0) is a real NUL and terminates the
7584 string, thus results in an empty string.
7585 To turn a list of character numbers into a string: >
7586 let list = [65, 66, 67]
7587 let str = join(map(list, {_, val -> nr2char(val)}), '')
7588< Result: "ABC"
7589
7590 Can also be used as a |method|: >
7591 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007592<
7593 Return type: |String|
7594
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007595
7596or({expr}, {expr}) *or()*
7597 Bitwise OR on the two arguments. The arguments are converted
7598 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007599 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007600 Example: >
7601 :let bits = or(bits, 0x80)
7602< Can also be used as a |method|: >
7603 :let bits = bits->or(0x80)
7604
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007605< Rationale: The reason this is a function and not using the "|"
7606 character like many languages, is that Vi has always used "|"
7607 to separate commands. In many places it would not be clear if
7608 "|" is an operator or a command separator.
7609
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007610 Return type: |Number|
7611
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007612
7613pathshorten({path} [, {len}]) *pathshorten()*
7614 Shorten directory names in the path {path} and return the
7615 result. The tail, the file name, is kept as-is. The other
7616 components in the path are reduced to {len} letters in length.
7617 If {len} is omitted or smaller than 1 then 1 is used (single
7618 letters). Leading '~' and '.' characters are kept. Examples: >
7619 :echo pathshorten('~/.vim/autoload/myfile.vim')
7620< ~/.v/a/myfile.vim ~
7621>
7622 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7623< ~/.vi/au/myfile.vim ~
7624 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007625 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007626
7627 Can also be used as a |method|: >
7628 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007629<
7630 Return type: |String|
7631
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007632
7633perleval({expr}) *perleval()*
7634 Evaluate Perl expression {expr} in scalar context and return
7635 its result converted to Vim data structures. If value can't be
7636 converted, it is returned as a string Perl representation.
7637 Note: If you want an array or hash, {expr} must return a
7638 reference to it.
7639 Example: >
7640 :echo perleval('[1 .. 4]')
7641< [1, 2, 3, 4]
7642
7643 Note that in a `:def` function local variables are not visible
7644 to {expr}.
7645
7646 Can also be used as a |method|: >
7647 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007648<
7649 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007650
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007651 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007652
7653
7654popup_ functions are documented here: |popup-functions|
7655
7656
7657pow({x}, {y}) *pow()*
7658 Return the power of {x} to the exponent {y} as a |Float|.
7659 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007660 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007661 Examples: >
7662 :echo pow(3, 3)
7663< 27.0 >
7664 :echo pow(2, 16)
7665< 65536.0 >
7666 :echo pow(32, 0.20)
7667< 2.0
7668
7669 Can also be used as a |method|: >
7670 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007671<
7672 Return type: |Number|
7673
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007674
7675prevnonblank({lnum}) *prevnonblank()*
7676 Return the line number of the first line at or above {lnum}
7677 that is not blank. Example: >
7678 let ind = indent(prevnonblank(v:lnum - 1))
7679< When {lnum} is invalid or there is no non-blank line at or
7680 above it, zero is returned.
7681 {lnum} is used like with |getline()|.
7682 Also see |nextnonblank()|.
7683
7684 Can also be used as a |method|: >
7685 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007686<
7687 Return type: |Number|
7688
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007689
7690printf({fmt}, {expr1} ...) *printf()*
7691 Return a String with {fmt}, where "%" items are replaced by
7692 the formatted form of their respective arguments. Example: >
7693 printf("%4d: E%d %.30s", lnum, errno, msg)
7694< May result in:
7695 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7696
7697 When used as a |method| the base is passed as the second
7698 argument: >
7699 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007700<
7701 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007702
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007703 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007704 %s string
7705 %6S string right-aligned in 6 display cells
7706 %6s string right-aligned in 6 bytes
7707 %.9s string truncated to 9 bytes
7708 %c single byte
7709 %d decimal number
7710 %5d decimal number padded with spaces to 5 characters
7711 %x hex number
7712 %04x hex number padded with zeros to at least 4 characters
7713 %X hex number using upper case letters
7714 %o octal number
7715 %08b binary number padded with zeros to at least 8 chars
7716 %f floating point number as 12.23, inf, -inf or nan
7717 %F floating point number as 12.23, INF, -INF or NAN
7718 %e floating point number as 1.23e3, inf, -inf or nan
7719 %E floating point number as 1.23E3, INF, -INF or NAN
7720 %g floating point number, as %f or %e depending on value
7721 %G floating point number, as %F or %E depending on value
7722 %% the % character itself
7723
7724 Conversion specifications start with '%' and end with the
7725 conversion type. All other characters are copied unchanged to
7726 the result.
7727
7728 The "%" starts a conversion specification. The following
7729 arguments appear in sequence:
7730
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007731 % [pos-argument] [flags] [field-width] [.precision] type
7732
7733 pos-argument
7734 At most one positional argument specifier. These
7735 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007736
7737 flags
7738 Zero or more of the following flags:
7739
7740 # The value should be converted to an "alternate
7741 form". For c, d, and s conversions, this option
7742 has no effect. For o conversions, the precision
7743 of the number is increased to force the first
7744 character of the output string to a zero (except
7745 if a zero value is printed with an explicit
7746 precision of zero).
7747 For b and B conversions, a non-zero result has
7748 the string "0b" (or "0B" for B conversions)
7749 prepended to it.
7750 For x and X conversions, a non-zero result has
7751 the string "0x" (or "0X" for X conversions)
7752 prepended to it.
7753
7754 0 (zero) Zero padding. For all conversions the converted
7755 value is padded on the left with zeros rather
7756 than blanks. If a precision is given with a
7757 numeric conversion (d, b, B, o, x, and X), the 0
7758 flag is ignored.
7759
7760 - A negative field width flag; the converted value
7761 is to be left adjusted on the field boundary.
7762 The converted value is padded on the right with
7763 blanks, rather than on the left with blanks or
7764 zeros. A - overrides a 0 if both are given.
7765
7766 ' ' (space) A blank should be left before a positive
7767 number produced by a signed conversion (d).
7768
7769 + A sign must always be placed before a number
7770 produced by a signed conversion. A + overrides
7771 a space if both are used.
7772
7773 field-width
7774 An optional decimal digit string specifying a minimum
7775 field width. If the converted value has fewer bytes
7776 than the field width, it will be padded with spaces on
7777 the left (or right, if the left-adjustment flag has
7778 been given) to fill out the field width. For the S
7779 conversion the count is in cells.
7780
7781 .precision
7782 An optional precision, in the form of a period '.'
7783 followed by an optional digit string. If the digit
7784 string is omitted, the precision is taken as zero.
7785 This gives the minimum number of digits to appear for
7786 d, o, x, and X conversions, the maximum number of
7787 bytes to be printed from a string for s conversions,
7788 or the maximum number of cells to be printed from a
7789 string for S conversions.
7790 For floating point it is the number of digits after
7791 the decimal point.
7792
7793 type
7794 A character that specifies the type of conversion to
7795 be applied, see below.
7796
7797 A field width or precision, or both, may be indicated by an
7798 asterisk '*' instead of a digit string. In this case, a
7799 Number argument supplies the field width or precision. A
7800 negative field width is treated as a left adjustment flag
7801 followed by a positive field width; a negative precision is
7802 treated as though it were missing. Example: >
7803 :echo printf("%d: %.*s", nr, width, line)
7804< This limits the length of the text used from "line" to
7805 "width" bytes.
7806
Dominique Pellé17dca3c2023-12-14 20:36:32 +01007807 If the argument to be formatted is specified using a
7808 positional argument specifier, and a '*' is used to indicate
7809 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007810 precision, the argument(s) to be used must also be specified
7811 using a {n$} positional argument specifier. See |printf-$|.
7812
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007813 The conversion specifiers and their meanings are:
7814
7815 *printf-d* *printf-b* *printf-B* *printf-o*
7816 *printf-x* *printf-X*
7817 dbBoxX The Number argument is converted to signed decimal
7818 (d), unsigned binary (b and B), unsigned octal (o), or
7819 unsigned hexadecimal (x and X) notation. The letters
7820 "abcdef" are used for x conversions; the letters
7821 "ABCDEF" are used for X conversions.
7822 The precision, if any, gives the minimum number of
7823 digits that must appear; if the converted value
7824 requires fewer digits, it is padded on the left with
7825 zeros.
7826 In no case does a non-existent or small field width
7827 cause truncation of a numeric field; if the result of
7828 a conversion is wider than the field width, the field
7829 is expanded to contain the conversion result.
7830 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02007831 The 'l' modifier indicates the argument is a long
7832 integer. The size will be 32 bits or 64 bits
7833 depending on your platform.
7834 The "ll" modifier indicates the argument is 64 bits.
7835 The b and B conversion specifiers never take a width
7836 modifier and always assume their argument is a 64 bit
7837 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007838 Generally, these modifiers are not useful. They are
7839 ignored when type is known from the argument.
7840
7841 i alias for d
7842 D alias for ld
7843 U alias for lu
7844 O alias for lo
7845
7846 *printf-c*
7847 c The Number argument is converted to a byte, and the
7848 resulting character is written.
7849
7850 *printf-s*
7851 s The text of the String argument is used. If a
7852 precision is specified, no more bytes than the number
7853 specified are used.
7854 If the argument is not a String type, it is
7855 automatically converted to text with the same format
7856 as ":echo".
7857 *printf-S*
7858 S The text of the String argument is used. If a
7859 precision is specified, no more display cells than the
7860 number specified are used.
7861
7862 *printf-f* *E807*
7863 f F The Float argument is converted into a string of the
7864 form 123.456. The precision specifies the number of
7865 digits after the decimal point. When the precision is
7866 zero the decimal point is omitted. When the precision
7867 is not specified 6 is used. A really big number
7868 (out of range or dividing by zero) results in "inf"
7869 or "-inf" with %f (INF or -INF with %F).
7870 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
7871 Example: >
7872 echo printf("%.2f", 12.115)
7873< 12.12
7874 Note that roundoff depends on the system libraries.
7875 Use |round()| when in doubt.
7876
7877 *printf-e* *printf-E*
7878 e E The Float argument is converted into a string of the
7879 form 1.234e+03 or 1.234E+03 when using 'E'. The
7880 precision specifies the number of digits after the
7881 decimal point, like with 'f'.
7882
7883 *printf-g* *printf-G*
7884 g G The Float argument is converted like with 'f' if the
7885 value is between 0.001 (inclusive) and 10000000.0
7886 (exclusive). Otherwise 'e' is used for 'g' and 'E'
7887 for 'G'. When no precision is specified superfluous
7888 zeroes and '+' signs are removed, except for the zero
7889 immediately after the decimal point. Thus 10000000.0
7890 results in 1.0e7.
7891
7892 *printf-%*
7893 % A '%' is written. No argument is converted. The
7894 complete conversion specification is "%%".
7895
7896 When a Number argument is expected a String argument is also
7897 accepted and automatically converted.
7898 When a Float or String argument is expected a Number argument
7899 is also accepted and automatically converted.
7900 Any other argument type results in an error message.
7901
7902 *E766* *E767*
7903 The number of {exprN} arguments must exactly match the number
7904 of "%" items. If there are not sufficient or too many
7905 arguments an error is given. Up to 18 arguments can be used.
7906
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007907 *printf-$*
7908 In certain languages, error and informative messages are
7909 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02007910 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007911 having a different word order, positional arguments may be
7912 used to indicate this. For instance: >
7913
h_east596a9f22023-11-21 21:24:23 +09007914 #, c-format
7915 msgid "%s returning %s"
7916 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007917<
h_east596a9f22023-11-21 21:24:23 +09007918 In this example, the sentence has its 2 string arguments
7919 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007920
h_east596a9f22023-11-21 21:24:23 +09007921 echo printf(
7922 "In The Netherlands, vim's creator's name is: %1$s %2$s",
7923 "Bram", "Moolenaar")
7924< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007925
h_east596a9f22023-11-21 21:24:23 +09007926 echo printf(
7927 "In Belgium, vim's creator's name is: %2$s %1$s",
7928 "Bram", "Moolenaar")
7929< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007930
7931 Width (and precision) can be specified using the '*' specifier.
7932 In this case, you must specify the field width position in the
7933 argument list. >
7934
h_east596a9f22023-11-21 21:24:23 +09007935 echo printf("%1$*2$.*3$d", 1, 2, 3)
7936< 001 >
7937 echo printf("%2$*3$.*1$d", 1, 2, 3)
7938< 2 >
7939 echo printf("%3$*1$.*2$d", 1, 2, 3)
7940< 03 >
7941 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
7942< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007943
7944 You can mix specifying the width and/or precision directly
7945 and via positional arguments: >
7946
h_east596a9f22023-11-21 21:24:23 +09007947 echo printf("%1$4.*2$f", 1.4142135, 6)
7948< 1.414214 >
7949 echo printf("%1$*2$.4f", 1.4142135, 6)
7950< 1.4142 >
7951 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
7952< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007953
Christ van Willegenc35fc032024-03-14 18:30:41 +01007954 You will get an overflow error |E1510|, when the field-width
7955 or precision will result in a string longer than 6400 chars.
7956
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007957 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007958 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09007959 echo printf("%s%1$s", "One", "Two")
7960< E1500: Cannot mix positional and non-positional arguments:
7961 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007962
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007963 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007964 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09007965 echo printf("%3$s%1$s", "One", "Two", "Three")
7966< E1501: format argument 2 unused in $-style format:
7967 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007968
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007969 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007970 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09007971 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
7972< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007973
7974 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09007975 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
7976< E1502: Positional argument 2 used as field width reused as
7977 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007978
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007979 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007980 When a positional argument is used, but not the correct number
7981 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09007982 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
7983< E1503: Positional argument 3 out of bounds: %1$d at width
7984 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007985
7986 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09007987 echo printf("%01$*2$.*3$d %4$d", 1, 2)
7988< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
7989 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007990
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007991 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007992 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09007993 echo printf("%1$s %2$s %1$s", "One", "Two")
7994< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007995
7996 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09007997 echo printf("%1$s %2$s %1$d", "One", "Two")
7998< E1504: Positional argument 1 type used inconsistently:
7999 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008000
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008001 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008002 Various other errors that lead to a format string being
8003 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09008004 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
8005< E1505: Invalid format specifier: %1$d at width %2$d is:
8006 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008007
Christ van Willegenea746f92023-10-05 20:48:36 +02008008 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08008009 This internal error indicates that the logic to parse a
8010 positional format argument ran into a problem that couldn't be
8011 otherwise reported. Please file a bug against Vim if you run
8012 into this, copying the exact format string and parameters that
8013 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02008014
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008015 Return type: |String|
8016
Christ van Willegenea746f92023-10-05 20:48:36 +02008017
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008018prompt_getprompt({buf}) *prompt_getprompt()*
8019 Returns the effective prompt text for buffer {buf}. {buf} can
8020 be a buffer name or number. See |prompt-buffer|.
8021
8022 If the buffer doesn't exist or isn't a prompt buffer, an empty
8023 string is returned.
8024
8025 Can also be used as a |method|: >
8026 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008027<
8028 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008029
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008030 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008031
8032
8033prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
8034 Set prompt callback for buffer {buf} to {expr}. When {expr}
8035 is an empty string the callback is removed. This has only
8036 effect if {buf} has 'buftype' set to "prompt".
8037
8038 The callback is invoked when pressing Enter. The current
8039 buffer will always be the prompt buffer. A new line for a
8040 prompt is added before invoking the callback, thus the prompt
8041 for which the callback was invoked will be in the last but one
8042 line.
8043 If the callback wants to add text to the buffer, it must
8044 insert it above the last line, since that is where the current
8045 prompt is. This can also be done asynchronously.
8046 The callback is invoked with one argument, which is the text
8047 that was entered at the prompt. This can be an empty string
8048 if the user only typed Enter.
8049 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008050 func s:TextEntered(text)
8051 if a:text == 'exit' || a:text == 'quit'
8052 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008053 " Reset 'modified' to allow the buffer to be closed.
8054 " We assume there is nothing useful to be saved.
8055 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008056 close
8057 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008058 " Do something useful with "a:text". In this example
8059 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008060 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008061 endif
8062 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008063 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008064
8065< Can also be used as a |method|: >
8066 GetBuffer()->prompt_setcallback(callback)
8067
8068< {only available when compiled with the |+channel| feature}
8069
8070prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
8071 Set a callback for buffer {buf} to {expr}. When {expr} is an
8072 empty string the callback is removed. This has only effect if
8073 {buf} has 'buftype' set to "prompt".
8074
8075 This callback will be invoked when pressing CTRL-C in Insert
8076 mode. Without setting a callback Vim will exit Insert mode,
8077 as in any buffer.
8078
8079 Can also be used as a |method|: >
8080 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008081<
8082 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008083
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008084 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008085
8086prompt_setprompt({buf}, {text}) *prompt_setprompt()*
8087 Set prompt for buffer {buf} to {text}. You most likely want
8088 {text} to end in a space.
8089 The result is only visible if {buf} has 'buftype' set to
8090 "prompt". Example: >
8091 call prompt_setprompt(bufnr(), 'command: ')
8092<
8093 Can also be used as a |method|: >
8094 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008095<
8096 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008097
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008098 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008099
8100prop_ functions are documented here: |text-prop-functions|
8101
8102pum_getpos() *pum_getpos()*
8103 If the popup menu (see |ins-completion-menu|) is not visible,
8104 returns an empty |Dictionary|, otherwise, returns a
8105 |Dictionary| with the following keys:
8106 height nr of items visible
8107 width screen cells
8108 row top screen row (0 first row)
8109 col leftmost screen column (0 first col)
8110 size total nr of items
8111 scrollbar |TRUE| if scrollbar is visible
8112
8113 The values are the same as in |v:event| during
8114 |CompleteChanged|.
8115
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008116 Return type: dict<any>
8117
8118
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008119pumvisible() *pumvisible()*
8120 Returns non-zero when the popup menu is visible, zero
8121 otherwise. See |ins-completion-menu|.
8122 This can be used to avoid some things that would remove the
8123 popup menu.
8124
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008125 Return type: |Number|
8126
8127
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008128py3eval({expr}) *py3eval()*
8129 Evaluate Python expression {expr} and return its result
8130 converted to Vim data structures.
8131 Numbers and strings are returned as they are (strings are
8132 copied though, Unicode strings are additionally converted to
8133 'encoding').
8134 Lists are represented as Vim |List| type.
8135 Dictionaries are represented as Vim |Dictionary| type with
8136 keys converted to strings.
8137 Note that in a `:def` function local variables are not visible
8138 to {expr}.
8139
8140 Can also be used as a |method|: >
8141 GetExpr()->py3eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008142<
8143 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008144
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008145 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008146
8147 *E858* *E859*
8148pyeval({expr}) *pyeval()*
8149 Evaluate Python expression {expr} and return its result
8150 converted to Vim data structures.
8151 Numbers and strings are returned as they are (strings are
8152 copied though).
8153 Lists are represented as Vim |List| type.
8154 Dictionaries are represented as Vim |Dictionary| type,
8155 non-string keys result in error.
8156 Note that in a `:def` function local variables are not visible
8157 to {expr}.
8158
8159 Can also be used as a |method|: >
8160 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008161<
8162 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008163
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008164 {only available when compiled with the |+python| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008165
8166pyxeval({expr}) *pyxeval()*
8167 Evaluate Python expression {expr} and return its result
8168 converted to Vim data structures.
8169 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8170 See also: |pyeval()|, |py3eval()|
8171
8172 Can also be used as a |method|: >
h-east52e7cc22024-07-28 17:03:29 +02008173 GetExpr()->pyxeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008174<
8175 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008176
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008177 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008178 |+python3| feature}
8179
8180rand([{expr}]) *rand()* *random*
8181 Return a pseudo-random Number generated with an xoshiro128**
8182 algorithm using seed {expr}. The returned number is 32 bits,
8183 also on 64 bits systems, for consistency.
8184 {expr} can be initialized by |srand()| and will be updated by
8185 rand(). If {expr} is omitted, an internal seed value is used
8186 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008187 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008188
8189 Examples: >
8190 :echo rand()
8191 :let seed = srand()
8192 :echo rand(seed)
8193 :echo rand(seed) % 16 " random number 0 - 15
8194<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008195 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008196
8197 *E726* *E727*
8198range({expr} [, {max} [, {stride}]]) *range()*
8199 Returns a |List| with Numbers:
8200 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8201 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8202 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8203 {max}] (increasing {expr} with {stride} each time, not
8204 producing a value past {max}).
8205 When the maximum is one before the start the result is an
8206 empty list. When the maximum is more than one before the
8207 start this is an error.
8208 Examples: >
8209 range(4) " [0, 1, 2, 3]
8210 range(2, 4) " [2, 3, 4]
8211 range(2, 9, 3) " [2, 5, 8]
8212 range(2, -2, -1) " [2, 1, 0, -1, -2]
8213 range(0) " []
8214 range(2, 0) " error!
8215<
8216 Can also be used as a |method|: >
8217 GetExpr()->range()
8218<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008219 Return type: list<number>
8220
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008221
K.Takata11df3ae2022-10-19 14:02:40 +01008222readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008223 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008224 If {offset} is specified, read the file from the specified
8225 offset. If it is a negative value, it is used as an offset
8226 from the end of the file. E.g., to read the last 12 bytes: >
8227 readblob('file.bin', -12)
8228< If {size} is specified, only the specified size will be read.
8229 E.g. to read the first 100 bytes of a file: >
8230 readblob('file.bin', 0, 100)
8231< If {size} is -1 or omitted, the whole data starting from
8232 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008233 This can be also used to read the data from a character device
8234 on Unix when {size} is explicitly set. Only if the device
8235 supports seeking {offset} can be used. Otherwise it should be
8236 zero. E.g. to read 10 bytes from a serial console: >
8237 readblob('/dev/ttyS0', 0, 10)
8238< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008239 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008240 When the offset is beyond the end of the file the result is an
8241 empty blob.
8242 When trying to read more bytes than are available the result
8243 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008244 Also see |readfile()| and |writefile()|.
8245
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008246 Return type: |Blob|
8247
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008248
8249readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8250 Return a list with file and directory names in {directory}.
8251 You can also use |glob()| if you don't need to do complicated
8252 things, such as limiting the number of matches.
8253 The list will be sorted (case sensitive), see the {dict}
8254 argument below for changing the sort order.
8255
8256 When {expr} is omitted all entries are included.
8257 When {expr} is given, it is evaluated to check what to do:
8258 If {expr} results in -1 then no further entries will
8259 be handled.
8260 If {expr} results in 0 then this entry will not be
8261 added to the list.
8262 If {expr} results in 1 then this entry will be added
8263 to the list.
8264 The entries "." and ".." are always excluded.
8265 Each time {expr} is evaluated |v:val| is set to the entry name.
8266 When {expr} is a function the name is passed as the argument.
8267 For example, to get a list of files ending in ".txt": >
8268 readdir(dirname, {n -> n =~ '.txt$'})
8269< To skip hidden and backup files: >
8270 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008271< *E857*
8272 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008273 values. Currently this is used to specify if and how sorting
8274 should be performed. The dict can have the following members:
8275
8276 sort How to sort the result returned from the system.
8277 Valid values are:
8278 "none" do not sort (fastest method)
8279 "case" sort case sensitive (byte value of
8280 each character, technically, using
8281 strcmp()) (default)
8282 "icase" sort case insensitive (technically
8283 using strcasecmp())
8284 "collate" sort using the collation order
8285 of the "POSIX" or "C" |locale|
8286 (technically using strcoll())
8287 Other values are silently ignored.
8288
8289 For example, to get a list of all files in the current
8290 directory without sorting the individual entries: >
8291 readdir('.', '1', #{sort: 'none'})
8292< If you want to get a directory tree: >
8293 function! s:tree(dir)
8294 return {a:dir : map(readdir(a:dir),
8295 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008296 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008297 endfunction
8298 echo s:tree(".")
8299<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008300 Returns an empty List on error.
8301
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008302 Can also be used as a |method|: >
8303 GetDirName()->readdir()
8304<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008305 Return type: list<string> or list<any>
8306
8307
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008308readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8309 Extended version of |readdir()|.
8310 Return a list of Dictionaries with file and directory
8311 information in {directory}.
8312 This is useful if you want to get the attributes of file and
8313 directory at the same time as getting a list of a directory.
8314 This is much faster than calling |readdir()| then calling
8315 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8316 each file and directory especially on MS-Windows.
8317 The list will by default be sorted by name (case sensitive),
8318 the sorting can be changed by using the optional {dict}
8319 argument, see |readdir()|.
8320
8321 The Dictionary for file and directory information has the
8322 following items:
8323 group Group name of the entry. (Only on Unix)
8324 name Name of the entry.
8325 perm Permissions of the entry. See |getfperm()|.
8326 size Size of the entry. See |getfsize()|.
8327 time Timestamp of the entry. See |getftime()|.
8328 type Type of the entry.
8329 On Unix, almost same as |getftype()| except:
8330 Symlink to a dir "linkd"
8331 Other symlink "link"
8332 On MS-Windows:
8333 Normal file "file"
8334 Directory "dir"
8335 Junction "junction"
8336 Symlink to a dir "linkd"
8337 Other symlink "link"
8338 Other reparse point "reparse"
8339 user User name of the entry's owner. (Only on Unix)
8340 On Unix, if the entry is a symlink, the Dictionary includes
8341 the information of the target (except the "type" item).
8342 On MS-Windows, it includes the information of the symlink
8343 itself because of performance reasons.
8344
8345 When {expr} is omitted all entries are included.
8346 When {expr} is given, it is evaluated to check what to do:
8347 If {expr} results in -1 then no further entries will
8348 be handled.
8349 If {expr} results in 0 then this entry will not be
8350 added to the list.
8351 If {expr} results in 1 then this entry will be added
8352 to the list.
8353 The entries "." and ".." are always excluded.
8354 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8355 of the entry.
8356 When {expr} is a function the entry is passed as the argument.
8357 For example, to get a list of files ending in ".txt": >
8358 readdirex(dirname, {e -> e.name =~ '.txt$'})
8359<
8360 For example, to get a list of all files in the current
8361 directory without sorting the individual entries: >
8362 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008363<
8364 Can also be used as a |method|: >
8365 GetDirName()->readdirex()
8366<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008367 Return type: list<dict<any>> or list<any>
8368
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008369
8370 *readfile()*
8371readfile({fname} [, {type} [, {max}]])
8372 Read file {fname} and return a |List|, each line of the file
8373 as an item. Lines are broken at NL characters. Macintosh
8374 files separated with CR will result in a single long line
8375 (unless a NL appears somewhere).
8376 All NUL characters are replaced with a NL character.
8377 When {type} contains "b" binary mode is used:
8378 - When the last line ends in a NL an extra empty list item is
8379 added.
8380 - No CR characters are removed.
8381 Otherwise:
8382 - CR characters that appear before a NL are removed.
8383 - Whether the last line ends in a NL or not does not matter.
8384 - When 'encoding' is Unicode any UTF-8 byte order mark is
8385 removed from the text.
8386 When {max} is given this specifies the maximum number of lines
8387 to be read. Useful if you only want to check the first ten
8388 lines of a file: >
8389 :for line in readfile(fname, '', 10)
8390 : if line =~ 'Date' | echo line | endif
8391 :endfor
8392< When {max} is negative -{max} lines from the end of the file
8393 are returned, or as many as there are.
8394 When {max} is zero the result is an empty list.
8395 Note that without {max} the whole file is read into memory.
8396 Also note that there is no recognition of encoding. Read a
8397 file into a buffer if you need to.
8398 Deprecated (use |readblob()| instead): When {type} contains
8399 "B" a |Blob| is returned with the binary data of the file
8400 unmodified.
8401 When the file can't be opened an error message is given and
8402 the result is an empty list.
8403 Also see |writefile()|.
8404
8405 Can also be used as a |method|: >
8406 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008407<
8408 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008409
8410reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8411 {func} is called for every item in {object}, which can be a
8412 |String|, |List| or a |Blob|. {func} is called with two
8413 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008414 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008415
8416 {initial} is the initial result. When omitted, the first item
8417 in {object} is used and {func} is first called for the second
8418 item. If {initial} is not given and {object} is empty no
8419 result can be computed, an E998 error is given.
8420
8421 Examples: >
8422 echo reduce([1, 3, 5], { acc, val -> acc + val })
8423 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8424 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8425 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8426<
8427 Can also be used as a |method|: >
8428 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008429<
8430 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8431 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008432
8433
8434reg_executing() *reg_executing()*
8435 Returns the single letter name of the register being executed.
8436 Returns an empty string when no register is being executed.
8437 See |@|.
8438
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008439 Return type: |String|
8440
8441
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008442reg_recording() *reg_recording()*
8443 Returns the single letter name of the register being recorded.
8444 Returns an empty string when not recording. See |q|.
8445
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008446 Return type: |String|
8447
8448
8449reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008450reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008451reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008452 Return an item that represents a time value. The item is a
8453 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008454 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008455 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008456 string or |reltimefloat()| to convert to a Float. For
8457 example, to see the time spent in function Work(): >
8458 var startTime = reltime()
8459 Work()
8460 echo startTime->reltime()->reltimestr()
8461<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008462 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008463 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008464 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008465 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008466 specified in the argument.
8467 With two arguments it returns the time passed between {start}
8468 and {end}.
8469
8470 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008471 reltime(). If there is an error an empty List is returned in
8472 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008473
8474 Can also be used as a |method|: >
8475 GetStart()->reltime()
8476<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008477 Return type: list<number>
8478
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008479 {only available when compiled with the |+reltime| feature}
8480
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008481
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008482reltimefloat({time}) *reltimefloat()*
8483 Return a Float that represents the time value of {time}.
8484 Example: >
8485 let start = reltime()
8486 call MyFunction()
8487 let seconds = reltimefloat(reltime(start))
8488< See the note of reltimestr() about overhead.
8489 Also see |profiling|.
8490 If there is an error 0.0 is returned in legacy script, in Vim9
8491 script an error is given.
8492
8493 Can also be used as a |method|: >
8494 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008495<
8496 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008497
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008498 {only available when compiled with the |+reltime| feature}
8499
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008500
8501reltimestr({time}) *reltimestr()*
8502 Return a String that represents the time value of {time}.
8503 This is the number of seconds, a dot and the number of
8504 microseconds. Example: >
8505 let start = reltime()
8506 call MyFunction()
8507 echo reltimestr(reltime(start))
8508< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008509 The accuracy depends on the system. Use reltimefloat() for the
8510 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008511 Leading spaces are used to make the string align nicely. You
8512 can use split() to remove it. >
8513 echo split(reltimestr(reltime(start)))[0]
8514< Also see |profiling|.
8515 If there is an error an empty string is returned in legacy
8516 script, in Vim9 script an error is given.
8517
8518 Can also be used as a |method|: >
8519 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008520<
8521 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008522
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008523 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008524
8525 *remote_expr()* *E449*
8526remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008527 Send the {string} to {server}. The {server} argument is a
8528 string, also see |{server}|.
8529
8530 The string is sent as an expression and the result is returned
8531 after evaluation. The result must be a String or a |List|. A
8532 |List| is turned into a String by joining the items with a
8533 line break in between (not at the end), like with join(expr,
8534 "\n").
8535
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008536 If {idvar} is present and not empty, it is taken as the name
8537 of a variable and a {serverid} for later use with
8538 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008539
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008540 If {timeout} is given the read times out after this many
8541 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008542
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008543 See also |clientserver| |RemoteReply|.
8544 This function is not available in the |sandbox|.
8545 {only available when compiled with the |+clientserver| feature}
8546 Note: Any errors will cause a local error message to be issued
8547 and the result will be the empty string.
8548
8549 Variables will be evaluated in the global namespace,
8550 independent of a function currently being active. Except
8551 when in debug mode, then local function variables and
8552 arguments can be evaluated.
8553
8554 Examples: >
8555 :echo remote_expr("gvim", "2+2")
8556 :echo remote_expr("gvim1", "b:current_syntax")
8557<
8558 Can also be used as a |method|: >
8559 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008560<
8561 Return type: |String| or list<{type}>
8562
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008563
8564remote_foreground({server}) *remote_foreground()*
8565 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008566 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008567 This works like: >
8568 remote_expr({server}, "foreground()")
8569< Except that on Win32 systems the client does the work, to work
8570 around the problem that the OS doesn't always allow the server
8571 to bring itself to the foreground.
8572 Note: This does not restore the window if it was minimized,
8573 like foreground() does.
8574 This function is not available in the |sandbox|.
8575
8576 Can also be used as a |method|: >
8577 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008578<
8579 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008580
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008581 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008582 Win32 console version}
8583
8584
8585remote_peek({serverid} [, {retvar}]) *remote_peek()*
8586 Returns a positive number if there are available strings
8587 from {serverid}. Copies any reply string into the variable
8588 {retvar} if specified. {retvar} must be a string with the
8589 name of a variable.
8590 Returns zero if none are available.
8591 Returns -1 if something is wrong.
8592 See also |clientserver|.
8593 This function is not available in the |sandbox|.
8594 {only available when compiled with the |+clientserver| feature}
8595 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008596 :let repl = ""
8597 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008598
8599< Can also be used as a |method|: >
8600 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008601<
8602 Return type: |Number|
8603
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008604
8605remote_read({serverid}, [{timeout}]) *remote_read()*
8606 Return the oldest available reply from {serverid} and consume
8607 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008608 reply is available. Returns an empty string, if a reply is
8609 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008610 See also |clientserver|.
8611 This function is not available in the |sandbox|.
8612 {only available when compiled with the |+clientserver| feature}
8613 Example: >
8614 :echo remote_read(id)
8615
8616< Can also be used as a |method|: >
8617 ServerId()->remote_read()
8618<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008619 Return type: |String|
8620
8621
8622remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008623 Send the {string} to {server}. The {server} argument is a
8624 string, also see |{server}|.
8625
8626 The string is sent as input keys and the function returns
8627 immediately. At the Vim server the keys are not mapped
8628 |:map|.
8629
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008630 If {idvar} is present, it is taken as the name of a variable
8631 and a {serverid} for later use with remote_read() is stored
8632 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008633
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008634 See also |clientserver| |RemoteReply|.
8635 This function is not available in the |sandbox|.
8636 {only available when compiled with the |+clientserver| feature}
8637
8638 Note: Any errors will be reported in the server and may mess
8639 up the display.
8640 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008641 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008642 \ remote_read(serverid)
8643
8644 :autocmd NONE RemoteReply *
8645 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008646 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008647 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8648<
8649 Can also be used as a |method|: >
8650 ServerName()->remote_send(keys)
8651<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008652 Return type: |String|
8653
8654
8655remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008656 Become the server {name}. {name} must be a non-empty string.
8657 This fails if already running as a server, when |v:servername|
8658 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008659
8660 Can also be used as a |method|: >
8661 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008662<
8663 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008664
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008665 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008666
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008667
8668remove({list}, {idx}) *remove()*
8669remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008670 Without {end}: Remove the item at {idx} from |List| {list} and
8671 return the item.
8672 With {end}: Remove items from {idx} to {end} (inclusive) and
8673 return a |List| with these items. When {idx} points to the same
8674 item as {end} a list with one item is returned. When {end}
8675 points to an item before {idx} this is an error.
8676 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008677 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008678 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008679 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008680 :call remove(mylist, 0, 9)
8681<
8682 Use |delete()| to remove a file.
8683
8684 Can also be used as a |method|: >
8685 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008686<
8687 Return type: any, depending on {list}
8688
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008689
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008690remove({blob}, {idx})
8691remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008692 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8693 return the byte.
8694 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8695 return a |Blob| with these bytes. When {idx} points to the same
8696 byte as {end} a |Blob| with one byte is returned. When {end}
8697 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008698 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008699 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008700 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008701 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008702<
8703 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008704
8705remove({dict}, {key})
8706 Remove the entry from {dict} with key {key} and return it.
8707 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008708 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008709< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008710 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008711
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008712 Return type: any, depending on {dict}
8713
8714
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008715rename({from}, {to}) *rename()*
8716 Rename the file by the name {from} to the name {to}. This
8717 should also work to move files across file systems. The
8718 result is a Number, which is 0 if the file was renamed
8719 successfully, and non-zero when the renaming failed.
8720 NOTE: If {to} exists it is overwritten without warning.
8721 This function is not available in the |sandbox|.
8722
8723 Can also be used as a |method|: >
8724 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008725<
8726 Return type: |Number|
8727
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008728
8729repeat({expr}, {count}) *repeat()*
8730 Repeat {expr} {count} times and return the concatenated
8731 result. Example: >
8732 :let separator = repeat('-', 80)
8733< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01008734 When {expr} is a |List| or a |Blob| the result is {expr}
8735 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008736 :let longlist = repeat(['a', 'b'], 3)
8737< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
8738
8739 Can also be used as a |method|: >
8740 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008741<
8742 Return type: |String|, |Blob| or list<{type}> depending on
8743 {expr}
8744
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008745
8746resolve({filename}) *resolve()* *E655*
8747 On MS-Windows, when {filename} is a shortcut (a .lnk file),
8748 returns the path the shortcut points to in a simplified form.
8749 When {filename} is a symbolic link or junction point, return
8750 the full path to the target. If the target of junction is
8751 removed, return {filename}.
8752 On Unix, repeat resolving symbolic links in all path
8753 components of {filename} and return the simplified result.
8754 To cope with link cycles, resolving of symbolic links is
8755 stopped after 100 iterations.
8756 On other systems, return the simplified {filename}.
8757 The simplification step is done as by |simplify()|.
8758 resolve() keeps a leading path component specifying the
8759 current directory (provided the result is still a relative
8760 path name) and also keeps a trailing path separator.
8761
8762 Can also be used as a |method|: >
8763 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008764<
8765 Return type: |String|
8766
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008767
8768reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01008769 Reverse the order of items in {object}. {object} can be a
8770 |List|, a |Blob| or a |String|. For a List and a Blob the
8771 items are reversed in-place and {object} is returned.
8772 For a String a new String is returned.
8773 Returns zero if {object} is not a List, Blob or a String.
8774 If you want a List or Blob to remain unmodified make a copy
8775 first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008776 :let revlist = reverse(copy(mylist))
8777< Can also be used as a |method|: >
8778 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008779<
8780 Return type: |String|, |Blob| or list<{type}> depending on
8781 {object}
8782
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008783
8784round({expr}) *round()*
8785 Round off {expr} to the nearest integral value and return it
8786 as a |Float|. If {expr} lies halfway between two integral
8787 values, then use the larger one (away from zero).
8788 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008789 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008790 Examples: >
8791 echo round(0.456)
8792< 0.0 >
8793 echo round(4.5)
8794< 5.0 >
8795 echo round(-4.5)
8796< -5.0
8797
8798 Can also be used as a |method|: >
8799 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008800<
8801 Return type: |Float|
8802
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008803
8804rubyeval({expr}) *rubyeval()*
8805 Evaluate Ruby expression {expr} and return its result
8806 converted to Vim data structures.
8807 Numbers, floats and strings are returned as they are (strings
8808 are copied though).
8809 Arrays are represented as Vim |List| type.
8810 Hashes are represented as Vim |Dictionary| type.
8811 Other objects are represented as strings resulted from their
8812 "Object#to_s" method.
8813 Note that in a `:def` function local variables are not visible
8814 to {expr}.
8815
8816 Can also be used as a |method|: >
8817 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008818<
8819 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008820
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008821 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008822
8823screenattr({row}, {col}) *screenattr()*
8824 Like |screenchar()|, but return the attribute. This is a rather
8825 arbitrary number that can only be used to compare to the
8826 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008827 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008828
8829 Can also be used as a |method|: >
8830 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008831<
8832 Return type: |Number|
8833
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008834
8835screenchar({row}, {col}) *screenchar()*
8836 The result is a Number, which is the character at position
8837 [row, col] on the screen. This works for every possible
8838 screen position, also status lines, window separators and the
8839 command line. The top left position is row one, column one
8840 The character excludes composing characters. For double-byte
8841 encodings it may only be the first byte.
8842 This is mainly to be used for testing.
8843 Returns -1 when row or col is out of range.
8844
8845 Can also be used as a |method|: >
8846 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008847<
8848 Return type: |Number|
8849
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008850
8851screenchars({row}, {col}) *screenchars()*
8852 The result is a |List| of Numbers. The first number is the same
8853 as what |screenchar()| returns. Further numbers are
8854 composing characters on top of the base character.
8855 This is mainly to be used for testing.
8856 Returns an empty List when row or col is out of range.
8857
8858 Can also be used as a |method|: >
8859 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008860<
8861 Return type: list<number> or list<any>
8862
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008863
8864screencol() *screencol()*
8865 The result is a Number, which is the current screen column of
8866 the cursor. The leftmost column has number 1.
8867 This function is mainly used for testing.
8868
8869 Note: Always returns the current screen column, thus if used
8870 in a command (e.g. ":echo screencol()") it will return the
8871 column inside the command line, which is 1 when the command is
8872 executed. To get the cursor position in the file use one of
8873 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008874 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008875 nnoremap <silent> GG :echom screencol()<CR>
8876 nnoremap GG <Cmd>echom screencol()<CR>
8877<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008878 Return type: |Number|
8879
8880
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008881screenpos({winid}, {lnum}, {col}) *screenpos()*
8882 The result is a Dict with the screen position of the text
8883 character in window {winid} at buffer line {lnum} and column
8884 {col}. {col} is a one-based byte index.
8885 The Dict has these members:
8886 row screen row
8887 col first screen column
8888 endcol last screen column
8889 curscol cursor screen column
8890 If the specified position is not visible, all values are zero.
8891 The "endcol" value differs from "col" when the character
8892 occupies more than one screen cell. E.g. for a Tab "col" can
8893 be 1 and "endcol" can be 8.
8894 The "curscol" value is where the cursor would be placed. For
8895 a Tab it would be the same as "endcol", while for a double
8896 width character it would be the same as "col".
8897 The |conceal| feature is ignored here, the column numbers are
8898 as if 'conceallevel' is zero. You can set the cursor to the
8899 right position and use |screencol()| to get the value with
8900 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008901 If the position is in a closed fold the screen position of the
8902 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008903 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008904
8905 Can also be used as a |method|: >
8906 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008907<
8908 Return type: dict<number> or dict<any>
8909
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008910
8911screenrow() *screenrow()*
8912 The result is a Number, which is the current screen row of the
8913 cursor. The top line has number one.
8914 This function is mainly used for testing.
8915 Alternatively you can use |winline()|.
8916
8917 Note: Same restrictions as with |screencol()|.
8918
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008919 Return type: |Number|
8920
8921
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008922screenstring({row}, {col}) *screenstring()*
8923 The result is a String that contains the base character and
8924 any composing characters at position [row, col] on the screen.
8925 This is like |screenchars()| but returning a String with the
8926 characters.
8927 This is mainly to be used for testing.
8928 Returns an empty String when row or col is out of range.
8929
8930 Can also be used as a |method|: >
8931 GetRow()->screenstring(col)
8932<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008933 Return type: |String|
8934
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008935 *search()*
8936search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
8937 Search for regexp pattern {pattern}. The search starts at the
8938 cursor position (you can use |cursor()| to set it).
8939
8940 When a match has been found its line number is returned.
8941 If there is no match a 0 is returned and the cursor doesn't
8942 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01008943 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008944
8945 {flags} is a String, which can contain these character flags:
8946 'b' search Backward instead of forward
8947 'c' accept a match at the Cursor position
8948 'e' move to the End of the match
8949 'n' do Not move the cursor
8950 'p' return number of matching sub-Pattern (see below)
8951 's' Set the ' mark at the previous location of the cursor
8952 'w' Wrap around the end of the file
8953 'W' don't Wrap around the end of the file
8954 'z' start searching at the cursor column instead of zero
8955 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
8956
8957 If the 's' flag is supplied, the ' mark is set, only if the
8958 cursor is moved. The 's' flag cannot be combined with the 'n'
8959 flag.
8960
8961 'ignorecase', 'smartcase' and 'magic' are used.
8962
8963 When the 'z' flag is not given, forward searching always
8964 starts in column zero and then matches before the cursor are
8965 skipped. When the 'c' flag is present in 'cpo' the next
8966 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01008967 search starts one column after the start of the match. This
8968 matters for overlapping matches. See |cpo-c|. You can also
8969 insert "\ze" to change where the match ends, see |/\ze|.
8970
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008971 When searching backwards and the 'z' flag is given then the
8972 search starts in column zero, thus no match in the current
8973 line will be found (unless wrapping around the end of the
8974 file).
8975
8976 When the {stopline} argument is given then the search stops
8977 after searching this line. This is useful to restrict the
8978 search to a range of lines. Examples: >
8979 let match = search('(', 'b', line("w0"))
8980 let end = search('END', '', line("w$"))
8981< When {stopline} is used and it is not zero this also implies
8982 that the search does not wrap around the end of the file.
8983 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01008984 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008985 When the {timeout} argument is given the search stops when
8986 more than this many milliseconds have passed. Thus when
8987 {timeout} is 500 the search stops after half a second.
8988 The value must not be negative. A zero value is like not
8989 giving the argument.
Christian Brabandtd657d3d2024-09-10 21:55:49 +02008990
8991 Note: the timeout is only considered when searching, not
8992 while evaluating the {skip} expression.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008993 {only available when compiled with the |+reltime| feature}
8994
8995 If the {skip} expression is given it is evaluated with the
8996 cursor positioned on the start of a match. If it evaluates to
8997 non-zero this match is skipped. This can be used, for
8998 example, to skip a match in a comment or a string.
8999 {skip} can be a string, which is evaluated as an expression, a
9000 function reference or a lambda.
9001 When {skip} is omitted or empty, every match is accepted.
9002 When evaluating {skip} causes an error the search is aborted
9003 and -1 returned.
9004 *search()-sub-match*
9005 With the 'p' flag the returned value is one more than the
9006 first sub-match in \(\). One if none of them matched but the
9007 whole pattern did match.
9008 To get the column number too use |searchpos()|.
9009
9010 The cursor will be positioned at the match, unless the 'n'
9011 flag is used.
9012
9013 Example (goes over all files in the argument list): >
9014 :let n = 1
9015 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009016 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009017 : " start at the last char in the file and wrap for the
9018 : " first search to find match at start of file
9019 : normal G$
9020 : let flags = "w"
9021 : while search("foo", flags) > 0
9022 : s/foo/bar/g
9023 : let flags = "W"
9024 : endwhile
9025 : update " write the file if modified
9026 : let n = n + 1
9027 :endwhile
9028<
9029 Example for using some flags: >
9030 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
9031< This will search for the keywords "if", "else", and "endif"
9032 under or after the cursor. Because of the 'p' flag, it
9033 returns 1, 2, or 3 depending on which keyword is found, or 0
9034 if the search fails. With the cursor on the first word of the
9035 line:
9036 if (foo == 0) | let foo = foo + 1 | endif ~
9037 the function returns 1. Without the 'c' flag, the function
9038 finds the "endif" and returns 3. The same thing happens
9039 without the 'e' flag if the cursor is on the "f" of "if".
9040 The 'n' flag tells the function not to move the cursor.
9041
9042 Can also be used as a |method|: >
9043 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009044<
9045 Return type: |Number|
9046
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009047
9048searchcount([{options}]) *searchcount()*
9049 Get or update the last search count, like what is displayed
9050 without the "S" flag in 'shortmess'. This works even if
9051 'shortmess' does contain the "S" flag.
9052
9053 This returns a |Dictionary|. The dictionary is empty if the
9054 previous pattern was not set and "pattern" was not specified.
9055
9056 key type meaning ~
9057 current |Number| current position of match;
9058 0 if the cursor position is
9059 before the first match
9060 exact_match |Boolean| 1 if "current" is matched on
9061 "pos", otherwise 0
9062 total |Number| total count of matches found
9063 incomplete |Number| 0: search was fully completed
9064 1: recomputing was timed out
9065 2: max count exceeded
9066
9067 For {options} see further down.
9068
9069 To get the last search count when |n| or |N| was pressed, call
9070 this function with `recompute: 0` . This sometimes returns
9071 wrong information because |n| and |N|'s maximum count is 99.
9072 If it exceeded 99 the result must be max count + 1 (100). If
9073 you want to get correct information, specify `recompute: 1`: >
9074
9075 " result == maxcount + 1 (100) when many matches
9076 let result = searchcount(#{recompute: 0})
9077
9078 " Below returns correct result (recompute defaults
9079 " to 1)
9080 let result = searchcount()
9081<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01009082 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009083 function! LastSearchCount() abort
9084 let result = searchcount(#{recompute: 0})
9085 if empty(result)
9086 return ''
9087 endif
9088 if result.incomplete ==# 1 " timed out
9089 return printf(' /%s [?/??]', @/)
9090 elseif result.incomplete ==# 2 " max count exceeded
9091 if result.total > result.maxcount &&
9092 \ result.current > result.maxcount
9093 return printf(' /%s [>%d/>%d]', @/,
9094 \ result.current, result.total)
9095 elseif result.total > result.maxcount
9096 return printf(' /%s [%d/>%d]', @/,
9097 \ result.current, result.total)
9098 endif
9099 endif
9100 return printf(' /%s [%d/%d]', @/,
9101 \ result.current, result.total)
9102 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009103 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009104
9105 " Or if you want to show the count only when
9106 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009107 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009108 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9109<
9110 You can also update the search count, which can be useful in a
9111 |CursorMoved| or |CursorMovedI| autocommand: >
9112
9113 autocmd CursorMoved,CursorMovedI *
9114 \ let s:searchcount_timer = timer_start(
9115 \ 200, function('s:update_searchcount'))
9116 function! s:update_searchcount(timer) abort
9117 if a:timer ==# s:searchcount_timer
9118 call searchcount(#{
9119 \ recompute: 1, maxcount: 0, timeout: 100})
9120 redrawstatus
9121 endif
9122 endfunction
9123<
9124 This can also be used to count matched texts with specified
9125 pattern in the current buffer using "pattern": >
9126
9127 " Count '\<foo\>' in this buffer
9128 " (Note that it also updates search count)
9129 let result = searchcount(#{pattern: '\<foo\>'})
9130
9131 " To restore old search count by old pattern,
9132 " search again
9133 call searchcount()
9134<
9135 {options} must be a |Dictionary|. It can contain:
9136 key type meaning ~
9137 recompute |Boolean| if |TRUE|, recompute the count
9138 like |n| or |N| was executed.
9139 otherwise returns the last
9140 computed result (when |n| or
9141 |N| was used when "S" is not
9142 in 'shortmess', or this
9143 function was called).
9144 (default: |TRUE|)
9145 pattern |String| recompute if this was given
9146 and different with |@/|.
9147 this works as same as the
9148 below command is executed
9149 before calling this function >
9150 let @/ = pattern
9151< (default: |@/|)
9152 timeout |Number| 0 or negative number is no
9153 timeout. timeout milliseconds
9154 for recomputing the result
9155 (default: 0)
9156 maxcount |Number| 0 or negative number is no
9157 limit. max count of matched
9158 text while recomputing the
9159 result. if search exceeded
9160 total count, "total" value
9161 becomes `maxcount + 1`
9162 (default: 99)
9163 pos |List| `[lnum, col, off]` value
9164 when recomputing the result.
9165 this changes "current" result
9166 value. see |cursor()|,
9167 |getpos()|
9168 (default: cursor's position)
9169
9170 Can also be used as a |method|: >
9171 GetSearchOpts()->searchcount()
9172<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009173 Return type: dict<number>
9174
9175
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009176searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9177 Search for the declaration of {name}.
9178
9179 With a non-zero {global} argument it works like |gD|, find
9180 first match in the file. Otherwise it works like |gd|, find
9181 first match in the function.
9182
9183 With a non-zero {thisblock} argument matches in a {} block
9184 that ends before the cursor position are ignored. Avoids
9185 finding variable declarations only valid in another scope.
9186
9187 Moves the cursor to the found match.
9188 Returns zero for success, non-zero for failure.
9189 Example: >
9190 if searchdecl('myvar') == 0
9191 echo getline('.')
9192 endif
9193<
9194 Can also be used as a |method|: >
9195 GetName()->searchdecl()
9196<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009197 Return type: |Number|
9198
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009199 *searchpair()*
9200searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9201 [, {stopline} [, {timeout}]]]])
9202 Search for the match of a nested start-end pair. This can be
9203 used to find the "endif" that matches an "if", while other
9204 if/endif pairs in between are ignored.
9205 The search starts at the cursor. The default is to search
9206 forward, include 'b' in {flags} to search backward.
9207 If a match is found, the cursor is positioned at it and the
9208 line number is returned. If no match is found 0 or -1 is
9209 returned and the cursor doesn't move. No error message is
9210 given.
9211
9212 {start}, {middle} and {end} are patterns, see |pattern|. They
9213 must not contain \( \) pairs. Use of \%( \) is allowed. When
9214 {middle} is not empty, it is found when searching from either
9215 direction, but only when not in a nested start-end pair. A
9216 typical use is: >
9217 searchpair('\<if\>', '\<else\>', '\<endif\>')
9218< By leaving {middle} empty the "else" is skipped.
9219
9220 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9221 |search()|. Additionally:
9222 'r' Repeat until no more matches found; will find the
9223 outer pair. Implies the 'W' flag.
9224 'm' Return number of matches instead of line number with
9225 the match; will be > 1 when 'r' is used.
9226 Note: it's nearly always a good idea to use the 'W' flag, to
9227 avoid wrapping around the end of the file.
9228
9229 When a match for {start}, {middle} or {end} is found, the
9230 {skip} expression is evaluated with the cursor positioned on
9231 the start of the match. It should return non-zero if this
9232 match is to be skipped. E.g., because it is inside a comment
9233 or a string.
9234 When {skip} is omitted or empty, every match is accepted.
9235 When evaluating {skip} causes an error the search is aborted
9236 and -1 returned.
9237 {skip} can be a string, a lambda, a funcref or a partial.
9238 Anything else makes the function fail.
9239 In a `:def` function when the {skip} argument is a string
9240 constant it is compiled into instructions.
9241
9242 For {stopline} and {timeout} see |search()|.
9243
9244 The value of 'ignorecase' is used. 'magic' is ignored, the
9245 patterns are used like it's on.
9246
9247 The search starts exactly at the cursor. A match with
9248 {start}, {middle} or {end} at the next character, in the
9249 direction of searching, is the first one found. Example: >
9250 if 1
9251 if 2
9252 endif 2
9253 endif 1
9254< When starting at the "if 2", with the cursor on the "i", and
9255 searching forwards, the "endif 2" is found. When starting on
9256 the character just before the "if 2", the "endif 1" will be
9257 found. That's because the "if 2" will be found first, and
9258 then this is considered to be a nested if/endif from "if 2" to
9259 "endif 2".
9260 When searching backwards and {end} is more than one character,
9261 it may be useful to put "\zs" at the end of the pattern, so
9262 that when the cursor is inside a match with the end it finds
9263 the matching start.
9264
9265 Example, to find the "endif" command in a Vim script: >
9266
9267 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9268 \ 'getline(".") =~ "^\\s*\""')
9269
9270< The cursor must be at or after the "if" for which a match is
9271 to be found. Note that single-quote strings are used to avoid
9272 having to double the backslashes. The skip expression only
9273 catches comments at the start of a line, not after a command.
9274 Also, a word "en" or "if" halfway a line is considered a
9275 match.
9276 Another example, to search for the matching "{" of a "}": >
9277
9278 :echo searchpair('{', '', '}', 'bW')
9279
9280< This works when the cursor is at or before the "}" for which a
9281 match is to be found. To reject matches that syntax
9282 highlighting recognized as strings: >
9283
9284 :echo searchpair('{', '', '}', 'bW',
9285 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9286<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009287 Return type: |Number|
9288
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009289 *searchpairpos()*
9290searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9291 [, {stopline} [, {timeout}]]]])
9292 Same as |searchpair()|, but returns a |List| with the line and
9293 column position of the match. The first element of the |List|
9294 is the line number and the second element is the byte index of
9295 the column position of the match. If no match is found,
9296 returns [0, 0]. >
9297
9298 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9299<
9300 See |match-parens| for a bigger and more useful example.
9301
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009302 Return type: list<number>
9303
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009304 *searchpos()*
9305searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9306 Same as |search()|, but returns a |List| with the line and
9307 column position of the match. The first element of the |List|
9308 is the line number and the second element is the byte index of
9309 the column position of the match. If no match is found,
9310 returns [0, 0].
9311 Example: >
9312 :let [lnum, col] = searchpos('mypattern', 'n')
9313
9314< When the 'p' flag is given then there is an extra item with
9315 the sub-pattern match number |search()-sub-match|. Example: >
9316 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9317< In this example "submatch" is 2 when a lowercase letter is
9318 found |/\l|, 3 when an uppercase letter is found |/\u|.
9319
9320 Can also be used as a |method|: >
9321 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009322<
9323 Return type: list<number>
9324
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009325
9326server2client({clientid}, {string}) *server2client()*
9327 Send a reply string to {clientid}. The most recent {clientid}
9328 that sent a string can be retrieved with expand("<client>").
9329 {only available when compiled with the |+clientserver| feature}
9330 Returns zero for success, -1 for failure.
9331 Note:
9332 This id has to be stored before the next command can be
9333 received. I.e. before returning from the received command and
9334 before calling any commands that waits for input.
9335 See also |clientserver|.
9336 Example: >
9337 :echo server2client(expand("<client>"), "HELLO")
9338
9339< Can also be used as a |method|: >
9340 GetClientId()->server2client(string)
9341<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009342 Return type: |Number|
9343
9344
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009345serverlist() *serverlist()*
9346 Return a list of available server names, one per line.
9347 When there are no servers or the information is not available
9348 an empty string is returned. See also |clientserver|.
9349 {only available when compiled with the |+clientserver| feature}
9350 Example: >
9351 :echo serverlist()
9352<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009353 Return type: |String|
9354
9355
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009356setbufline({buf}, {lnum}, {text}) *setbufline()*
9357 Set line {lnum} to {text} in buffer {buf}. This works like
9358 |setline()| for the specified buffer.
9359
9360 This function works only for loaded buffers. First call
9361 |bufload()| if needed.
9362
9363 To insert lines use |appendbufline()|.
9364 Any text properties in {lnum} are cleared.
9365
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009366 {text} can be a string to set one line, or a List of strings
9367 to set multiple lines. If the List extends below the last
9368 line then those lines are added. If the List is empty then
9369 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009370
9371 For the use of {buf}, see |bufname()| above.
9372
9373 {lnum} is used like with |setline()|.
9374 Use "$" to refer to the last line in buffer {buf}.
9375 When {lnum} is just below the last line the {text} will be
9376 added below the last line.
9377
9378 When {buf} is not a valid buffer, the buffer is not loaded or
9379 {lnum} is not valid then 1 is returned. In |Vim9| script an
9380 error is given.
9381 On success 0 is returned.
9382
9383 Can also be used as a |method|, the base is passed as the
9384 third argument: >
9385 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009386<
9387 Return type: |Number|
9388
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009389
9390setbufvar({buf}, {varname}, {val}) *setbufvar()*
9391 Set option or local variable {varname} in buffer {buf} to
9392 {val}.
9393 This also works for a global or local window option, but it
9394 doesn't work for a global or local window variable.
9395 For a local window option the global value is unchanged.
9396 For the use of {buf}, see |bufname()| above.
9397 The {varname} argument is a string.
9398 Note that the variable name without "b:" must be used.
9399 Examples: >
9400 :call setbufvar(1, "&mod", 1)
9401 :call setbufvar("todo", "myvar", "foobar")
9402< This function is not available in the |sandbox|.
9403
9404 Can also be used as a |method|, the base is passed as the
9405 third argument: >
9406 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009407<
9408 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009409
9410
9411setcellwidths({list}) *setcellwidths()*
9412 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009413 tells Vim how wide characters are when displayed in the
9414 terminal, counted in screen cells. The values override
9415 'ambiwidth'. Example: >
9416 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009417 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009418 \ [0x2194, 0x2199, 2],
9419 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009420
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009421< The {list} argument is a List of Lists with each three
9422 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9423 {low} and {high} can be the same, in which case this refers to
9424 one character. Otherwise it is the range of characters from
9425 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009426 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009427
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009428 {width} must be either 1 or 2, indicating the character width
9429 in screen cells. *E1112*
9430 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009431 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009432
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009433 If the new value causes 'fillchars' or 'listchars' to become
9434 invalid it is rejected and an error is given.
9435
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009436 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009437 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009438
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009439< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009440 the effect for known emoji characters. Move the cursor
9441 through the text to check if the cell widths of your terminal
9442 match with what Vim knows about each emoji. If it doesn't
9443 look right you need to adjust the {list} argument.
9444
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009445 Return type: |Number|
9446
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009447
9448setcharpos({expr}, {list}) *setcharpos()*
9449 Same as |setpos()| but uses the specified column number as the
9450 character index instead of the byte index in the line.
9451
9452 Example:
9453 With the text "여보세요" in line 8: >
9454 call setcharpos('.', [0, 8, 4, 0])
9455< positions the cursor on the fourth character '요'. >
9456 call setpos('.', [0, 8, 4, 0])
9457< positions the cursor on the second character '보'.
9458
9459 Can also be used as a |method|: >
9460 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009461<
9462 Return type: |Number|
9463
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009464
9465setcharsearch({dict}) *setcharsearch()*
9466 Set the current character search information to {dict},
9467 which contains one or more of the following entries:
9468
9469 char character which will be used for a subsequent
9470 |,| or |;| command; an empty string clears the
9471 character search
9472 forward direction of character search; 1 for forward,
9473 0 for backward
9474 until type of character search; 1 for a |t| or |T|
9475 character search, 0 for an |f| or |F|
9476 character search
9477
9478 This can be useful to save/restore a user's character search
9479 from a script: >
9480 :let prevsearch = getcharsearch()
9481 :" Perform a command which clobbers user's search
9482 :call setcharsearch(prevsearch)
9483< Also see |getcharsearch()|.
9484
9485 Can also be used as a |method|: >
9486 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009487<
9488 Return type: dict<any>
9489
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009490
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009491setcmdline({str} [, {pos}]) *setcmdline()*
9492 Set the command line to {str} and set the cursor position to
9493 {pos}.
9494 If {pos} is omitted, the cursor is positioned after the text.
9495 Returns 0 when successful, 1 when not editing the command
9496 line.
9497
9498 Can also be used as a |method|: >
9499 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009500<
9501 Return type: |Number|
9502
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009503
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009504setcmdpos({pos}) *setcmdpos()*
9505 Set the cursor position in the command line to byte position
9506 {pos}. The first position is 1.
9507 Use |getcmdpos()| to obtain the current position.
9508 Only works while editing the command line, thus you must use
9509 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9510 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9511 set after the command line is set to the expression. For
9512 |c_CTRL-R_=| it is set after evaluating the expression but
9513 before inserting the resulting text.
9514 When the number is too big the cursor is put at the end of the
9515 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009516 Returns 0 when successful, 1 when not editing the command
9517 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009518
9519 Can also be used as a |method|: >
9520 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009521<
9522 Return type: |Number|
9523
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009524
9525setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9526setcursorcharpos({list})
9527 Same as |cursor()| but uses the specified column number as the
9528 character index instead of the byte index in the line.
9529
9530 Example:
9531 With the text "여보세요" in line 4: >
9532 call setcursorcharpos(4, 3)
9533< positions the cursor on the third character '세'. >
9534 call cursor(4, 3)
9535< positions the cursor on the first character '여'.
9536
9537 Can also be used as a |method|: >
9538 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009539<
9540 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009541
9542
9543setenv({name}, {val}) *setenv()*
9544 Set environment variable {name} to {val}. Example: >
9545 call setenv('HOME', '/home/myhome')
9546
9547< When {val} is |v:null| the environment variable is deleted.
9548 See also |expr-env|.
9549
9550 Can also be used as a |method|, the base is passed as the
9551 second argument: >
9552 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009553<
9554 Return type: |Number|
9555
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009556
9557setfperm({fname}, {mode}) *setfperm()* *chmod*
9558 Set the file permissions for {fname} to {mode}.
9559 {mode} must be a string with 9 characters. It is of the form
9560 "rwxrwxrwx", where each group of "rwx" flags represent, in
9561 turn, the permissions of the owner of the file, the group the
9562 file belongs to, and other users. A '-' character means the
9563 permission is off, any other character means on. Multi-byte
9564 characters are not supported.
9565
9566 For example "rw-r-----" means read-write for the user,
9567 readable by the group, not accessible by others. "xx-x-----"
9568 would do the same thing.
9569
9570 Returns non-zero for success, zero for failure.
9571
9572 Can also be used as a |method|: >
9573 GetFilename()->setfperm(mode)
9574<
9575 To read permissions see |getfperm()|.
9576
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009577 Return type: |Number|
9578
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009579
9580setline({lnum}, {text}) *setline()*
9581 Set line {lnum} of the current buffer to {text}. To insert
9582 lines use |append()|. To set lines in another buffer use
Christian Brabandt946f61c2024-06-17 13:17:58 +02009583 |setbufline()|.
h-east52e7cc22024-07-28 17:03:29 +02009584 Any text properties in {lnum} are cleared. See
9585 |text-prop-cleared|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009586
9587 {lnum} is used like with |getline()|.
9588 When {lnum} is just below the last line the {text} will be
9589 added below the last line.
9590 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009591 converted to a String. When {text} is an empty List then
9592 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009593
9594 If this succeeds, FALSE is returned. If this fails (most likely
9595 because {lnum} is invalid) TRUE is returned.
9596 In |Vim9| script an error is given if {lnum} is invalid.
9597
9598 Example: >
9599 :call setline(5, strftime("%c"))
9600
9601< When {text} is a |List| then line {lnum} and following lines
9602 will be set to the items in the list. Example: >
9603 :call setline(5, ['aaa', 'bbb', 'ccc'])
9604< This is equivalent to: >
9605 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9606 : call setline(n, l)
9607 :endfor
9608
9609< Note: The '[ and '] marks are not set.
9610
9611 Can also be used as a |method|, the base is passed as the
9612 second argument: >
9613 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009614<
9615 Return type: |Number|
9616
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009617
9618setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9619 Create or replace or add to the location list for window {nr}.
9620 {nr} can be the window number or the |window-ID|.
9621 When {nr} is zero the current window is used.
9622
9623 For a location list window, the displayed location list is
9624 modified. For an invalid window number {nr}, -1 is returned.
9625 Otherwise, same as |setqflist()|.
9626 Also see |location-list|.
9627
9628 For {action} see |setqflist-action|.
9629
9630 If the optional {what} dictionary argument is supplied, then
9631 only the items listed in {what} are set. Refer to |setqflist()|
9632 for the list of supported keys in {what}.
9633
9634 Can also be used as a |method|, the base is passed as the
9635 second argument: >
9636 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009637<
9638 Return type: |Number|
9639
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009640
9641setmatches({list} [, {win}]) *setmatches()*
9642 Restores a list of matches saved by |getmatches()| for the
9643 current window. Returns 0 if successful, otherwise -1. All
9644 current matches are cleared before the list is restored. See
9645 example for |getmatches()|.
9646 If {win} is specified, use the window with this number or
9647 window ID instead of the current window.
9648
9649 Can also be used as a |method|: >
9650 GetMatches()->setmatches()
9651<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009652 Return type: |Number|
9653
9654
9655setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009656 Set the position for String {expr}. Possible values:
9657 . the cursor
9658 'x mark x
9659
9660 {list} must be a |List| with four or five numbers:
9661 [bufnum, lnum, col, off]
9662 [bufnum, lnum, col, off, curswant]
9663
9664 "bufnum" is the buffer number. Zero can be used for the
9665 current buffer. When setting an uppercase mark "bufnum" is
9666 used for the mark position. For other marks it specifies the
9667 buffer to set the mark in. You can use the |bufnr()| function
9668 to turn a file name into a buffer number.
9669 For setting the cursor and the ' mark "bufnum" is ignored,
9670 since these are associated with a window, not a buffer.
9671 Does not change the jumplist.
9672
9673 "lnum" and "col" are the position in the buffer. The first
9674 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9675 smaller than 1 then 1 is used. To use the character count
9676 instead of the byte count, use |setcharpos()|.
9677
9678 The "off" number is only used when 'virtualedit' is set. Then
9679 it is the offset in screen columns from the start of the
9680 character. E.g., a position within a <Tab> or after the last
9681 character.
9682
9683 The "curswant" number is only used when setting the cursor
9684 position. It sets the preferred column for when moving the
9685 cursor vertically. When the "curswant" number is missing the
9686 preferred column is not set. When it is present and setting a
9687 mark position it is not used.
9688
9689 Note that for '< and '> changing the line number may result in
9690 the marks to be effectively be swapped, so that '< is always
9691 before '>.
9692
9693 Returns 0 when the position could be set, -1 otherwise.
9694 An error message is given if {expr} is invalid.
9695
9696 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9697
9698 This does not restore the preferred column for moving
9699 vertically; if you set the cursor position with this, |j| and
9700 |k| motions will jump to previous columns! Use |cursor()| to
9701 also set the preferred column. Also see the "curswant" key in
9702 |winrestview()|.
9703
9704 Can also be used as a |method|: >
9705 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009706<
9707 Return type: |Number|
9708
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009709
9710setqflist({list} [, {action} [, {what}]]) *setqflist()*
9711 Create or replace or add to the quickfix list.
9712
9713 If the optional {what} dictionary argument is supplied, then
9714 only the items listed in {what} are set. The first {list}
9715 argument is ignored. See below for the supported items in
9716 {what}.
9717 *setqflist-what*
9718 When {what} is not present, the items in {list} are used. Each
9719 item must be a dictionary. Non-dictionary items in {list} are
9720 ignored. Each dictionary item can contain the following
9721 entries:
9722
9723 bufnr buffer number; must be the number of a valid
9724 buffer
9725 filename name of a file; only used when "bufnr" is not
9726 present or it is invalid.
9727 module name of a module; if given it will be used in
9728 quickfix error window instead of the filename.
9729 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00009730 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009731 pattern search pattern used to locate the error
9732 col column number
9733 vcol when non-zero: "col" is visual column
9734 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00009735 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009736 nr error number
9737 text description of the error
9738 type single-character error type, 'E', 'W', etc.
9739 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +02009740 user_data custom data associated with the item, can be
9741 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009742
9743 The "col", "vcol", "nr", "type" and "text" entries are
9744 optional. Either "lnum" or "pattern" entry can be used to
9745 locate a matching error line.
9746 If the "filename" and "bufnr" entries are not present or
9747 neither the "lnum" or "pattern" entries are present, then the
9748 item will not be handled as an error line.
9749 If both "pattern" and "lnum" are present then "pattern" will
9750 be used.
9751 If the "valid" entry is not supplied, then the valid flag is
9752 set when "bufnr" is a valid buffer or "filename" exists.
9753 If you supply an empty {list}, the quickfix list will be
9754 cleared.
9755 Note that the list is not exactly the same as what
9756 |getqflist()| returns.
9757
9758 {action} values: *setqflist-action* *E927*
9759 'a' The items from {list} are added to the existing
9760 quickfix list. If there is no existing list, then a
9761 new list is created.
9762
9763 'r' The items from the current quickfix list are replaced
9764 with the items from {list}. This can also be used to
9765 clear the list: >
9766 :call setqflist([], 'r')
9767<
9768 'f' All the quickfix lists in the quickfix stack are
9769 freed.
9770
9771 If {action} is not present or is set to ' ', then a new list
9772 is created. The new quickfix list is added after the current
9773 quickfix list in the stack and all the following lists are
9774 freed. To add a new quickfix list at the end of the stack,
9775 set "nr" in {what} to "$".
9776
9777 The following items can be specified in dictionary {what}:
9778 context quickfix list context. See |quickfix-context|
9779 efm errorformat to use when parsing text from
9780 "lines". If this is not present, then the
9781 'errorformat' option value is used.
9782 See |quickfix-parse|
9783 id quickfix list identifier |quickfix-ID|
9784 idx index of the current entry in the quickfix
9785 list specified by 'id' or 'nr'. If set to '$',
9786 then the last entry in the list is set as the
9787 current entry. See |quickfix-index|
9788 items list of quickfix entries. Same as the {list}
9789 argument.
9790 lines use 'errorformat' to parse a list of lines and
9791 add the resulting entries to the quickfix list
9792 {nr} or {id}. Only a |List| value is supported.
9793 See |quickfix-parse|
9794 nr list number in the quickfix stack; zero
9795 means the current quickfix list and "$" means
9796 the last quickfix list.
9797 quickfixtextfunc
9798 function to get the text to display in the
9799 quickfix window. The value can be the name of
9800 a function or a funcref or a lambda. Refer to
9801 |quickfix-window-function| for an explanation
9802 of how to write the function and an example.
9803 title quickfix list title text. See |quickfix-title|
9804 Unsupported keys in {what} are ignored.
9805 If the "nr" item is not present, then the current quickfix list
9806 is modified. When creating a new quickfix list, "nr" can be
9807 set to a value one greater than the quickfix stack size.
9808 When modifying a quickfix list, to guarantee that the correct
9809 list is modified, "id" should be used instead of "nr" to
9810 specify the list.
9811
9812 Examples (See also |setqflist-examples|): >
9813 :call setqflist([], 'r', {'title': 'My search'})
9814 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
9815 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
9816<
9817 Returns zero for success, -1 for failure.
9818
9819 This function can be used to create a quickfix list
9820 independent of the 'errorformat' setting. Use a command like
9821 `:cc 1` to jump to the first position.
9822
9823 Can also be used as a |method|, the base is passed as the
9824 second argument: >
9825 GetErrorlist()->setqflist()
9826<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009827 Return type: |Number|
9828
9829
9830setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009831 Set the register {regname} to {value}.
9832 If {regname} is "" or "@", the unnamed register '"' is used.
9833 The {regname} argument is a string. In |Vim9-script|
9834 {regname} must be one character.
9835
9836 {value} may be any value returned by |getreg()| or
9837 |getreginfo()|, including a |List| or |Dict|.
9838 If {options} contains "a" or {regname} is upper case,
9839 then the value is appended.
9840
9841 {options} can also contain a register type specification:
9842 "c" or "v" |characterwise| mode
9843 "l" or "V" |linewise| mode
9844 "b" or "<CTRL-V>" |blockwise-visual| mode
9845 If a number immediately follows "b" or "<CTRL-V>" then this is
9846 used as the width of the selection - if it is not specified
9847 then the width of the block is set to the number of characters
9848 in the longest line (counting a <Tab> as 1 character).
9849
9850 If {options} contains no register settings, then the default
9851 is to use character mode unless {value} ends in a <NL> for
9852 string {value} and linewise mode for list {value}. Blockwise
9853 mode is never selected automatically.
9854 Returns zero for success, non-zero for failure.
9855
9856 *E883*
9857 Note: you may not use |List| containing more than one item to
9858 set search and expression registers. Lists containing no
9859 items act like empty strings.
9860
9861 Examples: >
9862 :call setreg(v:register, @*)
9863 :call setreg('*', @%, 'ac')
9864 :call setreg('a', "1\n2\n3", 'b5')
9865 :call setreg('"', { 'points_to': 'a'})
9866
9867< This example shows using the functions to save and restore a
9868 register: >
9869 :let var_a = getreginfo()
9870 :call setreg('a', var_a)
9871< or: >
9872 :let var_a = getreg('a', 1, 1)
9873 :let var_amode = getregtype('a')
9874 ....
9875 :call setreg('a', var_a, var_amode)
9876< Note: you may not reliably restore register value
9877 without using the third argument to |getreg()| as without it
9878 newlines are represented as newlines AND Nul bytes are
9879 represented as newlines as well, see |NL-used-for-Nul|.
9880
9881 You can also change the type of a register by appending
9882 nothing: >
9883 :call setreg('a', '', 'al')
9884
9885< Can also be used as a |method|, the base is passed as the
9886 second argument: >
9887 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009888<
9889 Return type: |Number|
9890
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009891
9892settabvar({tabnr}, {varname}, {val}) *settabvar()*
9893 Set tab-local variable {varname} to {val} in tab page {tabnr}.
9894 |t:var|
9895 The {varname} argument is a string.
9896 Note that autocommands are blocked, side effects may not be
9897 triggered, e.g. when setting 'filetype'.
9898 Note that the variable name without "t:" must be used.
9899 Tabs are numbered starting with one.
9900 This function is not available in the |sandbox|.
9901
9902 Can also be used as a |method|, the base is passed as the
9903 third argument: >
9904 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009905<
9906 Return type: |Number|
9907
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009908
9909settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
9910 Set option or local variable {varname} in window {winnr} to
9911 {val}.
9912 Tabs are numbered starting with one. For the current tabpage
9913 use |setwinvar()|.
9914 {winnr} can be the window number or the |window-ID|.
9915 When {winnr} is zero the current window is used.
9916 Note that autocommands are blocked, side effects may not be
9917 triggered, e.g. when setting 'filetype' or 'syntax'.
9918 This also works for a global or local buffer option, but it
9919 doesn't work for a global or local buffer variable.
9920 For a local buffer option the global value is unchanged.
9921 Note that the variable name without "w:" must be used.
9922 Examples: >
9923 :call settabwinvar(1, 1, "&list", 0)
9924 :call settabwinvar(3, 2, "myvar", "foobar")
9925< This function is not available in the |sandbox|.
9926
9927 Can also be used as a |method|, the base is passed as the
9928 fourth argument: >
9929 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009930<
9931 Return type: |Number|
9932
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009933
9934settagstack({nr}, {dict} [, {action}]) *settagstack()*
9935 Modify the tag stack of the window {nr} using {dict}.
9936 {nr} can be the window number or the |window-ID|.
9937
9938 For a list of supported items in {dict}, refer to
9939 |gettagstack()|. "curidx" takes effect before changing the tag
9940 stack.
9941 *E962*
9942 How the tag stack is modified depends on the {action}
9943 argument:
9944 - If {action} is not present or is set to 'r', then the tag
9945 stack is replaced.
9946 - If {action} is set to 'a', then new entries from {dict} are
9947 pushed (added) onto the tag stack.
9948 - If {action} is set to 't', then all the entries from the
9949 current entry in the tag stack or "curidx" in {dict} are
9950 removed and then new entries are pushed to the stack.
9951
9952 The current index is set to one after the length of the tag
9953 stack after the modification.
9954
9955 Returns zero for success, -1 for failure.
9956
9957 Examples (for more examples see |tagstack-examples|):
9958 Empty the tag stack of window 3: >
9959 call settagstack(3, {'items' : []})
9960
9961< Save and restore the tag stack: >
9962 let stack = gettagstack(1003)
9963 " do something else
9964 call settagstack(1003, stack)
9965 unlet stack
9966<
9967 Can also be used as a |method|, the base is passed as the
9968 second argument: >
9969 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009970<
9971 Return type: |Number|
9972
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009973
9974setwinvar({winnr}, {varname}, {val}) *setwinvar()*
9975 Like |settabwinvar()| for the current tab page.
9976 Examples: >
9977 :call setwinvar(1, "&list", 0)
9978 :call setwinvar(2, "myvar", "foobar")
9979
9980< Can also be used as a |method|, the base is passed as the
9981 third argument: >
9982 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009983<
9984 Return type: |Number|
9985
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009986
9987sha256({string}) *sha256()*
9988 Returns a String with 64 hex characters, which is the SHA256
9989 checksum of {string}.
9990
9991 Can also be used as a |method|: >
9992 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009993<
9994 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009995
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009996 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009997
9998shellescape({string} [, {special}]) *shellescape()*
9999 Escape {string} for use as a shell command argument.
10000 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +000010001 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010002 in single quotes and will double up all internal single
10003 quotes.
10004 On MS-Windows, when 'shellslash' is not set, it will enclose
10005 {string} in double quotes and double all double quotes within
10006 {string}.
10007 Otherwise it will enclose {string} in single quotes and
10008 replace all "'" with "'\''".
10009
Enno5faeb602024-05-15 21:54:19 +020010010 The {special} argument adds additional escaping of keywords
10011 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +090010012 number or a non-empty String (|non-zero-arg|), then special
10013 items such as "!", "%", "#" and "<cword>" (as listed in
10014 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +020010015 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010016
10017 The "!" character will be escaped (again with a |non-zero-arg|
10018 {special}) when 'shell' contains "csh" in the tail. That is
10019 because for csh and tcsh "!" is used for history replacement
10020 even when inside single quotes.
10021
10022 With a |non-zero-arg| {special} the <NL> character is also
10023 escaped. When 'shell' containing "csh" in the tail it's
10024 escaped a second time.
10025
10026 The "\" character will be escaped when 'shell' contains "fish"
10027 in the tail. That is because for fish "\" is used as an escape
10028 character inside single quotes.
10029
10030 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010031 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010032< This results in a directory listing for the file under the
10033 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010034 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010035< See also |::S|.
10036
10037 Can also be used as a |method|: >
10038 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010039<
10040 Return type: |String|
10041
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010042
10043shiftwidth([{col}]) *shiftwidth()*
10044 Returns the effective value of 'shiftwidth'. This is the
10045 'shiftwidth' value unless it is zero, in which case it is the
10046 'tabstop' value. This function was introduced with patch
10047 7.3.694 in 2012, everybody should have it by now (however it
10048 did not allow for the optional {col} argument until 8.1.542).
10049
10050 When there is one argument {col} this is used as column number
10051 for which to return the 'shiftwidth' value. This matters for the
10052 'vartabstop' feature. If the 'vartabstop' setting is enabled and
10053 no {col} argument is given, column 1 will be assumed.
10054
10055 Can also be used as a |method|: >
10056 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010057<
10058 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010059
10060sign_ functions are documented here: |sign-functions-details|
10061
10062
10063simplify({filename}) *simplify()*
10064 Simplify the file name as much as possible without changing
10065 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
10066 Unix) are not resolved. If the first path component in
10067 {filename} designates the current directory, this will be
10068 valid for the result as well. A trailing path separator is
10069 not removed either. On Unix "//path" is unchanged, but
10070 "///path" is simplified to "/path" (this follows the Posix
10071 standard).
10072 Example: >
10073 simplify("./dir/.././/file/") == "./file/"
10074< Note: The combination "dir/.." is only removed if "dir" is
10075 a searchable directory or does not exist. On Unix, it is also
10076 removed when "dir" is a symbolic link within the same
10077 directory. In order to resolve all the involved symbolic
10078 links before simplifying the path name, use |resolve()|.
10079
10080 Can also be used as a |method|: >
10081 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010082<
10083 Return type: |String|
10084
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010085
10086sin({expr}) *sin()*
10087 Return the sine of {expr}, measured in radians, as a |Float|.
10088 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010089 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010090 Examples: >
10091 :echo sin(100)
10092< -0.506366 >
10093 :echo sin(-4.01)
10094< 0.763301
10095
10096 Can also be used as a |method|: >
10097 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010098<
10099 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010100
10101
10102sinh({expr}) *sinh()*
10103 Return the hyperbolic sine of {expr} as a |Float| in the range
10104 [-inf, inf].
10105 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010106 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010107 Examples: >
10108 :echo sinh(0.5)
10109< 0.521095 >
10110 :echo sinh(-0.9)
10111< -1.026517
10112
10113 Can also be used as a |method|: >
10114 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010115<
10116 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010117
10118
10119slice({expr}, {start} [, {end}]) *slice()*
10120 Similar to using a |slice| "expr[start : end]", but "end" is
10121 used exclusive. And for a string the indexes are used as
10122 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010123 |vim9script|. Also, composing characters are treated as a
10124 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010125 When {end} is omitted the slice continues to the last item.
10126 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010127 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010128
10129 Can also be used as a |method|: >
10130 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010131<
10132 Return type: list<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010133
10134
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010135sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010136 Sort the items in {list} in-place. Returns {list}.
10137
10138 If you want a list to remain unmodified make a copy first: >
10139 :let sortedlist = sort(copy(mylist))
10140
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010141< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010142 string representation of each item to sort on. Numbers sort
10143 after Strings, |Lists| after Numbers. For sorting text in the
10144 current buffer use |:sort|.
10145
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010146 When {how} is given and it is 'i' then case is ignored.
10147 In legacy script, for backwards compatibility, the value one
10148 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010149
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010150 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010151 locale is used for ordering. Implementation details: strcoll()
10152 is used to compare strings. See |:language| check or set the
10153 collation locale. |v:collate| can also be used to check the
10154 current locale. Sorting using the locale typically ignores
10155 case. Example: >
10156 " ö is sorted similarly to o with English locale.
10157 :language collate en_US.UTF8
10158 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10159< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10160>
10161 " ö is sorted after z with Swedish locale.
10162 :language collate sv_SE.UTF8
10163 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10164< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10165 This does not work properly on Mac.
10166
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010167 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010168 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010169 strtod() function to parse numbers. Strings, Lists, Dicts and
10170 Funcrefs will be considered as being 0). Note that this won't
10171 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010172
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010173 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010174 sorted numerical. This is like 'n' but a string containing
10175 digits will be used as the number they represent.
10176
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010177 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010178 sorted numerical. All values must be a Number or a Float.
10179
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010180 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010181 is called to compare items. The function is invoked with two
10182 items as argument and must return zero if they are equal, 1 or
10183 bigger if the first one sorts after the second one, -1 or
10184 smaller if the first one sorts before the second one.
10185
10186 {dict} is for functions with the "dict" attribute. It will be
10187 used to set the local variable "self". |Dictionary-function|
10188
10189 The sort is stable, items which compare equal (as number or as
10190 string) will keep their relative position. E.g., when sorting
10191 on numbers, text strings will sort next to each other, in the
10192 same order as they were originally.
10193
10194 Can also be used as a |method|: >
10195 mylist->sort()
10196
10197< Also see |uniq()|.
10198
10199 Example: >
10200 func MyCompare(i1, i2)
10201 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10202 endfunc
10203 eval mylist->sort("MyCompare")
10204< A shorter compare version for this specific simple case, which
10205 ignores overflow: >
10206 func MyCompare(i1, i2)
10207 return a:i1 - a:i2
10208 endfunc
10209< For a simple expression you can use a lambda: >
10210 eval mylist->sort({i1, i2 -> i1 - i2})
10211<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010212 Return type: list<{type}>
10213
10214
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010215sound_clear() *sound_clear()*
10216 Stop playing all sounds.
10217
10218 On some Linux systems you may need the libcanberra-pulse
10219 package, otherwise sound may not stop.
10220
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010221 Return type: |Number|
10222
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010223 {only available when compiled with the |+sound| feature}
10224
10225 *sound_playevent()*
10226sound_playevent({name} [, {callback}])
10227 Play a sound identified by {name}. Which event names are
10228 supported depends on the system. Often the XDG sound names
10229 are used. On Ubuntu they may be found in
10230 /usr/share/sounds/freedesktop/stereo. Example: >
10231 call sound_playevent('bell')
10232< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10233 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10234 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010235 On macOS, {name} refers to files located in
10236 /System/Library/Sounds (e.g. "Tink"). It will also work for
10237 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010238
10239 When {callback} is specified it is invoked when the sound is
10240 finished. The first argument is the sound ID, the second
10241 argument is the status:
10242 0 sound was played to the end
10243 1 sound was interrupted
10244 2 error occurred after sound started
10245 Example: >
10246 func Callback(id, status)
10247 echomsg "sound " .. a:id .. " finished with " .. a:status
10248 endfunc
10249 call sound_playevent('bell', 'Callback')
10250
10251< MS-Windows: {callback} doesn't work for this function.
10252
10253 Returns the sound ID, which can be passed to `sound_stop()`.
10254 Returns zero if the sound could not be played.
10255
10256 Can also be used as a |method|: >
10257 GetSoundName()->sound_playevent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010258<
10259 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010260
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010261 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010262
10263 *sound_playfile()*
10264sound_playfile({path} [, {callback}])
10265 Like `sound_playevent()` but play sound file {path}. {path}
10266 must be a full path. On Ubuntu you may find files to play
10267 with this command: >
10268 :!find /usr/share/sounds -type f | grep -v index.theme
10269
10270< Can also be used as a |method|: >
10271 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010272<
10273 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010274
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010275 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010276
10277
10278sound_stop({id}) *sound_stop()*
10279 Stop playing sound {id}. {id} must be previously returned by
10280 `sound_playevent()` or `sound_playfile()`.
10281
10282 On some Linux systems you may need the libcanberra-pulse
10283 package, otherwise sound may not stop.
10284
10285 On MS-Windows, this does not work for event sound started by
10286 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10287
10288 Can also be used as a |method|: >
10289 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010290<
10291 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010292
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010293 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010294
10295 *soundfold()*
10296soundfold({word})
10297 Return the sound-folded equivalent of {word}. Uses the first
10298 language in 'spelllang' for the current window that supports
10299 soundfolding. 'spell' must be set. When no sound folding is
10300 possible the {word} is returned unmodified.
10301 This can be used for making spelling suggestions. Note that
10302 the method can be quite slow.
10303
10304 Can also be used as a |method|: >
10305 GetWord()->soundfold()
10306<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010307 Return type: |String|
10308
10309
10310spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010311 Without argument: The result is the badly spelled word under
10312 or after the cursor. The cursor is moved to the start of the
10313 bad word. When no bad word is found in the cursor line the
10314 result is an empty string and the cursor doesn't move.
10315
10316 With argument: The result is the first word in {sentence} that
10317 is badly spelled. If there are no spelling mistakes the
10318 result is an empty string.
10319
10320 The return value is a list with two items:
10321 - The badly spelled word or an empty string.
10322 - The type of the spelling error:
10323 "bad" spelling mistake
10324 "rare" rare word
10325 "local" word only valid in another region
10326 "caps" word should start with Capital
10327 Example: >
10328 echo spellbadword("the quik brown fox")
10329< ['quik', 'bad'] ~
10330
10331 The spelling information for the current window and the value
10332 of 'spelllang' are used.
10333
10334 Can also be used as a |method|: >
10335 GetText()->spellbadword()
10336<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010337 Return type: list<string>
10338
10339
10340spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010341 Return a |List| with spelling suggestions to replace {word}.
10342 When {max} is given up to this number of suggestions are
10343 returned. Otherwise up to 25 suggestions are returned.
10344
10345 When the {capital} argument is given and it's non-zero only
10346 suggestions with a leading capital will be given. Use this
10347 after a match with 'spellcapcheck'.
10348
10349 {word} can be a badly spelled word followed by other text.
10350 This allows for joining two words that were split. The
10351 suggestions also include the following text, thus you can
10352 replace a line.
10353
10354 {word} may also be a good word. Similar words will then be
10355 returned. {word} itself is not included in the suggestions,
10356 although it may appear capitalized.
10357
10358 The spelling information for the current window is used. The
10359 values of 'spelllang' and 'spellsuggest' are used.
10360
10361 Can also be used as a |method|: >
10362 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010363<
10364 Return type: list<string> or list<any>
10365
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010366
10367split({string} [, {pattern} [, {keepempty}]]) *split()*
10368 Make a |List| out of {string}. When {pattern} is omitted or
Shane Harperc1b39842024-07-17 19:40:40 +020010369 empty each white space separated sequence of characters
10370 becomes an item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010371 Otherwise the string is split where {pattern} matches,
10372 removing the matched characters. 'ignorecase' is not used
10373 here, add \c to ignore case. |/\c|
10374 When the first or last item is empty it is omitted, unless the
10375 {keepempty} argument is given and it's non-zero.
10376 Other empty items are kept when {pattern} matches at least one
10377 character or when {keepempty} is non-zero.
10378 Example: >
10379 :let words = split(getline('.'), '\W\+')
10380< To split a string in individual characters: >
10381 :for c in split(mystring, '\zs')
10382< If you want to keep the separator you can also use '\zs' at
10383 the end of the pattern: >
10384 :echo split('abc:def:ghi', ':\zs')
10385< ['abc:', 'def:', 'ghi'] ~
10386 Splitting a table where the first element can be empty: >
10387 :let items = split(line, ':', 1)
10388< The opposite function is |join()|.
10389
10390 Can also be used as a |method|: >
10391 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010392<
10393 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010394
10395sqrt({expr}) *sqrt()*
10396 Return the non-negative square root of Float {expr} as a
10397 |Float|.
10398 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010399 is negative the result is NaN (Not a Number). Returns 0.0 if
10400 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010401 Examples: >
10402 :echo sqrt(100)
10403< 10.0 >
10404 :echo sqrt(-4.01)
10405< nan
10406 "nan" may be different, it depends on system libraries.
10407
10408 Can also be used as a |method|: >
10409 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010410<
10411 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010412
10413
10414srand([{expr}]) *srand()*
10415 Initialize seed used by |rand()|:
10416 - If {expr} is not given, seed values are initialized by
10417 reading from /dev/urandom, if possible, or using time(NULL)
10418 a.k.a. epoch time otherwise; this only has second accuracy.
10419 - If {expr} is given it must be a Number. It is used to
10420 initialize the seed values. This is useful for testing or
10421 when a predictable sequence is intended.
10422
10423 Examples: >
10424 :let seed = srand()
10425 :let seed = srand(userinput)
10426 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010427<
10428 Return type: list<number>
10429
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010430
10431state([{what}]) *state()*
10432 Return a string which contains characters indicating the
10433 current state. Mostly useful in callbacks that want to do
10434 work that may not always be safe. Roughly this works like:
10435 - callback uses state() to check if work is safe to do.
10436 Yes: then do it right away.
10437 No: add to work queue and add a |SafeState| and/or
10438 |SafeStateAgain| autocommand (|SafeState| triggers at
10439 toplevel, |SafeStateAgain| triggers after handling
10440 messages and callbacks).
10441 - When SafeState or SafeStateAgain is triggered and executes
10442 your autocommand, check with `state()` if the work can be
10443 done now, and if yes remove it from the queue and execute.
10444 Remove the autocommand if the queue is now empty.
10445 Also see |mode()|.
10446
10447 When {what} is given only characters in this string will be
10448 added. E.g, this checks if the screen has scrolled: >
10449 if state('s') == ''
10450 " screen has not scrolled
10451<
10452 These characters indicate the state, generally indicating that
10453 something is busy:
10454 m halfway a mapping, :normal command, feedkeys() or
10455 stuffed command
10456 o operator pending, e.g. after |d|
10457 a Insert mode autocomplete active
10458 x executing an autocommand
10459 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10460 ch_readraw() when reading json
10461 S not triggering SafeState or SafeStateAgain, e.g. after
10462 |f| or a count
10463 c callback invoked, including timer (repeats for
10464 recursiveness up to "ccc")
10465 s screen has scrolled for messages
10466
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010467 Return type: |String|
10468
10469
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010470str2float({string} [, {quoted}]) *str2float()*
10471 Convert String {string} to a Float. This mostly works the
10472 same as when using a floating point number in an expression,
10473 see |floating-point-format|. But it's a bit more permissive.
10474 E.g., "1e40" is accepted, while in an expression you need to
10475 write "1.0e40". The hexadecimal form "0x123" is also
10476 accepted, but not others, like binary or octal.
10477 When {quoted} is present and non-zero then embedded single
10478 quotes before the dot are ignored, thus "1'000.0" is a
10479 thousand.
10480 Text after the number is silently ignored.
10481 The decimal point is always '.', no matter what the locale is
10482 set to. A comma ends the number: "12,345.67" is converted to
10483 12.0. You can strip out thousands separators with
10484 |substitute()|: >
10485 let f = str2float(substitute(text, ',', '', 'g'))
10486<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010487 Returns 0.0 if the conversion fails.
10488
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010489 Can also be used as a |method|: >
10490 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010491<
10492 Return type: |Float|
10493
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010494
10495str2list({string} [, {utf8}]) *str2list()*
10496 Return a list containing the number values which represent
10497 each character in String {string}. Examples: >
10498 str2list(" ") returns [32]
10499 str2list("ABC") returns [65, 66, 67]
10500< |list2str()| does the opposite.
10501
10502 When {utf8} is omitted or zero, the current 'encoding' is used.
10503 When {utf8} is TRUE, always treat the String as UTF-8
10504 characters. With UTF-8 composing characters are handled
10505 properly: >
10506 str2list("á") returns [97, 769]
10507
10508< Can also be used as a |method|: >
10509 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010510<
10511 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010512
10513
10514str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10515 Convert string {string} to a number.
10516 {base} is the conversion base, it can be 2, 8, 10 or 16.
10517 When {quoted} is present and non-zero then embedded single
10518 quotes are ignored, thus "1'000'000" is a million.
10519
10520 When {base} is omitted base 10 is used. This also means that
10521 a leading zero doesn't cause octal conversion to be used, as
10522 with the default String to Number conversion. Example: >
10523 let nr = str2nr('0123')
10524<
10525 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10526 different base the result will be zero. Similarly, when
10527 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10528 {base} is 2 a leading "0b" or "0B" is ignored.
10529 Text after the number is silently ignored.
10530
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010531 Returns 0 if {string} is empty or on error.
10532
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010533 Can also be used as a |method|: >
10534 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010535<
10536 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010537
10538
10539strcharlen({string}) *strcharlen()*
10540 The result is a Number, which is the number of characters
10541 in String {string}. Composing characters are ignored.
10542 |strchars()| can count the number of characters, counting
10543 composing characters separately.
10544
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010545 Returns 0 if {string} is empty or on error.
10546
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010547 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10548
10549 Can also be used as a |method|: >
10550 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010551<
10552 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010553
10554
10555strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10556 Like |strpart()| but using character index and length instead
10557 of byte index and length.
10558 When {skipcc} is omitted or zero, composing characters are
10559 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010560 When {skipcc} set to 1, composing characters are treated as a
10561 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010562 When a character index is used where a character does not
10563 exist it is omitted and counted as one character. For
10564 example: >
10565 strcharpart('abc', -1, 2)
10566< results in 'a'.
10567
Bram Moolenaard592deb2022-06-17 15:42:40 +010010568 Returns an empty string on error.
10569
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010570 Can also be used as a |method|: >
10571 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010572<
10573 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010574
10575
10576strchars({string} [, {skipcc}]) *strchars()*
10577 The result is a Number, which is the number of characters
10578 in String {string}.
10579 When {skipcc} is omitted or zero, composing characters are
10580 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010581 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010582 |strcharlen()| always does this.
10583
Bram Moolenaard592deb2022-06-17 15:42:40 +010010584 Returns zero on error.
10585
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010586 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10587
10588 {skipcc} is only available after 7.4.755. For backward
10589 compatibility, you can define a wrapper function: >
10590 if has("patch-7.4.755")
10591 function s:strchars(str, skipcc)
10592 return strchars(a:str, a:skipcc)
10593 endfunction
10594 else
10595 function s:strchars(str, skipcc)
10596 if a:skipcc
10597 return strlen(substitute(a:str, ".", "x", "g"))
10598 else
10599 return strchars(a:str)
10600 endif
10601 endfunction
10602 endif
10603<
10604 Can also be used as a |method|: >
10605 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010606<
10607 Return type: |Number|
10608
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010609
10610strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10611 The result is a Number, which is the number of display cells
10612 String {string} occupies on the screen when it starts at {col}
10613 (first column is zero). When {col} is omitted zero is used.
10614 Otherwise it is the screen column where to start. This
10615 matters for Tab characters.
10616 The option settings of the current window are used. This
10617 matters for anything that's displayed differently, such as
10618 'tabstop' and 'display'.
10619 When {string} contains characters with East Asian Width Class
10620 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010621 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010622 Also see |strlen()|, |strwidth()| and |strchars()|.
10623
10624 Can also be used as a |method|: >
10625 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010626<
10627 Return type: |Number|
10628
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010629
10630strftime({format} [, {time}]) *strftime()*
10631 The result is a String, which is a formatted date and time, as
10632 specified by the {format} string. The given {time} is used,
10633 or the current time if no time is given. The accepted
10634 {format} depends on your system, thus this is not portable!
10635 See the manual page of the C function strftime() for the
10636 format. The maximum length of the result is 80 characters.
10637 See also |localtime()|, |getftime()| and |strptime()|.
10638 The language can be changed with the |:language| command.
10639 Examples: >
10640 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10641 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10642 :echo strftime("%y%m%d %T") 970427 11:53:55
10643 :echo strftime("%H:%M") 11:55
10644 :echo strftime("%c", getftime("file.c"))
10645 Show mod time of file.c.
10646< Not available on all systems. To check use: >
10647 :if exists("*strftime")
10648
10649< Can also be used as a |method|: >
10650 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010651<
10652 Return type: |String|
10653
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010654
10655strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010656 Get a Number corresponding to the character at {index} in
10657 {str}. This uses a zero-based character index, not a byte
10658 index. Composing characters are considered separate
10659 characters here. Use |nr2char()| to convert the Number to a
10660 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010661 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010662 Also see |strcharpart()| and |strchars()|.
10663
10664 Can also be used as a |method|: >
10665 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010666<
10667 Return type: |Number|
10668
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010669
10670stridx({haystack}, {needle} [, {start}]) *stridx()*
10671 The result is a Number, which gives the byte index in
10672 {haystack} of the first occurrence of the String {needle}.
10673 If {start} is specified, the search starts at index {start}.
10674 This can be used to find a second match: >
10675 :let colon1 = stridx(line, ":")
10676 :let colon2 = stridx(line, ":", colon1 + 1)
10677< The search is done case-sensitive.
10678 For pattern searches use |match()|.
10679 -1 is returned if the {needle} does not occur in {haystack}.
10680 See also |strridx()|.
10681 Examples: >
10682 :echo stridx("An Example", "Example") 3
10683 :echo stridx("Starting point", "Start") 0
10684 :echo stridx("Starting point", "start") -1
10685< *strstr()* *strchr()*
10686 stridx() works similar to the C function strstr(). When used
10687 with a single character it works similar to strchr().
10688
10689 Can also be used as a |method|: >
10690 GetHaystack()->stridx(needle)
10691<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010692 Return type: |Number|
10693
10694
10695string({expr}) *string()*
10696 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010697 Float, String, Blob or a composition of them, then the result
10698 can be parsed back with |eval()|.
10699 {expr} type result ~
10700 String 'string' (single quotes are doubled)
10701 Number 123
10702 Float 123.123456 or 1.123456e8
10703 Funcref function('name')
10704 Blob 0z00112233.44556677.8899
10705 List [item, item]
10706 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000010707 Class class SomeName
10708 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010010709 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020010710 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010711
10712 When a |List| or |Dictionary| has a recursive reference it is
10713 replaced by "[...]" or "{...}". Using eval() on the result
10714 will then fail.
10715
mityu7f0bba22024-03-29 10:14:41 +010010716 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010717 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010010718 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010719
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010720 Can also be used as a |method|: >
10721 mylist->string()
10722
10723< Also see |strtrans()|.
10724
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010725 Return type: |String|
10726
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010727
10728strlen({string}) *strlen()*
10729 The result is a Number, which is the length of the String
10730 {string} in bytes.
10731 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010732 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010733 If you want to count the number of multibyte characters use
10734 |strchars()|.
10735 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
10736
10737 Can also be used as a |method|: >
10738 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010739<
10740 Return type: |Number|
10741
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010742
10743strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
10744 The result is a String, which is part of {src}, starting from
10745 byte {start}, with the byte length {len}.
10746 When {chars} is present and TRUE then {len} is the number of
10747 characters positions (composing characters are not counted
10748 separately, thus "1" means one base character and any
10749 following composing characters).
10750 To count {start} as characters instead of bytes use
10751 |strcharpart()|.
10752
10753 When bytes are selected which do not exist, this doesn't
10754 result in an error, the bytes are simply omitted.
10755 If {len} is missing, the copy continues from {start} till the
10756 end of the {src}. >
10757 strpart("abcdefg", 3, 2) == "de"
10758 strpart("abcdefg", -2, 4) == "ab"
10759 strpart("abcdefg", 5, 4) == "fg"
10760 strpart("abcdefg", 3) == "defg"
10761
10762< Note: To get the first character, {start} must be 0. For
10763 example, to get the character under the cursor: >
10764 strpart(getline("."), col(".") - 1, 1, v:true)
10765<
Bram Moolenaard592deb2022-06-17 15:42:40 +010010766 Returns an empty string on error.
10767
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010768 Can also be used as a |method|: >
10769 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010770<
10771 Return type: |String|
10772
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010773
10774strptime({format}, {timestring}) *strptime()*
10775 The result is a Number, which is a unix timestamp representing
10776 the date and time in {timestring}, which is expected to match
10777 the format specified in {format}.
10778
10779 The accepted {format} depends on your system, thus this is not
10780 portable! See the manual page of the C function strptime()
10781 for the format. Especially avoid "%c". The value of $TZ also
10782 matters.
10783
10784 If the {timestring} cannot be parsed with {format} zero is
10785 returned. If you do not know the format of {timestring} you
10786 can try different {format} values until you get a non-zero
10787 result.
10788
10789 See also |strftime()|.
10790 Examples: >
10791 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
10792< 862156163 >
10793 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
10794< Sun Apr 27 11:53:55 1997 >
10795 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
10796< Sun Apr 27 12:53:55 1997
10797
10798 Can also be used as a |method|: >
10799 GetFormat()->strptime(timestring)
10800<
10801 Not available on all systems. To check use: >
10802 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010803<
10804 Return type: |Number|
10805
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010806
10807strridx({haystack}, {needle} [, {start}]) *strridx()*
10808 The result is a Number, which gives the byte index in
10809 {haystack} of the last occurrence of the String {needle}.
10810 When {start} is specified, matches beyond this index are
10811 ignored. This can be used to find a match before a previous
10812 match: >
10813 :let lastcomma = strridx(line, ",")
10814 :let comma2 = strridx(line, ",", lastcomma - 1)
10815< The search is done case-sensitive.
10816 For pattern searches use |match()|.
10817 -1 is returned if the {needle} does not occur in {haystack}.
10818 If the {needle} is empty the length of {haystack} is returned.
10819 See also |stridx()|. Examples: >
10820 :echo strridx("an angry armadillo", "an") 3
10821< *strrchr()*
10822 When used with a single character it works similar to the C
10823 function strrchr().
10824
10825 Can also be used as a |method|: >
10826 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010827<
10828 Return type: |Number|
10829
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010830
10831strtrans({string}) *strtrans()*
10832 The result is a String, which is {string} with all unprintable
10833 characters translated into printable characters |'isprint'|.
10834 Like they are shown in a window. Example: >
10835 echo strtrans(@a)
10836< This displays a newline in register a as "^@" instead of
10837 starting a new line.
10838
Bram Moolenaard592deb2022-06-17 15:42:40 +010010839 Returns an empty string on error.
10840
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010841 Can also be used as a |method|: >
10842 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010843<
10844 Return type: |String|
10845
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010846
Christian Brabandt67672ef2023-04-24 21:09:54 +010010847strutf16len({string} [, {countcc}]) *strutf16len()*
10848 The result is a Number, which is the number of UTF-16 code
10849 units in String {string} (after converting it to UTF-16).
10850
10851 When {countcc} is TRUE, composing characters are counted
10852 separately.
10853 When {countcc} is omitted or FALSE, composing characters are
10854 ignored.
10855
10856 Returns zero on error.
10857
10858 Also see |strlen()| and |strcharlen()|.
10859 Examples: >
10860 echo strutf16len('a') returns 1
10861 echo strutf16len('©') returns 1
10862 echo strutf16len('😊') returns 2
10863 echo strutf16len('ą́') returns 1
10864 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090010865<
Christian Brabandt67672ef2023-04-24 21:09:54 +010010866 Can also be used as a |method|: >
10867 GetText()->strutf16len()
10868<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010869 Return type: |Number|
10870
10871
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010872strwidth({string}) *strwidth()*
10873 The result is a Number, which is the number of display cells
10874 String {string} occupies. A Tab character is counted as one
10875 cell, alternatively use |strdisplaywidth()|.
10876 When {string} contains characters with East Asian Width Class
10877 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010878 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010879 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
10880
10881 Can also be used as a |method|: >
10882 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010883<
10884 Return type: |Number|
10885
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010886
10887submatch({nr} [, {list}]) *submatch()* *E935*
10888 Only for an expression in a |:substitute| command or
10889 substitute() function.
10890 Returns the {nr}'th submatch of the matched text. When {nr}
10891 is 0 the whole matched text is returned.
10892 Note that a NL in the string can stand for a line break of a
10893 multi-line match or a NUL character in the text.
10894 Also see |sub-replace-expression|.
10895
10896 If {list} is present and non-zero then submatch() returns
10897 a list of strings, similar to |getline()| with two arguments.
10898 NL characters in the text represent NUL characters in the
10899 text.
10900 Only returns more than one item for |:substitute|, inside
10901 |substitute()| this list will always contain one or zero
10902 items, since there are no real line breaks.
10903
10904 When substitute() is used recursively only the submatches in
10905 the current (deepest) call can be obtained.
10906
Bram Moolenaard592deb2022-06-17 15:42:40 +010010907 Returns an empty string or list on error.
10908
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010909 Examples: >
10910 :s/\d\+/\=submatch(0) + 1/
10911 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
10912< This finds the first number in the line and adds one to it.
10913 A line break is included as a newline character.
10914
10915 Can also be used as a |method|: >
10916 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010917<
10918 Return type: |String| or list<string> depending on {list}
10919
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010920
10921substitute({string}, {pat}, {sub}, {flags}) *substitute()*
10922 The result is a String, which is a copy of {string}, in which
10923 the first match of {pat} is replaced with {sub}.
10924 When {flags} is "g", all matches of {pat} in {string} are
10925 replaced. Otherwise {flags} should be "".
10926
10927 This works like the ":substitute" command (without any flags).
10928 But the matching with {pat} is always done like the 'magic'
10929 option is set and 'cpoptions' is empty (to make scripts
10930 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
10931 if you want to ignore or match case and ignore 'ignorecase'.
10932 'smartcase' is not used. See |string-match| for how {pat} is
10933 used.
10934
10935 A "~" in {sub} is not replaced with the previous {sub}.
10936 Note that some codes in {sub} have a special meaning
10937 |sub-replace-special|. For example, to replace something with
10938 "\n" (two characters), use "\\\\n" or '\\n'.
10939
10940 When {pat} does not match in {string}, {string} is returned
10941 unmodified.
10942
10943 Example: >
10944 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
10945< This removes the last component of the 'path' option. >
10946 :echo substitute("testing", ".*", "\\U\\0", "")
10947< results in "TESTING".
10948
10949 When {sub} starts with "\=", the remainder is interpreted as
10950 an expression. See |sub-replace-expression|. Example: >
10951 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010952 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010953
10954< When {sub} is a Funcref that function is called, with one
10955 optional argument. Example: >
10956 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
10957< The optional argument is a list which contains the whole
10958 matched string and up to nine submatches, like what
10959 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010960 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010961
Bram Moolenaard592deb2022-06-17 15:42:40 +010010962< Returns an empty string on error.
10963
10964 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010965 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010966<
10967 Return type: |String|
10968
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010969
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000010970swapfilelist() *swapfilelist()*
10971 Returns a list of swap file names, like what "vim -r" shows.
10972 See the |-r| command argument. The 'directory' option is used
10973 for the directories to inspect. If you only want to get a
10974 list of swap files in the current directory then temporarily
10975 set 'directory' to a dot: >
10976 let save_dir = &directory
10977 let &directory = '.'
10978 let swapfiles = swapfilelist()
10979 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010980<
10981 Return type: list<string>
10982
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000010983
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010984swapinfo({fname}) *swapinfo()*
10985 The result is a dictionary, which holds information about the
10986 swapfile {fname}. The available fields are:
10987 version Vim version
10988 user user name
10989 host host name
10990 fname original file name
10991 pid PID of the Vim process that created the swap
10992 file
10993 mtime last modification time in seconds
10994 inode Optional: INODE number of the file
10995 dirty 1 if file was modified, 0 if not
10996 Note that "user" and "host" are truncated to at most 39 bytes.
10997 In case of failure an "error" item is added with the reason:
10998 Cannot open file: file not found or in accessible
10999 Cannot read file: cannot read first block
11000 Not a swap file: does not contain correct block ID
11001 Magic number mismatch: Info in first block is invalid
11002
11003 Can also be used as a |method|: >
11004 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011005<
11006 Return type: dict<any> or dict<string>
11007
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011008
11009swapname({buf}) *swapname()*
11010 The result is the swap file path of the buffer {expr}.
11011 For the use of {buf}, see |bufname()| above.
11012 If buffer {buf} is the current buffer, the result is equal to
11013 |:swapname| (unless there is no swap file).
11014 If buffer {buf} has no swap file, returns an empty string.
11015
11016 Can also be used as a |method|: >
11017 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011018<
11019 Return type: |String|
11020
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011021
11022synID({lnum}, {col}, {trans}) *synID()*
11023 The result is a Number, which is the syntax ID at the position
11024 {lnum} and {col} in the current window.
11025 The syntax ID can be used with |synIDattr()| and
11026 |synIDtrans()| to obtain syntax information about text.
11027
11028 {col} is 1 for the leftmost column, {lnum} is 1 for the first
11029 line. 'synmaxcol' applies, in a longer line zero is returned.
11030 Note that when the position is after the last character,
11031 that's where the cursor can be in Insert mode, synID() returns
11032 zero. {lnum} is used like with |getline()|.
11033
11034 When {trans} is |TRUE|, transparent items are reduced to the
11035 item that they reveal. This is useful when wanting to know
11036 the effective color. When {trans} is |FALSE|, the transparent
11037 item is returned. This is useful when wanting to know which
11038 syntax item is effective (e.g. inside parens).
11039 Warning: This function can be very slow. Best speed is
11040 obtained by going through the file in forward direction.
11041
Bram Moolenaard592deb2022-06-17 15:42:40 +010011042 Returns zero on error.
11043
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011044 Example (echoes the name of the syntax item under the cursor): >
11045 :echo synIDattr(synID(line("."), col("."), 1), "name")
11046<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011047 Return type: |Number|
11048
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011049
11050synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
11051 The result is a String, which is the {what} attribute of
11052 syntax ID {synID}. This can be used to obtain information
11053 about a syntax item.
11054 {mode} can be "gui", "cterm" or "term", to get the attributes
11055 for that mode. When {mode} is omitted, or an invalid value is
11056 used, the attributes for the currently active highlighting are
11057 used (GUI, cterm or term).
11058 Use synIDtrans() to follow linked highlight groups.
11059 {what} result
11060 "name" the name of the syntax item
11061 "fg" foreground color (GUI: color name used to set
11062 the color, cterm: color number as a string,
11063 term: empty string)
11064 "bg" background color (as with "fg")
11065 "font" font name (only available in the GUI)
11066 |highlight-font|
11067 "sp" special color for the GUI (as with "fg")
11068 |highlight-guisp|
11069 "ul" underline color for cterm: number as a string
11070 "fg#" like "fg", but for the GUI and the GUI is
11071 running the name in "#RRGGBB" form
11072 "bg#" like "fg#" for "bg"
11073 "sp#" like "fg#" for "sp"
11074 "bold" "1" if bold
11075 "italic" "1" if italic
11076 "reverse" "1" if reverse
11077 "inverse" "1" if inverse (= reverse)
11078 "standout" "1" if standout
11079 "underline" "1" if underlined
11080 "undercurl" "1" if undercurled
11081 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010011082 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011083
Bram Moolenaard592deb2022-06-17 15:42:40 +010011084 Returns an empty string on error.
11085
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011086 Example (echoes the color of the syntax item under the
11087 cursor): >
11088 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
11089<
11090 Can also be used as a |method|: >
11091 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011092<
11093 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011094
11095
11096synIDtrans({synID}) *synIDtrans()*
11097 The result is a Number, which is the translated syntax ID of
11098 {synID}. This is the syntax group ID of what is being used to
11099 highlight the character. Highlight links given with
11100 ":highlight link" are followed.
11101
Bram Moolenaard592deb2022-06-17 15:42:40 +010011102 Returns zero on error.
11103
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011104 Can also be used as a |method|: >
11105 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011106<
11107 Return type: |Number|
11108
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011109
11110synconcealed({lnum}, {col}) *synconcealed()*
11111 The result is a |List| with currently three items:
11112 1. The first item in the list is 0 if the character at the
11113 position {lnum} and {col} is not part of a concealable
11114 region, 1 if it is. {lnum} is used like with |getline()|.
11115 2. The second item in the list is a string. If the first item
11116 is 1, the second item contains the text which will be
11117 displayed in place of the concealed text, depending on the
11118 current setting of 'conceallevel' and 'listchars'.
11119 3. The third and final item in the list is a number
11120 representing the specific syntax region matched in the
11121 line. When the character is not concealed the value is
11122 zero. This allows detection of the beginning of a new
11123 concealable region if there are two consecutive regions
11124 with the same replacement character. For an example, if
11125 the text is "123456" and both "23" and "45" are concealed
11126 and replaced by the character "X", then:
11127 call returns ~
11128 synconcealed(lnum, 1) [0, '', 0]
11129 synconcealed(lnum, 2) [1, 'X', 1]
11130 synconcealed(lnum, 3) [1, 'X', 1]
11131 synconcealed(lnum, 4) [1, 'X', 2]
11132 synconcealed(lnum, 5) [1, 'X', 2]
11133 synconcealed(lnum, 6) [0, '', 0]
11134
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011135 Note: Doesn't consider |matchadd()| highlighting items,
11136 since syntax and matching highlighting are two different
11137 mechanisms |syntax-vs-match|.
h-east52e7cc22024-07-28 17:03:29 +020011138
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011139 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011140
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011141
11142synstack({lnum}, {col}) *synstack()*
11143 Return a |List|, which is the stack of syntax items at the
11144 position {lnum} and {col} in the current window. {lnum} is
11145 used like with |getline()|. Each item in the List is an ID
11146 like what |synID()| returns.
11147 The first item in the List is the outer region, following are
11148 items contained in that one. The last one is what |synID()|
11149 returns, unless not the whole item is highlighted or it is a
11150 transparent item.
11151 This function is useful for debugging a syntax file.
11152 Example that shows the syntax stack under the cursor: >
11153 for id in synstack(line("."), col("."))
11154 echo synIDattr(id, "name")
11155 endfor
11156< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011157 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011158 character in a line and the first column in an empty line are
11159 valid positions.
11160
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011161 Return type: list<number> or list<any>
11162
11163
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011164system({expr} [, {input}]) *system()* *E677*
11165 Get the output of the shell command {expr} as a |String|. See
11166 |systemlist()| to get the output as a |List|.
11167
11168 When {input} is given and is a |String| this string is written
11169 to a file and passed as stdin to the command. The string is
11170 written as-is, you need to take care of using the correct line
11171 separators yourself.
11172 If {input} is given and is a |List| it is written to the file
11173 in a way |writefile()| does with {binary} set to "b" (i.e.
11174 with a newline between each list item with newlines inside
11175 list items converted to NULs).
11176 When {input} is given and is a number that is a valid id for
11177 an existing buffer then the content of the buffer is written
11178 to the file line by line, each line terminated by a NL and
11179 NULs characters where the text has a NL.
11180
11181 Pipes are not used, the 'shelltemp' option is not used.
11182
11183 When prepended by |:silent| the terminal will not be set to
11184 cooked mode. This is meant to be used for commands that do
11185 not need the user to type. It avoids stray characters showing
11186 up on the screen which require |CTRL-L| to remove. >
11187 :silent let f = system('ls *.vim')
11188<
11189 Note: Use |shellescape()| or |::S| with |expand()| or
11190 |fnamemodify()| to escape special characters in a command
11191 argument. Newlines in {expr} may cause the command to fail.
11192 The characters in 'shellquote' and 'shellxquote' may also
11193 cause trouble.
11194 This is not to be used for interactive commands.
11195
11196 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011197 :let files = system('ls ' .. shellescape(expand('%:h')))
11198 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011199
11200< To make the result more system-independent, the shell output
11201 is filtered to replace <CR> with <NL> for Macintosh, and
11202 <CR><NL> with <NL> for DOS-like systems.
11203 To avoid the string being truncated at a NUL, all NUL
11204 characters are replaced with SOH (0x01).
11205
11206 The command executed is constructed using several options:
11207 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11208 ({tmp} is an automatically generated file name).
11209 For Unix, braces are put around {expr} to allow for
11210 concatenated commands.
11211
11212 The command will be executed in "cooked" mode, so that a
11213 CTRL-C will interrupt the command (on Unix at least).
11214
11215 The resulting error code can be found in |v:shell_error|.
11216 This function will fail in |restricted-mode|.
11217
11218 Note that any wrong value in the options mentioned above may
11219 make the function fail. It has also been reported to fail
11220 when using a security agent application.
11221 Unlike ":!cmd" there is no automatic check for changed files.
11222 Use |:checktime| to force a check.
11223
11224 Can also be used as a |method|: >
11225 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011226<
11227 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011228
11229
11230systemlist({expr} [, {input}]) *systemlist()*
11231 Same as |system()|, but returns a |List| with lines (parts of
11232 output separated by NL) with NULs transformed into NLs. Output
11233 is the same as |readfile()| will output with {binary} argument
11234 set to "b", except that there is no extra empty item when the
11235 result ends in a NL.
11236 Note that on MS-Windows you may get trailing CR characters.
11237
11238 To see the difference between "echo hello" and "echo -n hello"
11239 use |system()| and |split()|: >
11240 echo system('echo hello')->split('\n', 1)
11241<
11242 Returns an empty string on error.
11243
11244 Can also be used as a |method|: >
11245 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011246<
11247 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011248
11249
11250tabpagebuflist([{arg}]) *tabpagebuflist()*
11251 The result is a |List|, where each item is the number of the
11252 buffer associated with each window in the current tab page.
11253 {arg} specifies the number of the tab page to be used. When
11254 omitted the current tab page is used.
11255 When {arg} is invalid the number zero is returned.
11256 To get a list of all buffers in all tabs use this: >
11257 let buflist = []
11258 for i in range(tabpagenr('$'))
11259 call extend(buflist, tabpagebuflist(i + 1))
11260 endfor
11261< Note that a buffer may appear in more than one window.
11262
11263 Can also be used as a |method|: >
11264 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011265<
11266 Return type: list<number>
11267
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011268
11269tabpagenr([{arg}]) *tabpagenr()*
11270 The result is a Number, which is the number of the current
11271 tab page. The first tab page has number 1.
11272
11273 The optional argument {arg} supports the following values:
11274 $ the number of the last tab page (the tab page
11275 count).
11276 # the number of the last accessed tab page
11277 (where |g<Tab>| goes to). if there is no
11278 previous tab page 0 is returned.
11279 The number can be used with the |:tab| command.
11280
Bram Moolenaard592deb2022-06-17 15:42:40 +010011281 Returns zero on error.
11282
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011283 Return type: |Number|
11284
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011285
11286tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11287 Like |winnr()| but for tab page {tabarg}.
11288 {tabarg} specifies the number of tab page to be used.
11289 {arg} is used like with |winnr()|:
11290 - When omitted the current window number is returned. This is
11291 the window which will be used when going to this tab page.
11292 - When "$" the number of windows is returned.
11293 - When "#" the previous window nr is returned.
11294 Useful examples: >
11295 tabpagewinnr(1) " current window of tab page 1
11296 tabpagewinnr(4, '$') " number of windows in tab page 4
11297< When {tabarg} is invalid zero is returned.
11298
11299 Can also be used as a |method|: >
11300 GetTabpage()->tabpagewinnr()
11301<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011302 Return type: |Number|
11303
11304
11305tagfiles() *tagfiles()*
11306 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011307 for the current buffer. This is the 'tags' option expanded.
11308
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011309 Return type: list<string> or list<any>
11310
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011311
11312taglist({expr} [, {filename}]) *taglist()*
11313 Returns a |List| of tags matching the regular expression {expr}.
11314
11315 If {filename} is passed it is used to prioritize the results
11316 in the same way that |:tselect| does. See |tag-priority|.
11317 {filename} should be the full path of the file.
11318
11319 Each list item is a dictionary with at least the following
11320 entries:
11321 name Name of the tag.
11322 filename Name of the file where the tag is
11323 defined. It is either relative to the
11324 current directory or a full path.
11325 cmd Ex command used to locate the tag in
11326 the file.
11327 kind Type of the tag. The value for this
11328 entry depends on the language specific
11329 kind values. Only available when
11330 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011331 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011332 static A file specific tag. Refer to
11333 |static-tag| for more information.
11334 More entries may be present, depending on the content of the
11335 tags file: access, implementation, inherits and signature.
11336 Refer to the ctags documentation for information about these
11337 fields. For C code the fields "struct", "class" and "enum"
11338 may appear, they give the name of the entity the tag is
11339 contained in.
11340
11341 The ex-command "cmd" can be either an ex search pattern, a
11342 line number or a line number followed by a byte number.
11343
11344 If there are no matching tags, then an empty list is returned.
11345
11346 To get an exact tag match, the anchors '^' and '$' should be
11347 used in {expr}. This also make the function work faster.
11348 Refer to |tag-regexp| for more information about the tag
11349 search regular expression pattern.
11350
11351 Refer to |'tags'| for information about how the tags file is
11352 located by Vim. Refer to |tags-file-format| for the format of
11353 the tags file generated by the different ctags tools.
11354
11355 Can also be used as a |method|: >
11356 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011357<
11358 Return type: list<dict<any>> or list<any>
11359
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011360
11361tan({expr}) *tan()*
11362 Return the tangent of {expr}, measured in radians, as a |Float|
11363 in the range [-inf, inf].
11364 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011365 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011366 Examples: >
11367 :echo tan(10)
11368< 0.648361 >
11369 :echo tan(-4.01)
11370< -1.181502
11371
11372 Can also be used as a |method|: >
11373 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011374<
11375 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011376
11377
11378tanh({expr}) *tanh()*
11379 Return the hyperbolic tangent of {expr} as a |Float| in the
11380 range [-1, 1].
11381 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011382 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011383 Examples: >
11384 :echo tanh(0.5)
11385< 0.462117 >
11386 :echo tanh(-1)
11387< -0.761594
11388
11389 Can also be used as a |method|: >
11390 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011391<
11392 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011393
11394
11395tempname() *tempname()* *temp-file-name*
11396 The result is a String, which is the name of a file that
11397 doesn't exist. It can be used for a temporary file. The name
11398 is different for at least 26 consecutive calls. Example: >
11399 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011400 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011401< For Unix, the file will be in a private directory |tempfile|
11402 that is recursively deleted when Vim exits, on other systems
11403 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011404 For MS-Windows forward slashes are used when the 'shellslash'
11405 option is set, or when 'shellcmdflag' starts with '-' and
11406 'shell' does not contain powershell or pwsh.
11407
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011408 Return type: |String|
11409
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011410
11411term_ functions are documented here: |terminal-function-details|
11412
11413
11414terminalprops() *terminalprops()*
11415 Returns a |Dictionary| with properties of the terminal that Vim
11416 detected from the response to |t_RV| request. See
11417 |v:termresponse| for the response itself. If |v:termresponse|
11418 is empty most values here will be 'u' for unknown.
11419 cursor_style whether sending |t_RS| works **
11420 cursor_blink_mode whether sending |t_RC| works **
11421 underline_rgb whether |t_8u| works **
11422 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011423 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011424
11425 ** value 'u' for unknown, 'y' for yes, 'n' for no
11426
11427 If the |+termresponse| feature is missing then the result is
11428 an empty dictionary.
11429
11430 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11431 current cursor style.
11432 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11433 request the cursor blink status.
11434 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11435 is not empty, Vim will detect the working of sending |t_RS|
11436 and |t_RC| on startup.
11437
11438 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11439 This avoids sending it to xterm, which would clear the colors.
11440
11441 For "mouse" the value 'u' is unknown
11442
11443 Also see:
11444 - 'ambiwidth' - detected by using |t_u7|.
11445 - |v:termstyleresp| and |v:termblinkresp| for the response to
11446 |t_RS| and |t_RC|.
11447
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011448 Return type: dict<string>
11449
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011450
11451test_ functions are documented here: |test-functions-details|
11452
11453
11454 *timer_info()*
11455timer_info([{id}])
11456 Return a list with information about timers.
11457 When {id} is given only information about this timer is
11458 returned. When timer {id} does not exist an empty list is
11459 returned.
11460 When {id} is omitted information about all timers is returned.
11461
11462 For each timer the information is stored in a |Dictionary| with
11463 these items:
11464 "id" the timer ID
11465 "time" time the timer was started with
11466 "remaining" time until the timer fires
11467 "repeat" number of times the timer will still fire;
11468 -1 means forever
11469 "callback" the callback
11470 "paused" 1 if the timer is paused, 0 otherwise
11471
11472 Can also be used as a |method|: >
11473 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011474<
11475 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011476
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011477 {only available when compiled with the |+timers| feature}
11478
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011479
11480timer_pause({timer}, {paused}) *timer_pause()*
11481 Pause or unpause a timer. A paused timer does not invoke its
11482 callback when its time expires. Unpausing a timer may cause
11483 the callback to be invoked almost immediately if enough time
11484 has passed.
11485
11486 Pausing a timer is useful to avoid the callback to be called
11487 for a short time.
11488
11489 If {paused} evaluates to a non-zero Number or a non-empty
11490 String, then the timer is paused, otherwise it is unpaused.
11491 See |non-zero-arg|.
11492
11493 Can also be used as a |method|: >
11494 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011495<
11496 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011497
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011498 {only available when compiled with the |+timers| feature}
11499
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011500
11501 *timer_start()* *timer* *timers*
11502timer_start({time}, {callback} [, {options}])
11503 Create a timer and return the timer ID.
11504
11505 {time} is the waiting time in milliseconds. This is the
11506 minimum time before invoking the callback. When the system is
11507 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011508 Zero can be used to execute the callback when Vim is back in
11509 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011510
11511 {callback} is the function to call. It can be the name of a
11512 function or a |Funcref|. It is called with one argument, which
11513 is the timer ID. The callback is only invoked when Vim is
11514 waiting for input.
11515 If you want to show a message look at |popup_notification()|
11516 to avoid interfering with what the user is doing.
11517
11518 {options} is a dictionary. Supported entries:
11519 "repeat" Number of times to repeat calling the
11520 callback. -1 means forever. When not present
11521 the callback will be called once.
11522 If the timer causes an error three times in a
11523 row the repeat is cancelled. This avoids that
11524 Vim becomes unusable because of all the error
11525 messages.
11526
Bram Moolenaard592deb2022-06-17 15:42:40 +010011527 Returns -1 on error.
11528
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011529 Example: >
11530 func MyHandler(timer)
11531 echo 'Handler called'
11532 endfunc
11533 let timer = timer_start(500, 'MyHandler',
11534 \ {'repeat': 3})
11535< This will invoke MyHandler() three times at 500 msec
11536 intervals.
11537
11538 Can also be used as a |method|: >
11539 GetMsec()->timer_start(callback)
11540
11541< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011542
11543 Return type: |Number|
11544
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011545 {only available when compiled with the |+timers| feature}
11546
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011547
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011548timer_stop({timer}) *timer_stop()*
11549 Stop a timer. The timer callback will no longer be invoked.
11550 {timer} is an ID returned by timer_start(), thus it must be a
11551 Number. If {timer} does not exist there is no error.
11552
11553 Can also be used as a |method|: >
11554 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011555<
11556 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011557
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011558 {only available when compiled with the |+timers| feature}
11559
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011560
11561timer_stopall() *timer_stopall()*
11562 Stop all timers. The timer callbacks will no longer be
11563 invoked. Useful if a timer is misbehaving. If there are no
11564 timers there is no error.
11565
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011566 Return type: |Number|
11567
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011568 {only available when compiled with the |+timers| feature}
11569
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011570
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011571tolower({expr}) *tolower()*
11572 The result is a copy of the String given, with all uppercase
11573 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011574 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011575
11576 Can also be used as a |method|: >
11577 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011578<
11579 Return type: |String|
11580
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011581
11582toupper({expr}) *toupper()*
11583 The result is a copy of the String given, with all lowercase
11584 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011585 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011586
11587 Can also be used as a |method|: >
11588 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011589<
11590 Return type: |String|
11591
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011592
11593tr({src}, {fromstr}, {tostr}) *tr()*
11594 The result is a copy of the {src} string with all characters
11595 which appear in {fromstr} replaced by the character in that
11596 position in the {tostr} string. Thus the first character in
11597 {fromstr} is translated into the first character in {tostr}
11598 and so on. Exactly like the unix "tr" command.
11599 This code also deals with multibyte characters properly.
11600
Bram Moolenaard592deb2022-06-17 15:42:40 +010011601 Returns an empty string on error.
11602
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011603 Examples: >
11604 echo tr("hello there", "ht", "HT")
11605< returns "Hello THere" >
11606 echo tr("<blob>", "<>", "{}")
11607< returns "{blob}"
11608
11609 Can also be used as a |method|: >
11610 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011611<
11612 Return type: |String|
11613
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011614
11615trim({text} [, {mask} [, {dir}]]) *trim()*
11616 Return {text} as a String where any character in {mask} is
11617 removed from the beginning and/or end of {text}.
11618
Illia Bobyr80799172023-10-17 18:00:50 +020011619 If {mask} is not given, or is an empty string, {mask} is all
11620 characters up to 0x20, which includes Tab, space, NL and CR,
11621 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011622
11623 The optional {dir} argument specifies where to remove the
11624 characters:
11625 0 remove from the beginning and end of {text}
11626 1 remove only at the beginning of {text}
11627 2 remove only at the end of {text}
11628 When omitted both ends are trimmed.
11629
11630 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011631 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011632
11633 Examples: >
11634 echo trim(" some text ")
11635< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011636 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011637< returns "RESERVE_TAIL" >
11638 echo trim("rm<Xrm<>X>rrm", "rm<>")
11639< returns "Xrm<>X" (characters in the middle are not removed) >
11640 echo trim(" vim ", " ", 2)
11641< returns " vim"
11642
11643 Can also be used as a |method|: >
11644 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011645<
11646 Return type: |String|
11647
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011648
11649trunc({expr}) *trunc()*
11650 Return the largest integral value with magnitude less than or
11651 equal to {expr} as a |Float| (truncate towards zero).
11652 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011653 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011654 Examples: >
11655 echo trunc(1.456)
11656< 1.0 >
11657 echo trunc(-5.456)
11658< -5.0 >
11659 echo trunc(4.0)
11660< 4.0
11661
11662 Can also be used as a |method|: >
11663 Compute()->trunc()
11664<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011665 Return type: |Float|
11666
11667
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011668 *type()*
11669type({expr}) The result is a Number representing the type of {expr}.
11670 Instead of using the number directly, it is better to use the
11671 v:t_ variable that has the value:
11672 Number: 0 |v:t_number|
11673 String: 1 |v:t_string|
11674 Funcref: 2 |v:t_func|
11675 List: 3 |v:t_list|
11676 Dictionary: 4 |v:t_dict|
11677 Float: 5 |v:t_float|
11678 Boolean: 6 |v:t_bool| (v:false and v:true)
11679 None: 7 |v:t_none| (v:null and v:none)
11680 Job: 8 |v:t_job|
11681 Channel: 9 |v:t_channel|
11682 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090011683 Class: 12 |v:t_class|
11684 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010011685 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011686 Enum: 15 |v:t_enum|
11687 EnumValue: 16 |v:t_enumvalue|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011688 For backward compatibility, this method can be used: >
11689 :if type(myvar) == type(0)
11690 :if type(myvar) == type("")
11691 :if type(myvar) == type(function("tr"))
11692 :if type(myvar) == type([])
11693 :if type(myvar) == type({})
11694 :if type(myvar) == type(0.0)
11695 :if type(myvar) == type(v:false)
11696 :if type(myvar) == type(v:none)
11697< To check if the v:t_ variables exist use this: >
11698 :if exists('v:t_number')
11699
11700< Can also be used as a |method|: >
11701 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011702<
11703 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011704
11705
11706typename({expr}) *typename()*
11707 Return a string representation of the type of {expr}.
11708 Example: >
11709 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000011710< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011711
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011712 Return type: |String|
11713
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011714
11715undofile({name}) *undofile()*
11716 Return the name of the undo file that would be used for a file
11717 with name {name} when writing. This uses the 'undodir'
11718 option, finding directories that exist. It does not check if
11719 the undo file exists.
11720 {name} is always expanded to the full path, since that is what
11721 is used internally.
11722 If {name} is empty undofile() returns an empty string, since a
11723 buffer without a file name will not write an undo file.
11724 Useful in combination with |:wundo| and |:rundo|.
11725 When compiled without the |+persistent_undo| option this always
11726 returns an empty string.
11727
11728 Can also be used as a |method|: >
11729 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011730<
11731 Return type: |String|
11732
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011733
Devin J. Pohly5fee1112023-04-23 20:26:59 -050011734undotree([{buf}]) *undotree()*
11735 Return the current state of the undo tree for the current
11736 buffer, or for a specific buffer if {buf} is given. The
11737 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011738 "seq_last" The highest undo sequence number used.
11739 "seq_cur" The sequence number of the current position in
11740 the undo tree. This differs from "seq_last"
11741 when some changes were undone.
11742 "time_cur" Time last used for |:earlier| and related
11743 commands. Use |strftime()| to convert to
11744 something readable.
11745 "save_last" Number of the last file write. Zero when no
11746 write yet.
11747 "save_cur" Number of the current position in the undo
11748 tree.
11749 "synced" Non-zero when the last undo block was synced.
11750 This happens when waiting from input from the
11751 user. See |undo-blocks|.
11752 "entries" A list of dictionaries with information about
11753 undo blocks.
11754
11755 The first item in the "entries" list is the oldest undo item.
11756 Each List item is a |Dictionary| with these items:
11757 "seq" Undo sequence number. Same as what appears in
11758 |:undolist|.
11759 "time" Timestamp when the change happened. Use
11760 |strftime()| to convert to something readable.
11761 "newhead" Only appears in the item that is the last one
11762 that was added. This marks the last change
11763 and where further changes will be added.
11764 "curhead" Only appears in the item that is the last one
11765 that was undone. This marks the current
11766 position in the undo tree, the block that will
11767 be used by a redo command. When nothing was
11768 undone after the last change this item will
11769 not appear anywhere.
11770 "save" Only appears on the last block before a file
11771 write. The number is the write count. The
11772 first write has number 1, the last one the
11773 "save_last" mentioned above.
11774 "alt" Alternate entry. This is again a List of undo
11775 blocks. Each item may again have an "alt"
11776 item.
11777
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011778 Return type: dict<any>
11779
11780
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011781uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
11782 Remove second and succeeding copies of repeated adjacent
11783 {list} items in-place. Returns {list}. If you want a list
11784 to remain unmodified make a copy first: >
11785 :let newlist = uniq(copy(mylist))
11786< The default compare function uses the string representation of
11787 each item. For the use of {func} and {dict} see |sort()|.
11788
Bram Moolenaard592deb2022-06-17 15:42:40 +010011789 Returns zero if {list} is not a |List|.
11790
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011791 Can also be used as a |method|: >
11792 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010011793<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011794 Return type: list<{type}>
11795
11796
Christian Brabandt67672ef2023-04-24 21:09:54 +010011797 *utf16idx()*
11798utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011799 Same as |charidx()| but returns the UTF-16 code unit index of
11800 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010011801
11802 When {charidx} is present and TRUE, {idx} is used as the
11803 character index in the String {string} instead of as the byte
11804 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010011805 An {idx} in the middle of a UTF-8 sequence is rounded
11806 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010011807
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011808 Returns -1 if the arguments are invalid or if there are less
11809 than {idx} bytes in {string}. If there are exactly {idx} bytes
11810 the length of the string in UTF-16 code units is returned.
11811
Christian Brabandt67672ef2023-04-24 21:09:54 +010011812 See |byteidx()| and |byteidxcomp()| for getting the byte index
11813 from the UTF-16 index and |charidx()| for getting the
11814 character index from the UTF-16 index.
11815 Refer to |string-offset-encoding| for more information.
11816 Examples: >
11817 echo utf16idx('a😊😊', 3) returns 2
11818 echo utf16idx('a😊😊', 7) returns 4
11819 echo utf16idx('a😊😊', 1, 0, 1) returns 2
11820 echo utf16idx('a😊😊', 2, 0, 1) returns 4
11821 echo utf16idx('aą́c', 6) returns 2
11822 echo utf16idx('aą́c', 6, 1) returns 4
11823 echo utf16idx('a😊😊', 9) returns -1
11824<
11825 Can also be used as a |method|: >
11826 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011827<
11828 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010011829
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011830
11831values({dict}) *values()*
11832 Return a |List| with all the values of {dict}. The |List| is
11833 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011834 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011835
11836 Can also be used as a |method|: >
11837 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011838<
11839 Return type: list<any>
11840
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011841
zeertzjq825cf812023-08-17 22:55:25 +020011842virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011843 The result is a Number, which is the screen column of the file
11844 position given with {expr}. That is, the last screen position
11845 occupied by the character at that position, when the screen
11846 would be of unlimited width. When there is a <Tab> at the
11847 position, the returned Number will be the column at the end of
11848 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
11849 set to 8, it returns 8. |conceal| is ignored.
11850 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011851
zeertzjq02f3eba2024-06-12 20:45:24 +020011852 For the use of {expr} see |getpos()| and |col()|.
zeertzjqd353d272024-06-13 23:00:25 +080011853 When {expr} is "$", it means the end of the cursor line, so
11854 the result is the number of cells in the cursor line plus one.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011855
11856 When 'virtualedit' is used {expr} can be [lnum, col, off],
11857 where "off" is the offset in screen columns from the start of
11858 the character. E.g., a position within a <Tab> or after the
11859 last character. When "off" is omitted zero is used. When
11860 Virtual editing is active in the current mode, a position
11861 beyond the end of the line can be returned. Also see
11862 |'virtualedit'|
11863
zeertzjq825cf812023-08-17 22:55:25 +020011864 If {list} is present and non-zero then virtcol() returns a
11865 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010011866 character.
11867
zeertzjq825cf812023-08-17 22:55:25 +020011868 With the optional {winid} argument the values are obtained for
11869 that window instead of the current window.
11870
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011871 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +020011872
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011873 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010011874 " With text "foo^Lbar" and cursor on the "^L":
11875
11876 virtcol(".") " returns 5
11877 virtcol(".", 1) " returns [4, 5]
11878 virtcol("$") " returns 9
11879
11880 " With text " there", with 't at 'h':
11881
11882 virtcol("'t") " returns 6
zeertzjq02f3eba2024-06-12 20:45:24 +020011883<
11884 The first column is 1. 0 or [0, 0] is returned for an error.
11885
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011886 A more advanced example that echoes the maximum length of
11887 all lines: >
11888 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
11889
11890< Can also be used as a |method|: >
11891 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011892<
11893 Return type: |Number|
11894
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011895
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011896virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
11897 The result is a Number, which is the byte index of the
11898 character in window {winid} at buffer line {lnum} and virtual
11899 column {col}.
11900
zeertzjqb583eda2023-10-14 11:32:28 +020011901 If buffer line {lnum} is an empty line, 0 is returned.
11902
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011903 If {col} is greater than the last virtual column in line
11904 {lnum}, then the byte index of the character at the last
11905 virtual column is returned.
11906
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020011907 For a multi-byte character, the column number of the first
11908 byte in the character is returned.
11909
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011910 The {winid} argument can be the window number or the
11911 |window-ID|. If this is zero, then the current window is used.
11912
11913 Returns -1 if the window {winid} doesn't exist or the buffer
11914 line {lnum} or virtual column {col} is invalid.
11915
11916 See also |screenpos()|, |virtcol()| and |col()|.
11917
11918 Can also be used as a |method|: >
11919 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011920<
11921 Return type: |Number|
11922
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011923
11924visualmode([{expr}]) *visualmode()*
11925 The result is a String, which describes the last Visual mode
11926 used in the current buffer. Initially it returns an empty
11927 string, but once Visual mode has been used, it returns "v",
11928 "V", or "<CTRL-V>" (a single CTRL-V character) for
11929 character-wise, line-wise, or block-wise Visual mode
11930 respectively.
11931 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011932 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011933< This enters the same Visual mode as before. It is also useful
11934 in scripts if you wish to act differently depending on the
11935 Visual mode that was used.
11936 If Visual mode is active, use |mode()| to get the Visual mode
11937 (e.g., in a |:vmap|).
11938 If {expr} is supplied and it evaluates to a non-zero Number or
11939 a non-empty String, then the Visual mode will be cleared and
11940 the old value is returned. See |non-zero-arg|.
11941
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011942 Return type: |String|
11943
11944
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011945wildmenumode() *wildmenumode()*
11946 Returns |TRUE| when the wildmenu is active and |FALSE|
11947 otherwise. See 'wildmenu' and 'wildmode'.
11948 This can be used in mappings to handle the 'wildcharm' option
11949 gracefully. (Makes only sense with |mapmode-c| mappings).
11950
11951 For example to make <c-j> work like <down> in wildmode, use: >
11952 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
11953<
11954 (Note, this needs the 'wildcharm' option set appropriately).
11955
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011956 Return type: |Number|
11957
11958
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011959win_execute({id}, {command} [, {silent}]) *win_execute()*
11960 Like `execute()` but in the context of window {id}.
11961 The window will temporarily be made the current window,
11962 without triggering autocommands or changing directory. When
11963 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010011964 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011965 Example: >
11966 call win_execute(winid, 'set syntax=python')
11967< Doing the same with `setwinvar()` would not trigger
11968 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011969 *E994*
11970 Not all commands are allowed in popup windows.
11971 When window {id} does not exist then no error is given and
11972 an empty string is returned.
11973
11974 Can also be used as a |method|, the base is passed as the
11975 second argument: >
11976 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011977<
11978 Return type: |String|
11979
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011980
11981win_findbuf({bufnr}) *win_findbuf()*
11982 Returns a |List| with |window-ID|s for windows that contain
11983 buffer {bufnr}. When there is none the list is empty.
11984
11985 Can also be used as a |method|: >
11986 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011987<
11988 Return type: list<number> or list<any>
11989
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011990
11991win_getid([{win} [, {tab}]]) *win_getid()*
11992 Get the |window-ID| for the specified window.
11993 When {win} is missing use the current window.
11994 With {win} this is the window number. The top window has
11995 number 1.
11996 Without {tab} use the current tab, otherwise the tab with
11997 number {tab}. The first tab has number one.
11998 Return zero if the window cannot be found.
11999
12000 Can also be used as a |method|: >
12001 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012002<
12003 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012004
12005
12006win_gettype([{nr}]) *win_gettype()*
12007 Return the type of the window:
12008 "autocmd" autocommand window. Temporary window
12009 used to execute autocommands.
12010 "command" command-line window |cmdwin|
12011 (empty) normal window
12012 "loclist" |location-list-window|
12013 "popup" popup window |popup|
12014 "preview" preview window |preview-window|
12015 "quickfix" |quickfix-window|
12016 "unknown" window {nr} not found
12017
12018 When {nr} is omitted return the type of the current window.
12019 When {nr} is given return the type of this window by number or
12020 |window-ID|.
12021
12022 Also see the 'buftype' option. When running a terminal in a
12023 popup window then 'buftype' is "terminal" and win_gettype()
12024 returns "popup".
12025
12026 Can also be used as a |method|: >
12027 GetWinid()->win_gettype()
12028<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012029 Return type: |String|
12030
12031
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012032win_gotoid({expr}) *win_gotoid()*
12033 Go to window with ID {expr}. This may also change the current
12034 tabpage.
12035 Return TRUE if successful, FALSE if the window cannot be found.
12036
12037 Can also be used as a |method|: >
12038 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012039<
12040 Return type: |Number|
12041
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012042
12043win_id2tabwin({expr}) *win_id2tabwin()*
12044 Return a list with the tab number and window number of window
12045 with ID {expr}: [tabnr, winnr].
12046 Return [0, 0] if the window cannot be found.
12047
12048 Can also be used as a |method|: >
12049 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012050<
12051 Return type: list<number>
12052
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012053
12054win_id2win({expr}) *win_id2win()*
12055 Return the window number of window with ID {expr}.
12056 Return 0 if the window cannot be found in the current tabpage.
12057
12058 Can also be used as a |method|: >
12059 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012060<
12061 Return type: |Number|
12062
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012063
Daniel Steinbergee630312022-01-10 13:36:34 +000012064win_move_separator({nr}, {offset}) *win_move_separator()*
12065 Move window {nr}'s vertical separator (i.e., the right border)
12066 by {offset} columns, as if being dragged by the mouse. {nr}
12067 can be a window number or |window-ID|. A positive {offset}
12068 moves right and a negative {offset} moves left. Moving a
12069 window's vertical separator will change the width of the
12070 window and the width of other windows adjacent to the vertical
12071 separator. The magnitude of movement may be smaller than
12072 specified (e.g., as a consequence of maintaining
12073 'winminwidth'). Returns TRUE if the window can be found and
12074 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012075 This will fail for the rightmost window and a full-width
12076 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012077 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000012078
12079 Can also be used as a |method|: >
12080 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012081<
12082 Return type: |Number|
12083
Daniel Steinbergee630312022-01-10 13:36:34 +000012084
12085win_move_statusline({nr}, {offset}) *win_move_statusline()*
12086 Move window {nr}'s status line (i.e., the bottom border) by
12087 {offset} rows, as if being dragged by the mouse. {nr} can be a
12088 window number or |window-ID|. A positive {offset} moves down
12089 and a negative {offset} moves up. Moving a window's status
12090 line will change the height of the window and the height of
12091 other windows adjacent to the status line. The magnitude of
12092 movement may be smaller than specified (e.g., as a consequence
12093 of maintaining 'winminheight'). Returns TRUE if the window can
12094 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012095 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000012096
12097 Can also be used as a |method|: >
12098 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012099<
12100 Return type: |Number|
12101
Daniel Steinbergee630312022-01-10 13:36:34 +000012102
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012103win_screenpos({nr}) *win_screenpos()*
12104 Return the screen position of window {nr} as a list with two
12105 numbers: [row, col]. The first window always has position
12106 [1, 1], unless there is a tabline, then it is [2, 1].
12107 {nr} can be the window number or the |window-ID|. Use zero
12108 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012109 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012110
12111 Can also be used as a |method|: >
12112 GetWinid()->win_screenpos()
12113<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012114 Return type: list<number>
12115
12116
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012117win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012118 Temporarily switch to window {target}, then move window {nr}
12119 to a new split adjacent to {target}.
12120 Unlike commands such as |:split|, no new windows are created
12121 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012122
12123 Both {nr} and {target} can be window numbers or |window-ID|s.
12124 Both must be in the current tab page.
12125
12126 Returns zero for success, non-zero for failure.
12127
12128 {options} is a |Dictionary| with the following optional entries:
12129 "vertical" When TRUE, the split is created vertically,
12130 like with |:vsplit|.
12131 "rightbelow" When TRUE, the split is made below or to the
12132 right (if vertical). When FALSE, it is done
12133 above or to the left (if vertical). When not
12134 present, the values of 'splitbelow' and
12135 'splitright' are used.
12136
12137 Can also be used as a |method|: >
12138 GetWinid()->win_splitmove(target)
12139<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012140 Return type: |Number|
12141
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012142
12143 *winbufnr()*
12144winbufnr({nr}) The result is a Number, which is the number of the buffer
12145 associated with window {nr}. {nr} can be the window number or
12146 the |window-ID|.
12147 When {nr} is zero, the number of the buffer in the current
12148 window is returned.
12149 When window {nr} doesn't exist, -1 is returned.
12150 Example: >
12151 :echo "The file in the current window is " . bufname(winbufnr(0))
12152<
12153 Can also be used as a |method|: >
12154 FindWindow()->winbufnr()->bufname()
12155<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012156 Return type: |Number|
12157
12158
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012159 *wincol()*
12160wincol() The result is a Number, which is the virtual column of the
12161 cursor in the window. This is counting screen cells from the
12162 left side of the window. The leftmost column is one.
12163
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012164 Return type: |Number|
12165
12166
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012167 *windowsversion()*
12168windowsversion()
12169 The result is a String. For MS-Windows it indicates the OS
12170 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12171 Windows XP is "5.1". For non-MS-Windows systems the result is
12172 an empty string.
12173
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012174 Return type: |String|
12175
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012176winheight({nr}) *winheight()*
12177 The result is a Number, which is the height of window {nr}.
12178 {nr} can be the window number or the |window-ID|.
12179 When {nr} is zero, the height of the current window is
12180 returned. When window {nr} doesn't exist, -1 is returned.
12181 An existing window always has a height of zero or more.
12182 This excludes any window toolbar line.
12183 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012184 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012185
12186< Can also be used as a |method|: >
12187 GetWinid()->winheight()
12188<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012189 Return type: |Number|
12190
12191
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012192winlayout([{tabnr}]) *winlayout()*
12193 The result is a nested List containing the layout of windows
12194 in a tabpage.
12195
12196 Without {tabnr} use the current tabpage, otherwise the tabpage
12197 with number {tabnr}. If the tabpage {tabnr} is not found,
12198 returns an empty list.
12199
12200 For a leaf window, it returns:
12201 ['leaf', {winid}]
12202 For horizontally split windows, which form a column, it
12203 returns:
12204 ['col', [{nested list of windows}]]
12205 For vertically split windows, which form a row, it returns:
12206 ['row', [{nested list of windows}]]
12207
12208 Example: >
12209 " Only one window in the tab page
12210 :echo winlayout()
12211 ['leaf', 1000]
12212 " Two horizontally split windows
12213 :echo winlayout()
12214 ['col', [['leaf', 1000], ['leaf', 1001]]]
12215 " The second tab page, with three horizontally split
12216 " windows, with two vertically split windows in the
12217 " middle window
12218 :echo winlayout(2)
12219 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12220 ['leaf', 1001]]], ['leaf', 1000]]]
12221<
12222 Can also be used as a |method|: >
12223 GetTabnr()->winlayout()
12224<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012225 Return type: list<any>
12226
12227
12228winline() *winline()*
12229 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012230 in the window. This is counting screen lines from the top of
12231 the window. The first line is one.
12232 If the cursor was moved the view on the file will be updated
12233 first, this may cause a scroll.
12234
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012235 Return type: |Number|
12236
12237
12238winnr([{arg}]) *winnr()*
12239 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012240 window. The top window has number 1.
12241 Returns zero for a popup window.
12242
12243 The optional argument {arg} supports the following values:
12244 $ the number of the last window (the window
12245 count).
12246 # the number of the last accessed window (where
12247 |CTRL-W_p| goes to). If there is no previous
12248 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012249 returned. May refer to the current window in
12250 some cases (e.g. when evaluating 'statusline'
12251 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012252 {N}j the number of the Nth window below the
12253 current window (where |CTRL-W_j| goes to).
12254 {N}k the number of the Nth window above the current
12255 window (where |CTRL-W_k| goes to).
12256 {N}h the number of the Nth window left of the
12257 current window (where |CTRL-W_h| goes to).
12258 {N}l the number of the Nth window right of the
12259 current window (where |CTRL-W_l| goes to).
12260 The number can be used with |CTRL-W_w| and ":wincmd w"
12261 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012262 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012263 Also see |tabpagewinnr()| and |win_getid()|.
12264 Examples: >
12265 let window_count = winnr('$')
12266 let prev_window = winnr('#')
12267 let wnum = winnr('3k')
12268
12269< Can also be used as a |method|: >
12270 GetWinval()->winnr()
12271<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012272 Return type: |Number|
12273
12274
12275winrestcmd() *winrestcmd()*
12276 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012277 the current window sizes. Only works properly when no windows
12278 are opened or closed and the current window and tab page is
12279 unchanged.
12280 Example: >
12281 :let cmd = winrestcmd()
12282 :call MessWithWindowSizes()
12283 :exe cmd
12284<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012285 Return type: |String|
12286
12287
12288winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012289 Uses the |Dictionary| returned by |winsaveview()| to restore
12290 the view of the current window.
12291 Note: The {dict} does not have to contain all values, that are
12292 returned by |winsaveview()|. If values are missing, those
12293 settings won't be restored. So you can use: >
12294 :call winrestview({'curswant': 4})
12295<
12296 This will only set the curswant value (the column the cursor
12297 wants to move on vertical movements) of the cursor to column 5
12298 (yes, that is 5), while all other settings will remain the
12299 same. This is useful, if you set the cursor position manually.
12300
12301 If you have changed the values the result is unpredictable.
12302 If the window size changed the result won't be the same.
12303
12304 Can also be used as a |method|: >
12305 GetView()->winrestview()
12306<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012307 Return type: |Number|
12308
12309
12310winsaveview() *winsaveview()*
12311 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012312 the view of the current window. Use |winrestview()| to
12313 restore the view.
12314 This is useful if you have a mapping that jumps around in the
12315 buffer and you want to go back to the original view.
12316 This does not save fold information. Use the 'foldenable'
12317 option to temporarily switch off folding, so that folds are
12318 not opened when moving around. This may have side effects.
12319 The return value includes:
12320 lnum cursor line number
12321 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012322 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012323 returns)
12324 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012325 curswant column for vertical movement (Note:
12326 the first column is zero, as opposed
12327 to what |getcurpos()| returns). After
12328 |$| command it will be a very large
12329 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012330 topline first line in the window
12331 topfill filler lines, only in diff mode
12332 leftcol first column displayed; only used when
12333 'wrap' is off
12334 skipcol columns skipped
12335 Note that no option values are saved.
12336
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012337 Return type: dict<number>
12338
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012339
12340winwidth({nr}) *winwidth()*
12341 The result is a Number, which is the width of window {nr}.
12342 {nr} can be the window number or the |window-ID|.
12343 When {nr} is zero, the width of the current window is
12344 returned. When window {nr} doesn't exist, -1 is returned.
12345 An existing window always has a width of zero or more.
12346 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012347 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012348 :if winwidth(0) <= 50
12349 : 50 wincmd |
12350 :endif
12351< For getting the terminal or screen size, see the 'columns'
12352 option.
12353
12354 Can also be used as a |method|: >
12355 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012356<
12357 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012358
12359
12360wordcount() *wordcount()*
12361 The result is a dictionary of byte/chars/word statistics for
12362 the current buffer. This is the same info as provided by
12363 |g_CTRL-G|
12364 The return value includes:
12365 bytes Number of bytes in the buffer
12366 chars Number of chars in the buffer
12367 words Number of words in the buffer
12368 cursor_bytes Number of bytes before cursor position
12369 (not in Visual mode)
12370 cursor_chars Number of chars before cursor position
12371 (not in Visual mode)
12372 cursor_words Number of words before cursor position
12373 (not in Visual mode)
12374 visual_bytes Number of bytes visually selected
12375 (only in Visual mode)
12376 visual_chars Number of chars visually selected
12377 (only in Visual mode)
12378 visual_words Number of words visually selected
12379 (only in Visual mode)
12380
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012381 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012382
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012383
12384writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012385 When {object} is a |List| write it to file {fname}. Each list
12386 item is separated with a NL. Each list item must be a String
12387 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012388 All NL characters are replaced with a NUL character.
12389 Inserting CR characters needs to be done before passing {list}
12390 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012391
12392 When {object} is a |Blob| write the bytes to file {fname}
12393 unmodified, also when binary mode is not specified.
12394
12395 {flags} must be a String. These characters are recognized:
12396
12397 'b' Binary mode is used: There will not be a NL after the
12398 last list item. An empty item at the end does cause the
12399 last line in the file to end in a NL.
12400
12401 'a' Append mode is used, lines are appended to the file: >
12402 :call writefile(["foo"], "event.log", "a")
12403 :call writefile(["bar"], "event.log", "a")
12404<
12405 'D' Delete the file when the current function ends. This
12406 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012407 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012408< Fails when not in a function. Also see |:defer|.
12409
12410 's' fsync() is called after writing the file. This flushes
12411 the file to disk, if possible. This takes more time but
12412 avoids losing the file if the system crashes.
12413
12414 'S' fsync() is not called, even when 'fsync' is set.
12415
12416 When {flags} does not contain "S" or "s" then fsync() is
12417 called if the 'fsync' option is set.
12418
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012419 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012420
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012421 When the write fails -1 is returned, otherwise 0. There is an
12422 error message if the file can't be created or when writing
12423 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012424
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012425 Also see |readfile()|.
12426 To copy a file byte for byte: >
12427 :let fl = readfile("foo", "b")
12428 :call writefile(fl, "foocopy", "b")
12429
12430< Can also be used as a |method|: >
12431 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012432<
12433 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012434
12435
12436xor({expr}, {expr}) *xor()*
12437 Bitwise XOR on the two arguments. The arguments are converted
12438 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012439 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012440 Example: >
12441 :let bits = xor(bits, 0x80)
12442<
12443 Can also be used as a |method|: >
12444 :let bits = bits->xor(0x80)
12445<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012446 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012447
12448==============================================================================
124493. Feature list *feature-list*
12450
12451There are three types of features:
124521. Features that are only supported when they have been enabled when Vim
12453 was compiled |+feature-list|. Example: >
12454 :if has("cindent")
12455< *gui_running*
124562. Features that are only supported when certain conditions have been met.
12457 Example: >
12458 :if has("gui_running")
12459< *has-patch*
124603. Beyond a certain version or at a certain version and including a specific
12461 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12462 later, or it is version 7.4 and patch 248 was included. Example: >
12463 :if has("patch-7.4.248")
12464< Note that it's possible for patch 248 to be omitted even though 249 is
12465 included. Only happens when cherry-picking patches.
12466 Note that this form only works for patch 7.4.237 and later, before that
12467 you need to check for the patch and the v:version. Example (checking
12468 version 6.2.148 or later): >
12469 :if v:version > 602 || (v:version == 602 && has("patch148"))
12470
12471Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12472use: `if exists('+shellslash')`
12473
12474
12475acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012476all_builtin_terms Compiled with all builtin terminals enabled. (always
12477 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012478amiga Amiga version of Vim.
12479arabic Compiled with Arabic support |Arabic|.
12480arp Compiled with ARP support (Amiga).
12481autocmd Compiled with autocommand support. (always true)
12482autochdir Compiled with support for 'autochdir'
12483autoservername Automatically enable |clientserver|
12484balloon_eval Compiled with |balloon-eval| support.
12485balloon_multiline GUI supports multiline balloons.
12486beos BeOS version of Vim.
12487browse Compiled with |:browse| support, and browse() will
12488 work.
12489browsefilter Compiled with support for |browsefilter|.
12490bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012491builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012492byte_offset Compiled with support for 'o' in 'statusline'
12493channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012494cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012495clientserver Compiled with remote invocation support |clientserver|.
12496clipboard Compiled with 'clipboard' support.
12497clipboard_working Compiled with 'clipboard' support and it can be used.
12498cmdline_compl Compiled with |cmdline-completion| support.
12499cmdline_hist Compiled with |cmdline-history| support.
12500cmdline_info Compiled with 'showcmd' and 'ruler' support.
12501comments Compiled with |'comments'| support.
12502compatible Compiled to be very Vi compatible.
12503conpty Platform where |ConPTY| can be used.
12504cryptv Compiled with encryption support |encryption|.
12505cscope Compiled with |cscope| support.
12506cursorbind Compiled with |'cursorbind'| (always true)
12507debug Compiled with "DEBUG" defined.
12508dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012509dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012510dialog_gui Compiled with GUI dialog support.
12511diff Compiled with |vimdiff| and 'diff' support.
12512digraphs Compiled with support for digraphs.
12513directx Compiled with support for DirectX and 'renderoptions'.
12514dnd Compiled with support for the "~ register |quote_~|.
12515drop_file Compiled with |drop_file| support.
12516ebcdic Compiled on a machine with ebcdic character set.
12517emacs_tags Compiled with support for Emacs tags.
12518eval Compiled with expression evaluation support. Always
12519 true, of course!
12520ex_extra |+ex_extra| (always true)
12521extra_search Compiled with support for |'incsearch'| and
12522 |'hlsearch'|
12523farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012524file_in_path Compiled with support for |gf| and |<cfile>| (always
12525 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012526filterpipe When 'shelltemp' is off pipes are used for shell
12527 read/write/filter commands
12528find_in_path Compiled with support for include file searches
12529 |+find_in_path|.
12530float Compiled with support for |Float|.
12531fname_case Case in file names matters (for Amiga and MS-Windows
12532 this is not present).
12533folding Compiled with |folding| support.
12534footer Compiled with GUI footer support. |gui-footer|
12535fork Compiled to use fork()/exec() instead of system().
12536gettext Compiled with message translation |multi-lang|
12537gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012538gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012539gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12540gui_gtk Compiled with GTK+ GUI (any version).
12541gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12542gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12543gui_haiku Compiled with Haiku GUI.
12544gui_mac Compiled with Macintosh GUI.
12545gui_motif Compiled with Motif GUI.
12546gui_photon Compiled with Photon GUI.
12547gui_running Vim is running in the GUI, or it will start soon.
12548gui_win32 Compiled with MS-Windows Win32 GUI.
12549gui_win32s idem, and Win32s system being used (Windows 3.1)
12550haiku Haiku version of Vim.
12551hangul_input Compiled with Hangul input support. |hangul|
12552hpux HP-UX version of Vim.
12553iconv Can use iconv() for conversion.
12554insert_expand Compiled with support for CTRL-X expansion commands in
12555 Insert mode. (always true)
12556job Compiled with support for |channel| and |job|
12557ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012558jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012559keymap Compiled with 'keymap' support.
12560lambda Compiled with |lambda| support.
12561langmap Compiled with 'langmap' support.
12562libcall Compiled with |libcall()| support.
12563linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12564 'breakindent' support.
12565linux Linux version of Vim.
12566lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012567 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012568listcmds Compiled with commands for the buffer list |:files|
12569 and the argument list |arglist|.
12570localmap Compiled with local mappings and abbr. |:map-local|
12571lua Compiled with Lua interface |Lua|.
12572mac Any Macintosh version of Vim cf. osx
12573macunix Synonym for osxdarwin
12574menu Compiled with support for |:menu|.
12575mksession Compiled with support for |:mksession|.
12576modify_fname Compiled with file name modifiers. |filename-modifiers|
12577 (always true)
12578mouse Compiled with support for mouse.
12579mouse_dec Compiled with support for Dec terminal mouse.
12580mouse_gpm Compiled with support for gpm (Linux console mouse)
12581mouse_gpm_enabled GPM mouse is working
12582mouse_netterm Compiled with support for netterm mouse.
12583mouse_pterm Compiled with support for qnx pterm mouse.
12584mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12585mouse_sgr Compiled with support for sgr mouse.
12586mouse_urxvt Compiled with support for urxvt mouse.
12587mouse_xterm Compiled with support for xterm mouse.
12588mouseshape Compiled with support for 'mouseshape'.
12589multi_byte Compiled with support for 'encoding' (always true)
12590multi_byte_encoding 'encoding' is set to a multibyte encoding.
12591multi_byte_ime Compiled with support for IME input method.
12592multi_lang Compiled with support for multiple languages.
12593mzscheme Compiled with MzScheme interface |mzscheme|.
12594nanotime Compiled with sub-second time stamp checks.
12595netbeans_enabled Compiled with support for |netbeans| and connected.
12596netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012597num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012598ole Compiled with OLE automation support for Win32.
12599osx Compiled for macOS cf. mac
12600osxdarwin Compiled for macOS, with |mac-darwin-feature|
12601packages Compiled with |packages| support.
12602path_extra Compiled with up/downwards search in 'path' and 'tags'
12603perl Compiled with Perl interface.
12604persistent_undo Compiled with support for persistent undo history.
12605postscript Compiled with PostScript file printing.
12606printer Compiled with |:hardcopy| support.
12607profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012608prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012609python Python 2.x interface available. |has-python|
12610python_compiled Compiled with Python 2.x interface. |has-python|
12611python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12612python3 Python 3.x interface available. |has-python|
12613python3_compiled Compiled with Python 3.x interface. |has-python|
12614python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012615python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012616pythonx Python 2.x and/or 3.x interface available. |python_x|
12617qnx QNX version of Vim.
12618quickfix Compiled with |quickfix| support.
12619reltime Compiled with |reltime()| support.
12620rightleft Compiled with 'rightleft' support.
12621ruby Compiled with Ruby interface |ruby|.
12622scrollbind Compiled with 'scrollbind' support. (always true)
12623showcmd Compiled with 'showcmd' support.
12624signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012625smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012626sodium Compiled with libsodium for better crypt support
12627sound Compiled with sound support, e.g. `sound_playevent()`
12628spell Compiled with spell checking support |spell|.
12629startuptime Compiled with |--startuptime| support.
12630statusline Compiled with support for 'statusline', 'rulerformat'
12631 and special formats of 'titlestring' and 'iconstring'.
12632sun SunOS version of Vim.
12633sun_workshop Support for Sun |workshop| has been removed.
12634syntax Compiled with syntax highlighting support |syntax|.
12635syntax_items There are active syntax highlighting items for the
12636 current buffer.
12637system Compiled to use system() instead of fork()/exec().
12638tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012639 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012640tag_old_static Support for old static tags was removed, see
12641 |tag-old-static|.
12642tcl Compiled with Tcl interface.
12643termguicolors Compiled with true color in terminal support.
12644terminal Compiled with |terminal| support.
12645terminfo Compiled with terminfo instead of termcap.
12646termresponse Compiled with support for |t_RV| and |v:termresponse|.
12647textobjects Compiled with support for |text-objects|.
12648textprop Compiled with support for |text-properties|.
12649tgetent Compiled with tgetent support, able to use a termcap
12650 or terminfo file.
12651timers Compiled with |timer_start()| support.
12652title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012653 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012654toolbar Compiled with support for |gui-toolbar|.
12655ttyin input is a terminal (tty)
12656ttyout output is a terminal (tty)
12657unix Unix version of Vim. *+unix*
12658unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
12659user_commands User-defined commands. (always true)
12660vartabs Compiled with variable tabstop support |'vartabstop'|.
12661vcon Win32: Virtual console support is working, can use
12662 'termguicolors'. Also see |+vtp|.
12663vertsplit Compiled with vertically split windows |:vsplit|.
12664 (always true)
12665vim_starting True while initial source'ing takes place. |startup|
12666 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000012667vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012668viminfo Compiled with viminfo support.
12669vimscript-1 Compiled Vim script version 1 support
12670vimscript-2 Compiled Vim script version 2 support
12671vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010012672vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012673virtualedit Compiled with 'virtualedit' option. (always true)
12674visual Compiled with Visual mode. (always true)
12675visualextra Compiled with extra Visual mode commands. (always
12676 true) |blockwise-operators|.
12677vms VMS version of Vim.
12678vreplace Compiled with |gR| and |gr| commands. (always true)
12679vtp Compiled for vcon support |+vtp| (check vcon to find
12680 out if it works in the current console).
12681wildignore Compiled with 'wildignore' option.
12682wildmenu Compiled with 'wildmenu' option.
12683win16 old version for MS-Windows 3.1 (always false)
12684win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
12685 64 bits)
12686win32unix Win32 version of Vim, using Unix files (Cygwin)
12687win64 Win64 version of Vim (MS-Windows 64 bit).
12688win95 Win32 version for MS-Windows 95/98/ME (always false)
12689winaltkeys Compiled with 'winaltkeys' option.
12690windows Compiled with support for more than one window.
12691 (always true)
12692writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020012693xattr Compiled with extended attributes support |xattr|
12694 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012695xfontset Compiled with X fontset support |xfontset|.
12696xim Compiled with X input method support |xim|.
12697xpm Compiled with pixmap support.
12698xpm_w32 Compiled with pixmap support for Win32. (Only for
12699 backward compatibility. Use "xpm" instead.)
12700xsmp Compiled with X session management support.
12701xsmp_interact Compiled with interactive X session management support.
12702xterm_clipboard Compiled with support for xterm clipboard.
12703xterm_save Compiled with support for saving and restoring the
12704 xterm screen.
12705x11 Compiled with X11 support.
12706
12707
12708==============================================================================
127094. Matching a pattern in a String *string-match*
12710
12711This is common between several functions. A regexp pattern as explained at
12712|pattern| is normally used to find a match in the buffer lines. When a
12713pattern is used to find a match in a String, almost everything works in the
12714same way. The difference is that a String is handled like it is one line.
12715When it contains a "\n" character, this is not seen as a line break for the
12716pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
12717>
12718 :let a = "aaaa\nxxxx"
12719 :echo matchstr(a, "..\n..")
12720 aa
12721 xx
12722 :echo matchstr(a, "a.x")
12723 a
12724 x
12725
12726Don't forget that "^" will only match at the first character of the String and
12727"$" at the last character of the string. They don't match after or before a
12728"\n".
12729
12730 vim:tw=78:ts=8:noet:ft=help:norl: