blob: edc425a5aba5137fd644a48a0c32411a9ade1ea3 [file] [log] [blame]
Christian Brabandtb5e7da12024-11-01 09:33:00 +01001*builtin.txt* For Vim version 9.1. Last change: 2024 Nov 01
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
Christian Brabandtb5e7da12024-11-01 09:33:00 +01001628 2 word character (depends on 'iskeyword')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001629 3 emoji
1630 other specific Unicode class
1631 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001632 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001633
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001634 Return type: |Number|
1635
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001636
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001637charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001638 Same as |col()| but returns the character index of the column
1639 position given with {expr} instead of the byte position.
1640
1641 Example:
1642 With the cursor on '세' in line 5 with text "여보세요": >
1643 charcol('.') returns 3
1644 col('.') returns 7
1645
1646< Can also be used as a |method|: >
1647 GetPos()->col()
1648<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001649 Return type: |Number|
1650
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001651 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001652charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001653 Return the character index of the byte at {idx} in {string}.
1654 The index of the first character is zero.
1655 If there are no multibyte characters the returned value is
1656 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001657
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001658 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001659 are not counted separately, their byte length is added to the
1660 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001661 When {countcc} is |TRUE|, then composing characters are
1662 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001663
1664 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1665 index in the String {expr} instead of as the byte index.
1666
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001667 Returns -1 if the arguments are invalid or if there are less
1668 than {idx} bytes. If there are exactly {idx} bytes the length
1669 of the string in characters is returned.
1670
1671 An error is given and -1 is returned if the first argument is
1672 not a string, the second argument is not a number or when the
1673 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001674
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001675 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001676 from the character index and |utf16idx()| for getting the
1677 UTF-16 index from the character index.
1678 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001679 Examples: >
1680 echo charidx('áb́ć', 3) returns 1
1681 echo charidx('áb́ć', 6, 1) returns 4
1682 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001683 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001684<
1685 Can also be used as a |method|: >
1686 GetName()->charidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001687<
1688 Return type: |Number|
1689
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001690
1691chdir({dir}) *chdir()*
1692 Change the current working directory to {dir}. The scope of
1693 the directory change depends on the directory of the current
1694 window:
1695 - If the current window has a window-local directory
1696 (|:lcd|), then changes the window local directory.
1697 - Otherwise, if the current tabpage has a local
1698 directory (|:tcd|) then changes the tabpage local
1699 directory.
1700 - Otherwise, changes the global directory.
1701 {dir} must be a String.
1702 If successful, returns the previous working directory. Pass
1703 this to another chdir() to restore the directory.
1704 On failure, returns an empty string.
1705
1706 Example: >
1707 let save_dir = chdir(newdir)
1708 if save_dir != ""
1709 " ... do some work
1710 call chdir(save_dir)
1711 endif
1712
1713< Can also be used as a |method|: >
1714 GetDir()->chdir()
1715<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001716 Return type: |String|
1717
1718
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001719cindent({lnum}) *cindent()*
1720 Get the amount of indent for line {lnum} according the C
1721 indenting rules, as with 'cindent'.
1722 The indent is counted in spaces, the value of 'tabstop' is
1723 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001724 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001725 See |C-indenting|.
1726
1727 Can also be used as a |method|: >
1728 GetLnum()->cindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001729<
1730 Return type: |Number|
1731
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001732
1733clearmatches([{win}]) *clearmatches()*
1734 Clears all matches previously defined for the current window
1735 by |matchadd()| and the |:match| commands.
1736 If {win} is specified, use the window with this number or
1737 window ID instead of the current window.
1738
1739 Can also be used as a |method|: >
1740 GetWin()->clearmatches()
1741<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001742 Return type: |Number|
1743
1744
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001745col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001746 The result is a Number, which is the byte index of the column
zeertzjq02f3eba2024-06-12 20:45:24 +02001747 position given with {expr}.
1748 For accepted positions see |getpos()|.
zeertzjqd353d272024-06-13 23:00:25 +08001749 When {expr} is "$", it means the end of the cursor line, so
1750 the result is the number of bytes in the cursor line plus one.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001751 Additionally {expr} can be [lnum, col]: a |List| with the line
1752 and column number. Most useful when the column is "$", to get
1753 the last column of a specific line. When "lnum" or "col" is
1754 out of range then col() returns zero.
zeertzjq02f3eba2024-06-12 20:45:24 +02001755
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001756 With the optional {winid} argument the values are obtained for
1757 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02001758
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001759 To get the line number use |line()|. To get both use
1760 |getpos()|.
1761 For the screen column position use |virtcol()|. For the
1762 character position use |charcol()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02001763
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001764 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +02001765
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001766 Examples: >
1767 col(".") column of cursor
1768 col("$") length of cursor line plus one
1769 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001770 col("'" .. markname) column of mark markname
zeertzjq02f3eba2024-06-12 20:45:24 +02001771<
1772 The first column is 1. Returns 0 if {expr} is invalid or when
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001773 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001774 For an uppercase mark the column may actually be in another
1775 buffer.
1776 For the cursor position, when 'virtualedit' is active, the
1777 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001778 line. Also, when using a <Cmd> mapping the cursor isn't
1779 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001780 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001781
1782< Can also be used as a |method|: >
1783 GetPos()->col()
1784<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001785 Return type: |Number|
1786
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001787
1788complete({startcol}, {matches}) *complete()* *E785*
1789 Set the matches for Insert mode completion.
1790 Can only be used in Insert mode. You need to use a mapping
1791 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1792 or with an expression mapping.
1793 {startcol} is the byte offset in the line where the completed
1794 text start. The text up to the cursor is the original text
1795 that will be replaced by the matches. Use col('.') for an
1796 empty string. "col('.') - 1" will replace one character by a
1797 match.
1798 {matches} must be a |List|. Each |List| item is one match.
1799 See |complete-items| for the kind of items that are possible.
1800 "longest" in 'completeopt' is ignored.
1801 Note that the after calling this function you need to avoid
1802 inserting anything that would cause completion to stop.
1803 The match can be selected with CTRL-N and CTRL-P as usual with
1804 Insert mode completion. The popup menu will appear if
1805 specified, see |ins-completion-menu|.
1806 Example: >
1807 inoremap <F5> <C-R>=ListMonths()<CR>
1808
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001809 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001810 call complete(col('.'), ['January', 'February', 'March',
1811 \ 'April', 'May', 'June', 'July', 'August', 'September',
1812 \ 'October', 'November', 'December'])
1813 return ''
1814 endfunc
1815< This isn't very useful, but it shows how it works. Note that
1816 an empty string is returned to avoid a zero being inserted.
1817
1818 Can also be used as a |method|, the base is passed as the
1819 second argument: >
1820 GetMatches()->complete(col('.'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001821<
1822 Return type: |Number|
1823
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001824
1825complete_add({expr}) *complete_add()*
1826 Add {expr} to the list of matches. Only to be used by the
1827 function specified with the 'completefunc' option.
1828 Returns 0 for failure (empty string or out of memory),
1829 1 when the match was added, 2 when the match was already in
1830 the list.
1831 See |complete-functions| for an explanation of {expr}. It is
1832 the same as one item in the list that 'omnifunc' would return.
1833
1834 Can also be used as a |method|: >
1835 GetMoreMatches()->complete_add()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001836<
1837 Return type: |Number|
1838
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001839
1840complete_check() *complete_check()*
1841 Check for a key typed while looking for completion matches.
1842 This is to be used when looking for matches takes some time.
1843 Returns |TRUE| when searching for matches is to be aborted,
1844 zero otherwise.
1845 Only to be used by the function specified with the
1846 'completefunc' option.
1847
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001848 Return type: |Number|
1849
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001850
1851complete_info([{what}]) *complete_info()*
1852 Returns a |Dictionary| with information about Insert mode
1853 completion. See |ins-completion|.
1854 The items are:
1855 mode Current completion mode name string.
1856 See |complete_info_mode| for the values.
1857 pum_visible |TRUE| if popup menu is visible.
1858 See |pumvisible()|.
1859 items List of completion matches. Each item is a
1860 dictionary containing the entries "word",
1861 "abbr", "menu", "kind", "info" and "user_data".
1862 See |complete-items|.
1863 selected Selected item index. First index is zero.
1864 Index is -1 if no item is selected (showing
1865 typed text only, or the last completion after
1866 no item is selected when using the <Up> or
1867 <Down> keys)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01001868 inserted Inserted string. [NOT IMPLEMENTED YET]
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001869
1870 *complete_info_mode*
1871 mode values are:
1872 "" Not in completion mode
1873 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1874 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1875 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1876 |i_CTRL-X_CTRL-Y|
1877 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1878 "files" File names |i_CTRL-X_CTRL-F|
1879 "tags" Tags |i_CTRL-X_CTRL-]|
1880 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1881 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1882 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1883 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1884 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1885 "function" User defined completion |i_CTRL-X_CTRL-U|
1886 "omni" Omni completion |i_CTRL-X_CTRL-O|
1887 "spell" Spelling suggestions |i_CTRL-X_s|
1888 "eval" |complete()| completion
1889 "unknown" Other internal modes
1890
1891 If the optional {what} list argument is supplied, then only
1892 the items listed in {what} are returned. Unsupported items in
1893 {what} are silently ignored.
1894
1895 To get the position and size of the popup menu, see
1896 |pum_getpos()|. It's also available in |v:event| during the
1897 |CompleteChanged| event.
1898
Bram Moolenaar016188f2022-06-06 20:52:59 +01001899 Returns an empty |Dictionary| on error.
1900
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001901 Examples: >
1902 " Get all items
1903 call complete_info()
1904 " Get only 'mode'
1905 call complete_info(['mode'])
1906 " Get only 'mode' and 'pum_visible'
1907 call complete_info(['mode', 'pum_visible'])
1908
1909< Can also be used as a |method|: >
1910 GetItems()->complete_info()
1911<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001912 Return type: dict<any>
1913
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001914 *confirm()*
1915confirm({msg} [, {choices} [, {default} [, {type}]]])
1916 confirm() offers the user a dialog, from which a choice can be
1917 made. It returns the number of the choice. For the first
1918 choice this is 1.
1919 Note: confirm() is only supported when compiled with dialog
glepnirdf461152024-04-04 22:23:29 +02001920 support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001921
1922 {msg} is displayed in a |dialog| with {choices} as the
1923 alternatives. When {choices} is missing or empty, "&OK" is
1924 used (and translated).
1925 {msg} is a String, use '\n' to include a newline. Only on
1926 some systems the string is wrapped when it doesn't fit.
1927
1928 {choices} is a String, with the individual choices separated
1929 by '\n', e.g. >
1930 confirm("Save changes?", "&Yes\n&No\n&Cancel")
1931< The letter after the '&' is the shortcut key for that choice.
1932 Thus you can type 'c' to select "Cancel". The shortcut does
1933 not need to be the first letter: >
1934 confirm("file has been modified", "&Save\nSave &All")
1935< For the console, the first letter of each choice is used as
1936 the default shortcut key. Case is ignored.
1937
1938 The optional {default} argument is the number of the choice
1939 that is made if the user hits <CR>. Use 1 to make the first
1940 choice the default one. Use 0 to not set a default. If
1941 {default} is omitted, 1 is used.
1942
1943 The optional {type} String argument gives the type of dialog.
1944 This is only used for the icon of the GTK, Mac, Motif and
1945 Win32 GUI. It can be one of these values: "Error",
1946 "Question", "Info", "Warning" or "Generic". Only the first
1947 character is relevant. When {type} is omitted, "Generic" is
1948 used.
1949
1950 If the user aborts the dialog by pressing <Esc>, CTRL-C,
1951 or another valid interrupt key, confirm() returns 0.
1952
1953 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01001954 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001955 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01001956 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001957 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001958 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001959 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001960 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001961 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01001962 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001963< In a GUI dialog, buttons are used. The layout of the buttons
1964 depends on the 'v' flag in 'guioptions'. If it is included,
1965 the buttons are always put vertically. Otherwise, confirm()
1966 tries to put the buttons in one horizontal line. If they
1967 don't fit, a vertical layout is used anyway. For some systems
1968 the horizontal layout is always used.
1969
1970 Can also be used as a |method|in: >
1971 BuildMessage()->confirm("&Yes\n&No")
1972<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001973 Return type: |Number|
1974
1975
1976copy({expr}) *copy()*
1977 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001978 different from using {expr} directly.
1979 When {expr} is a |List| a shallow copy is created. This means
1980 that the original |List| can be changed without changing the
1981 copy, and vice versa. But the items are identical, thus
1982 changing an item changes the contents of both |Lists|.
1983 A |Dictionary| is copied in a similar way as a |List|.
1984 Also see |deepcopy()|.
1985 Can also be used as a |method|: >
1986 mylist->copy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001987<
1988 Return type: any, depending on {expr}
1989
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001990
1991cos({expr}) *cos()*
1992 Return the cosine of {expr}, measured in radians, as a |Float|.
1993 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001994 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001995 Examples: >
1996 :echo cos(100)
1997< 0.862319 >
1998 :echo cos(-4.01)
1999< -0.646043
2000
2001 Can also be used as a |method|: >
2002 Compute()->cos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002003<
2004 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002005
2006
2007cosh({expr}) *cosh()*
2008 Return the hyperbolic cosine of {expr} as a |Float| in the range
2009 [1, inf].
2010 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002011 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002012 Examples: >
2013 :echo cosh(0.5)
2014< 1.127626 >
2015 :echo cosh(-0.5)
2016< -1.127626
2017
2018 Can also be used as a |method|: >
2019 Compute()->cosh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002020<
2021 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002022
2023
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07002024count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002025 Return the number of times an item with value {expr} appears
2026 in |String|, |List| or |Dictionary| {comp}.
2027
2028 If {start} is given then start with the item with this index.
2029 {start} can only be used with a |List|.
2030
2031 When {ic} is given and it's |TRUE| then case is ignored.
2032
2033 When {comp} is a string then the number of not overlapping
2034 occurrences of {expr} is returned. Zero is returned when
2035 {expr} is an empty string.
2036
2037 Can also be used as a |method|: >
2038 mylist->count(val)
2039<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002040 Return type: |Number|
2041
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002042 *cscope_connection()*
2043cscope_connection([{num} , {dbpath} [, {prepend}]])
2044 Checks for the existence of a |cscope| connection. If no
2045 parameters are specified, then the function returns:
2046 0, if cscope was not available (not compiled in), or
2047 if there are no cscope connections;
2048 1, if there is at least one cscope connection.
2049
2050 If parameters are specified, then the value of {num}
2051 determines how existence of a cscope connection is checked:
2052
2053 {num} Description of existence check
2054 ----- ------------------------------
2055 0 Same as no parameters (e.g., "cscope_connection()").
2056 1 Ignore {prepend}, and use partial string matches for
2057 {dbpath}.
2058 2 Ignore {prepend}, and use exact string matches for
2059 {dbpath}.
2060 3 Use {prepend}, use partial string matches for both
2061 {dbpath} and {prepend}.
2062 4 Use {prepend}, use exact string matches for both
2063 {dbpath} and {prepend}.
2064
2065 Note: All string comparisons are case sensitive!
2066
2067 Examples. Suppose we had the following (from ":cs show"): >
2068
2069 # pid database name prepend path
2070 0 27664 cscope.out /usr/local
2071<
2072 Invocation Return Val ~
2073 ---------- ---------- >
2074 cscope_connection() 1
2075 cscope_connection(1, "out") 1
2076 cscope_connection(2, "out") 0
2077 cscope_connection(3, "out") 0
2078 cscope_connection(3, "out", "local") 1
2079 cscope_connection(4, "out") 0
2080 cscope_connection(4, "out", "local") 0
2081 cscope_connection(4, "cscope.out", "/usr/local") 1
2082<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002083 Return type: |Number|
2084
2085
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002086cursor({lnum}, {col} [, {off}]) *cursor()*
2087cursor({list})
2088 Positions the cursor at the column (byte count) {col} in the
2089 line {lnum}. The first column is one.
2090
2091 When there is one argument {list} this is used as a |List|
2092 with two, three or four item:
2093 [{lnum}, {col}]
2094 [{lnum}, {col}, {off}]
2095 [{lnum}, {col}, {off}, {curswant}]
2096 This is like the return value of |getpos()| or |getcurpos()|,
2097 but without the first item.
2098
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01002099 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002100 |setcursorcharpos()|.
2101
2102 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01002103 {lnum} is used like with |getline()|, except that if {lnum} is
2104 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002105 If {lnum} is greater than the number of lines in the buffer,
2106 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002107 If {col} is greater than the number of bytes in the line,
2108 the cursor will be positioned at the last character in the
2109 line.
2110 If {col} is zero, the cursor will stay in the current column.
2111 If {curswant} is given it is used to set the preferred column
2112 for vertical movement. Otherwise {col} is used.
2113
2114 When 'virtualedit' is used {off} specifies the offset in
2115 screen columns from the start of the character. E.g., a
2116 position within a <Tab> or after the last character.
2117 Returns 0 when the position could be set, -1 otherwise.
2118
2119 Can also be used as a |method|: >
2120 GetCursorPos()->cursor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002121<
2122 Return type: |Number|
2123
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002124
2125debugbreak({pid}) *debugbreak()*
2126 Specifically used to interrupt a program being debugged. It
2127 will cause process {pid} to get a SIGTRAP. Behavior for other
2128 processes is undefined. See |terminal-debugger|.
2129 {only available on MS-Windows}
2130
Bram Moolenaar016188f2022-06-06 20:52:59 +01002131 Returns |TRUE| if successfully interrupted the program.
2132 Otherwise returns |FALSE|.
2133
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002134 Can also be used as a |method|: >
2135 GetPid()->debugbreak()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002136<
2137 Return type: |Number|
2138
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002139
2140deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
2141 Make a copy of {expr}. For Numbers and Strings this isn't
2142 different from using {expr} directly.
2143 When {expr} is a |List| a full copy is created. This means
2144 that the original |List| can be changed without changing the
2145 copy, and vice versa. When an item is a |List| or
2146 |Dictionary|, a copy for it is made, recursively. Thus
2147 changing an item in the copy does not change the contents of
2148 the original |List|.
2149 A |Dictionary| is copied in a similar way as a |List|.
2150
2151 When {noref} is omitted or zero a contained |List| or
2152 |Dictionary| is only copied once. All references point to
2153 this single copy. With {noref} set to 1 every occurrence of a
2154 |List| or |Dictionary| results in a new copy. This also means
2155 that a cyclic reference causes deepcopy() to fail.
2156 *E724*
2157 Nesting is possible up to 100 levels. When there is an item
2158 that refers back to a higher level making a deep copy with
2159 {noref} set to 1 will fail.
2160 Also see |copy()|.
2161
2162 Can also be used as a |method|: >
2163 GetObject()->deepcopy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002164<
2165 Return type: any, depending on {expr}
2166
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002167
2168delete({fname} [, {flags}]) *delete()*
2169 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002170 name {fname}.
2171
2172 This also works when {fname} is a symbolic link. The symbolic
2173 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002174
2175 When {flags} is "d": Deletes the directory by the name
2176 {fname}. This fails when directory {fname} is not empty.
2177
2178 When {flags} is "rf": Deletes the directory by the name
2179 {fname} and everything in it, recursively. BE CAREFUL!
2180 Note: on MS-Windows it is not possible to delete a directory
2181 that is being used.
2182
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002183 The result is a Number, which is 0/false if the delete
2184 operation was successful and -1/true when the deletion failed
2185 or partly failed.
2186
2187 Use |remove()| to delete an item from a |List|.
2188 To delete a line from the buffer use |:delete| or
2189 |deletebufline()|.
2190
2191 Can also be used as a |method|: >
2192 GetName()->delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002193<
2194 Return type: |Number|
2195
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002196
2197deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2198 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2199 If {last} is omitted then delete line {first} only.
2200 On success 0 is returned, on failure 1 is returned.
2201
2202 This function works only for loaded buffers. First call
2203 |bufload()| if needed.
2204
2205 For the use of {buf}, see |bufname()| above.
2206
2207 {first} and {last} are used like with |getline()|. Note that
2208 when using |line()| this refers to the current buffer. Use "$"
2209 to refer to the last line in buffer {buf}.
2210
2211 Can also be used as a |method|: >
2212 GetBuffer()->deletebufline(1)
2213<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002214 Return type: |Number|
2215
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002216 *did_filetype()*
2217did_filetype() Returns |TRUE| when autocommands are being executed and the
2218 FileType event has been triggered at least once. Can be used
2219 to avoid triggering the FileType event again in the scripts
2220 that detect the file type. |FileType|
2221 Returns |FALSE| when `:setf FALLBACK` was used.
2222 When editing another file, the counter is reset, thus this
2223 really checks if the FileType event has been triggered for the
2224 current buffer. This allows an autocommand that starts
2225 editing another buffer to set 'filetype' and load a syntax
2226 file.
2227
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002228 Return type: |Number|
2229
2230
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002231diff({fromlist}, {tolist} [, {options}]) *diff()*
2232 Returns a String or a List containing the diff between the
2233 strings in {fromlist} and {tolist}. Uses the Vim internal
2234 diff library to compute the diff.
2235
2236 *E106*
2237 The optional "output" item in {options} specifies the returned
2238 diff format. The following values are supported:
2239 indices Return a List of the starting and ending
2240 indices and a count of the strings in each
2241 diff hunk.
2242 unified Return the unified diff output as a String.
2243 This is the default.
2244
2245 If the "output" item in {options} is "indices", then a List is
2246 returned. Each List item contains a Dict with the following
2247 items for each diff hunk:
2248 from_idx start index in {fromlist} for this diff hunk.
2249 from_count number of strings in {fromlist} that are
2250 added/removed/modified in this diff hunk.
2251 to_idx start index in {tolist} for this diff hunk.
2252 to_count number of strings in {tolist} that are
2253 added/removed/modified in this diff hunk.
2254
2255 The {options} Dict argument also specifies diff options
2256 (similar to 'diffopt') and supports the following items:
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002257 algorithm Dict specifying the diff algorithm to
2258 use. Supported boolean items are
2259 "myers", "minimal", "patience" and
2260 "histogram".
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002261 context diff context length. Default is 0.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002262 iblank ignore changes where lines are all
2263 blank.
2264 icase ignore changes in case of text.
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002265 indent-heuristic use the indent heuristic for the
2266 internal diff library.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002267 iwhite ignore changes in amount of white
2268 space.
2269 iwhiteall ignore all white space changes.
2270 iwhiteeol ignore white space changes at end of
2271 line.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002272 For more information about these options, refer to 'diffopt'.
2273
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002274 To compute the unified diff, all the items in {fromlist} are
2275 concatenated into a string using a newline separator and the
2276 same for {tolist}. The unified diff output uses line numbers.
2277
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002278 Returns an empty List or String if {fromlist} and {tolist} are
2279 identical.
2280
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002281 Examples: >
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002282 :echo diff(['abc'], ['xxx'])
2283 @@ -1 +1 @@
2284 -abc
2285 +xxx
2286
2287 :echo diff(['abc'], ['xxx'], {'output': 'indices'})
2288 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}]
2289 :echo diff(readfile('oldfile'), readfile('newfile'))
2290 :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$'))
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002291<
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002292 For more examples, refer to |diff-func-examples|
2293
2294 Can also be used as a |method|: >
2295 GetFromList->diff(to_list)
2296<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002297 Return type: |String| or list<dict<number>> or list<any>
2298 depending on {options}
2299
2300
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002301diff_filler({lnum}) *diff_filler()*
2302 Returns the number of filler lines above line {lnum}.
2303 These are the lines that were inserted at this point in
2304 another diff'ed window. These filler lines are shown in the
2305 display but don't exist in the buffer.
2306 {lnum} is used like with |getline()|. Thus "." is the current
2307 line, "'m" mark m, etc.
2308 Returns 0 if the current window is not in diff mode.
2309
2310 Can also be used as a |method|: >
2311 GetLnum()->diff_filler()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002312<
2313 Return type: |Number|
2314
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002315
2316diff_hlID({lnum}, {col}) *diff_hlID()*
2317 Returns the highlight ID for diff mode at line {lnum} column
2318 {col} (byte index). When the current line does not have a
2319 diff change zero is returned.
2320 {lnum} is used like with |getline()|. Thus "." is the current
2321 line, "'m" mark m, etc.
2322 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2323 line.
2324 The highlight ID can be used with |synIDattr()| to obtain
2325 syntax information about the highlighting.
2326
2327 Can also be used as a |method|: >
2328 GetLnum()->diff_hlID(col)
2329<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002330 Return type: |Number|
2331
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002332
2333digraph_get({chars}) *digraph_get()* *E1214*
2334 Return the digraph of {chars}. This should be a string with
2335 exactly two characters. If {chars} are not just two
2336 characters, or the digraph of {chars} does not exist, an error
2337 is given and an empty string is returned.
2338
2339 The character will be converted from Unicode to 'encoding'
2340 when needed. This does require the conversion to be
2341 available, it might fail.
2342
2343 Also see |digraph_getlist()|.
2344
2345 Examples: >
2346 " Get a built-in digraph
2347 :echo digraph_get('00') " Returns '∞'
2348
2349 " Get a user-defined digraph
2350 :call digraph_set('aa', 'あ')
2351 :echo digraph_get('aa') " Returns 'あ'
2352<
2353 Can also be used as a |method|: >
2354 GetChars()->digraph_get()
2355<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002356 Return type: |String|
2357
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002358 This function works only when compiled with the |+digraphs|
2359 feature. If this feature is disabled, this function will
2360 display an error message.
2361
2362
2363digraph_getlist([{listall}]) *digraph_getlist()*
2364 Return a list of digraphs. If the {listall} argument is given
2365 and it is TRUE, return all digraphs, including the default
2366 digraphs. Otherwise, return only user-defined digraphs.
2367
2368 The characters will be converted from Unicode to 'encoding'
2369 when needed. This does require the conservation to be
2370 available, it might fail.
2371
2372 Also see |digraph_get()|.
2373
2374 Examples: >
2375 " Get user-defined digraphs
2376 :echo digraph_getlist()
2377
2378 " Get all the digraphs, including default digraphs
2379 :echo digraph_getlist(1)
2380<
2381 Can also be used as a |method|: >
2382 GetNumber()->digraph_getlist()
2383<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002384 Return type: list<list<string>>
2385
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002386 This function works only when compiled with the |+digraphs|
2387 feature. If this feature is disabled, this function will
2388 display an error message.
2389
2390
Bram Moolenaara2baa732022-02-04 16:09:54 +00002391digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002392 Add digraph {chars} to the list. {chars} must be a string
2393 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002394 encoded character. *E1215*
2395 Be careful, composing characters are NOT ignored. This
2396 function is similar to |:digraphs| command, but useful to add
2397 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002398
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002399 The function returns v:true if |digraph| is registered. If
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002400 this fails an error message is given and v:false is returned.
2401
2402 If you want to define multiple digraphs at once, you can use
2403 |digraph_setlist()|.
2404
2405 Example: >
2406 call digraph_set(' ', 'あ')
2407<
2408 Can be used as a |method|: >
2409 GetString()->digraph_set('あ')
2410<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002411 Return type: |vim9-boolean|
2412
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002413 This function works only when compiled with the |+digraphs|
2414 feature. If this feature is disabled, this function will
2415 display an error message.
2416
2417
2418digraph_setlist({digraphlist}) *digraph_setlist()*
2419 Similar to |digraph_set()| but this function can add multiple
2420 digraphs at once. {digraphlist} is a list composed of lists,
2421 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002422 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002423 Example: >
2424 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2425<
2426 It is similar to the following: >
2427 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2428 call digraph_set(chars, digraph)
2429 endfor
2430< Except that the function returns after the first error,
2431 following digraphs will not be added.
2432
2433 Can be used as a |method|: >
2434 GetList()->digraph_setlist()
2435<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002436 Return type: |vim9-boolean|
2437
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002438 This function works only when compiled with the |+digraphs|
2439 feature. If this feature is disabled, this function will
2440 display an error message.
2441
2442
2443echoraw({string}) *echoraw()*
2444 Output {string} as-is, including unprintable characters.
2445 This can be used to output a terminal code. For example, to
2446 disable modifyOtherKeys: >
2447 call echoraw(&t_TE)
2448< and to enable it again: >
2449 call echoraw(&t_TI)
2450< Use with care, you can mess up the terminal this way.
2451
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002452 Return type: |Number|
2453
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002454
2455empty({expr}) *empty()*
2456 Return the Number 1 if {expr} is empty, zero otherwise.
2457 - A |List| or |Dictionary| is empty when it does not have any
2458 items.
2459 - A |String| is empty when its length is zero.
2460 - A |Number| and |Float| are empty when their value is zero.
2461 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2462 - A |Job| is empty when it failed to start.
2463 - A |Channel| is empty when it is closed.
2464 - A |Blob| is empty when its length is zero.
mityu7f0bba22024-03-29 10:14:41 +01002465 - An |Object| is empty, when the empty() method in the object
2466 (if present) returns true. |object-empty()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002467
2468 For a long |List| this is much faster than comparing the
2469 length with zero.
2470
2471 Can also be used as a |method|: >
2472 mylist->empty()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002473<
2474 Return type: |Number|
2475
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002476
2477environ() *environ()*
2478 Return all of environment variables as dictionary. You can
2479 check if an environment variable exists like this: >
2480 :echo has_key(environ(), 'HOME')
2481< Note that the variable name may be CamelCase; to ignore case
2482 use this: >
2483 :echo index(keys(environ()), 'HOME', 0, 1) != -1
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002484<
2485 Return type: dict<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002486
Bram Moolenaar416bd912023-07-07 23:19:18 +01002487
2488err_teapot([{expr}]) *err_teapot()*
2489 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002490 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002491 If {expr} is present and it is TRUE error 503 is given,
2492 indicating that coffee is temporarily not available.
2493 If {expr} is present it must be a String.
2494
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002495 Return type: |Number|
2496
Bram Moolenaar416bd912023-07-07 23:19:18 +01002497
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002498escape({string}, {chars}) *escape()*
2499 Escape the characters in {chars} that occur in {string} with a
2500 backslash. Example: >
2501 :echo escape('c:\program files\vim', ' \')
2502< results in: >
2503 c:\\program\ files\\vim
2504< Also see |shellescape()| and |fnameescape()|.
2505
2506 Can also be used as a |method|: >
2507 GetText()->escape(' \')
2508<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002509 Return type: |String|
2510
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002511 *eval()*
2512eval({string}) Evaluate {string} and return the result. Especially useful to
2513 turn the result of |string()| back into the original value.
2514 This works for Numbers, Floats, Strings, Blobs and composites
2515 of them. Also works for |Funcref|s that refer to existing
Aliaksei Budavei95740222024-04-04 23:05:33 +03002516 functions. In |Vim9| script, it can be used to obtain |enum|
2517 values from their fully qualified names.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002518
2519 Can also be used as a |method|: >
2520 argv->join()->eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002521<
2522 Return type: any, depending on {string}
2523
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002524
2525eventhandler() *eventhandler()*
2526 Returns 1 when inside an event handler. That is that Vim got
2527 interrupted while waiting for the user to type a character,
2528 e.g., when dropping a file on Vim. This means interactive
2529 commands cannot be used. Otherwise zero is returned.
2530
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002531 Return type: |Number|
2532
2533
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002534executable({expr}) *executable()*
2535 This function checks if an executable with the name {expr}
2536 exists. {expr} must be the name of the program without any
2537 arguments.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002538
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002539 executable() uses the value of $PATH and/or the normal
zeertzjq0cc5dce2024-08-08 21:12:15 +02002540 searchpath for programs.
2541 *PATHEXT*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002542 On MS-Windows the ".exe", ".bat", etc. can optionally be
2543 included. Then the extensions in $PATHEXT are tried. Thus if
2544 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2545 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2546 by itself can be used in $PATHEXT to try using the name
2547 without an extension. When 'shell' looks like a Unix shell,
2548 then the name is also tried without adding an extension.
2549 On MS-Windows it only checks if the file exists and is not a
2550 directory, not if it's really executable.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002551 On MS-Windows an executable in the same directory as the Vim
2552 executable is always found. Since this directory is added to
2553 $PATH it should also work to execute it |win32-PATH|.
2554 *NoDefaultCurrentDirectoryInExePath*
2555 On MS-Windows an executable in Vim's current working directory
2556 is also normally found, but this can be disabled by setting
2557 the $NoDefaultCurrentDirectoryInExePath environment variable.
2558
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002559 The result is a Number:
2560 1 exists
2561 0 does not exist
2562 -1 not implemented on this system
2563 |exepath()| can be used to get the full path of an executable.
2564
2565 Can also be used as a |method|: >
2566 GetCommand()->executable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002567<
2568 Return type: |Number|
2569
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002570
2571execute({command} [, {silent}]) *execute()*
2572 Execute an Ex command or commands and return the output as a
2573 string.
2574 {command} can be a string or a List. In case of a List the
2575 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002576 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002577 redir => var
2578 {command}
2579 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002580< Except that line continuation in {command} is not recognized.
2581
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002582 The optional {silent} argument can have these values:
2583 "" no `:silent` used
2584 "silent" `:silent` used
2585 "silent!" `:silent!` used
2586 The default is "silent". Note that with "silent!", unlike
2587 `:redir`, error messages are dropped. When using an external
2588 command the screen may be messed up, use `system()` instead.
2589 *E930*
2590 It is not possible to use `:redir` anywhere in {command}.
2591
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002592 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002593 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002594
2595< To execute a command in another window than the current one
2596 use `win_execute()`.
2597
2598 When used recursively the output of the recursive call is not
2599 included in the output of the higher level call.
2600
2601 Can also be used as a |method|: >
2602 GetCommand()->execute()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002603<
Marius Gedminasc98bfb92024-06-19 19:59:23 +02002604 Return type: |String|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002605
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002606
2607exepath({expr}) *exepath()*
2608 If {expr} is an executable and is either an absolute path, a
2609 relative path or found in $PATH, return the full path.
2610 Note that the current directory is used when {expr} starts
2611 with "./", which may be a problem for Vim: >
2612 echo exepath(v:progpath)
2613< If {expr} cannot be found in $PATH or is not executable then
2614 an empty string is returned.
2615
2616 Can also be used as a |method|: >
2617 GetCommand()->exepath()
2618<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002619 Return type: |String|
2620
2621
2622exists({expr}) *exists()*
2623 The result is a Number, which is |TRUE| if {expr} is defined,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002624 zero otherwise.
2625
2626 Note: In a compiled |:def| function the evaluation is done at
2627 runtime. Use `exists_compiled()` to evaluate the expression
2628 at compile time.
2629
2630 For checking for a supported feature use |has()|.
2631 For checking if a file exists use |filereadable()|.
2632
2633 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002634 varname internal variable (see
2635 dict.key |internal-variables|). Also works
2636 list[i] for |curly-braces-names|, |Dictionary|
Yegappan Lakshmanana2ebb6e2024-02-25 08:40:10 +01002637 import.Func entries, |List| items, class and
2638 class.Func object methods, imported items, etc.
2639 object.Func Does not work for local variables in a
2640 class.varname compiled `:def` function.
2641 object.varname Also works for a function in |Vim9|
Bram Moolenaar944697a2022-02-20 19:48:20 +00002642 script, since it can be used as a
2643 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002644 Beware that evaluating an index may
2645 cause an error message for an invalid
2646 expression. E.g.: >
2647 :let l = [1, 2, 3]
2648 :echo exists("l[5]")
2649< 0 >
2650 :echo exists("l[xx]")
2651< E121: Undefined variable: xx
2652 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002653 &option-name Vim option (only checks if it exists,
2654 not if it really works)
2655 +option-name Vim option that works.
2656 $ENVNAME environment variable (could also be
2657 done by comparing with an empty
2658 string)
2659 *funcname built-in function (see |functions|)
2660 or user defined function (see
2661 |user-functions|) that is implemented.
2662 Also works for a variable that is a
2663 Funcref.
2664 ?funcname built-in function that could be
2665 implemented; to be used to check if
2666 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002667 :cmdname Ex command: built-in command, user
2668 command or command modifier |:command|.
2669 Returns:
2670 1 for match with start of a command
2671 2 full match with a command
2672 3 matches several user commands
2673 To check for a supported command
2674 always check the return value to be 2.
2675 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002676 :3match The |:3match| command (but you
2677 probably should not use it, it is
2678 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002679 #event autocommand defined for this event
2680 #event#pattern autocommand defined for this event and
2681 pattern (the pattern is taken
2682 literally and compared to the
2683 autocommand patterns character by
2684 character)
2685 #group autocommand group exists
2686 #group#event autocommand defined for this group and
2687 event.
2688 #group#event#pattern
2689 autocommand defined for this group,
2690 event and pattern.
2691 ##event autocommand for this event is
2692 supported.
2693
2694 Examples: >
2695 exists("&shortname")
2696 exists("$HOSTNAME")
2697 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002698 exists("*s:MyFunc") " only for legacy script
2699 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002700 exists("bufcount")
2701 exists(":Make")
2702 exists("#CursorHold")
2703 exists("#BufReadPre#*.gz")
2704 exists("#filetypeindent")
2705 exists("#filetypeindent#FileType")
2706 exists("#filetypeindent#FileType#*")
2707 exists("##ColorScheme")
2708< There must be no space between the symbol (&/$/*/#) and the
2709 name.
2710 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002711 a few cases this is ignored. That may become stricter in the
2712 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002713 Working example: >
2714 exists(":make")
2715< NOT working example: >
2716 exists(":make install")
2717
2718< Note that the argument must be a string, not the name of the
2719 variable itself. For example: >
2720 exists(bufcount)
2721< This doesn't check for existence of the "bufcount" variable,
2722 but gets the value of "bufcount", and checks if that exists.
2723
2724 Can also be used as a |method|: >
2725 Varname()->exists()
2726<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002727 Return type: |String|
2728
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002729
2730exists_compiled({expr}) *exists_compiled()*
2731 Like `exists()` but evaluated at compile time. This is useful
2732 to skip a block where a function is used that would otherwise
2733 give an error: >
2734 if exists_compiled('*ThatFunction')
2735 ThatFunction('works')
2736 endif
2737< If `exists()` were used then a compilation error would be
2738 given if ThatFunction() is not defined.
2739
2740 {expr} must be a literal string. *E1232*
2741 Can only be used in a |:def| function. *E1233*
2742 This does not work to check for arguments or local variables.
2743
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002744 Return type: |String|
2745
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002746
2747exp({expr}) *exp()*
2748 Return the exponential of {expr} as a |Float| in the range
2749 [0, inf].
2750 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002751 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002752 Examples: >
2753 :echo exp(2)
2754< 7.389056 >
2755 :echo exp(-1)
2756< 0.367879
2757
2758 Can also be used as a |method|: >
2759 Compute()->exp()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002760<
2761 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002762
2763
2764expand({string} [, {nosuf} [, {list}]]) *expand()*
2765 Expand wildcards and the following special keywords in
2766 {string}. 'wildignorecase' applies.
2767
2768 If {list} is given and it is |TRUE|, a List will be returned.
2769 Otherwise the result is a String and when there are several
2770 matches, they are separated by <NL> characters. [Note: in
2771 version 5.0 a space was used, which caused problems when a
2772 file name contains a space]
2773
2774 If the expansion fails, the result is an empty string. A name
2775 for a non-existing file is not included, unless {string} does
2776 not start with '%', '#' or '<', see below.
2777
Christian Brabandtec9c3262024-02-21 20:40:05 +01002778 For a |:terminal| window '%' expands to a '!' followed by
h-east53753f62024-05-05 18:42:31 +02002779 the command or shell that is run. |terminal-bufname|
Christian Brabandtec9c3262024-02-21 20:40:05 +01002780
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002781 When {string} starts with '%', '#' or '<', the expansion is
2782 done like for the |cmdline-special| variables with their
2783 associated modifiers. Here is a short overview:
2784
2785 % current file name
2786 # alternate file name
2787 #n alternate file name n
2788 <cfile> file name under the cursor
2789 <afile> autocmd file name
2790 <abuf> autocmd buffer number (as a String!)
2791 <amatch> autocmd matched name
2792 <cexpr> C expression under the cursor
2793 <sfile> sourced script file or function name
2794 <slnum> sourced script line number or function
2795 line number
2796 <sflnum> script file line number, also when in
2797 a function
2798 <SID> "<SNR>123_" where "123" is the
2799 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002800 <script> sourced script file, or script file
2801 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002802 <stack> call stack
2803 <cword> word under the cursor
2804 <cWORD> WORD under the cursor
2805 <client> the {clientid} of the last received
2806 message |server2client()|
2807 Modifiers:
2808 :p expand to full path
2809 :h head (last path component removed)
2810 :t tail (last path component only)
2811 :r root (one extension removed)
2812 :e extension only
2813
2814 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002815 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002816< Note that when expanding a string that starts with '%', '#' or
2817 '<', any following text is ignored. This does NOT work: >
2818 :let doesntwork = expand("%:h.bak")
2819< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002820 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002821< Also note that expanding "<cfile>" and others only returns the
2822 referenced file name without further expansion. If "<cfile>"
2823 is "~/.cshrc", you need to do another expand() to have the
2824 "~/" expanded into the path of the home directory: >
2825 :echo expand(expand("<cfile>"))
2826<
2827 There cannot be white space between the variables and the
2828 following modifier. The |fnamemodify()| function can be used
2829 to modify normal file names.
2830
2831 When using '%' or '#', and the current or alternate file name
2832 is not defined, an empty string is used. Using "%:p" in a
2833 buffer with no name, results in the current directory, with a
2834 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002835 When 'verbose' is set then expanding '%', '#' and <> items
2836 will result in an error message if the argument cannot be
2837 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002838
2839 When {string} does not start with '%', '#' or '<', it is
2840 expanded like a file name is expanded on the command line.
2841 'suffixes' and 'wildignore' are used, unless the optional
2842 {nosuf} argument is given and it is |TRUE|.
2843 Names for non-existing files are included. The "**" item can
2844 be used to search in a directory tree. For example, to find
2845 all "README" files in the current directory and below: >
2846 :echo expand("**/README")
2847<
2848 expand() can also be used to expand variables and environment
2849 variables that are only known in a shell. But this can be
2850 slow, because a shell may be used to do the expansion. See
2851 |expr-env-expand|.
2852 The expanded variable is still handled like a list of file
2853 names. When an environment variable cannot be expanded, it is
2854 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2855 "$FOOBAR".
2856
2857 See |glob()| for finding existing files. See |system()| for
2858 getting the raw output of an external command.
2859
2860 Can also be used as a |method|: >
2861 Getpattern()->expand()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002862<
2863 Return type: |String| or list<string> depending on {list}
2864
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002865
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002866expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002867 Expand special items in String {string} like what is done for
2868 an Ex command such as `:edit`. This expands special keywords,
2869 like with |expand()|, and environment variables, anywhere in
2870 {string}. "~user" and "~/path" are only expanded at the
2871 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002872
2873 The following items are supported in the {options} Dict
2874 argument:
2875 errmsg If set to TRUE, error messages are displayed
2876 if an error is encountered during expansion.
2877 By default, error messages are not displayed.
2878
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002879 Returns the expanded string. If an error is encountered
2880 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002881
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002882 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002883 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002884 make /path/runtime/doc/builtin.o
2885 :echo expandcmd('make %<.o', {'errmsg': v:true})
2886<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002887 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002888 GetCommand()->expandcmd()
2889<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002890 Return type: |String| or list<string> depending on {list}
2891
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002892extend({expr1}, {expr2} [, {expr3}]) *extend()*
2893 {expr1} and {expr2} must be both |Lists| or both
2894 |Dictionaries|.
2895
2896 If they are |Lists|: Append {expr2} to {expr1}.
2897 If {expr3} is given insert the items of {expr2} before the
2898 item with index {expr3} in {expr1}. When {expr3} is zero
2899 insert before the first item. When {expr3} is equal to
2900 len({expr1}) then {expr2} is appended.
2901 Examples: >
2902 :echo sort(extend(mylist, [7, 5]))
2903 :call extend(mylist, [2, 3], 1)
2904< When {expr1} is the same List as {expr2} then the number of
2905 items copied is equal to the original length of the List.
2906 E.g., when {expr3} is 1 you get N new copies of the first item
2907 (where N is the original length of the List).
2908 Use |add()| to concatenate one item to a list. To concatenate
2909 two lists into a new list use the + operator: >
2910 :let newlist = [1, 2, 3] + [4, 5]
2911<
2912 If they are |Dictionaries|:
2913 Add all entries from {expr2} to {expr1}.
2914 If a key exists in both {expr1} and {expr2} then {expr3} is
2915 used to decide what to do:
2916 {expr3} = "keep": keep the value of {expr1}
2917 {expr3} = "force": use the value of {expr2}
2918 {expr3} = "error": give an error message *E737*
2919 When {expr3} is omitted then "force" is assumed.
2920
2921 {expr1} is changed when {expr2} is not empty. If necessary
2922 make a copy of {expr1} first.
2923 {expr2} remains unchanged.
2924 When {expr1} is locked and {expr2} is not empty the operation
2925 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002926 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002927
2928 Can also be used as a |method|: >
2929 mylist->extend(otherlist)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002930<
2931 Return type: list<{type}> or dict<{type}> depending on {expr1}
2932 and {expr2}, in case of error: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002933
2934
2935extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
2936 Like |extend()| but instead of adding items to {expr1} a new
2937 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00002938 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002939
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002940 Return type: list<{type}> or dict<{type}> depending on {expr1}
2941 and {expr2}, in case of error: |Number|
2942
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002943
2944feedkeys({string} [, {mode}]) *feedkeys()*
2945 Characters in {string} are queued for processing as if they
2946 come from a mapping or were typed by the user.
2947
2948 By default the string is added to the end of the typeahead
2949 buffer, thus if a mapping is still being executed the
2950 characters come after them. Use the 'i' flag to insert before
2951 other characters, they will be executed next, before any
2952 characters from a mapping.
2953
2954 The function does not wait for processing of keys contained in
2955 {string}.
2956
2957 To include special keys into {string}, use double-quotes
2958 and "\..." notation |expr-quote|. For example,
2959 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
2960 feedkeys('\<CR>') pushes 5 characters.
2961 A special code that might be useful is <Ignore>, it exits the
2962 wait for a character without doing anything. *<Ignore>*
2963
2964 {mode} is a String, which can contain these character flags:
2965 'm' Remap keys. This is default. If {mode} is absent,
2966 keys are remapped.
2967 'n' Do not remap keys.
2968 't' Handle keys as if typed; otherwise they are handled as
2969 if coming from a mapping. This matters for undo,
2970 opening folds, etc.
2971 'L' Lowlevel input. Only works for Unix or when using the
2972 GUI. Keys are used as if they were coming from the
2973 terminal. Other flags are not used. *E980*
2974 When a CTRL-C interrupts and 't' is included it sets
2975 the internal "got_int" flag.
2976 'i' Insert the string instead of appending (see above).
2977 'x' Execute commands until typeahead is empty. This is
2978 similar to using ":normal!". You can call feedkeys()
2979 several times without 'x' and then one time with 'x'
2980 (possibly with an empty {string}) to execute all the
2981 typeahead. Note that when Vim ends in Insert mode it
2982 will behave as if <Esc> is typed, to avoid getting
2983 stuck, waiting for a character to be typed before the
2984 script continues.
2985 Note that if you manage to call feedkeys() while
2986 executing commands, thus calling it recursively, then
2987 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00002988 'c' Remove any script context when executing, so that
2989 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01002990 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01002991 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002992 '!' When used with 'x' will not end Insert mode. Can be
2993 used in a test when a timer is set to exit Insert mode
2994 a little later. Useful for testing CursorHoldI.
2995
2996 Return value is always 0.
2997
2998 Can also be used as a |method|: >
2999 GetInput()->feedkeys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003000<
3001 Return type: |String| or list<string> depending on {list}
3002
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003003
Shougo Matsushita60c87432024-06-03 22:59:27 +02003004filecopy({from}, {to}) *filecopy()*
3005 Copy the file pointed to by the name {from} to {to}. The
3006 result is a Number, which is |TRUE| if the file was copied
3007 successfully, and |FALSE| when it failed.
3008 If a file with name {to} already exists, it will fail.
3009 Note that it does not handle directories (yet).
3010
3011 This function is not available in the |sandbox|.
3012
3013 Can also be used as a |method|: >
3014 GetOldName()->filecopy(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003015<
3016 Return type: |Number|
3017
Shougo Matsushita60c87432024-06-03 22:59:27 +02003018
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003019filereadable({file}) *filereadable()*
3020 The result is a Number, which is |TRUE| when a file with the
3021 name {file} exists, and can be read. If {file} doesn't exist,
3022 or is a directory, the result is |FALSE|. {file} is any
3023 expression, which is used as a String.
3024 If you don't care about the file being readable you can use
3025 |glob()|.
3026 {file} is used as-is, you may want to expand wildcards first: >
3027 echo filereadable('~/.vimrc')
3028 0
3029 echo filereadable(expand('~/.vimrc'))
3030 1
3031
3032< Can also be used as a |method|: >
3033 GetName()->filereadable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003034<
3035 Return type: |Number|
3036
3037 *file_readable()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003038 Obsolete name: file_readable().
3039
3040
3041filewritable({file}) *filewritable()*
3042 The result is a Number, which is 1 when a file with the
3043 name {file} exists, and can be written. If {file} doesn't
3044 exist, or is not writable, the result is 0. If {file} is a
3045 directory, and we can write to it, the result is 2.
3046
3047 Can also be used as a |method|: >
3048 GetName()->filewritable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003049<
3050 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003051
3052
3053filter({expr1}, {expr2}) *filter()*
3054 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3055 For each item in {expr1} evaluate {expr2} and when the result
3056 is zero or false remove the item from the |List| or
3057 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003058 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003059
3060 {expr2} must be a |string| or |Funcref|.
3061
3062 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3063 of the current item. For a |Dictionary| |v:key| has the key
3064 of the current item and for a |List| |v:key| has the index of
3065 the current item. For a |Blob| |v:key| has the index of the
3066 current byte. For a |String| |v:key| has the index of the
3067 current character.
3068 Examples: >
3069 call filter(mylist, 'v:val !~ "OLD"')
3070< Removes the items where "OLD" appears. >
3071 call filter(mydict, 'v:key >= 8')
3072< Removes the items with a key below 8. >
3073 call filter(var, 0)
3074< Removes all the items, thus clears the |List| or |Dictionary|.
3075
3076 Note that {expr2} is the result of expression and is then
3077 used as an expression again. Often it is good to use a
3078 |literal-string| to avoid having to double backslashes.
3079
3080 If {expr2} is a |Funcref| it must take two arguments:
3081 1. the key or the index of the current item.
3082 2. the value of the current item.
3083 The function must return |TRUE| if the item should be kept.
3084 Example that keeps the odd items of a list: >
3085 func Odd(idx, val)
3086 return a:idx % 2 == 1
3087 endfunc
3088 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003089< It is shorter when using a |lambda|. In |Vim9| syntax: >
3090 call filter(myList, (idx, val) => idx * val <= 42)
3091< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003092 call filter(myList, {idx, val -> idx * val <= 42})
3093< If you do not use "val" you can leave it out: >
3094 call filter(myList, {idx -> idx % 2 == 1})
3095<
3096 In |Vim9| script the result must be true, false, zero or one.
3097 Other values will result in a type error.
3098
3099 For a |List| and a |Dictionary| the operation is done
3100 in-place. If you want it to remain unmodified make a copy
3101 first: >
3102 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
3103
3104< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00003105 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003106 When an error is encountered while evaluating {expr2} no
3107 further items in {expr1} are processed.
3108 When {expr2} is a Funcref errors inside a function are ignored,
3109 unless it was defined with the "abort" flag.
3110
3111 Can also be used as a |method|: >
3112 mylist->filter(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003113<
3114 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
3115 depending on {expr1}
3116
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003117
3118finddir({name} [, {path} [, {count}]]) *finddir()*
3119 Find directory {name} in {path}. Supports both downwards and
3120 upwards recursive directory searches. See |file-searching|
3121 for the syntax of {path}.
3122
3123 Returns the path of the first found match. When the found
3124 directory is below the current directory a relative path is
3125 returned. Otherwise a full path is returned.
3126 If {path} is omitted or empty then 'path' is used.
3127
3128 If the optional {count} is given, find {count}'s occurrence of
3129 {name} in {path} instead of the first one.
3130 When {count} is negative return all the matches in a |List|.
3131
Bram Moolenaar016188f2022-06-06 20:52:59 +01003132 Returns an empty string if the directory is not found.
3133
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003134 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003135
3136 Can also be used as a |method|: >
3137 GetName()->finddir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003138<
3139 Return type: |String|
3140
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003141
3142findfile({name} [, {path} [, {count}]]) *findfile()*
3143 Just like |finddir()|, but find a file instead of a directory.
3144 Uses 'suffixesadd'.
3145 Example: >
3146 :echo findfile("tags.vim", ".;")
3147< Searches from the directory of the current file upwards until
3148 it finds the file "tags.vim".
3149
3150 Can also be used as a |method|: >
3151 GetName()->findfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003152<
3153 Return type: |String|
3154
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003155
3156flatten({list} [, {maxdepth}]) *flatten()*
3157 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
3158 the result is a |List| without nesting, as if {maxdepth} is
3159 a very large number.
3160 The {list} is changed in place, use |flattennew()| if you do
3161 not want that.
3162 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00003163 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003164 *E900*
3165 {maxdepth} means how deep in nested lists changes are made.
3166 {list} is not modified when {maxdepth} is 0.
3167 {maxdepth} must be positive number.
3168
3169 If there is an error the number zero is returned.
3170
3171 Example: >
3172 :echo flatten([1, [2, [3, 4]], 5])
3173< [1, 2, 3, 4, 5] >
3174 :echo flatten([1, [2, [3, 4]], 5], 1)
3175< [1, 2, [3, 4], 5]
3176
3177 Can also be used as a |method|: >
3178 mylist->flatten()
3179<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003180 Return type: list<{type}>
3181
3182
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003183flattennew({list} [, {maxdepth}]) *flattennew()*
3184 Like |flatten()| but first make a copy of {list}.
3185
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003186 Return type: list<{type}>
3187
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003188
3189float2nr({expr}) *float2nr()*
3190 Convert {expr} to a Number by omitting the part after the
3191 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00003192 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003193 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003194 When the value of {expr} is out of range for a |Number| the
3195 result is truncated to 0x7fffffff or -0x7fffffff (or when
3196 64-bit Number support is enabled, 0x7fffffffffffffff or
3197 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
3198 64-bit Number support is enabled, -0x8000000000000000).
3199 Examples: >
3200 echo float2nr(3.95)
3201< 3 >
3202 echo float2nr(-23.45)
3203< -23 >
3204 echo float2nr(1.0e100)
3205< 2147483647 (or 9223372036854775807) >
3206 echo float2nr(-1.0e150)
3207< -2147483647 (or -9223372036854775807) >
3208 echo float2nr(1.0e-100)
3209< 0
3210
3211 Can also be used as a |method|: >
3212 Compute()->float2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003213<
3214 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003215
3216
3217floor({expr}) *floor()*
3218 Return the largest integral value less than or equal to
3219 {expr} as a |Float| (round down).
3220 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003221 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003222 Examples: >
3223 echo floor(1.856)
3224< 1.0 >
3225 echo floor(-5.456)
3226< -6.0 >
3227 echo floor(4.0)
3228< 4.0
3229
3230 Can also be used as a |method|: >
3231 Compute()->floor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003232<
3233 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003234
3235
3236fmod({expr1}, {expr2}) *fmod()*
3237 Return the remainder of {expr1} / {expr2}, even if the
3238 division is not representable. Returns {expr1} - i * {expr2}
3239 for some integer i such that if {expr2} is non-zero, the
3240 result has the same sign as {expr1} and magnitude less than
3241 the magnitude of {expr2}. If {expr2} is zero, the value
3242 returned is zero. The value returned is a |Float|.
3243 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003244 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
3245 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003246 Examples: >
3247 :echo fmod(12.33, 1.22)
3248< 0.13 >
3249 :echo fmod(-12.33, 1.22)
3250< -0.13
3251
3252 Can also be used as a |method|: >
3253 Compute()->fmod(1.22)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003254<
3255 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003256
3257
3258fnameescape({string}) *fnameescape()*
3259 Escape {string} for use as file name command argument. All
3260 characters that have a special meaning, such as '%' and '|'
3261 are escaped with a backslash.
3262 For most systems the characters escaped are
3263 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3264 appears in a filename, it depends on the value of 'isfname'.
3265 A leading '+' and '>' is also escaped (special after |:edit|
3266 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01003267 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003268 Example: >
3269 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003270 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003271< results in executing: >
3272 edit \+some\ str\%nge\|name
3273<
3274 Can also be used as a |method|: >
3275 GetName()->fnameescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003276<
3277 Return type: |String|
3278
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003279
3280fnamemodify({fname}, {mods}) *fnamemodify()*
3281 Modify file name {fname} according to {mods}. {mods} is a
3282 string of characters like it is used for file names on the
3283 command line. See |filename-modifiers|.
3284 Example: >
3285 :echo fnamemodify("main.c", ":p:h")
3286< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01003287 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01003288< If {mods} is empty or an unsupported modifier is used then
3289 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01003290 When {fname} is empty then with {mods} ":h" returns ".", so
3291 that `:cd` can be used with it. This is different from
3292 expand('%:h') without a buffer name, which returns an empty
3293 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003294 Note: Environment variables don't work in {fname}, use
3295 |expand()| first then.
3296
3297 Can also be used as a |method|: >
3298 GetName()->fnamemodify(':p:h')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003299<
3300 Return type: |String|
3301
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003302
3303foldclosed({lnum}) *foldclosed()*
3304 The result is a Number. If the line {lnum} is in a closed
3305 fold, the result is the number of the first line in that fold.
3306 If the line {lnum} is not in a closed fold, -1 is returned.
3307 {lnum} is used like with |getline()|. Thus "." is the current
3308 line, "'m" mark m, etc.
3309
3310 Can also be used as a |method|: >
3311 GetLnum()->foldclosed()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003312<
3313 Return type: |Number|
3314
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003315
3316foldclosedend({lnum}) *foldclosedend()*
3317 The result is a Number. If the line {lnum} is in a closed
3318 fold, the result is the number of the last line in that fold.
3319 If the line {lnum} is not in a closed fold, -1 is returned.
3320 {lnum} is used like with |getline()|. Thus "." is the current
3321 line, "'m" mark m, etc.
3322
3323 Can also be used as a |method|: >
3324 GetLnum()->foldclosedend()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003325<
3326 Return type: |Number|
3327
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003328
3329foldlevel({lnum}) *foldlevel()*
3330 The result is a Number, which is the foldlevel of line {lnum}
3331 in the current buffer. For nested folds the deepest level is
3332 returned. If there is no fold at line {lnum}, zero is
3333 returned. It doesn't matter if the folds are open or closed.
3334 When used while updating folds (from 'foldexpr') -1 is
3335 returned for lines where folds are still to be updated and the
3336 foldlevel is unknown. As a special case the level of the
3337 previous line is usually available.
3338 {lnum} is used like with |getline()|. Thus "." is the current
3339 line, "'m" mark m, etc.
3340
3341 Can also be used as a |method|: >
3342 GetLnum()->foldlevel()
3343<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003344 Return type: |Number|
3345
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003346 *foldtext()*
3347foldtext() Returns a String, to be displayed for a closed fold. This is
3348 the default function used for the 'foldtext' option and should
3349 only be called from evaluating 'foldtext'. It uses the
3350 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3351 The returned string looks like this: >
3352 +-- 45 lines: abcdef
3353< The number of leading dashes depends on the foldlevel. The
3354 "45" is the number of lines in the fold. "abcdef" is the text
3355 in the first non-blank line of the fold. Leading white space,
3356 "//" or "/*" and the text from the 'foldmarker' and
3357 'commentstring' options is removed.
3358 When used to draw the actual foldtext, the rest of the line
3359 will be filled with the fold char from the 'fillchars'
3360 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003361 Returns an empty string when there is no fold.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003362
3363 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003364 {not available when compiled without the |+folding| feature}
3365
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003366
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003367foldtextresult({lnum}) *foldtextresult()*
3368 Returns the text that is displayed for the closed fold at line
3369 {lnum}. Evaluates 'foldtext' in the appropriate context.
3370 When there is no closed fold at {lnum} an empty string is
3371 returned.
3372 {lnum} is used like with |getline()|. Thus "." is the current
3373 line, "'m" mark m, etc.
3374 Useful when exporting folded text, e.g., to HTML.
3375 {not available when compiled without the |+folding| feature}
3376
3377
3378 Can also be used as a |method|: >
3379 GetLnum()->foldtextresult()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003380<
3381 Return type: |String|
3382
Ernie Raele79e2072024-01-13 11:47:33 +01003383
3384foreach({expr1}, {expr2}) *foreach()*
3385 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3386 For each item in {expr1} execute {expr2}. {expr1} is not
erraelc92b8be2024-01-14 10:11:07 -08003387 modified; its values may be, as with |:lockvar| 1. |E741|
Ernie Raele79e2072024-01-13 11:47:33 +01003388 See |map()| and |filter()| to modify {expr1}.
3389
3390 {expr2} must be a |string| or |Funcref|.
3391
3392 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3393 of the current item. For a |Dictionary| |v:key| has the key
3394 of the current item and for a |List| |v:key| has the index of
3395 the current item. For a |Blob| |v:key| has the index of the
3396 current byte. For a |String| |v:key| has the index of the
3397 current character.
3398 Examples: >
3399 call foreach(mylist, 'used[v:val] = true')
3400< This records the items that are in the {expr1} list.
3401
3402 Note that {expr2} is the result of expression and is then used
3403 as a command. Often it is good to use a |literal-string| to
3404 avoid having to double backslashes.
3405
3406 If {expr2} is a |Funcref| it must take two arguments:
3407 1. the key or the index of the current item.
3408 2. the value of the current item.
3409 With a legacy script lambda you don't get an error if it only
3410 accepts one argument, but with a Vim9 lambda you get "E1106:
3411 One argument too many", the number of arguments must match.
3412 If the function returns a value, it is ignored.
3413
3414 Returns {expr1} in all cases.
3415 When an error is encountered while executing {expr2} no
3416 further items in {expr1} are processed.
3417 When {expr2} is a Funcref errors inside a function are ignored,
3418 unless it was defined with the "abort" flag.
3419
3420 Can also be used as a |method|: >
3421 mylist->foreach(expr2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003422<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003423 Return type: |String|, |Blob| list<{type}> or dict<{type}>
3424 depending on {expr1}
3425
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003426 *foreground()*
3427foreground() Move the Vim window to the foreground. Useful when sent from
3428 a client to a Vim server. |remote_send()|
3429 On Win32 systems this might not work, the OS does not always
3430 allow a window to bring itself to the foreground. Use
3431 |remote_foreground()| instead.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003432
3433 Return type: |Number|
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003434 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003435 Win32 console version}
3436
Bram Moolenaaraa534142022-09-15 21:46:02 +01003437fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003438 Get the full command name from a short abbreviated command
3439 name; see |20.2| for details on command abbreviations.
3440
3441 The string argument {name} may start with a `:` and can
3442 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003443 Returns an empty string if a command doesn't exist, if it's
3444 ambiguous (for user-defined commands) or cannot be shortened
3445 this way. |vim9-no-shorten|
3446
3447 Without the {vim9} argument uses the current script version.
3448 If {vim9} is present and FALSE then legacy script rules are
3449 used. When {vim9} is present and TRUE then Vim9 rules are
3450 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003451
3452 For example `fullcommand('s')`, `fullcommand('sub')`,
3453 `fullcommand(':%substitute')` all return "substitute".
3454
3455 Can also be used as a |method|: >
3456 GetName()->fullcommand()
3457<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003458 Return type: |String|
3459
3460
3461funcref({name} [, {arglist}] [, {dict}]) *funcref()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003462 Just like |function()|, but the returned Funcref will lookup
3463 the function by reference, not by name. This matters when the
3464 function {name} is redefined later.
3465
3466 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003467 It only works for an autoloaded function if it has already
3468 been loaded (to avoid mistakenly loading the autoload script
3469 when only intending to use the function name, use |function()|
3470 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003471 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003472
3473 Can also be used as a |method|: >
3474 GetFuncname()->funcref([arg])
3475<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003476 Return type: func(...): any or |Number| on error
3477
Dominique Pellee764d1b2023-03-12 21:20:59 +00003478 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003479function({name} [, {arglist}] [, {dict}])
3480 Return a |Funcref| variable that refers to function {name}.
3481 {name} can be the name of a user defined function or an
3482 internal function.
3483
3484 {name} can also be a Funcref or a partial. When it is a
3485 partial the dict stored in it will be used and the {dict}
3486 argument is not allowed. E.g.: >
3487 let FuncWithArg = function(dict.Func, [arg])
3488 let Broken = function(dict.Func, [arg], dict)
3489<
3490 When using the Funcref the function will be found by {name},
3491 also when it was redefined later. Use |funcref()| to keep the
3492 same function.
3493
3494 When {arglist} or {dict} is present this creates a partial.
3495 That means the argument list and/or the dictionary is stored in
3496 the Funcref and will be used when the Funcref is called.
3497
3498 The arguments are passed to the function in front of other
3499 arguments, but after any argument from |method|. Example: >
3500 func Callback(arg1, arg2, name)
3501 ...
3502 let Partial = function('Callback', ['one', 'two'])
3503 ...
3504 call Partial('name')
3505< Invokes the function as with: >
3506 call Callback('one', 'two', 'name')
3507
3508< With a |method|: >
3509 func Callback(one, two, three)
3510 ...
3511 let Partial = function('Callback', ['two'])
3512 ...
3513 eval 'one'->Partial('three')
3514< Invokes the function as with: >
3515 call Callback('one', 'two', 'three')
3516
3517< The function() call can be nested to add more arguments to the
3518 Funcref. The extra arguments are appended to the list of
3519 arguments. Example: >
3520 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003521 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003522 let Func = function('Callback', ['one'])
3523 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003524 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003525 call Func2('name')
3526< Invokes the function as with: >
3527 call Callback('one', 'two', 'name')
3528
3529< The Dictionary is only useful when calling a "dict" function.
3530 In that case the {dict} is passed in as "self". Example: >
3531 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003532 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003533 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003534 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003535 let context = {"name": "example"}
3536 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003537 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003538 call Func() " will echo: called for example
3539< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003540 arguments, these two are equivalent, if Callback() is defined
3541 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003542 let Func = function('Callback', context)
3543 let Func = context.Callback
3544
3545< The argument list and the Dictionary can be combined: >
3546 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003547 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003548 let context = {"name": "example"}
3549 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003550 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003551 call Func(500)
3552< Invokes the function as with: >
3553 call context.Callback('one', 500)
3554<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003555 Returns 0 on error.
3556
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003557 Can also be used as a |method|: >
3558 GetFuncname()->function([arg])
3559
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003560<
3561 Return type: func(...): any or |Number| on error
3562
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003563
3564garbagecollect([{atexit}]) *garbagecollect()*
3565 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3566 that have circular references.
3567
3568 There is hardly ever a need to invoke this function, as it is
3569 automatically done when Vim runs out of memory or is waiting
3570 for the user to press a key after 'updatetime'. Items without
3571 circular references are always freed when they become unused.
3572 This is useful if you have deleted a very big |List| and/or
3573 |Dictionary| with circular references in a script that runs
3574 for a long time.
3575
3576 When the optional {atexit} argument is one, garbage
3577 collection will also be done when exiting Vim, if it wasn't
3578 done before. This is useful when checking for memory leaks.
3579
3580 The garbage collection is not done immediately but only when
3581 it's safe to perform. This is when waiting for the user to
3582 type a character. To force garbage collection immediately use
3583 |test_garbagecollect_now()|.
3584
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003585 Return type: |String|
3586
3587
LemonBoy48b7d052024-07-09 18:24:59 +02003588get({list}, {idx} [, {default}]) *get()* *get()-list*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003589 Get item {idx} from |List| {list}. When this item is not
3590 available return {default}. Return zero when {default} is
3591 omitted.
3592 Preferably used as a |method|: >
3593 mylist->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003594<
3595 Return type: any, depending on {list}
3596
LemonBoy48b7d052024-07-09 18:24:59 +02003597get({blob}, {idx} [, {default}]) *get()-blob*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003598 Get byte {idx} from |Blob| {blob}. When this byte is not
3599 available return {default}. Return -1 when {default} is
3600 omitted.
3601 Preferably used as a |method|: >
3602 myblob->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003603<
3604 Return type: |Number|
3605
LemonBoy48b7d052024-07-09 18:24:59 +02003606get({dict}, {key} [, {default}]) *get()-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003607 Get item with key {key} from |Dictionary| {dict}. When this
3608 item is not available return {default}. Return zero when
3609 {default} is omitted. Useful example: >
3610 let val = get(g:, 'var_name', 'default')
3611< This gets the value of g:var_name if it exists, and uses
3612 'default' when it does not exist.
3613 Preferably used as a |method|: >
3614 mydict->get(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003615<
h-east84ac2122024-06-17 18:12:30 +02003616 Return type: any, depending on {dict}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003617
LemonBoy48b7d052024-07-09 18:24:59 +02003618get({func}, {what}) *get()-func*
3619 Get item {what} from |Funcref| {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003620 {what} are:
LemonBoy48b7d052024-07-09 18:24:59 +02003621 "name" The function name
3622 "func" The function
3623 "dict" The dictionary
3624 "args" The list with arguments
3625 "arity" A dictionary with information about the number of
3626 arguments accepted by the function (minus the
3627 {arglist}) with the following fields:
3628 required the number of positional arguments
3629 optional the number of optional arguments,
3630 in addition to the required ones
3631 varargs |TRUE| if the function accepts a
3632 variable number of arguments |...|
3633
3634 Note: There is no error, if the {arglist} of
3635 the Funcref contains more arguments than the
3636 Funcref expects, it's not validated.
3637
Bram Moolenaar016188f2022-06-06 20:52:59 +01003638 Returns zero on error.
LemonBoy48b7d052024-07-09 18:24:59 +02003639
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003640 Preferably used as a |method|: >
3641 myfunc->get(what)
3642<
LemonBoy48b7d052024-07-09 18:24:59 +02003643 Return type: any, depending on {func} and {what}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003644
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003645 *getbufinfo()*
3646getbufinfo([{buf}])
3647getbufinfo([{dict}])
3648 Get information about buffers as a List of Dictionaries.
3649
3650 Without an argument information about all the buffers is
3651 returned.
3652
3653 When the argument is a |Dictionary| only the buffers matching
3654 the specified criteria are returned. The following keys can
3655 be specified in {dict}:
3656 buflisted include only listed buffers.
3657 bufloaded include only loaded buffers.
3658 bufmodified include only modified buffers.
3659
3660 Otherwise, {buf} specifies a particular buffer to return
3661 information for. For the use of {buf}, see |bufname()|
3662 above. If the buffer is found the returned List has one item.
3663 Otherwise the result is an empty list.
3664
3665 Each returned List item is a dictionary with the following
3666 entries:
3667 bufnr Buffer number.
3668 changed TRUE if the buffer is modified.
3669 changedtick Number of changes made to the buffer.
Sean Dewar1fb41032023-08-16 17:15:05 +01003670 command TRUE if the buffer belongs to the
3671 command-line window |cmdwin|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003672 hidden TRUE if the buffer is hidden.
3673 lastused Timestamp in seconds, like
3674 |localtime()|, when the buffer was
3675 last used.
3676 {only with the |+viminfo| feature}
3677 listed TRUE if the buffer is listed.
3678 lnum Line number used for the buffer when
3679 opened in the current window.
3680 Only valid if the buffer has been
3681 displayed in the window in the past.
3682 If you want the line number of the
3683 last known cursor position in a given
3684 window, use |line()|: >
3685 :echo line('.', {winid})
3686<
3687 linecount Number of lines in the buffer (only
3688 valid when loaded)
3689 loaded TRUE if the buffer is loaded.
3690 name Full path to the file in the buffer.
3691 signs List of signs placed in the buffer.
3692 Each list item is a dictionary with
3693 the following fields:
3694 id sign identifier
3695 lnum line number
3696 name sign name
3697 variables A reference to the dictionary with
3698 buffer-local variables.
3699 windows List of |window-ID|s that display this
3700 buffer
3701 popups List of popup |window-ID|s that
3702 display this buffer
3703
3704 Examples: >
3705 for buf in getbufinfo()
3706 echo buf.name
3707 endfor
3708 for buf in getbufinfo({'buflisted':1})
3709 if buf.changed
3710 ....
3711 endif
3712 endfor
3713<
3714 To get buffer-local options use: >
3715 getbufvar({bufnr}, '&option_name')
3716<
3717 Can also be used as a |method|: >
3718 GetBufnr()->getbufinfo()
3719<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003720 Return type: list<dict<any>>
3721
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003722
3723 *getbufline()*
3724getbufline({buf}, {lnum} [, {end}])
3725 Return a |List| with the lines starting from {lnum} to {end}
3726 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003727 |List| with only the line {lnum} is returned. See
3728 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003729
3730 For the use of {buf}, see |bufname()| above.
3731
3732 For {lnum} and {end} "$" can be used for the last line of the
3733 buffer. Otherwise a number must be used.
3734
3735 When {lnum} is smaller than 1 or bigger than the number of
3736 lines in the buffer, an empty |List| is returned.
3737
3738 When {end} is greater than the number of lines in the buffer,
3739 it is treated as {end} is set to the number of lines in the
3740 buffer. When {end} is before {lnum} an empty |List| is
3741 returned.
3742
3743 This function works only for loaded buffers. For unloaded and
3744 non-existing buffers, an empty |List| is returned.
3745
3746 Example: >
3747 :let lines = getbufline(bufnr("myfile"), 1, "$")
3748
3749< Can also be used as a |method|: >
3750 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003751<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003752 Return type: list<string>
3753
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003754 *getbufoneline()*
3755getbufoneline({buf}, {lnum})
3756 Just like `getbufline()` but only get one line and return it
3757 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003758
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003759 Return type: |String|
3760
3761
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003762getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3763 The result is the value of option or local buffer variable
3764 {varname} in buffer {buf}. Note that the name without "b:"
3765 must be used.
3766 The {varname} argument is a string.
3767 When {varname} is empty returns a |Dictionary| with all the
3768 buffer-local variables.
3769 When {varname} is equal to "&" returns a |Dictionary| with all
3770 the buffer-local options.
3771 Otherwise, when {varname} starts with "&" returns the value of
3772 a buffer-local option.
3773 This also works for a global or buffer-local option, but it
3774 doesn't work for a global variable, window-local variable or
3775 window-local option.
3776 For the use of {buf}, see |bufname()| above.
3777 When the buffer or variable doesn't exist {def} or an empty
3778 string is returned, there is no error message.
3779 Examples: >
3780 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003781 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003782
3783< Can also be used as a |method|: >
3784 GetBufnr()->getbufvar(varname)
3785<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003786 Return type: any, depending on {varname}
3787
3788
Kota Kato66bb9ae2023-01-17 18:31:56 +00003789getcellwidths() *getcellwidths()*
3790 Returns a |List| of cell widths of character ranges overridden
3791 by |setcellwidths()|. The format is equal to the argument of
3792 |setcellwidths()|. If no character ranges have their cell
3793 widths overridden, an empty List is returned.
h-east84ac2122024-06-17 18:12:30 +02003794
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003795 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003796
3797
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003798getchangelist([{buf}]) *getchangelist()*
3799 Returns the |changelist| for the buffer {buf}. For the use
3800 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3801 exist, an empty list is returned.
3802
3803 The returned list contains two entries: a list with the change
3804 locations and the current position in the list. Each
3805 entry in the change list is a dictionary with the following
3806 entries:
3807 col column number
3808 coladd column offset for 'virtualedit'
3809 lnum line number
3810 If buffer {buf} is the current buffer, then the current
3811 position refers to the position in the list. For other
3812 buffers, it is set to the length of the list.
3813
3814 Can also be used as a |method|: >
3815 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003816<
3817 Return type: list<any>
3818
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003819
Doug Kearns9cd9e752024-04-07 17:42:17 +02003820getchar([{expr}]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003821 Get a single character from the user or input stream.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003822 If {expr} is omitted, wait until a character is available.
3823 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003824 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003825 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003826 not consumed. Return zero if no character available.
3827 If you prefer always getting a string use |getcharstr()|.
3828
Doug Kearns9cd9e752024-04-07 17:42:17 +02003829 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003830 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003831 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003832 Otherwise a String is returned with the encoded character.
3833 For a special key it's a String with a sequence of bytes
3834 starting with 0x80 (decimal: 128). This is the same value as
3835 the String "\<Key>", e.g., "\<Left>". The returned value is
3836 also a String when a modifier (shift, control, alt) was used
3837 that is not included in the character.
3838
Doug Kearns9cd9e752024-04-07 17:42:17 +02003839 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003840 while Vim waits to see if this is the start of an escape
3841 sequence.
3842
Doug Kearns9cd9e752024-04-07 17:42:17 +02003843 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003844 one-byte character it is the character itself as a number.
3845 Use nr2char() to convert it to a String.
3846
3847 Use getcharmod() to obtain any additional modifiers.
3848
3849 When the user clicks a mouse button, the mouse event will be
3850 returned. The position can then be found in |v:mouse_col|,
3851 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3852 |getmousepos()| can also be used. Mouse move events will be
3853 ignored.
3854 This example positions the mouse as it would normally happen: >
3855 let c = getchar()
3856 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003857 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003858 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003859 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003860 endif
3861<
3862 When using bracketed paste only the first character is
3863 returned, the rest of the pasted text is dropped.
3864 |xterm-bracketed-paste|.
3865
3866 There is no prompt, you will somehow have to make clear to the
3867 user that a character has to be typed. The screen is not
3868 redrawn, e.g. when resizing the window. When using a popup
3869 window it should work better with a |popup-filter|.
3870
3871 There is no mapping for the character.
3872 Key codes are replaced, thus when the user presses the <Del>
3873 key you get the code for the <Del> key, not the raw character
3874 sequence. Examples: >
3875 getchar() == "\<Del>"
3876 getchar() == "\<S-Left>"
3877< This example redefines "f" to ignore case: >
3878 :nmap f :call FindChar()<CR>
3879 :function FindChar()
3880 : let c = nr2char(getchar())
3881 : while col('.') < col('$') - 1
3882 : normal l
3883 : if getline('.')[col('.') - 1] ==? c
3884 : break
3885 : endif
3886 : endwhile
3887 :endfunction
3888<
3889 You may also receive synthetic characters, such as
3890 |<CursorHold>|. Often you will want to ignore this and get
3891 another character: >
3892 :function GetKey()
3893 : let c = getchar()
3894 : while c == "\<CursorHold>"
3895 : let c = getchar()
3896 : endwhile
3897 : return c
3898 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003899<
3900 Return type: |Number| or |String|
3901
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003902
3903getcharmod() *getcharmod()*
3904 The result is a Number which is the state of the modifiers for
3905 the last obtained character with getchar() or in another way.
3906 These values are added together:
3907 2 shift
3908 4 control
3909 8 alt (meta)
3910 16 meta (when it's different from ALT)
3911 32 mouse double click
3912 64 mouse triple click
3913 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01003914 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003915 Only the modifiers that have not been included in the
3916 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01003917 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003918
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003919 Return type: |Number|
3920
3921
3922getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003923 Get the position for String {expr}. Same as |getpos()| but the
3924 column number in the returned List is a character index
3925 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00003926 If |getpos()| returns a very large column number, equal to
3927 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003928 of the last character.
3929
3930 Example:
3931 With the cursor on '세' in line 5 with text "여보세요": >
3932 getcharpos('.') returns [0, 5, 3, 0]
3933 getpos('.') returns [0, 5, 7, 0]
3934<
3935 Can also be used as a |method|: >
3936 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003937<
3938 Return type: list<number>
3939
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003940
3941getcharsearch() *getcharsearch()*
3942 Return the current character search information as a {dict}
3943 with the following entries:
3944
3945 char character previously used for a character
3946 search (|t|, |f|, |T|, or |F|); empty string
3947 if no character search has been performed
3948 forward direction of character search; 1 for forward,
3949 0 for backward
3950 until type of character search; 1 for a |t| or |T|
3951 character search, 0 for an |f| or |F|
3952 character search
3953
3954 This can be useful to always have |;| and |,| search
3955 forward/backward regardless of the direction of the previous
3956 character search: >
3957 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
3958 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
3959< Also see |setcharsearch()|.
3960
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003961 Return type: dict<any>
3962
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003963
Doug Kearns9cd9e752024-04-07 17:42:17 +02003964getcharstr([{expr}]) *getcharstr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003965 Get a single character from the user or input stream as a
3966 string.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003967 If {expr} is omitted, wait until a character is available.
3968 If {expr} is 0 or false, only get a character when one is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003969 available. Return an empty string otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003970 If {expr} is 1 or true, only check if a character is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003971 available, it is not consumed. Return an empty string
3972 if no character is available.
3973 Otherwise this works like |getchar()|, except that a number
3974 result is converted to a string.
3975
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003976 Return type: |String|
3977
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003978getcmdcomplpat() *getcmdcomplpat()*
3979 Return completion pattern of the current command-line.
3980 Only works when the command line is being edited, thus
3981 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
3982 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
3983 |getcmdprompt()|, |getcmdcompltype()| and |setcmdline()|.
3984 Returns an empty string when completion is not defined.
3985
3986 Return type: |String|
3987
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003988
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003989getcmdcompltype() *getcmdcompltype()*
3990 Return the type of the current command-line completion.
3991 Only works when the command line is being edited, thus
3992 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01003993 See |:command-completion| for the return string.
Shougo Matsushita69084282024-09-23 20:34:47 +02003994 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
Ruslan Russkikh0407d622024-10-08 22:21:05 +02003995 |getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003996 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003997
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003998 Return type: |String|
3999
4000
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004001getcmdline() *getcmdline()*
Shougo Matsushita69084282024-09-23 20:34:47 +02004002 Return the current command-line input. Only works when the
4003 command line is being edited, thus requires use of
4004 |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004005 Example: >
4006 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita69084282024-09-23 20:34:47 +02004007< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()|,
4008 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004009 Returns an empty string when entering a password or using
4010 |inputsecret()|.
4011
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004012 Return type: |String|
4013
4014
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004015getcmdpos() *getcmdpos()*
4016 Return the position of the cursor in the command line as a
4017 byte count. The first column is 1.
4018 Only works when editing the command line, thus requires use of
4019 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4020 Returns 0 otherwise.
Shougo Matsushita69084282024-09-23 20:34:47 +02004021 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4022 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004023
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004024 Return type: |Number|
4025
4026
Shougo Matsushita69084282024-09-23 20:34:47 +02004027getcmdprompt() *getcmdprompt()*
4028 Return the current command-line prompt when using functions
4029 like |input()| or |confirm()|.
4030 Only works when the command line is being edited, thus
4031 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4032 Also see |getcmdtype()|, |getcmdline()|, |getcmdpos()|,
4033 |setcmdpos()| and |setcmdline()|.
4034
4035 Return type: |String|
4036
4037
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004038getcmdscreenpos() *getcmdscreenpos()*
4039 Return the screen position of the cursor in the command line
4040 as a byte count. The first column is 1.
4041 Instead of |getcmdpos()|, it adds the prompt position.
4042 Only works when editing the command line, thus requires use of
4043 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4044 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004045 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
4046 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004047
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004048 Return type: |Number|
4049
4050
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004051getcmdtype() *getcmdtype()*
4052 Return the current command-line type. Possible return values
4053 are:
4054 : normal Ex command
4055 > debug mode command |debug-mode|
4056 / forward search command
4057 ? backward search command
4058 @ |input()| command
4059 - |:insert| or |:append| command
4060 = |i_CTRL-R_=|
4061 Only works when editing the command line, thus requires use of
4062 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4063 Returns an empty string otherwise.
4064 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4065
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004066 Return type: |String|
4067
4068
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004069getcmdwintype() *getcmdwintype()*
4070 Return the current |command-line-window| type. Possible return
4071 values are the same as |getcmdtype()|. Returns an empty string
4072 when not in the command-line window.
4073
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004074 Return type: |String|
4075
4076
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004077getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4078 Return a list of command-line completion matches. The String
4079 {type} argument specifies what for. The following completion
4080 types are supported:
4081
4082 arglist file names in argument list
4083 augroup autocmd groups
4084 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004085 behave |:behave| suboptions
4086 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004087 color color schemes
4088 command Ex command
4089 cmdline |cmdline-completion| result
4090 compiler compilers
4091 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004092 custom,{func} custom completion, defined via {func}
4093 customlist,{func} custom completion, defined via {func}
zeertzjq85f36d62024-10-10 19:14:13 +02004094 diff_buffer |:diffget| and |:diffput| completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004095 dir directory names
LemonBoya20bf692024-07-11 22:35:53 +02004096 dir_in_path directory names in |'cdpath'|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004097 environment environment variable names
4098 event autocommand events
4099 expression Vim expression
4100 file file and directory names
4101 file_in_path file and directory names in |'path'|
4102 filetype filetype names |'filetype'|
4103 function function name
4104 help help subjects
4105 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004106 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004107 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004108 locale locale names (as output of locale -a)
4109 mapclear buffer argument
4110 mapping mapping name
4111 menu menus
4112 messages |:messages| suboptions
4113 option options
4114 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004115 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004116 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004117 shellcmd Shell command
zeertzjq85f36d62024-10-10 19:14:13 +02004118 shellcmdline Shell command line with filename arguments
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004119 sign |:sign| suboptions
4120 syntax syntax file names |'syntax'|
4121 syntime |:syntime| suboptions
4122 tag tags
4123 tag_listfiles tags, file names
4124 user user names
4125 var user variables
4126
4127 If {pat} is an empty string, then all the matches are
4128 returned. Otherwise only items matching {pat} are returned.
4129 See |wildcards| for the use of special characters in {pat}.
4130
4131 If the optional {filtered} flag is set to 1, then 'wildignore'
4132 is applied to filter the results. Otherwise all the matches
4133 are returned. The 'wildignorecase' option always applies.
4134
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004135 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4136 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004137 regular expression matching is used. Thus this function
4138 follows the user preference, what happens on the command line.
4139 If you do not want this you can make 'wildoptions' empty
4140 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004141
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004142 If {type} is "cmdline", then the |cmdline-completion| result is
4143 returned. For example, to complete the possible values after
4144 a ":call" command: >
4145 echo getcompletion('call ', 'cmdline')
4146<
4147 If there are no matches, an empty list is returned. An
4148 invalid value for {type} produces an error.
4149
4150 Can also be used as a |method|: >
4151 GetPattern()->getcompletion('color')
4152<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004153 Return type: list<string>
4154
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004155 *getcurpos()*
4156getcurpos([{winid}])
4157 Get the position of the cursor. This is like getpos('.'), but
4158 includes an extra "curswant" item in the list:
4159 [0, lnum, col, off, curswant] ~
4160 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004161 cursor vertically. After |$| command it will be a very large
4162 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004163 |getpos()|.
4164 The first "bufnum" item is always zero. The byte position of
4165 the cursor is returned in 'col'. To get the character
4166 position, use |getcursorcharpos()|.
4167
4168 The optional {winid} argument can specify the window. It can
4169 be the window number or the |window-ID|. The last known
4170 cursor position is returned, this may be invalid for the
4171 current value of the buffer if it is not the current window.
4172 If {winid} is invalid a list with zeroes is returned.
4173
4174 This can be used to save and restore the cursor position: >
4175 let save_cursor = getcurpos()
4176 MoveTheCursorAround
4177 call setpos('.', save_cursor)
4178< Note that this only works within the window. See
4179 |winrestview()| for restoring more state.
4180
4181 Can also be used as a |method|: >
4182 GetWinid()->getcurpos()
4183<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004184 Return type: list<number>
4185
4186
4187getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004188 Same as |getcurpos()| but the column number in the returned
4189 List is a character index instead of a byte index.
4190
4191 Example:
4192 With the cursor on '보' in line 3 with text "여보세요": >
4193 getcursorcharpos() returns [0, 3, 2, 0, 3]
4194 getcurpos() returns [0, 3, 4, 0, 3]
4195<
4196 Can also be used as a |method|: >
4197 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004198<
4199 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004200
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004201
4202getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004203 The result is a String, which is the name of the current
4204 working directory. 'autochdir' is ignored.
4205
4206 With {winnr} return the local current directory of this window
4207 in the current tab page. {winnr} can be the window number or
4208 the |window-ID|.
4209 If {winnr} is -1 return the name of the global working
4210 directory. See also |haslocaldir()|.
4211
4212 With {winnr} and {tabnr} return the local current directory of
4213 the window in the specified tab page. If {winnr} is -1 return
4214 the working directory of the tabpage.
4215 If {winnr} is zero use the current window, if {tabnr} is zero
4216 use the current tabpage.
4217 Without any arguments, return the actual working directory of
4218 the current window.
4219 Return an empty string if the arguments are invalid.
4220
4221 Examples: >
4222 " Get the working directory of the current window
4223 :echo getcwd()
4224 :echo getcwd(0)
4225 :echo getcwd(0, 0)
4226 " Get the working directory of window 3 in tabpage 2
4227 :echo getcwd(3, 2)
4228 " Get the global working directory
4229 :echo getcwd(-1)
4230 " Get the working directory of tabpage 3
4231 :echo getcwd(-1, 3)
4232 " Get the working directory of current tabpage
4233 :echo getcwd(-1, 0)
4234
4235< Can also be used as a |method|: >
4236 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004237<
4238 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004239
4240getenv({name}) *getenv()*
4241 Return the value of environment variable {name}. The {name}
4242 argument is a string, without a leading '$'. Example: >
4243 myHome = getenv('HOME')
4244
4245< When the variable does not exist |v:null| is returned. That
4246 is different from a variable set to an empty string, although
4247 some systems interpret the empty value as the variable being
4248 deleted. See also |expr-env|.
4249
4250 Can also be used as a |method|: >
4251 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004252<
4253 Return type: |String| or |Number|
4254
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004255
4256getfontname([{name}]) *getfontname()*
4257 Without an argument returns the name of the normal font being
4258 used. Like what is used for the Normal highlight group
4259 |hl-Normal|.
4260 With an argument a check is done whether String {name} is a
4261 valid font name. If not then an empty string is returned.
4262 Otherwise the actual font name is returned, or {name} if the
4263 GUI does not support obtaining the real name.
4264 Only works when the GUI is running, thus not in your vimrc or
4265 gvimrc file. Use the |GUIEnter| autocommand to use this
4266 function just after the GUI has started.
4267 Note that the GTK GUI accepts any font name, thus checking for
4268 a valid name does not work.
4269
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004270 Return type: |String|
4271
4272
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004273getfperm({fname}) *getfperm()*
4274 The result is a String, which is the read, write, and execute
4275 permissions of the given file {fname}.
4276 If {fname} does not exist or its directory cannot be read, an
4277 empty string is returned.
4278 The result is of the form "rwxrwxrwx", where each group of
4279 "rwx" flags represent, in turn, the permissions of the owner
4280 of the file, the group the file belongs to, and other users.
4281 If a user does not have a given permission the flag for this
4282 is replaced with the string "-". Examples: >
4283 :echo getfperm("/etc/passwd")
4284 :echo getfperm(expand("~/.vimrc"))
4285< This will hopefully (from a security point of view) display
4286 the string "rw-r--r--" or even "rw-------".
4287
4288 Can also be used as a |method|: >
4289 GetFilename()->getfperm()
4290<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004291 Return type: |String|
4292
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004293 For setting permissions use |setfperm()|.
4294
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004295
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004296getfsize({fname}) *getfsize()*
4297 The result is a Number, which is the size in bytes of the
4298 given file {fname}.
4299 If {fname} is a directory, 0 is returned.
4300 If the file {fname} can't be found, -1 is returned.
4301 If the size of {fname} is too big to fit in a Number then -2
4302 is returned.
4303
4304 Can also be used as a |method|: >
4305 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004306<
4307 Return type: |Number|
4308
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004309
4310getftime({fname}) *getftime()*
4311 The result is a Number, which is the last modification time of
4312 the given file {fname}. The value is measured as seconds
4313 since 1st Jan 1970, and may be passed to strftime(). See also
4314 |localtime()| and |strftime()|.
4315 If the file {fname} can't be found -1 is returned.
4316
4317 Can also be used as a |method|: >
4318 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004319<
4320 Return type: |Number|
4321
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004322
4323getftype({fname}) *getftype()*
4324 The result is a String, which is a description of the kind of
4325 file of the given file {fname}.
4326 If {fname} does not exist an empty string is returned.
4327 Here is a table over different kinds of files and their
4328 results:
4329 Normal file "file"
4330 Directory "dir"
4331 Symbolic link "link"
4332 Block device "bdev"
4333 Character device "cdev"
4334 Socket "socket"
4335 FIFO "fifo"
4336 All other "other"
4337 Example: >
4338 getftype("/home")
4339< Note that a type such as "link" will only be returned on
4340 systems that support it. On some systems only "dir" and
4341 "file" are returned. On MS-Windows a symbolic link to a
4342 directory returns "dir" instead of "link".
4343
4344 Can also be used as a |method|: >
4345 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004346<
4347 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004348
4349getimstatus() *getimstatus()*
4350 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004351 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004352 See 'imstatusfunc'.
4353
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004354 Return type: |Number|
4355
4356
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004357getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4358 Returns the |jumplist| for the specified window.
4359
4360 Without arguments use the current window.
4361 With {winnr} only use this window in the current tab page.
4362 {winnr} can also be a |window-ID|.
4363 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004364 page. If {winnr} or {tabnr} is invalid, an empty list is
4365 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004366
4367 The returned list contains two entries: a list with the jump
4368 locations and the last used jump position number in the list.
4369 Each entry in the jump location list is a dictionary with
4370 the following entries:
4371 bufnr buffer number
4372 col column number
4373 coladd column offset for 'virtualedit'
4374 filename filename if available
4375 lnum line number
4376
4377 Can also be used as a |method|: >
4378 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004379<
4380 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004381
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004382 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004383getline({lnum} [, {end}])
4384 Without {end} the result is a String, which is line {lnum}
4385 from the current buffer. Example: >
4386 getline(1)
4387< When {lnum} is a String that doesn't start with a
4388 digit, |line()| is called to translate the String into a Number.
4389 To get the line under the cursor: >
4390 getline(".")
4391< When {lnum} is a number smaller than 1 or bigger than the
4392 number of lines in the buffer, an empty string is returned.
4393
4394 When {end} is given the result is a |List| where each item is
4395 a line from the current buffer in the range {lnum} to {end},
4396 including line {end}.
4397 {end} is used in the same way as {lnum}.
4398 Non-existing lines are silently omitted.
4399 When {end} is before {lnum} an empty |List| is returned.
4400 Example: >
4401 :let start = line('.')
4402 :let end = search("^$") - 1
4403 :let lines = getline(start, end)
4404
4405< Can also be used as a |method|: >
4406 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004407<
4408 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004409
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004410 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004411 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004412
4413getloclist({nr} [, {what}]) *getloclist()*
4414 Returns a |List| with all the entries in the location list for
4415 window {nr}. {nr} can be the window number or the |window-ID|.
4416 When {nr} is zero the current window is used.
4417
4418 For a location list window, the displayed location list is
4419 returned. For an invalid window number {nr}, an empty list is
4420 returned. Otherwise, same as |getqflist()|.
4421
4422 If the optional {what} dictionary argument is supplied, then
4423 returns the items listed in {what} as a dictionary. Refer to
4424 |getqflist()| for the supported items in {what}.
4425
4426 In addition to the items supported by |getqflist()| in {what},
4427 the following item is supported by |getloclist()|:
4428
4429 filewinid id of the window used to display files
4430 from the location list. This field is
4431 applicable only when called from a
4432 location list window. See
4433 |location-list-file-window| for more
4434 details.
4435
4436 Returns a |Dictionary| with default values if there is no
4437 location list for the window {nr}.
4438 Returns an empty Dictionary if window {nr} does not exist.
4439
4440 Examples (See also |getqflist-examples|): >
4441 :echo getloclist(3, {'all': 0})
4442 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004443<
4444 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004445
4446
4447getmarklist([{buf}]) *getmarklist()*
4448 Without the {buf} argument returns a |List| with information
4449 about all the global marks. |mark|
4450
4451 If the optional {buf} argument is specified, returns the
4452 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004453 see |bufname()|. If {buf} is invalid, an empty list is
4454 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004455
4456 Each item in the returned List is a |Dict| with the following:
4457 mark name of the mark prefixed by "'"
4458 pos a |List| with the position of the mark:
4459 [bufnum, lnum, col, off]
4460 Refer to |getpos()| for more information.
4461 file file name
4462
4463 Refer to |getpos()| for getting information about a specific
4464 mark.
4465
4466 Can also be used as a |method|: >
4467 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004468<
4469 Return type: list<dict<any>> or list<any>
4470
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004471
4472getmatches([{win}]) *getmatches()*
4473 Returns a |List| with all matches previously defined for the
4474 current window by |matchadd()| and the |:match| commands.
4475 |getmatches()| is useful in combination with |setmatches()|,
4476 as |setmatches()| can restore a list of matches saved by
4477 |getmatches()|.
4478 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004479 window ID instead of the current window. If {win} is invalid,
4480 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004481 Example: >
4482 :echo getmatches()
4483< [{'group': 'MyGroup1', 'pattern': 'TODO',
4484 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4485 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4486 :let m = getmatches()
4487 :call clearmatches()
4488 :echo getmatches()
4489< [] >
4490 :call setmatches(m)
4491 :echo getmatches()
4492< [{'group': 'MyGroup1', 'pattern': 'TODO',
4493 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4494 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4495 :unlet m
4496<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004497 Return type: list<dict<any>> or list<any>
4498
4499
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004500getmousepos() *getmousepos()*
4501 Returns a |Dictionary| with the last known position of the
4502 mouse. This can be used in a mapping for a mouse click or in
4503 a filter of a popup window. The items are:
4504 screenrow screen row
4505 screencol screen column
4506 winid Window ID of the click
4507 winrow row inside "winid"
4508 wincol column inside "winid"
4509 line text line inside "winid"
4510 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004511 coladd offset (in screen columns) from the
4512 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004513 All numbers are 1-based.
4514
4515 If not over a window, e.g. when in the command line, then only
4516 "screenrow" and "screencol" are valid, the others are zero.
4517
4518 When on the status line below a window or the vertical
4519 separator right of a window, the "line" and "column" values
4520 are zero.
4521
4522 When the position is after the text then "column" is the
4523 length of the text in bytes plus one.
4524
4525 If the mouse is over a popup window then that window is used.
4526
4527 When using |getchar()| the Vim variables |v:mouse_lnum|,
4528 |v:mouse_col| and |v:mouse_winid| also provide these values.
4529
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004530 Return type: dict<number>
4531
4532
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004533getmouseshape() *getmouseshape()*
4534 Returns the name of the currently showing mouse pointer.
4535 When the |+mouseshape| feature is not supported or the shape
4536 is unknown an empty string is returned.
4537 This function is mainly intended for testing.
4538
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004539 Return type: |String|
4540
4541
4542getpid() *getpid()*
4543 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004544 On Unix and MS-Windows this is a unique number, until Vim
4545 exits.
4546
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004547 Return type: |Number|
4548
4549
4550getpos({expr}) *getpos()*
zeertzjq02f3eba2024-06-12 20:45:24 +02004551 Get the position for String {expr}.
4552 The accepted values for {expr} are: *E1209*
4553 . The cursor position.
4554 $ The last line in the current buffer.
4555 'x Position of mark x (if the mark is not set, 0 is
zeertzjqd353d272024-06-13 23:00:25 +08004556 returned for all values).
zeertzjq02f3eba2024-06-12 20:45:24 +02004557 w0 First line visible in current window (one if the
4558 display isn't updated, e.g. in silent Ex mode).
4559 w$ Last line visible in current window (this is one
4560 less than "w0" if no lines are visible).
4561 v When not in Visual mode, returns the cursor
4562 position. In Visual mode, returns the other end
4563 of the Visual area. A good way to think about
4564 this is that in Visual mode "v" and "." complement
4565 each other. While "." refers to the cursor
4566 position, "v" refers to where |v_o| would move the
4567 cursor. As a result, you can use "v" and "."
4568 together to work on all of a selection in
4569 characterwise Visual mode. If the cursor is at
4570 the end of a characterwise Visual area, "v" refers
4571 to the start of the same Visual area. And if the
4572 cursor is at the start of a characterwise Visual
4573 area, "v" refers to the end of the same Visual
4574 area. "v" differs from |'<| and |'>| in that it's
4575 updated right away.
4576 Note that a mark in another file can be used. The line number
4577 then applies to another buffer.
4578
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004579 The result is a |List| with four numbers:
4580 [bufnum, lnum, col, off]
4581 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4582 is the buffer number of the mark.
4583 "lnum" and "col" are the position in the buffer. The first
4584 column is 1.
4585 The "off" number is zero, unless 'virtualedit' is used. Then
4586 it is the offset in screen columns from the start of the
4587 character. E.g., a position within a <Tab> or after the last
4588 character.
zeertzjq02f3eba2024-06-12 20:45:24 +02004589
4590 For getting the cursor position see |getcurpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004591 The column number in the returned List is the byte position
4592 within the line. To get the character position in the line,
4593 use |getcharpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02004594
4595 Note that for '< and '> Visual mode matters: when it is "V"
4596 (visual line mode) the column of '< is zero and the column of
4597 '> is a large number equal to |v:maxcol|.
naohiro ono56200ee2022-01-01 14:59:44 +00004598 A very large column number equal to |v:maxcol| can be returned,
4599 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004600 If {expr} is invalid, returns a list with all zeros.
zeertzjq02f3eba2024-06-12 20:45:24 +02004601
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004602 This can be used to save and restore the position of a mark: >
4603 let save_a_mark = getpos("'a")
4604 ...
4605 call setpos("'a", save_a_mark)
zeertzjqd353d272024-06-13 23:00:25 +08004606<
4607 Also see |getcharpos()|, |getcurpos()| and |setpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004608
4609 Can also be used as a |method|: >
4610 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004611<
4612 Return type: list<number>
4613
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004614
4615getqflist([{what}]) *getqflist()*
4616 Returns a |List| with all the current quickfix errors. Each
4617 list item is a dictionary with these entries:
4618 bufnr number of buffer that has the file name, use
4619 bufname() to get the name
4620 module module name
4621 lnum line number in the buffer (first line is 1)
4622 end_lnum
4623 end of line number if the item is multiline
4624 col column number (first column is 1)
4625 end_col end of column number if the item has range
4626 vcol |TRUE|: "col" is visual column
4627 |FALSE|: "col" is byte index
4628 nr error number
h-east84ac2122024-06-17 18:12:30 +02004629 pattern search pattern used to locate the error
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004630 text description of the error
4631 type type of the error, 'E', '1', etc.
4632 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004633 user_data
4634 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004635 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004636
4637 When there is no error list or it's empty, an empty list is
4638 returned. Quickfix list entries with a non-existing buffer
4639 number are returned with "bufnr" set to zero (Note: some
4640 functions accept buffer number zero for the alternate buffer,
4641 you may need to explicitly check for zero).
4642
4643 Useful application: Find pattern matches in multiple files and
4644 do something with them: >
4645 :vimgrep /theword/jg *.c
4646 :for d in getqflist()
4647 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4648 :endfor
4649<
4650 If the optional {what} dictionary argument is supplied, then
4651 returns only the items listed in {what} as a dictionary. The
4652 following string items are supported in {what}:
4653 changedtick get the total number of changes made
4654 to the list |quickfix-changedtick|
4655 context get the |quickfix-context|
4656 efm errorformat to use when parsing "lines". If
4657 not present, then the 'errorformat' option
4658 value is used.
4659 id get information for the quickfix list with
4660 |quickfix-ID|; zero means the id for the
4661 current list or the list specified by "nr"
4662 idx get information for the quickfix entry at this
4663 index in the list specified by 'id' or 'nr'.
4664 If set to zero, then uses the current entry.
4665 See |quickfix-index|
4666 items quickfix list entries
4667 lines parse a list of lines using 'efm' and return
4668 the resulting entries. Only a |List| type is
4669 accepted. The current quickfix list is not
4670 modified. See |quickfix-parse|.
4671 nr get information for this quickfix list; zero
4672 means the current quickfix list and "$" means
4673 the last quickfix list
4674 qfbufnr number of the buffer displayed in the quickfix
4675 window. Returns 0 if the quickfix buffer is
4676 not present. See |quickfix-buffer|.
4677 size number of entries in the quickfix list
4678 title get the list title |quickfix-title|
4679 winid get the quickfix |window-ID|
4680 all all of the above quickfix properties
4681 Non-string items in {what} are ignored. To get the value of a
4682 particular item, set it to zero.
4683 If "nr" is not present then the current quickfix list is used.
4684 If both "nr" and a non-zero "id" are specified, then the list
4685 specified by "id" is used.
4686 To get the number of lists in the quickfix stack, set "nr" to
4687 "$" in {what}. The "nr" value in the returned dictionary
4688 contains the quickfix stack size.
4689 When "lines" is specified, all the other items except "efm"
4690 are ignored. The returned dictionary contains the entry
4691 "items" with the list of entries.
4692
4693 The returned dictionary contains the following entries:
4694 changedtick total number of changes made to the
4695 list |quickfix-changedtick|
4696 context quickfix list context. See |quickfix-context|
4697 If not present, set to "".
4698 id quickfix list ID |quickfix-ID|. If not
4699 present, set to 0.
4700 idx index of the quickfix entry in the list. If not
4701 present, set to 0.
4702 items quickfix list entries. If not present, set to
4703 an empty list.
4704 nr quickfix list number. If not present, set to 0
4705 qfbufnr number of the buffer displayed in the quickfix
4706 window. If not present, set to 0.
4707 size number of entries in the quickfix list. If not
4708 present, set to 0.
4709 title quickfix list title text. If not present, set
4710 to "".
4711 winid quickfix |window-ID|. If not present, set to 0
4712
4713 Examples (See also |getqflist-examples|): >
4714 :echo getqflist({'all': 1})
4715 :echo getqflist({'nr': 2, 'title': 1})
4716 :echo getqflist({'lines' : ["F1:10:L10"]})
4717<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004718 Return type: list<dict<any>> or list<any>
4719
4720
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004721getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4722 The result is a String, which is the contents of register
4723 {regname}. Example: >
4724 :let cliptext = getreg('*')
4725< When register {regname} was not set the result is an empty
4726 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004727 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004728
4729 getreg('=') returns the last evaluated value of the expression
4730 register. (For use in maps.)
4731 getreg('=', 1) returns the expression itself, so that it can
4732 be restored with |setreg()|. For other registers the extra
4733 argument is ignored, thus you can always give it.
4734
4735 If {list} is present and |TRUE|, the result type is changed
4736 to |List|. Each list item is one text line. Use it if you care
4737 about zero bytes possibly present inside register: without
4738 third argument both NLs and zero bytes are represented as NLs
4739 (see |NL-used-for-Nul|).
4740 When the register was not set an empty list is returned.
4741
4742 If {regname} is "", the unnamed register '"' is used.
4743 If {regname} is not specified, |v:register| is used.
4744 In |Vim9-script| {regname} must be one character.
4745
4746 Can also be used as a |method|: >
4747 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004748<
4749 Return type: |String|
4750
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004751
4752getreginfo([{regname}]) *getreginfo()*
4753 Returns detailed information about register {regname} as a
4754 Dictionary with the following entries:
4755 regcontents List of lines contained in register
4756 {regname}, like
4757 |getreg|({regname}, 1, 1).
4758 regtype the type of register {regname}, as in
4759 |getregtype()|.
4760 isunnamed Boolean flag, v:true if this register
4761 is currently pointed to by the unnamed
4762 register.
4763 points_to for the unnamed register, gives the
4764 single letter name of the register
4765 currently pointed to (see |quotequote|).
4766 For example, after deleting a line
4767 with `dd`, this field will be "1",
4768 which is the register that got the
4769 deleted text.
4770
4771 The {regname} argument is a string. If {regname} is invalid
4772 or not set, an empty Dictionary will be returned.
4773 If {regname} is "" or "@", the unnamed register '"' is used.
4774 If {regname} is not specified, |v:register| is used.
4775 The returned Dictionary can be passed to |setreg()|.
4776 In |Vim9-script| {regname} must be one character.
4777
4778 Can also be used as a |method|: >
4779 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004780<
4781 Return type: dict<any>
4782
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004783
Shougo Matsushita19b71882024-02-28 22:48:12 +01004784getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004785 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01004786 buffer.
4787
4788 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004789 See |getpos()| for the format of the list. It's possible
4790 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01004791 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01004792
4793 The optional argument {opts} is a Dict and supports the
4794 following items:
4795
zeertzjqafc22952024-05-24 19:07:12 +02004796 type Specify the region's selection type.
4797 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02004798 except that the width can be omitted
4799 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02004800 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01004801
zeertzjq87410ab2024-03-02 06:00:23 +08004802 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02004803 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08004804 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01004805
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004806 You can get the last selection type by |visualmode()|.
4807 If Visual mode is active, use |mode()| to get the Visual mode
4808 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08004809 This function is useful to get text starting and ending in
4810 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004811
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004812 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004813 Note that:
4814 - Order of {pos1} and {pos2} doesn't matter, it will always
4815 return content from the upper left position to the lower
4816 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08004817 - If 'virtualedit' is enabled and the region is past the end
4818 of the lines, resulting lines are padded with spaces.
4819 - If the region is blockwise and it starts or ends in the
4820 middle of a multi-cell character, it is not included but
4821 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004822 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01004823 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004824 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01004825 - It is evaluated in current window context, which makes a
4826 difference if the buffer is displayed in a window with
4827 different 'virtualedit' or 'list' values.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004828
4829 Examples: >
4830 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01004831 \ <Cmd>echow getregion(
4832 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004833<
4834 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01004835 getpos('.')->getregion(getpos("'a"))
zeertzjqd4d12072024-07-16 20:34:16 +02004836<
4837 Return type: list<string>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004838
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01004839
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004840getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
4841 Same as |getregion()|, but returns a list of positions
4842 describing the buffer text segments bound by {pos1} and
4843 {pos2}.
4844 The segments are a pair of positions for every line: >
4845 [[{start_pos}, {end_pos}], ...]
4846<
4847 The position is a |List| with four numbers:
4848 [bufnum, lnum, col, off]
4849 "bufnum" is the buffer number.
4850 "lnum" and "col" are the position in the buffer. The first
4851 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02004852 If the "off" number of a starting position is non-zero, it is
4853 the offset in screen columns from the start of the character.
4854 E.g., a position within a <Tab> or after the last character.
4855 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02004856 the offset of the character's first cell not included in the
4857 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004858
zeertzjq2b09de92024-05-24 07:48:51 +02004859 Apart from the options supported by |getregion()|, {opts} also
4860 supports the following:
4861
4862 eol If |TRUE|, indicate positions beyond
4863 the end of a line with "col" values
4864 one more than the length of the line.
4865 If |FALSE|, positions are limited
4866 within their lines, and if a line is
4867 empty or the selection is entirely
4868 beyond the end of a line, a "col"
4869 value of 0 is used for both positions.
4870 (default: |FALSE|)
4871
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004872 Can also be used as a |method|: >
4873 getpos('.')->getregionpos(getpos("'a"))
4874<
zeertzjqd4d12072024-07-16 20:34:16 +02004875 Return type: list<list<list<number>>>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004876
4877
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004878getregtype([{regname}]) *getregtype()*
4879 The result is a String, which is type of register {regname}.
4880 The value will be one of:
4881 "v" for |characterwise| text
4882 "V" for |linewise| text
4883 "<CTRL-V>{width}" for |blockwise-visual| text
4884 "" for an empty or unknown register
4885 <CTRL-V> is one character with value 0x16.
4886 The {regname} argument is a string. If {regname} is "", the
4887 unnamed register '"' is used. If {regname} is not specified,
4888 |v:register| is used.
4889 In |Vim9-script| {regname} must be one character.
4890
4891 Can also be used as a |method|: >
4892 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004893<
4894 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004895
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01004896
Bram Moolenaar71badf92023-04-22 22:40:14 +01004897getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004898 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01004899 scripts in the order they were sourced, like what
4900 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004901
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004902 The optional Dict argument {opts} supports the following
4903 optional items:
4904 name Script name match pattern. If specified,
4905 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01004906 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004907 "name" are returned.
4908 sid Script ID |<SID>|. If specified, only
4909 information about the script with ID "sid" is
4910 returned and "name" is ignored.
4911
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004912 Each item in the returned List is a |Dict| with the following
4913 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004914 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01004915 `import autoload` but was not actually sourced
4916 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004917 functions List of script-local function names defined in
4918 the script. Present only when a particular
4919 script is specified using the "sid" item in
4920 {opts}.
4921 name Vim script file name.
4922 sid Script ID |<SID>|.
4923 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01004924 this script name links to, if any, otherwise
4925 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004926 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00004927 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004928 specified using the "sid" item in {opts}.
4929 Note that this is a copy, the value of
4930 script-local variables cannot be changed using
4931 this dictionary.
h_east59858792023-10-25 22:47:05 +09004932 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01004933
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004934 Examples: >
4935 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08004936 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004937<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004938 Return type: list<dict<any>>
4939
4940
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004941gettabinfo([{tabnr}]) *gettabinfo()*
4942 If {tabnr} is not specified, then information about all the
4943 tab pages is returned as a |List|. Each List item is a
4944 |Dictionary|. Otherwise, {tabnr} specifies the tab page
4945 number and information about that one is returned. If the tab
4946 page does not exist an empty List is returned.
4947
4948 Each List item is a |Dictionary| with the following entries:
4949 tabnr tab page number.
4950 variables a reference to the dictionary with
4951 tabpage-local variables
4952 windows List of |window-ID|s in the tab page.
4953
4954 Can also be used as a |method|: >
4955 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004956<
4957 Return type: list<dict<any>>
4958
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004959
4960gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
4961 Get the value of a tab-local variable {varname} in tab page
4962 {tabnr}. |t:var|
4963 Tabs are numbered starting with one.
4964 The {varname} argument is a string. When {varname} is empty a
4965 dictionary with all tab-local variables is returned.
4966 Note that the name without "t:" must be used.
4967 When the tab or variable doesn't exist {def} or an empty
4968 string is returned, there is no error message.
4969
4970 Can also be used as a |method|: >
4971 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004972<
4973 Return type: any, depending on {varname}
4974
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004975
4976gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
4977 Get the value of window-local variable {varname} in window
4978 {winnr} in tab page {tabnr}.
4979 The {varname} argument is a string. When {varname} is empty a
4980 dictionary with all window-local variables is returned.
4981 When {varname} is equal to "&" get the values of all
4982 window-local options in a |Dictionary|.
4983 Otherwise, when {varname} starts with "&" get the value of a
4984 window-local option.
4985 Note that {varname} must be the name without "w:".
4986 Tabs are numbered starting with one. For the current tabpage
4987 use |getwinvar()|.
4988 {winnr} can be the window number or the |window-ID|.
4989 When {winnr} is zero the current window is used.
4990 This also works for a global option, buffer-local option and
4991 window-local option, but it doesn't work for a global variable
4992 or buffer-local variable.
4993 When the tab, window or variable doesn't exist {def} or an
4994 empty string is returned, there is no error message.
4995 Examples: >
4996 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004997 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004998<
4999 To obtain all window-local variables use: >
5000 gettabwinvar({tabnr}, {winnr}, '&')
5001
5002< Can also be used as a |method|: >
5003 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005004<
5005 Return type: any, depending on {varname}
5006
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005007
5008gettagstack([{winnr}]) *gettagstack()*
5009 The result is a Dict, which is the tag stack of window {winnr}.
5010 {winnr} can be the window number or the |window-ID|.
5011 When {winnr} is not specified, the current window is used.
5012 When window {winnr} doesn't exist, an empty Dict is returned.
5013
5014 The returned dictionary contains the following entries:
5015 curidx Current index in the stack. When at
5016 top of the stack, set to (length + 1).
5017 Index of bottom of the stack is 1.
5018 items List of items in the stack. Each item
5019 is a dictionary containing the
5020 entries described below.
5021 length Number of entries in the stack.
5022
5023 Each item in the stack is a dictionary with the following
5024 entries:
5025 bufnr buffer number of the current jump
5026 from cursor position before the tag jump.
5027 See |getpos()| for the format of the
5028 returned list.
5029 matchnr current matching tag number. Used when
5030 multiple matching tags are found for a
5031 name.
5032 tagname name of the tag
5033
5034 See |tagstack| for more information about the tag stack.
5035
5036 Can also be used as a |method|: >
5037 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005038<
5039 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005040
5041
Christ van Willegence0ef912024-06-20 23:41:59 +02005042gettext({text} [, {package}]) *gettext()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005043 Translate String {text} if possible.
RestorerZ96509102024-07-11 21:14:15 +02005044 This is intended for use in Vim scripts. When generating
5045 message translations the {text} is extracted by `xgettext`,
5046 the translator can add translated messages into the .po file
5047 and Vim will lookup the translation when gettext() is called.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005048 For {text} double quoted strings are preferred, because
RestorerZ96509102024-07-11 21:14:15 +02005049 `xgettext` does not support single quoted escaped text.
5050
Christ van Willegence0ef912024-06-20 23:41:59 +02005051 When the {package} is specified, the translation is looked up
RestorerZ96509102024-07-11 21:14:15 +02005052 for that specific package. This is mainly required for
5053 third-party Vim scripts. You need to specify a path to the
5054 translations with the |bindtextdomain()| function before
5055 using the gettext() function.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005056
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005057 Return type: |String|
5058
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005059
5060getwininfo([{winid}]) *getwininfo()*
5061 Returns information about windows as a |List| with Dictionaries.
5062
5063 If {winid} is given Information about the window with that ID
5064 is returned, as a |List| with one item. If the window does not
5065 exist the result is an empty list.
5066
5067 Without {winid} information about all the windows in all the
5068 tab pages is returned.
5069
5070 Each List item is a |Dictionary| with the following entries:
5071 botline last complete displayed buffer line
5072 bufnr number of buffer in the window
5073 height window height (excluding winbar)
5074 loclist 1 if showing a location list
5075 {only with the +quickfix feature}
5076 quickfix 1 if quickfix or location list window
5077 {only with the +quickfix feature}
5078 terminal 1 if a terminal window
5079 {only with the +terminal feature}
5080 tabnr tab page number
5081 topline first displayed buffer line
5082 variables a reference to the dictionary with
5083 window-local variables
5084 width window width
5085 winbar 1 if the window has a toolbar, 0
5086 otherwise
5087 wincol leftmost screen column of the window;
5088 "col" from |win_screenpos()|
5089 textoff number of columns occupied by any
5090 'foldcolumn', 'signcolumn' and line
5091 number in front of the text
5092 winid |window-ID|
5093 winnr window number
5094 winrow topmost screen line of the window;
5095 "row" from |win_screenpos()|
5096
5097 Can also be used as a |method|: >
5098 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005099<
5100 Return type: list<dict<any>>
5101
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005102
5103getwinpos([{timeout}]) *getwinpos()*
5104 The result is a |List| with two numbers, the result of
5105 |getwinposx()| and |getwinposy()| combined:
5106 [x-pos, y-pos]
5107 {timeout} can be used to specify how long to wait in msec for
5108 a response from the terminal. When omitted 100 msec is used.
5109 Use a longer time for a remote terminal.
5110 When using a value less than 10 and no response is received
5111 within that time, a previously reported position is returned,
5112 if available. This can be used to poll for the position and
5113 do some work in the meantime: >
5114 while 1
5115 let res = getwinpos(1)
5116 if res[0] >= 0
5117 break
5118 endif
5119 " Do some work here
5120 endwhile
5121<
5122
5123 Can also be used as a |method|: >
5124 GetTimeout()->getwinpos()
5125<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005126 Return type: list<number>
5127
5128
5129getwinposx() *getwinposx()*
5130 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005131 the left hand side of the GUI Vim window. Also works for an
5132 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005133 The result will be -1 if the information is not available
5134 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005135 The value can be used with `:winpos`.
5136
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005137 Return type: |Number|
5138
5139
5140getwinposy() *getwinposy()*
5141 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005142 the top of the GUI Vim window. Also works for an xterm (uses
5143 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005144 The result will be -1 if the information is not available
5145 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005146 The value can be used with `:winpos`.
5147
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005148 Return type: |Number|
5149
5150
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005151getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5152 Like |gettabwinvar()| for the current tabpage.
5153 Examples: >
5154 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005155 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005156
5157< Can also be used as a |method|: >
5158 GetWinnr()->getwinvar(varname)
5159<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005160 Return type: any, depending on {varname}
5161
5162
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005163glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5164 Expand the file wildcards in {expr}. See |wildcards| for the
5165 use of special characters.
5166
5167 Unless the optional {nosuf} argument is given and is |TRUE|,
5168 the 'suffixes' and 'wildignore' options apply: Names matching
5169 one of the patterns in 'wildignore' will be skipped and
5170 'suffixes' affect the ordering of matches.
5171 'wildignorecase' always applies.
5172
5173 When {list} is present and it is |TRUE| the result is a |List|
5174 with all matching files. The advantage of using a List is,
5175 you also get filenames containing newlines correctly.
5176 Otherwise the result is a String and when there are several
5177 matches, they are separated by <NL> characters.
5178
5179 If the expansion fails, the result is an empty String or List.
5180
5181 You can also use |readdir()| if you need to do complicated
5182 things, such as limiting the number of matches.
5183
5184 A name for a non-existing file is not included. A symbolic
5185 link is only included if it points to an existing file.
5186 However, when the {alllinks} argument is present and it is
5187 |TRUE| then all symbolic links are included.
5188
5189 For most systems backticks can be used to get files names from
5190 any external command. Example: >
5191 :let tagfiles = glob("`find . -name tags -print`")
5192 :let &tags = substitute(tagfiles, "\n", ",", "g")
5193< The result of the program inside the backticks should be one
5194 item per line. Spaces inside an item are allowed.
5195
5196 See |expand()| for expanding special Vim variables. See
5197 |system()| for getting the raw output of an external command.
5198
5199 Can also be used as a |method|: >
5200 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005201<
5202 Return type: |String| or list<string> or list<any> depending
5203 on {list}
5204
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005205
5206glob2regpat({string}) *glob2regpat()*
5207 Convert a file pattern, as used by glob(), into a search
5208 pattern. The result can be used to match with a string that
5209 is a file name. E.g. >
5210 if filename =~ glob2regpat('Make*.mak')
5211< This is equivalent to: >
5212 if filename =~ '^Make.*\.mak$'
5213< When {string} is an empty string the result is "^$", match an
5214 empty string.
5215 Note that the result depends on the system. On MS-Windows
5216 a backslash usually means a path separator.
5217
5218 Can also be used as a |method|: >
5219 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005220<
5221 Return type: |String|
5222
5223 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005224globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5225 Perform glob() for String {expr} on all directories in {path}
5226 and concatenate the results. Example: >
5227 :echo globpath(&rtp, "syntax/c.vim")
5228<
5229 {path} is a comma-separated list of directory names. Each
5230 directory name is prepended to {expr} and expanded like with
5231 |glob()|. A path separator is inserted when needed.
5232 To add a comma inside a directory name escape it with a
5233 backslash. Note that on MS-Windows a directory may have a
5234 trailing backslash, remove it if you put a comma after it.
5235 If the expansion fails for one of the directories, there is no
5236 error message.
5237
5238 Unless the optional {nosuf} argument is given and is |TRUE|,
5239 the 'suffixes' and 'wildignore' options apply: Names matching
5240 one of the patterns in 'wildignore' will be skipped and
5241 'suffixes' affect the ordering of matches.
5242
5243 When {list} is present and it is |TRUE| the result is a |List|
5244 with all matching files. The advantage of using a List is, you
5245 also get filenames containing newlines correctly. Otherwise
5246 the result is a String and when there are several matches,
5247 they are separated by <NL> characters. Example: >
5248 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5249<
5250 {alllinks} is used as with |glob()|.
5251
5252 The "**" item can be used to search in a directory tree.
5253 For example, to find all "README.txt" files in the directories
5254 in 'runtimepath' and below: >
5255 :echo globpath(&rtp, "**/README.txt")
5256< Upwards search and limiting the depth of "**" is not
5257 supported, thus using 'path' will not always work properly.
5258
5259 Can also be used as a |method|, the base is passed as the
5260 second argument: >
5261 GetExpr()->globpath(&rtp)
5262<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005263 Return type: |String| or list<string> or list<any> depending
5264 on {list}
5265
5266
5267has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005268 When {check} is omitted or is zero: The result is a Number,
5269 which is 1 if the feature {feature} is supported, zero
5270 otherwise. The {feature} argument is a string, case is
5271 ignored. See |feature-list| below.
5272
5273 When {check} is present and not zero: The result is a Number,
5274 which is 1 if the feature {feature} could ever be supported,
5275 zero otherwise. This is useful to check for a typo in
5276 {feature} and to detect dead code. Keep in mind that an older
5277 Vim version will not know about a feature added later and
5278 features that have been abandoned will not be known by the
5279 current Vim version.
5280
5281 Also see |exists()| and |exists_compiled()|.
5282
5283 Note that to skip code that has a syntax error when the
5284 feature is not available, Vim may skip the rest of the line
5285 and miss a following `endif`. Therefore put the `endif` on a
5286 separate line: >
5287 if has('feature')
5288 let x = this->breaks->without->the->feature
5289 endif
5290< If the `endif` would be moved to the second line as "| endif" it
5291 would not be found.
5292
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005293 Return type: |Number|
5294
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005295
5296has_key({dict}, {key}) *has_key()*
5297 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005298 has an entry with key {key}. FALSE otherwise.
5299 The {key} argument is a string. In |Vim9| script a number is
5300 also accepted (and converted to a string) but no other types.
5301 In legacy script the usual automatic conversion to string is
5302 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005303
5304 Can also be used as a |method|: >
5305 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005306<
5307 Return type: |Number|
5308
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005309
5310haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5311 The result is a Number:
5312 1 when the window has set a local directory via |:lcd|
5313 2 when the tab-page has set a local directory via |:tcd|
5314 0 otherwise.
5315
5316 Without arguments use the current window.
5317 With {winnr} use this window in the current tab page.
5318 With {winnr} and {tabnr} use the window in the specified tab
5319 page.
5320 {winnr} can be the window number or the |window-ID|.
5321 If {winnr} is -1 it is ignored and only the tabpage is used.
5322 Return 0 if the arguments are invalid.
5323 Examples: >
5324 if haslocaldir() == 1
5325 " window local directory case
5326 elseif haslocaldir() == 2
5327 " tab-local directory case
5328 else
5329 " global directory case
5330 endif
5331
5332 " current window
5333 :echo haslocaldir()
5334 :echo haslocaldir(0)
5335 :echo haslocaldir(0, 0)
5336 " window n in current tab page
5337 :echo haslocaldir(n)
5338 :echo haslocaldir(n, 0)
5339 " window n in tab page m
5340 :echo haslocaldir(n, m)
5341 " tab page m
5342 :echo haslocaldir(-1, m)
5343<
5344 Can also be used as a |method|: >
5345 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005346<
5347 Return type: |Number|
5348
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005349
5350hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5351 The result is a Number, which is TRUE if there is a mapping
5352 that contains {what} in somewhere in the rhs (what it is
5353 mapped to) and this mapping exists in one of the modes
5354 indicated by {mode}.
5355 The arguments {what} and {mode} are strings.
5356 When {abbr} is there and it is |TRUE| use abbreviations
5357 instead of mappings. Don't forget to specify Insert and/or
5358 Command-line mode.
5359 Both the global mappings and the mappings local to the current
5360 buffer are checked for a match.
5361 If no matching mapping is found FALSE is returned.
5362 The following characters are recognized in {mode}:
5363 n Normal mode
5364 v Visual and Select mode
5365 x Visual mode
5366 s Select mode
5367 o Operator-pending mode
5368 i Insert mode
5369 l Language-Argument ("r", "f", "t", etc.)
5370 c Command-line mode
5371 When {mode} is omitted, "nvo" is used.
5372
5373 This function is useful to check if a mapping already exists
5374 to a function in a Vim script. Example: >
5375 :if !hasmapto('\ABCdoit')
5376 : map <Leader>d \ABCdoit
5377 :endif
5378< This installs the mapping to "\ABCdoit" only if there isn't
5379 already a mapping to "\ABCdoit".
5380
5381 Can also be used as a |method|: >
5382 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005383<
5384 Return type: |Number|
5385
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005386
5387histadd({history}, {item}) *histadd()*
5388 Add the String {item} to the history {history} which can be
5389 one of: *hist-names*
5390 "cmd" or ":" command line history
5391 "search" or "/" search pattern history
5392 "expr" or "=" typed expression history
5393 "input" or "@" input line history
5394 "debug" or ">" debug command history
5395 empty the current or last used history
5396 The {history} string does not need to be the whole name, one
5397 character is sufficient.
5398 If {item} does already exist in the history, it will be
5399 shifted to become the newest entry.
5400 The result is a Number: TRUE if the operation was successful,
5401 otherwise FALSE is returned.
5402
5403 Example: >
5404 :call histadd("input", strftime("%Y %b %d"))
5405 :let date=input("Enter date: ")
5406< This function is not available in the |sandbox|.
5407
5408 Can also be used as a |method|, the base is passed as the
5409 second argument: >
5410 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005411<
5412 Return type: |Number|
5413
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005414
5415histdel({history} [, {item}]) *histdel()*
5416 Clear {history}, i.e. delete all its entries. See |hist-names|
5417 for the possible values of {history}.
5418
5419 If the parameter {item} evaluates to a String, it is used as a
5420 regular expression. All entries matching that expression will
5421 be removed from the history (if there are any).
5422 Upper/lowercase must match, unless "\c" is used |/\c|.
5423 If {item} evaluates to a Number, it will be interpreted as
5424 an index, see |:history-indexing|. The respective entry will
5425 be removed if it exists.
5426
5427 The result is TRUE for a successful operation, otherwise FALSE
5428 is returned.
5429
5430 Examples:
5431 Clear expression register history: >
5432 :call histdel("expr")
5433<
5434 Remove all entries starting with "*" from the search history: >
5435 :call histdel("/", '^\*')
5436<
5437 The following three are equivalent: >
5438 :call histdel("search", histnr("search"))
5439 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005440 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005441<
5442 To delete the last search pattern and use the last-but-one for
5443 the "n" command and 'hlsearch': >
5444 :call histdel("search", -1)
5445 :let @/ = histget("search", -1)
5446<
5447 Can also be used as a |method|: >
5448 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005449<
5450 Return type: |Number|
5451
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005452
5453histget({history} [, {index}]) *histget()*
5454 The result is a String, the entry with Number {index} from
5455 {history}. See |hist-names| for the possible values of
5456 {history}, and |:history-indexing| for {index}. If there is
5457 no such entry, an empty String is returned. When {index} is
5458 omitted, the most recent item from the history is used.
5459
5460 Examples:
5461 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005462 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005463
5464< Define an Ex command ":H {num}" that supports re-execution of
5465 the {num}th entry from the output of |:history|. >
5466 :command -nargs=1 H execute histget("cmd", 0+<args>)
5467<
5468 Can also be used as a |method|: >
5469 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005470<
5471 Return type: |String|
5472
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005473
5474histnr({history}) *histnr()*
5475 The result is the Number of the current entry in {history}.
5476 See |hist-names| for the possible values of {history}.
5477 If an error occurred, -1 is returned.
5478
5479 Example: >
5480 :let inp_index = histnr("expr")
5481
5482< Can also be used as a |method|: >
5483 GetHistory()->histnr()
5484<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005485 Return type: |Number|
5486
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005487hlexists({name}) *hlexists()*
5488 The result is a Number, which is TRUE if a highlight group
5489 called {name} exists. This is when the group has been
5490 defined in some way. Not necessarily when highlighting has
5491 been defined for it, it may also have been used for a syntax
5492 item.
5493 *highlight_exists()*
5494 Obsolete name: highlight_exists().
5495
5496 Can also be used as a |method|: >
5497 GetName()->hlexists()
5498<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005499 Return type: |Number|
5500
5501
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005502hlget([{name} [, {resolve}]]) *hlget()*
5503 Returns a List of all the highlight group attributes. If the
5504 optional {name} is specified, then returns a List with only
5505 the attributes of the specified highlight group. Returns an
5506 empty List if the highlight group {name} is not present.
5507
5508 If the optional {resolve} argument is set to v:true and the
5509 highlight group {name} is linked to another group, then the
5510 link is resolved recursively and the attributes of the
5511 resolved highlight group are returned.
5512
5513 Each entry in the returned List is a Dictionary with the
5514 following items:
5515 cleared boolean flag, set to v:true if the highlight
5516 group attributes are cleared or not yet
5517 specified. See |highlight-clear|.
5518 cterm cterm attributes. See |highlight-cterm|.
5519 ctermbg cterm background color.
5520 See |highlight-ctermbg|.
5521 ctermfg cterm foreground color.
5522 See |highlight-ctermfg|.
5523 ctermul cterm underline color. See |highlight-ctermul|.
5524 default boolean flag, set to v:true if the highlight
5525 group link is a default link. See
5526 |highlight-default|.
5527 font highlight group font. See |highlight-font|.
5528 gui gui attributes. See |highlight-gui|.
5529 guibg gui background color. See |highlight-guibg|.
5530 guifg gui foreground color. See |highlight-guifg|.
5531 guisp gui special color. See |highlight-guisp|.
5532 id highlight group ID.
5533 linksto linked highlight group name.
5534 See |:highlight-link|.
5535 name highlight group name. See |group-name|.
5536 start start terminal keycode. See |highlight-start|.
5537 stop stop terminal keycode. See |highlight-stop|.
5538 term term attributes. See |highlight-term|.
5539
5540 The 'term', 'cterm' and 'gui' items in the above Dictionary
5541 have a dictionary value with the following optional boolean
5542 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5543 'reverse', 'inverse' and 'strikethrough'.
5544
5545 Example(s): >
5546 :echo hlget()
5547 :echo hlget('ModeMsg')
5548 :echo hlget('Number', v:true)
5549<
5550 Can also be used as a |method|: >
5551 GetName()->hlget()
5552<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005553 Return type: list<dict<any>>
5554
5555
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005556hlset({list}) *hlset()*
5557 Creates or modifies the attributes of a List of highlight
5558 groups. Each item in {list} is a dictionary containing the
5559 attributes of a highlight group. See |hlget()| for the list of
5560 supported items in this dictionary.
5561
5562 In addition to the items described in |hlget()|, the following
5563 additional items are supported in the dictionary:
5564
5565 force boolean flag to force the creation of
5566 a link for an existing highlight group
5567 with attributes.
5568
5569 The highlight group is identified using the 'name' item and
5570 the 'id' item (if supplied) is ignored. If a highlight group
5571 with a specified name doesn't exist, then it is created.
5572 Otherwise the attributes of an existing highlight group are
5573 modified.
5574
5575 If an empty dictionary value is used for the 'term' or 'cterm'
5576 or 'gui' entries, then the corresponding attributes are
5577 cleared. If the 'cleared' item is set to v:true, then all the
5578 attributes of the highlight group are cleared.
5579
5580 The 'linksto' item can be used to link a highlight group to
5581 another highlight group. See |:highlight-link|.
5582
5583 Returns zero for success, -1 for failure.
5584
5585 Example(s): >
5586 " add bold attribute to the Visual highlight group
5587 :call hlset([#{name: 'Visual',
5588 \ term: #{reverse: 1 , bold: 1}}])
5589 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5590 :let l = hlget()
5591 :call hlset(l)
5592 " clear the Search highlight group
5593 :call hlset([#{name: 'Search', cleared: v:true}])
5594 " clear the 'term' attributes for a highlight group
5595 :call hlset([#{name: 'Title', term: {}}])
5596 " create the MyHlg group linking it to DiffAdd
5597 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5598 " remove the MyHlg group link
5599 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5600 " clear the attributes and a link
5601 :call hlset([#{name: 'MyHlg', cleared: v:true,
5602 \ linksto: 'NONE'}])
5603<
5604 Can also be used as a |method|: >
5605 GetAttrList()->hlset()
5606<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005607 Return type: |Number|
5608
5609hlID({name}) *hlID()*
5610 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005611 with name {name}. When the highlight group doesn't exist,
5612 zero is returned.
5613 This can be used to retrieve information about the highlight
5614 group. For example, to get the background color of the
5615 "Comment" group: >
5616 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5617< *highlightID()*
5618 Obsolete name: highlightID().
5619
5620 Can also be used as a |method|: >
5621 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005622<
5623 Return type: |Number|
5624
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005625
5626hostname() *hostname()*
5627 The result is a String, which is the name of the machine on
5628 which Vim is currently running. Machine names greater than
5629 256 characters long are truncated.
5630
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005631 Return type: |String|
5632
5633
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005634iconv({string}, {from}, {to}) *iconv()*
5635 The result is a String, which is the text {string} converted
5636 from encoding {from} to encoding {to}.
5637 When the conversion completely fails an empty string is
5638 returned. When some characters could not be converted they
5639 are replaced with "?".
5640 The encoding names are whatever the iconv() library function
5641 can accept, see ":!man 3 iconv".
5642 Most conversions require Vim to be compiled with the |+iconv|
5643 feature. Otherwise only UTF-8 to latin1 conversion and back
5644 can be done.
5645 This can be used to display messages with special characters,
5646 no matter what 'encoding' is set to. Write the message in
5647 UTF-8 and use: >
5648 echo iconv(utf8_str, "utf-8", &enc)
5649< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5650 from/to UCS-2 is automatically changed to use UTF-8. You
5651 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5652
5653 Can also be used as a |method|: >
5654 GetText()->iconv('latin1', 'utf-8')
5655<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005656 Return type: |String|
5657
5658
Ernie Raelc8e158b2024-07-09 18:39:52 +02005659id({item}) *id()*
5660 The result is a unique String associated with the {item} and
5661 not with the {item}'s contents. It is only valid while the
5662 {item} exists and is referenced. It is valid only in the
5663 instance of vim that produces the result. The whole idea is
5664 that `id({item})` does not change if the contents of {item}
5665 changes. This is useful as a `key` for creating an identity
5666 dictionary, rather than one based on equals.
5667
5668 This operation does not reference {item} and there is no
5669 function to convert the `id` to the {item}. It may be useful to
5670 have a map of `id` to {item}. The following >
5671 var referenceMap: dict<any>
5672 var id = item->id()
5673 referenceMap[id] = item
5674< prevents {item} from being garbage collected and provides a
5675 way to get the {item} from the `id`.
5676
5677 {item} may be a List, Dictionary, Object, Job, Channel or
5678 Blob. If the item is not a permitted type, or it is a null
5679 value, then an empty String is returned.
5680
5681 Can also be used as a |method|: >
5682 GetItem()->id()
5683<
5684 Return type: |String|
5685
5686
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005687indent({lnum}) *indent()*
5688 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005689 current buffer. The indent is counted in spaces, the value
5690 of 'tabstop' is relevant. {lnum} is used just like in
5691 |getline()|.
5692 When {lnum} is invalid -1 is returned. In |Vim9| script an
5693 error is given.
5694
5695 Can also be used as a |method|: >
5696 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005697<
5698 Return type: |Number|
5699
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005700
5701index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005702 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005703 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005704
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005705 If {object} is a |List| return the lowest index where the item
5706 has a value equal to {expr}. There is no automatic
5707 conversion, so the String "4" is different from the Number 4.
5708 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005709 of 'ignorecase' is not used here, case matters as indicated by
5710 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005711
5712 If {object} is |Blob| return the lowest index where the byte
5713 value is equal to {expr}.
5714
5715 If {start} is given then start looking at the item with index
5716 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005717
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005718 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5719 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005720
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005721 -1 is returned when {expr} is not found in {object}.
5722 Example: >
5723 :let idx = index(words, "the")
5724 :if index(numbers, 123) >= 0
5725
5726< Can also be used as a |method|: >
5727 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005728<
5729 Return type: |Number|
5730
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005731
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005732indexof({object}, {expr} [, {opts}]) *indexof()*
5733 Returns the index of an item in {object} where {expr} is
5734 v:true. {object} must be a |List| or a |Blob|.
5735
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005736 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005737 List until the expression is v:true and return the index of
5738 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005739
5740 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005741 Blob until the expression is v:true and return the index of
5742 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005743
5744 {expr} must be a |string| or |Funcref|.
5745
5746 If {expr} is a |string|: If {object} is a |List|, inside
5747 {expr} |v:key| has the index of the current List item and
5748 |v:val| has the value of the item. If {object} is a |Blob|,
5749 inside {expr} |v:key| has the index of the current byte and
5750 |v:val| has the byte value.
5751
5752 If {expr} is a |Funcref| it must take two arguments:
5753 1. the key or the index of the current item.
5754 2. the value of the current item.
5755 The function must return |TRUE| if the item is found and the
5756 search should stop.
5757
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005758 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005759 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005760 startidx start evaluating {expr} at the item with this
5761 index; may be negative for an item relative to
5762 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005763 Returns -1 when {expr} evaluates to v:false for all the items.
5764 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005765 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
5766 :echo indexof(l, "v:val.n == 20")
5767 :echo indexof(l, {i, v -> v.n == 30})
5768 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005769
5770< Can also be used as a |method|: >
5771 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005772<
5773 Return type: |Number|
5774
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005775
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005776input({prompt} [, {text} [, {completion}]]) *input()*
5777 The result is a String, which is whatever the user typed on
5778 the command-line. The {prompt} argument is either a prompt
5779 string, or a blank string (for no prompt). A '\n' can be used
5780 in the prompt to start a new line.
5781 The highlighting set with |:echohl| is used for the prompt.
5782 The input is entered just like a command-line, with the same
5783 editing commands and mappings. There is a separate history
5784 for lines typed for input().
5785 Example: >
5786 :if input("Coffee or beer? ") == "beer"
5787 : echo "Cheers!"
5788 :endif
5789<
5790 If the optional {text} argument is present and not empty, this
5791 is used for the default reply, as if the user typed this.
5792 Example: >
5793 :let color = input("Color? ", "white")
5794
5795< The optional {completion} argument specifies the type of
5796 completion supported for the input. Without it completion is
5797 not performed. The supported completion types are the same as
5798 that can be supplied to a user-defined command using the
5799 "-complete=" argument. Refer to |:command-completion| for
5800 more information. Example: >
5801 let fname = input("File: ", "", "file")
5802<
5803 NOTE: This function must not be used in a startup file, for
5804 the versions that only run in GUI mode (e.g., the Win32 GUI).
5805 Note: When input() is called from within a mapping it will
5806 consume remaining characters from that mapping, because a
5807 mapping is handled like the characters were typed.
5808 Use |inputsave()| before input() and |inputrestore()|
5809 after input() to avoid that. Another solution is to avoid
5810 that further characters follow in the mapping, e.g., by using
5811 |:execute| or |:normal|.
5812
5813 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005814 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005815 :function GetFoo()
5816 : call inputsave()
5817 : let g:Foo = input("enter search pattern: ")
5818 : call inputrestore()
5819 :endfunction
5820
5821< Can also be used as a |method|: >
5822 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005823<
5824 Return type: |String|
5825
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005826
5827inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
5828 Like |input()|, but when the GUI is running and text dialogs
5829 are supported, a dialog window pops up to input the text.
5830 Example: >
5831 :let n = inputdialog("value for shiftwidth", shiftwidth())
5832 :if n != ""
5833 : let &sw = n
5834 :endif
5835< When the dialog is cancelled {cancelreturn} is returned. When
5836 omitted an empty string is returned.
5837 Hitting <Enter> works like pressing the OK button. Hitting
5838 <Esc> works like pressing the Cancel button.
5839 NOTE: Command-line completion is not supported.
5840
5841 Can also be used as a |method|: >
5842 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005843<
5844 Return type: |String|
5845
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005846
5847inputlist({textlist}) *inputlist()*
5848 {textlist} must be a |List| of strings. This |List| is
5849 displayed, one string per line. The user will be prompted to
5850 enter a number, which is returned.
5851 The user can also select an item by clicking on it with the
5852 mouse, if the mouse is enabled in the command line ('mouse' is
5853 "a" or includes "c"). For the first string 0 is returned.
5854 When clicking above the first item a negative number is
5855 returned. When clicking on the prompt one more than the
5856 length of {textlist} is returned.
5857 Make sure {textlist} has less than 'lines' entries, otherwise
5858 it won't work. It's a good idea to put the entry number at
5859 the start of the string. And put a prompt in the first item.
5860 Example: >
5861 let color = inputlist(['Select color:', '1. red',
5862 \ '2. green', '3. blue'])
5863
5864< Can also be used as a |method|: >
5865 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005866<
5867 Return type: |Number|
5868
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005869
5870inputrestore() *inputrestore()*
5871 Restore typeahead that was saved with a previous |inputsave()|.
5872 Should be called the same number of times inputsave() is
5873 called. Calling it more often is harmless though.
5874 Returns TRUE when there is nothing to restore, FALSE otherwise.
5875
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005876 Return type: |Number|
5877
5878
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005879inputsave() *inputsave()*
5880 Preserve typeahead (also from mappings) and clear it, so that
5881 a following prompt gets input from the user. Should be
5882 followed by a matching inputrestore() after the prompt. Can
5883 be used several times, in which case there must be just as
5884 many inputrestore() calls.
5885 Returns TRUE when out of memory, FALSE otherwise.
5886
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005887 Return type: |Number|
5888
5889
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005890inputsecret({prompt} [, {text}]) *inputsecret()*
5891 This function acts much like the |input()| function with but
5892 two exceptions:
5893 a) the user's response will be displayed as a sequence of
5894 asterisks ("*") thereby keeping the entry secret, and
5895 b) the user's response will not be recorded on the input
5896 |history| stack.
5897 The result is a String, which is whatever the user actually
5898 typed on the command-line in response to the issued prompt.
5899 NOTE: Command-line completion is not supported.
5900
5901 Can also be used as a |method|: >
5902 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005903<
5904 Return type: |String|
5905
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005906
5907insert({object}, {item} [, {idx}]) *insert()*
5908 When {object} is a |List| or a |Blob| insert {item} at the start
5909 of it.
5910
5911 If {idx} is specified insert {item} before the item with index
5912 {idx}. If {idx} is zero it goes before the first item, just
5913 like omitting {idx}. A negative {idx} is also possible, see
5914 |list-index|. -1 inserts just before the last item.
5915
5916 Returns the resulting |List| or |Blob|. Examples: >
5917 :let mylist = insert([2, 3, 5], 1)
5918 :call insert(mylist, 4, -1)
5919 :call insert(mylist, 6, len(mylist))
5920< The last example can be done simpler with |add()|.
5921 Note that when {item} is a |List| it is inserted as a single
5922 item. Use |extend()| to concatenate |Lists|.
5923
5924 Can also be used as a |method|: >
5925 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005926<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005927 Return type: |Number|
5928
5929
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005930 *instanceof()* *E614* *E616* *E693*
5931instanceof({object}, {class})
5932 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01005933 argument is a direct or indirect instance of a |Class|,
5934 |Interface|, or class |:type| alias specified by {class}.
5935 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005936 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02005937 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01005938 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02005939
5940< Can also be used as a |method|: >
5941 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005942<
5943 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02005944
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005945interrupt() *interrupt()*
5946 Interrupt script execution. It works more or less like the
5947 user typing CTRL-C, most commands won't execute and control
5948 returns to the user. This is useful to abort execution
5949 from lower down, e.g. in an autocommand. Example: >
5950 :function s:check_typoname(file)
5951 : if fnamemodify(a:file, ':t') == '['
5952 : echomsg 'Maybe typo'
5953 : call interrupt()
5954 : endif
5955 :endfunction
5956 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005957<
5958 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005959
5960invert({expr}) *invert()*
5961 Bitwise invert. The argument is converted to a number. A
5962 List, Dict or Float argument causes an error. Example: >
5963 :let bits = invert(bits)
5964< Can also be used as a |method|: >
5965 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005966<
5967 Return type: |Number|
5968
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005969
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005970isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01005971 The result is a Number, which is |TRUE| when {path} is an
5972 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005973 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01005974 On MS-Windows, it is considered absolute when it starts with an
5975 optional drive prefix and is followed by a '\' or '/'. UNC paths
5976 are always absolute.
5977 Example: >
5978 echo isabsolutepath('/usr/share/') " 1
5979 echo isabsolutepath('./foobar') " 0
5980 echo isabsolutepath('C:\Windows') " 1
5981 echo isabsolutepath('foobar') " 0
5982 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005983<
LemonBoydca1d402022-04-28 15:26:33 +01005984 Can also be used as a |method|: >
5985 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005986<
5987 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01005988
5989
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005990isdirectory({directory}) *isdirectory()*
5991 The result is a Number, which is |TRUE| when a directory
5992 with the name {directory} exists. If {directory} doesn't
5993 exist, or isn't a directory, the result is |FALSE|. {directory}
5994 is any expression, which is used as a String.
5995
5996 Can also be used as a |method|: >
5997 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005998<
5999 Return type: |Number|
6000
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006001
6002isinf({expr}) *isinf()*
6003 Return 1 if {expr} is a positive infinity, or -1 a negative
6004 infinity, otherwise 0. >
6005 :echo isinf(1.0 / 0.0)
6006< 1 >
6007 :echo isinf(-1.0 / 0.0)
6008< -1
6009
6010 Can also be used as a |method|: >
6011 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006012<
6013 Return type: |Number|
6014
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006015
6016islocked({expr}) *islocked()* *E786*
6017 The result is a Number, which is |TRUE| when {expr} is the
6018 name of a locked variable.
6019 The string argument {expr} must be the name of a variable,
6020 |List| item or |Dictionary| entry, not the variable itself!
6021 Example: >
6022 :let alist = [0, ['a', 'b'], 2, 3]
6023 :lockvar 1 alist
6024 :echo islocked('alist') " 1
6025 :echo islocked('alist[1]') " 0
6026
Bram Moolenaar9da17d72022-02-09 21:50:44 +00006027< When {expr} is a variable that does not exist -1 is returned.
6028 If {expr} uses a range, list or dict index that is out of
6029 range or does not exist you get an error message. Use
6030 |exists()| to check for existence.
6031 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006032
6033 Can also be used as a |method|: >
6034 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006035<
6036 Return type: |Number|
6037
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006038
6039isnan({expr}) *isnan()*
6040 Return |TRUE| if {expr} is a float with value NaN. >
6041 echo isnan(0.0 / 0.0)
6042< 1
6043
6044 Can also be used as a |method|: >
6045 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006046<
6047 Return type: |Number|
6048
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006049
6050items({dict}) *items()*
6051 Return a |List| with all the key-value pairs of {dict}. Each
6052 |List| item is a list with two items: the key of a {dict}
6053 entry and the value of this entry. The |List| is in arbitrary
6054 order. Also see |keys()| and |values()|.
6055 Example: >
6056 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006057 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006058 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006059<
6060 A List or a String argument is also supported. In these
6061 cases, items() returns a List with the index and the value at
6062 the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006063
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006064 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006065 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006066<
6067 Return type: list<list<any>> or list<any>
6068
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006069
6070job_ functions are documented here: |job-functions-details|
6071
6072
6073join({list} [, {sep}]) *join()*
6074 Join the items in {list} together into one String.
6075 When {sep} is specified it is put in between the items. If
6076 {sep} is omitted a single space is used.
6077 Note that {sep} is not added at the end. You might want to
6078 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006079 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006080< String items are used as-is. |Lists| and |Dictionaries| are
6081 converted into a string like with |string()|.
6082 The opposite function is |split()|.
6083
6084 Can also be used as a |method|: >
6085 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006086<
6087 Return type: |String|
6088
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006089
6090js_decode({string}) *js_decode()*
6091 This is similar to |json_decode()| with these differences:
6092 - Object key names do not have to be in quotes.
6093 - Strings can be in single quotes.
6094 - Empty items in an array (between two commas) are allowed and
6095 result in v:none items.
6096
6097 Can also be used as a |method|: >
6098 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006099<
6100 Return type: any, depending on {varname}
6101
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006102
6103js_encode({expr}) *js_encode()*
6104 This is similar to |json_encode()| with these differences:
6105 - Object key names are not in quotes.
6106 - v:none items in an array result in an empty item between
6107 commas.
6108 For example, the Vim object:
6109 [1,v:none,{"one":1},v:none] ~
6110 Will be encoded as:
6111 [1,,{one:1},,] ~
6112 While json_encode() would produce:
6113 [1,null,{"one":1},null] ~
6114 This encoding is valid for JavaScript. It is more efficient
6115 than JSON, especially when using an array with optional items.
6116
6117 Can also be used as a |method|: >
6118 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006119<
6120 Return type: |String|
6121
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006122
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006123json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006124 This parses a JSON formatted string and returns the equivalent
6125 in Vim values. See |json_encode()| for the relation between
6126 JSON and Vim values.
6127 The decoding is permissive:
6128 - A trailing comma in an array and object is ignored, e.g.
6129 "[1, 2, ]" is the same as "[1, 2]".
6130 - Integer keys are accepted in objects, e.g. {1:2} is the
6131 same as {"1":2}.
6132 - More floating point numbers are recognized, e.g. "1." for
6133 "1.0", or "001.2" for "1.2". Special floating point values
6134 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6135 are accepted.
6136 - Leading zeroes in integer numbers are ignored, e.g. "012"
6137 for "12" or "-012" for "-12".
6138 - Capitalization is ignored in literal names null, true or
6139 false, e.g. "NULL" for "null", "True" for "true".
6140 - Control characters U+0000 through U+001F which are not
6141 escaped in strings are accepted, e.g. " " (tab
6142 character in string) for "\t".
6143 - An empty JSON expression or made of only spaces is accepted
6144 and results in v:none.
6145 - Backslash in an invalid 2-character sequence escape is
6146 ignored, e.g. "\a" is decoded as "a".
6147 - A correct surrogate pair in JSON strings should normally be
6148 a 12 character sequence such as "\uD834\uDD1E", but
6149 json_decode() silently accepts truncated surrogate pairs
6150 such as "\uD834" or "\uD834\u"
6151 *E938*
6152 A duplicate key in an object, valid in rfc7159, is not
6153 accepted by json_decode() as the result must be a valid Vim
6154 type, e.g. this fails: {"a":"b", "a":"c"}
6155
6156 Can also be used as a |method|: >
6157 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006158<
6159 Return type: any, depending on {varname}
6160
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006161
6162json_encode({expr}) *json_encode()*
6163 Encode {expr} as JSON and return this as a string.
6164 The encoding is specified in:
6165 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006166 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006167 |Number| decimal number
6168 |Float| floating point number
6169 Float nan "NaN"
6170 Float inf "Infinity"
6171 Float -inf "-Infinity"
6172 |String| in double quotes (possibly null)
6173 |Funcref| not possible, error
6174 |List| as an array (possibly null); when
6175 used recursively: []
6176 |Dict| as an object (possibly null); when
6177 used recursively: {}
6178 |Blob| as an array of the individual bytes
6179 v:false "false"
6180 v:true "true"
6181 v:none "null"
6182 v:null "null"
6183 Note that NaN and Infinity are passed on as values. This is
6184 missing in the JSON standard, but several implementations do
6185 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006186 If a string contains an illegal character then the replacement
6187 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006188
6189 Can also be used as a |method|: >
6190 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006191<
6192 Return type: |String|
6193
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006194
6195keys({dict}) *keys()*
6196 Return a |List| with all the keys of {dict}. The |List| is in
6197 arbitrary order. Also see |items()| and |values()|.
6198
6199 Can also be used as a |method|: >
6200 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006201<
6202 Return type: list<string>
6203
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006204
zeertzjqcdc83932022-09-12 13:38:41 +01006205keytrans({string}) *keytrans()*
6206 Turn the internal byte representation of keys into a form that
6207 can be used for |:map|. E.g. >
6208 :let xx = "\<C-Home>"
6209 :echo keytrans(xx)
6210< <C-Home>
6211
6212 Can also be used as a |method|: >
6213 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006214<
6215 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006216
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006217
6218len({expr}) *len()* *E701*
6219 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006220 When {expr} is a String or a Number the length in bytes is
6221 used, as with |strlen()|.
6222 When {expr} is a |List| the number of items in the |List| is
6223 returned.
6224 When {expr} is a |Blob| the number of bytes is returned.
6225 When {expr} is a |Dictionary| the number of entries in the
6226 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006227 When {expr} is an |Object|, invokes the len() method in the
6228 object (if present) to get the length (|object-len()|).
6229 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006230
6231 Can also be used as a |method|: >
6232 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006233<
6234 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006235
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006236
6237 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006238libcall({libname}, {funcname}, {argument})
6239 Call function {funcname} in the run-time library {libname}
6240 with single argument {argument}.
6241 This is useful to call functions in a library that you
6242 especially made to be used with Vim. Since only one argument
6243 is possible, calling standard library functions is rather
6244 limited.
6245 The result is the String returned by the function. If the
6246 function returns NULL, this will appear as an empty string ""
6247 to Vim.
6248 If the function returns a number, use libcallnr()!
6249 If {argument} is a number, it is passed to the function as an
6250 int; if {argument} is a string, it is passed as a
6251 null-terminated string.
6252 This function will fail in |restricted-mode|.
6253
6254 libcall() allows you to write your own 'plug-in' extensions to
6255 Vim without having to recompile the program. It is NOT a
6256 means to call system functions! If you try to do so Vim will
6257 very probably crash.
6258
6259 For Win32, the functions you write must be placed in a DLL
6260 and use the normal C calling convention (NOT Pascal which is
6261 used in Windows System DLLs). The function must take exactly
6262 one parameter, either a character pointer or a long integer,
6263 and must return a character pointer or NULL. The character
6264 pointer returned must point to memory that will remain valid
6265 after the function has returned (e.g. in static data in the
6266 DLL). If it points to allocated memory, that memory will
6267 leak away. Using a static buffer in the function should work,
6268 it's then freed when the DLL is unloaded.
6269
6270 WARNING: If the function returns a non-valid pointer, Vim may
6271 crash! This also happens if the function returns a number,
6272 because Vim thinks it's a pointer.
6273 For Win32 systems, {libname} should be the filename of the DLL
6274 without the ".DLL" suffix. A full path is only required if
6275 the DLL is not in the usual places.
6276 For Unix: When compiling your own plugins, remember that the
6277 object code must be compiled as position-independent ('PIC').
6278 {only in Win32 and some Unix versions, when the |+libcall|
6279 feature is present}
6280 Examples: >
6281 :echo libcall("libc.so", "getenv", "HOME")
6282
6283< Can also be used as a |method|, the base is passed as the
6284 third argument: >
6285 GetValue()->libcall("libc.so", "getenv")
6286<
6287 *libcallnr()*
6288libcallnr({libname}, {funcname}, {argument})
6289 Just like |libcall()|, but used for a function that returns an
6290 int instead of a string.
6291 {only in Win32 on some Unix versions, when the |+libcall|
6292 feature is present}
6293 Examples: >
6294 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6295 :call libcallnr("libc.so", "printf", "Hello World!\n")
6296 :call libcallnr("libc.so", "sleep", 10)
6297<
6298 Can also be used as a |method|, the base is passed as the
6299 third argument: >
6300 GetValue()->libcallnr("libc.so", "printf")
6301<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006302 Return type: |String|
6303
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006304
6305line({expr} [, {winid}]) *line()*
6306 The result is a Number, which is the line number of the file
6307 position given with {expr}. The {expr} argument is a string.
zeertzjq02f3eba2024-06-12 20:45:24 +02006308 See |getpos()| for accepted positions.
6309
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006310 To get the column number use |col()|. To get both use
6311 |getpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02006312
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006313 With the optional {winid} argument the values are obtained for
6314 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02006315
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006316 Returns 0 for invalid values of {expr} and {winid}.
zeertzjq02f3eba2024-06-12 20:45:24 +02006317
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006318 Examples: >
6319 line(".") line number of the cursor
6320 line(".", winid) idem, in window "winid"
6321 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006322 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006323<
6324 To jump to the last known position when opening a file see
6325 |last-position-jump|.
6326
6327 Can also be used as a |method|: >
6328 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006329<
6330 Return type: |Number|
6331
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006332
6333line2byte({lnum}) *line2byte()*
6334 Return the byte count from the start of the buffer for line
6335 {lnum}. This includes the end-of-line character, depending on
6336 the 'fileformat' option for the current buffer. The first
6337 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6338 This can also be used to get the byte count for the line just
6339 below the last line: >
6340 line2byte(line("$") + 1)
6341< This is the buffer size plus one. If 'fileencoding' is empty
6342 it is the file size plus one. {lnum} is used like with
6343 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6344 feature has been disabled at compile time, -1 is returned.
6345 Also see |byte2line()|, |go| and |:goto|.
6346
6347 Can also be used as a |method|: >
6348 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006349<
6350 Return type: |Number|
6351
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006352
6353lispindent({lnum}) *lispindent()*
6354 Get the amount of indent for line {lnum} according the lisp
6355 indenting rules, as with 'lisp'.
6356 The indent is counted in spaces, the value of 'tabstop' is
6357 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006358 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006359 error is given.
6360
6361 Can also be used as a |method|: >
6362 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006363<
6364 Return type: |Number|
6365
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006366
6367list2blob({list}) *list2blob()*
6368 Return a Blob concatenating all the number values in {list}.
6369 Examples: >
6370 list2blob([1, 2, 3, 4]) returns 0z01020304
6371 list2blob([]) returns 0z
6372< Returns an empty Blob on error. If one of the numbers is
6373 negative or more than 255 error *E1239* is given.
6374
6375 |blob2list()| does the opposite.
6376
6377 Can also be used as a |method|: >
6378 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006379<
6380 Return type: |Blob|
6381
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006382
6383list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006384 Convert each number in {list} to a character string and
6385 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006386 list2str([32]) returns " "
6387 list2str([65, 66, 67]) returns "ABC"
6388< The same can be done (slowly) with: >
6389 join(map(list, {nr, val -> nr2char(val)}), '')
6390< |str2list()| does the opposite.
6391
6392 When {utf8} is omitted or zero, the current 'encoding' is used.
6393 When {utf8} is TRUE, always return UTF-8 characters.
6394 With UTF-8 composing characters work as expected: >
6395 list2str([97, 769]) returns "á"
6396<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006397 Returns an empty string on error.
6398
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006399 Can also be used as a |method|: >
6400 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006401<
6402 Return type: |String|
6403
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006404
6405listener_add({callback} [, {buf}]) *listener_add()*
6406 Add a callback function that will be invoked when changes have
6407 been made to buffer {buf}.
6408 {buf} refers to a buffer name or number. For the accepted
6409 values, see |bufname()|. When {buf} is omitted the current
6410 buffer is used.
6411 Returns a unique ID that can be passed to |listener_remove()|.
6412
6413 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006414 bufnr the buffer that was changed
6415 start first changed line number
6416 end first line number below the change
6417 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006418 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006419 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006420
6421 Example: >
6422 func Listener(bufnr, start, end, added, changes)
6423 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6424 endfunc
6425 call listener_add('Listener', bufnr)
6426
Bram Moolenaar944697a2022-02-20 19:48:20 +00006427< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006428 dictionary with these entries:
6429 lnum the first line number of the change
6430 end the first line below the change
6431 added number of lines added; negative if lines were
6432 deleted
6433 col first column in "lnum" that was affected by
6434 the change; one if unknown or the whole line
6435 was affected; this is a byte index, first
6436 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006437 When lines are inserted (not when a line is split, e.g. by
6438 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006439 lnum line above which the new line is added
6440 end equal to "lnum"
6441 added number of lines inserted
6442 col 1
6443 When lines are deleted the values are:
6444 lnum the first deleted line
6445 end the line below the first deleted line, before
6446 the deletion was done
6447 added negative, number of lines deleted
6448 col 1
6449 When lines are changed:
6450 lnum the first changed line
6451 end the line below the last changed line
6452 added 0
6453 col first column with a change or 1
6454
6455 The entries are in the order the changes were made, thus the
6456 most recent change is at the end. The line numbers are valid
6457 when the callback is invoked, but later changes may make them
6458 invalid, thus keeping a copy for later might not work.
6459
6460 The {callback} is invoked just before the screen is updated,
6461 when |listener_flush()| is called or when a change is being
6462 made that changes the line count in a way it causes a line
6463 number in the list of changes to become invalid.
6464
6465 The {callback} is invoked with the text locked, see
6466 |textlock|. If you do need to make changes to the buffer, use
6467 a timer to do this later |timer_start()|.
6468
6469 The {callback} is not invoked when the buffer is first loaded.
6470 Use the |BufReadPost| autocmd event to handle the initial text
6471 of a buffer.
6472 The {callback} is also not invoked when the buffer is
6473 unloaded, use the |BufUnload| autocmd event for that.
6474
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006475 Returns zero if {callback} or {buf} is invalid.
6476
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006477 Can also be used as a |method|, the base is passed as the
6478 second argument: >
6479 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006480<
6481 Return type: |Number|
6482
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006483
6484listener_flush([{buf}]) *listener_flush()*
6485 Invoke listener callbacks for buffer {buf}. If there are no
6486 pending changes then no callbacks are invoked.
6487
6488 {buf} refers to a buffer name or number. For the accepted
6489 values, see |bufname()|. When {buf} is omitted the current
6490 buffer is used.
6491
6492 Can also be used as a |method|: >
6493 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006494<
6495 Return type: |Number|
6496
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006497
6498listener_remove({id}) *listener_remove()*
6499 Remove a listener previously added with listener_add().
6500 Returns FALSE when {id} could not be found, TRUE when {id} was
6501 removed.
6502
6503 Can also be used as a |method|: >
6504 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006505<
6506 Return type: |Number|
6507
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006508
6509localtime() *localtime()*
6510 Return the current time, measured as seconds since 1st Jan
6511 1970. See also |strftime()|, |strptime()| and |getftime()|.
6512
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006513 Return type: |Number|
6514
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006515
6516log({expr}) *log()*
6517 Return the natural logarithm (base e) of {expr} as a |Float|.
6518 {expr} must evaluate to a |Float| or a |Number| in the range
6519 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006520 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006521 Examples: >
6522 :echo log(10)
6523< 2.302585 >
6524 :echo log(exp(5))
6525< 5.0
6526
6527 Can also be used as a |method|: >
6528 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006529<
6530 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006531
6532
6533log10({expr}) *log10()*
6534 Return the logarithm of Float {expr} to base 10 as a |Float|.
6535 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006536 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006537 Examples: >
6538 :echo log10(1000)
6539< 3.0 >
6540 :echo log10(0.01)
6541< -2.0
6542
6543 Can also be used as a |method|: >
6544 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006545<
6546 Return type: |Float|
6547
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006548
6549luaeval({expr} [, {expr}]) *luaeval()*
6550 Evaluate Lua expression {expr} and return its result converted
6551 to Vim data structures. Second {expr} may hold additional
6552 argument accessible as _A inside first {expr}.
6553 Strings are returned as they are.
6554 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006555 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006556 Dictionaries and lists obtained by vim.eval() are returned
6557 as-is.
6558 Other objects are returned as zero without any errors.
6559 See |lua-luaeval| for more details.
6560 Note that in a `:def` function local variables are not visible
6561 to {expr}.
6562
6563 Can also be used as a |method|: >
6564 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006565<
6566 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006567
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006568 {only available when compiled with the |+lua| feature}
6569
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006570
6571map({expr1}, {expr2}) *map()*
6572 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006573 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006574 item in {expr1} with the result of evaluating {expr2}.
6575 For a |Blob| each byte is replaced.
6576 For a |String|, each character, including composing
6577 characters, is replaced.
6578 If the item type changes you may want to use |mapnew()| to
6579 create a new List or Dictionary. This is required when using
6580 Vim9 script.
6581
6582 {expr2} must be a |String| or |Funcref|.
6583
6584 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6585 of the current item. For a |Dictionary| |v:key| has the key
6586 of the current item and for a |List| |v:key| has the index of
6587 the current item. For a |Blob| |v:key| has the index of the
6588 current byte. For a |String| |v:key| has the index of the
6589 current character.
6590 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006591 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006592< This puts "> " before and " <" after each item in "mylist".
6593
6594 Note that {expr2} is the result of an expression and is then
6595 used as an expression again. Often it is good to use a
6596 |literal-string| to avoid having to double backslashes. You
6597 still have to double ' quotes
6598
6599 If {expr2} is a |Funcref| it is called with two arguments:
6600 1. The key or the index of the current item.
6601 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006602 With a legacy script lambda you don't get an error if it only
6603 accepts one argument, but with a Vim9 lambda you get "E1106:
6604 One argument too many", the number of arguments must match.
6605
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006606 The function must return the new value of the item. Example
6607 that changes each value by "key-value": >
6608 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006609 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006610 endfunc
6611 call map(myDict, function('KeyValue'))
6612< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006613 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006614< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006615 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006616< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006617 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006618<
6619 The operation is done in-place for a |List| and |Dictionary|.
6620 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006621 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006622
6623< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6624 or a new |Blob| or |String|.
6625 When an error is encountered while evaluating {expr2} no
6626 further items in {expr1} are processed.
6627 When {expr2} is a Funcref errors inside a function are ignored,
6628 unless it was defined with the "abort" flag.
6629
6630 Can also be used as a |method|: >
6631 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006632<
6633 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6634 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006635
6636
6637maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6638 When {dict} is omitted or zero: Return the rhs of mapping
6639 {name} in mode {mode}. The returned String has special
6640 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006641 listing. When {dict} is TRUE a dictionary is returned, see
6642 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006643
6644 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006645 returned if {dict} is FALSE, otherwise returns an empty Dict.
6646 When the mapping for {name} is empty, then "<Nop>" is
6647 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006648
6649 The {name} can have special key names, like in the ":map"
6650 command.
6651
6652 {mode} can be one of these strings:
6653 "n" Normal
6654 "v" Visual (including Select)
6655 "o" Operator-pending
6656 "i" Insert
6657 "c" Cmd-line
6658 "s" Select
6659 "x" Visual
6660 "l" langmap |language-mapping|
6661 "t" Terminal-Job
6662 "" Normal, Visual and Operator-pending
6663 When {mode} is omitted, the modes for "" are used.
6664
6665 When {abbr} is there and it is |TRUE| use abbreviations
6666 instead of mappings.
6667
6668 When {dict} is there and it is |TRUE| return a dictionary
6669 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006670 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006671 "lhs" The {lhs} of the mapping as it would be typed
6672 "lhsraw" The {lhs} of the mapping as raw bytes
6673 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6674 form, only present when it differs from "lhsraw"
6675 "rhs" The {rhs} of the mapping as typed.
6676 "silent" 1 for a |:map-silent| mapping, else 0.
6677 "noremap" 1 if the {rhs} of the mapping is not remappable.
6678 "script" 1 if mapping was defined with <script>.
6679 "expr" 1 for an expression mapping (|:map-<expr>|).
6680 "buffer" 1 for a buffer local mapping (|:map-local|).
6681 "mode" Modes for which the mapping is defined. In
6682 addition to the modes mentioned above, these
6683 characters will be used:
6684 " " Normal, Visual and Operator-pending
6685 "!" Insert and Commandline mode
6686 (|mapmode-ic|)
6687 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006688 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006689 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006690 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006691 "lnum" The line number in "sid", zero if unknown.
6692 "nowait" Do not wait for other, longer mappings.
6693 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006694 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006695 "mode_bits" Vim's internal binary representation of "mode".
6696 |mapset()| ignores this; only "mode" is used.
6697 See |maplist()| for usage examples. The values
6698 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006699
6700 The dictionary can be used to restore a mapping with
6701 |mapset()|.
6702
6703 The mappings local to the current buffer are checked first,
6704 then the global mappings.
6705 This function can be used to map a key even when it's already
6706 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006707 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006708
6709< Can also be used as a |method|: >
6710 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006711<
6712 Return type: |String| or dict<any> depending on {dict}
6713
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006714
6715mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6716 Check if there is a mapping that matches with {name} in mode
6717 {mode}. See |maparg()| for {mode} and special names in
6718 {name}.
6719 When {abbr} is there and it is |TRUE| use abbreviations
6720 instead of mappings.
6721 A match happens with a mapping that starts with {name} and
6722 with a mapping which is equal to the start of {name}.
6723
6724 matches mapping "a" "ab" "abc" ~
6725 mapcheck("a") yes yes yes
6726 mapcheck("abc") yes yes yes
6727 mapcheck("ax") yes no no
6728 mapcheck("b") no no no
6729
6730 The difference with maparg() is that mapcheck() finds a
6731 mapping that matches with {name}, while maparg() only finds a
6732 mapping for {name} exactly.
6733 When there is no mapping that starts with {name}, an empty
6734 String is returned. If there is one, the RHS of that mapping
6735 is returned. If there are several mappings that start with
6736 {name}, the RHS of one of them is returned. This will be
6737 "<Nop>" if the RHS is empty.
6738 The mappings local to the current buffer are checked first,
6739 then the global mappings.
6740 This function can be used to check if a mapping can be added
6741 without being ambiguous. Example: >
6742 :if mapcheck("_vv") == ""
6743 : map _vv :set guifont=7x13<CR>
6744 :endif
6745< This avoids adding the "_vv" mapping when there already is a
6746 mapping for "_v" or for "_vvv".
6747
6748 Can also be used as a |method|: >
6749 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006750<
6751 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006752
6753
Ernie Rael09661202022-04-25 14:40:44 +01006754maplist([{abbr}]) *maplist()*
6755 Returns a |List| of all mappings. Each List item is a |Dict|,
6756 the same as what is returned by |maparg()|, see
6757 |mapping-dict|. When {abbr} is there and it is |TRUE| use
6758 abbreviations instead of mappings.
6759
6760 Example to show all mappings with 'MultiMatch' in rhs: >
6761 vim9script
6762 echo maplist()->filter(
6763 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01006764< It can be tricky to find mappings for particular |:map-modes|.
6765 |mapping-dict|'s "mode_bits" can simplify this. For example,
6766 the mode_bits for Normal, Insert or Command-line modes are
6767 0x19. To find all the mappings available in those modes you
6768 can do: >
6769 vim9script
6770 var saved_maps = []
6771 for m in maplist()
6772 if and(m.mode_bits, 0x19) != 0
6773 saved_maps->add(m)
6774 endif
6775 endfor
6776 echo saved_maps->mapnew((_, m) => m.lhs)
6777< The values of the mode_bits are defined in Vim's src/vim.h
6778 file and they can be discovered at runtime using
6779 |:map-commands| and "maplist()". Example: >
6780 vim9script
6781 omap xyzzy <Nop>
6782 var op_bit = maplist()->filter(
6783 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
6784 ounmap xyzzy
6785 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006786<
6787 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01006788
6789
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006790mapnew({expr1}, {expr2}) *mapnew()*
6791 Like |map()| but instead of replacing items in {expr1} a new
6792 List or Dictionary is created and returned. {expr1} remains
6793 unchanged. Items can still be changed by {expr2}, if you
6794 don't want that use |deepcopy()| first.
6795
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006796 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6797 depending on {expr1}
6798
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006799
6800mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01006801mapset({dict})
6802 Restore a mapping from a dictionary, possibly returned by
6803 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
6804 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006805 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01006806 feature allows copying mappings from one buffer to another.
6807 The dict.mode value may restore a single mapping that covers
6808 more than one mode, like with mode values of '!', ' ', 'nox',
6809 or 'v'. *E1276*
6810
6811 In the first form, {mode} and {abbr} should be the same as
6812 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006813 {mode} is used to define the mode in which the mapping is set,
6814 not the "mode" entry in {dict}.
6815 Example for saving and restoring a mapping: >
6816 let save_map = maparg('K', 'n', 0, 1)
6817 nnoremap K somethingelse
6818 ...
6819 call mapset('n', 0, save_map)
6820< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01006821 e.g. with `:map!`, you need to save/restore the mapping for
6822 all of them, when they might differ.
6823
6824 In the second form, with {dict} as the only argument, mode
6825 and abbr are taken from the dict.
6826 Example: >
6827 vim9script
6828 var save_maps = maplist()->filter(
6829 (_, m) => m.lhs == 'K')
6830 nnoremap K somethingelse
6831 cnoremap K somethingelse2
6832 # ...
6833 unmap K
6834 for d in save_maps
6835 mapset(d)
6836 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006837<
6838 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006839
6840
6841match({expr}, {pat} [, {start} [, {count}]]) *match()*
6842 When {expr} is a |List| then this returns the index of the
6843 first item where {pat} matches. Each item is used as a
6844 String, |Lists| and |Dictionaries| are used as echoed.
6845
6846 Otherwise, {expr} is used as a String. The result is a
6847 Number, which gives the index (byte offset) in {expr} where
6848 {pat} matches.
6849
6850 A match at the first character or |List| item returns zero.
6851 If there is no match -1 is returned.
6852
6853 For getting submatches see |matchlist()|.
6854 Example: >
6855 :echo match("testing", "ing") " results in 4
6856 :echo match([1, 'x'], '\a') " results in 1
6857< See |string-match| for how {pat} is used.
6858 *strpbrk()*
6859 Vim doesn't have a strpbrk() function. But you can do: >
6860 :let sepidx = match(line, '[.,;: \t]')
6861< *strcasestr()*
6862 Vim doesn't have a strcasestr() function. But you can add
6863 "\c" to the pattern to ignore case: >
6864 :let idx = match(haystack, '\cneedle')
6865<
6866 If {start} is given, the search starts from byte index
6867 {start} in a String or item {start} in a |List|.
6868 The result, however, is still the index counted from the
6869 first character/item. Example: >
6870 :echo match("testing", "ing", 2)
6871< result is again "4". >
6872 :echo match("testing", "ing", 4)
6873< result is again "4". >
6874 :echo match("testing", "t", 2)
6875< result is "3".
6876 For a String, if {start} > 0 then it is like the string starts
6877 {start} bytes later, thus "^" will match at {start}. Except
6878 when {count} is given, then it's like matches before the
6879 {start} byte are ignored (this is a bit complicated to keep it
6880 backwards compatible).
6881 For a String, if {start} < 0, it will be set to 0. For a list
6882 the index is counted from the end.
6883 If {start} is out of range ({start} > strlen({expr}) for a
6884 String or {start} > len({expr}) for a |List|) -1 is returned.
6885
6886 When {count} is given use the {count}'th match. When a match
6887 is found in a String the search for the next one starts one
6888 character further. Thus this example results in 1: >
6889 echo match("testing", "..", 0, 2)
6890< In a |List| the search continues in the next item.
6891 Note that when {count} is added the way {start} works changes,
6892 see above.
6893
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01006894 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006895 See |pattern| for the patterns that are accepted.
6896 The 'ignorecase' option is used to set the ignore-caseness of
6897 the pattern. 'smartcase' is NOT used. The matching is always
6898 done like 'magic' is set and 'cpoptions' is empty.
6899 Note that a match at the start is preferred, thus when the
6900 pattern is using "*" (any number of matches) it tends to find
6901 zero matches at the start instead of a number of matches
6902 further down in the text.
6903
6904 Can also be used as a |method|: >
6905 GetText()->match('word')
6906 GetList()->match('word')
6907<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006908 Return type: |Number|
6909
6910
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006911 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006912matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
6913 Defines a pattern to be highlighted in the current window (a
6914 "match"). It will be highlighted with {group}. Returns an
6915 identification number (ID), which can be used to delete the
6916 match using |matchdelete()|. The ID is bound to the window.
6917 Matching is case sensitive and magic, unless case sensitivity
6918 or magicness are explicitly overridden in {pattern}. The
6919 'magic', 'smartcase' and 'ignorecase' options are not used.
6920 The "Conceal" value is special, it causes the match to be
6921 concealed.
6922
6923 The optional {priority} argument assigns a priority to the
6924 match. A match with a high priority will have its
6925 highlighting overrule that of a match with a lower priority.
6926 A priority is specified as an integer (negative numbers are no
6927 exception). If the {priority} argument is not specified, the
6928 default priority is 10. The priority of 'hlsearch' is zero,
6929 hence all matches with a priority greater than zero will
6930 overrule it. Syntax highlighting (see 'syntax') is a separate
6931 mechanism, and regardless of the chosen priority a match will
6932 always overrule syntax highlighting.
6933
6934 The optional {id} argument allows the request for a specific
6935 match ID. If a specified ID is already taken, an error
6936 message will appear and the match will not be added. An ID
6937 is specified as a positive integer (zero excluded). IDs 1, 2
6938 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01006939 respectively. 3 is reserved for use by the |matchparen|
6940 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01006941 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01006942 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006943
6944 The optional {dict} argument allows for further custom
6945 values. Currently this is used to specify a match specific
6946 conceal character that will be shown for |hl-Conceal|
6947 highlighted matches. The dict can have the following members:
6948
6949 conceal Special character to show instead of the
6950 match (only for |hl-Conceal| highlighted
6951 matches, see |:syn-cchar|)
6952 window Instead of the current window use the
6953 window with this number or window ID.
6954
6955 The number of matches is not limited, as it is the case with
6956 the |:match| commands.
6957
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006958 Returns -1 on error.
6959
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006960 Example: >
6961 :highlight MyGroup ctermbg=green guibg=green
6962 :let m = matchadd("MyGroup", "TODO")
6963< Deletion of the pattern: >
6964 :call matchdelete(m)
6965
6966< A list of matches defined by |matchadd()| and |:match| are
6967 available from |getmatches()|. All matches can be deleted in
6968 one operation by |clearmatches()|.
6969
6970 Can also be used as a |method|: >
6971 GetGroup()->matchadd('TODO')
6972<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006973 Return type: |Number|
6974
6975
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006976 *matchaddpos()*
6977matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
6978 Same as |matchadd()|, but requires a list of positions {pos}
6979 instead of a pattern. This command is faster than |matchadd()|
Shane Harperc1b39842024-07-17 19:40:40 +02006980 because it does not handle regular expressions and it sets
6981 buffer line boundaries to redraw screen. It is supposed to be
6982 used when fast match additions and deletions are required, for
6983 example to highlight matching parentheses.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006984
6985 {pos} is a list of positions. Each position can be one of
6986 these:
6987 - A number. This whole line will be highlighted. The first
6988 line has number 1.
6989 - A list with one number, e.g., [23]. The whole line with this
6990 number will be highlighted.
6991 - A list with two numbers, e.g., [23, 11]. The first number is
6992 the line number, the second one is the column number (first
6993 column is 1, the value must correspond to the byte index as
6994 |col()| would return). The character at this position will
6995 be highlighted.
6996 - A list with three numbers, e.g., [23, 11, 3]. As above, but
6997 the third number gives the length of the highlight in bytes.
6998
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006999 Returns -1 on error.
7000
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007001 Example: >
7002 :highlight MyGroup ctermbg=green guibg=green
7003 :let m = matchaddpos("MyGroup", [[23, 24], 34])
7004< Deletion of the pattern: >
7005 :call matchdelete(m)
7006
7007< Matches added by |matchaddpos()| are returned by
7008 |getmatches()|.
7009
7010 Can also be used as a |method|: >
7011 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007012<
7013 Return type: |Number|
7014
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007015
7016matcharg({nr}) *matcharg()*
7017 Selects the {nr} match item, as set with a |:match|,
7018 |:2match| or |:3match| command.
7019 Return a |List| with two elements:
7020 The name of the highlight group used
7021 The pattern used.
7022 When {nr} is not 1, 2 or 3 returns an empty |List|.
7023 When there is no match item set returns ['', ''].
7024 This is useful to save and restore a |:match|.
7025 Highlighting matches using the |:match| commands are limited
7026 to three matches. |matchadd()| does not have this limitation.
7027
7028 Can also be used as a |method|: >
7029 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007030<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007031 Return type: list<string>
7032
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007033 *matchbufline()*
7034matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
7035 Returns the |List| of matches in lines from {lnum} to {end} in
7036 buffer {buf} where {pat} matches.
7037
7038 {lnum} and {end} can either be a line number or the string "$"
7039 to refer to the last line in {buf}.
7040
7041 The {dict} argument supports following items:
7042 submatches include submatch information (|/\(|)
7043
7044 For each match, a |Dict| with the following items is returned:
7045 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007046 lnum line number where there is a match
7047 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007048 Note that there can be multiple matches in a single line.
7049
7050 This function works only for loaded buffers. First call
7051 |bufload()| if needed.
7052
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007053 See |match-pattern| for information about the effect of some
7054 option settings on the pattern.
7055
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007056 When {buf} is not a valid buffer, the buffer is not loaded or
7057 {lnum} or {end} is not valid then an error is given and an
7058 empty |List| is returned.
7059
7060 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007061 " Assuming line 3 in buffer 5 contains "a"
7062 :echo matchbufline(5, '\<\k\+\>', 3, 3)
7063 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
7064 " Assuming line 4 in buffer 10 contains "tik tok"
7065 :echo matchbufline(10, '\<\k\+\>', 1, 4)
7066 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007067<
7068 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007069 "\1", "\2", etc. are also returned. Example: >
7070 " Assuming line 2 in buffer 2 contains "acd"
7071 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007072 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007073 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007074< The "submatches" List always contains 9 items. If a submatch
7075 is not found, then an empty string is returned for that
7076 submatch.
7077
7078 Can also be used as a |method|: >
7079 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007080<
7081 Return type: list<dict<any>> or list<any>
7082
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007083
7084matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
7085 Deletes a match with ID {id} previously defined by |matchadd()|
7086 or one of the |:match| commands. Returns 0 if successful,
7087 otherwise -1. See example for |matchadd()|. All matches can
7088 be deleted in one operation by |clearmatches()|.
7089 If {win} is specified, use the window with this number or
7090 window ID instead of the current window.
7091
7092 Can also be used as a |method|: >
7093 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007094<
7095 Return type: |Number|
7096
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007097
7098matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
7099 Same as |match()|, but return the index of first character
7100 after the match. Example: >
7101 :echo matchend("testing", "ing")
7102< results in "7".
7103 *strspn()* *strcspn()*
7104 Vim doesn't have a strspn() or strcspn() function, but you can
7105 do it with matchend(): >
7106 :let span = matchend(line, '[a-zA-Z]')
7107 :let span = matchend(line, '[^a-zA-Z]')
7108< Except that -1 is returned when there are no matches.
7109
7110 The {start}, if given, has the same meaning as for |match()|. >
7111 :echo matchend("testing", "ing", 2)
7112< results in "7". >
7113 :echo matchend("testing", "ing", 5)
7114< result is "-1".
7115 When {expr} is a |List| the result is equal to |match()|.
7116
7117 Can also be used as a |method|: >
7118 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007119<
7120 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007121
7122
7123matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7124 If {list} is a list of strings, then returns a |List| with all
7125 the strings in {list} that fuzzy match {str}. The strings in
7126 the returned list are sorted based on the matching score.
7127
7128 The optional {dict} argument always supports the following
7129 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007130 matchseq When this item is present return only matches
7131 that contain the characters in {str} in the
7132 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007133 limit Maximum number of matches in {list} to be
7134 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007135
7136 If {list} is a list of dictionaries, then the optional {dict}
7137 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007138 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007139 {str}. The value of this item should be a
7140 string.
7141 text_cb |Funcref| that will be called for every item
7142 in {list} to get the text for fuzzy matching.
7143 This should accept a dictionary item as the
7144 argument and return the text for that item to
7145 use for fuzzy matching.
7146
7147 {str} is treated as a literal string and regular expression
7148 matching is NOT supported. The maximum supported {str} length
7149 is 256.
7150
7151 When {str} has multiple words each separated by white space,
7152 then the list of strings that have all the words is returned.
7153
7154 If there are no matching strings or there is an error, then an
7155 empty list is returned. If length of {str} is greater than
7156 256, then returns an empty list.
7157
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007158 When {limit} is given, matchfuzzy() will find up to this
7159 number of matches in {list} and return them in sorted order.
7160
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007161 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007162 matching strings.
7163
7164 Example: >
7165 :echo matchfuzzy(["clay", "crow"], "cay")
7166< results in ["clay"]. >
7167 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7168< results in a list of buffer names fuzzy matching "ndl". >
7169 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7170< results in a list of buffer information dicts with buffer
7171 names fuzzy matching "ndl". >
7172 :echo getbufinfo()->matchfuzzy("spl",
7173 \ {'text_cb' : {v -> v.name}})
7174< results in a list of buffer information dicts with buffer
7175 names fuzzy matching "spl". >
7176 :echo v:oldfiles->matchfuzzy("test")
7177< results in a list of file names fuzzy matching "test". >
7178 :let l = readfile("buffer.c")->matchfuzzy("str")
7179< results in a list of lines in "buffer.c" fuzzy matching "str". >
7180 :echo ['one two', 'two one']->matchfuzzy('two one')
7181< results in ['two one', 'one two']. >
7182 :echo ['one two', 'two one']->matchfuzzy('two one',
7183 \ {'matchseq': 1})
7184< results in ['two one'].
7185
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007186 Return type: list<string> or list<any>
7187
7188
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007189matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7190 Same as |matchfuzzy()|, but returns the list of matched
7191 strings, the list of character positions where characters
7192 in {str} matches and a list of matching scores. You can
7193 use |byteidx()| to convert a character position to a byte
7194 position.
7195
7196 If {str} matches multiple times in a string, then only the
7197 positions for the best match is returned.
7198
7199 If there are no matching strings or there is an error, then a
7200 list with three empty list items is returned.
7201
7202 Example: >
7203 :echo matchfuzzypos(['testing'], 'tsg')
7204< results in [['testing'], [[0, 2, 6]], [99]] >
7205 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7206< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7207 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7208< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7209
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007210 Return type: list<list<any>>
7211
7212
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007213matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7214 Same as |match()|, but return a |List|. The first item in the
7215 list is the matched string, same as what matchstr() would
7216 return. Following items are submatches, like "\1", "\2", etc.
7217 in |:substitute|. When an optional submatch didn't match an
7218 empty string is used. Example: >
7219 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7220< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7221 When there is no match an empty list is returned.
7222
7223 You can pass in a List, but that is not very useful.
7224
7225 Can also be used as a |method|: >
7226 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007227<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007228 Return type: list<string> or list<any>
7229
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007230 *matchstrlist()*
7231matchstrlist({list}, {pat} [, {dict}])
7232 Returns the |List| of matches in {list} where {pat} matches.
7233 {list} is a |List| of strings. {pat} is matched against each
7234 string in {list}.
7235
7236 The {dict} argument supports following items:
7237 submatches include submatch information (|/\(|)
7238
7239 For each match, a |Dict| with the following items is returned:
7240 byteidx starting byte index of the match.
7241 idx index in {list} of the match.
7242 text matched string
7243 submatches a List of submatches. Present only if
7244 "submatches" is set to v:true in {dict}.
7245
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007246 See |match-pattern| for information about the effect of some
7247 option settings on the pattern.
7248
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007249 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007250 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7251 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7252 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7253 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007254<
7255 If "submatches" is present and is v:true, then submatches like
7256 "\1", "\2", etc. are also returned. Example: >
7257 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7258 \ #{submatches: v:true})
7259 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7260< The "submatches" List always contains 9 items. If a submatch
7261 is not found, then an empty string is returned for that
7262 submatch.
7263
7264 Can also be used as a |method|: >
7265 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007266<
7267 Return type: list<dict<any>> or list<any>
7268
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007269
7270matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7271 Same as |match()|, but return the matched string. Example: >
7272 :echo matchstr("testing", "ing")
7273< results in "ing".
7274 When there is no match "" is returned.
7275 The {start}, if given, has the same meaning as for |match()|. >
7276 :echo matchstr("testing", "ing", 2)
7277< results in "ing". >
7278 :echo matchstr("testing", "ing", 5)
7279< result is "".
7280 When {expr} is a |List| then the matching item is returned.
7281 The type isn't changed, it's not necessarily a String.
7282
7283 Can also be used as a |method|: >
7284 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007285<
7286 Return type: |String|
7287
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007288
7289matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7290 Same as |matchstr()|, but return the matched string, the start
7291 position and the end position of the match. Example: >
7292 :echo matchstrpos("testing", "ing")
7293< results in ["ing", 4, 7].
7294 When there is no match ["", -1, -1] is returned.
7295 The {start}, if given, has the same meaning as for |match()|. >
7296 :echo matchstrpos("testing", "ing", 2)
7297< results in ["ing", 4, 7]. >
7298 :echo matchstrpos("testing", "ing", 5)
7299< result is ["", -1, -1].
7300 When {expr} is a |List| then the matching item, the index
7301 of first item where {pat} matches, the start position and the
7302 end position of the match are returned. >
7303 :echo matchstrpos([1, '__x'], '\a')
7304< result is ["x", 1, 2, 3].
7305 The type isn't changed, it's not necessarily a String.
7306
7307 Can also be used as a |method|: >
7308 GetText()->matchstrpos('word')
7309<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007310 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007311
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007312
7313max({expr}) *max()*
7314 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007315 echo max([apples, pears, oranges])
7316
7317< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7318 it returns the maximum of all values in the Dictionary.
7319 If {expr} is neither a List nor a Dictionary, or one of the
7320 items in {expr} cannot be used as a Number this results in
7321 an error. An empty |List| or |Dictionary| results in zero.
7322
7323 Can also be used as a |method|: >
7324 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007325<
7326 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007327
7328
7329menu_info({name} [, {mode}]) *menu_info()*
7330 Return information about the specified menu {name} in
7331 mode {mode}. The menu name should be specified without the
7332 shortcut character ('&'). If {name} is "", then the top-level
7333 menu names are returned.
7334
7335 {mode} can be one of these strings:
7336 "n" Normal
7337 "v" Visual (including Select)
7338 "o" Operator-pending
7339 "i" Insert
7340 "c" Cmd-line
7341 "s" Select
7342 "x" Visual
7343 "t" Terminal-Job
7344 "" Normal, Visual and Operator-pending
7345 "!" Insert and Cmd-line
7346 When {mode} is omitted, the modes for "" are used.
7347
7348 Returns a |Dictionary| containing the following items:
7349 accel menu item accelerator text |menu-text|
7350 display display name (name without '&')
7351 enabled v:true if this menu item is enabled
7352 Refer to |:menu-enable|
7353 icon name of the icon file (for toolbar)
7354 |toolbar-icon|
7355 iconidx index of a built-in icon
7356 modes modes for which the menu is defined. In
7357 addition to the modes mentioned above, these
7358 characters will be used:
7359 " " Normal, Visual and Operator-pending
7360 name menu item name.
7361 noremenu v:true if the {rhs} of the menu item is not
7362 remappable else v:false.
7363 priority menu order priority |menu-priority|
7364 rhs right-hand-side of the menu item. The returned
7365 string has special characters translated like
7366 in the output of the ":menu" command listing.
7367 When the {rhs} of a menu item is empty, then
7368 "<Nop>" is returned.
7369 script v:true if script-local remapping of {rhs} is
7370 allowed else v:false. See |:menu-script|.
7371 shortcut shortcut key (character after '&' in
7372 the menu name) |menu-shortcut|
7373 silent v:true if the menu item is created
7374 with <silent> argument |:menu-silent|
7375 submenus |List| containing the names of
7376 all the submenus. Present only if the menu
7377 item has submenus.
7378
7379 Returns an empty dictionary if the menu item is not found.
7380
7381 Examples: >
7382 :echo menu_info('Edit.Cut')
7383 :echo menu_info('File.Save', 'n')
7384
7385 " Display the entire menu hierarchy in a buffer
7386 func ShowMenu(name, pfx)
7387 let m = menu_info(a:name)
7388 call append(line('$'), a:pfx .. m.display)
7389 for child in m->get('submenus', [])
7390 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7391 \ a:pfx .. ' ')
7392 endfor
7393 endfunc
7394 new
7395 for topmenu in menu_info('').submenus
7396 call ShowMenu(topmenu, '')
7397 endfor
7398<
7399 Can also be used as a |method|: >
7400 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007401<
7402 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007403
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007404min({expr}) *min()*
7405 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007406 echo min([apples, pears, oranges])
7407
7408< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7409 it returns the minimum of all values in the Dictionary.
7410 If {expr} is neither a List nor a Dictionary, or one of the
7411 items in {expr} cannot be used as a Number this results in
7412 an error. An empty |List| or |Dictionary| results in zero.
7413
7414 Can also be used as a |method|: >
7415 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007416<
7417 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007418
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007419
7420mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007421 Create directory {name}.
7422
Bram Moolenaar938ae282023-02-20 20:44:55 +00007423 When {flags} is present it must be a string. An empty string
7424 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007425
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007426 {flags} can contain these character flags:
7427 "p" intermediate directories will be created as necessary
7428 "D" {name} will be deleted at the end of the current
Christian Brabandtc509c002024-06-14 20:22:05 +02007429 function, but not recursively |:defer|
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007430 "R" {name} will be deleted recursively at the end of the
Christian Brabandtc509c002024-06-14 20:22:05 +02007431 current function |:defer|
Bram Moolenaar938ae282023-02-20 20:44:55 +00007432
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007433 Note that when {name} has more than one part and "p" is used
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007434 some directories may already exist. Only the first one that
7435 is created and what it contains is scheduled to be deleted.
7436 E.g. when using: >
7437 call mkdir('subdir/tmp/autoload', 'pR')
7438< and "subdir" already exists then "subdir/tmp" will be
7439 scheduled for deletion, like with: >
7440 defer delete('subdir/tmp', 'rf')
7441< Note that if scheduling the defer fails the directory is not
7442 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007443
7444 If {prot} is given it is used to set the protection bits of
7445 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7446 the user, readable for others). Use 0o700 to make it
7447 unreadable for others. This is only used for the last part of
7448 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
7449 created with 0o755.
7450 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007451 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007452
7453< This function is not available in the |sandbox|.
7454
7455 There is no error if the directory already exists and the "p"
7456 flag is passed (since patch 8.0.1708). However, without the
7457 "p" option the call will fail.
7458
7459 The function result is a Number, which is TRUE if the call was
7460 successful or FALSE if the directory creation failed or partly
7461 failed.
7462
7463 Not available on all systems. To check use: >
7464 :if exists("*mkdir")
7465
7466< Can also be used as a |method|: >
7467 GetName()->mkdir()
7468<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007469 Return type: |Number|
7470
7471
7472mode([{expr}]) *mode()*
7473 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007474 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007475 a non-empty String (|non-zero-arg|), then the full mode is
7476 returned, otherwise only the first letter is returned.
7477 Also see |state()|.
7478
7479 n Normal
7480 no Operator-pending
7481 nov Operator-pending (forced characterwise |o_v|)
7482 noV Operator-pending (forced linewise |o_V|)
7483 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7484 CTRL-V is one character
7485 niI Normal using |i_CTRL-O| in |Insert-mode|
7486 niR Normal using |i_CTRL-O| in |Replace-mode|
7487 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7488 nt Terminal-Normal (insert goes to Terminal-Job mode)
7489 v Visual by character
7490 vs Visual by character using |v_CTRL-O| in Select mode
7491 V Visual by line
7492 Vs Visual by line using |v_CTRL-O| in Select mode
7493 CTRL-V Visual blockwise
7494 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7495 s Select by character
7496 S Select by line
7497 CTRL-S Select blockwise
7498 i Insert
7499 ic Insert mode completion |compl-generic|
7500 ix Insert mode |i_CTRL-X| completion
7501 R Replace |R|
7502 Rc Replace mode completion |compl-generic|
7503 Rx Replace mode |i_CTRL-X| completion
7504 Rv Virtual Replace |gR|
7505 Rvc Virtual Replace mode completion |compl-generic|
7506 Rvx Virtual Replace mode |i_CTRL-X| completion
7507 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007508 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007509 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007510 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007511 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007512 ce Normal Ex mode |Q|
7513 r Hit-enter prompt
7514 rm The -- more -- prompt
7515 r? A |:confirm| query of some sort
7516 ! Shell or external command is executing
7517 t Terminal-Job mode: keys go to the job
7518
7519 This is useful in the 'statusline' option or when used
7520 with |remote_expr()| In most other places it always returns
7521 "c" or "n".
7522 Note that in the future more modes and more specific modes may
7523 be added. It's better not to compare the whole string but only
7524 the leading character(s).
7525 Also see |visualmode()|.
7526
7527 Can also be used as a |method|: >
7528 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007529<
7530 Return type: |String|
7531
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007532
7533mzeval({expr}) *mzeval()*
7534 Evaluate MzScheme expression {expr} and return its result
7535 converted to Vim data structures.
7536 Numbers and strings are returned as they are.
7537 Pairs (including lists and improper lists) and vectors are
7538 returned as Vim |Lists|.
7539 Hash tables are represented as Vim |Dictionary| type with keys
7540 converted to strings.
7541 All other types are converted to string with display function.
7542 Examples: >
7543 :mz (define l (list 1 2 3))
7544 :mz (define h (make-hash)) (hash-set! h "list" l)
7545 :echo mzeval("l")
7546 :echo mzeval("h")
7547<
7548 Note that in a `:def` function local variables are not visible
7549 to {expr}.
7550
7551 Can also be used as a |method|: >
7552 GetExpr()->mzeval()
7553<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007554 Return type: any, depending on {expr}
7555
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007556 {only available when compiled with the |+mzscheme| feature}
7557
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007558
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007559nextnonblank({lnum}) *nextnonblank()*
7560 Return the line number of the first line at or below {lnum}
7561 that is not blank. Example: >
7562 if getline(nextnonblank(1)) =~ "Java"
7563< When {lnum} is invalid or there is no non-blank line at or
7564 below it, zero is returned.
7565 {lnum} is used like with |getline()|.
7566 See also |prevnonblank()|.
7567
7568 Can also be used as a |method|: >
7569 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007570<
7571 Return type: |Number|
7572
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007573
7574nr2char({expr} [, {utf8}]) *nr2char()*
7575 Return a string with a single character, which has the number
7576 value {expr}. Examples: >
7577 nr2char(64) returns "@"
7578 nr2char(32) returns " "
7579< When {utf8} is omitted or zero, the current 'encoding' is used.
7580 Example for "utf-8": >
7581 nr2char(300) returns I with bow character
7582< When {utf8} is TRUE, always return UTF-8 characters.
7583 Note that a NUL character in the file is specified with
7584 nr2char(10), because NULs are represented with newline
7585 characters. nr2char(0) is a real NUL and terminates the
7586 string, thus results in an empty string.
7587 To turn a list of character numbers into a string: >
7588 let list = [65, 66, 67]
7589 let str = join(map(list, {_, val -> nr2char(val)}), '')
7590< Result: "ABC"
7591
7592 Can also be used as a |method|: >
7593 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007594<
7595 Return type: |String|
7596
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007597
7598or({expr}, {expr}) *or()*
7599 Bitwise OR on the two arguments. The arguments are converted
7600 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007601 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007602 Example: >
7603 :let bits = or(bits, 0x80)
7604< Can also be used as a |method|: >
7605 :let bits = bits->or(0x80)
7606
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007607< Rationale: The reason this is a function and not using the "|"
7608 character like many languages, is that Vi has always used "|"
7609 to separate commands. In many places it would not be clear if
7610 "|" is an operator or a command separator.
7611
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007612 Return type: |Number|
7613
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007614
7615pathshorten({path} [, {len}]) *pathshorten()*
7616 Shorten directory names in the path {path} and return the
7617 result. The tail, the file name, is kept as-is. The other
7618 components in the path are reduced to {len} letters in length.
7619 If {len} is omitted or smaller than 1 then 1 is used (single
7620 letters). Leading '~' and '.' characters are kept. Examples: >
7621 :echo pathshorten('~/.vim/autoload/myfile.vim')
7622< ~/.v/a/myfile.vim ~
7623>
7624 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7625< ~/.vi/au/myfile.vim ~
7626 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007627 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007628
7629 Can also be used as a |method|: >
7630 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007631<
7632 Return type: |String|
7633
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007634
7635perleval({expr}) *perleval()*
7636 Evaluate Perl expression {expr} in scalar context and return
7637 its result converted to Vim data structures. If value can't be
7638 converted, it is returned as a string Perl representation.
7639 Note: If you want an array or hash, {expr} must return a
7640 reference to it.
7641 Example: >
7642 :echo perleval('[1 .. 4]')
7643< [1, 2, 3, 4]
7644
7645 Note that in a `:def` function local variables are not visible
7646 to {expr}.
7647
7648 Can also be used as a |method|: >
7649 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007650<
7651 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007652
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007653 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007654
7655
7656popup_ functions are documented here: |popup-functions|
7657
7658
7659pow({x}, {y}) *pow()*
7660 Return the power of {x} to the exponent {y} as a |Float|.
7661 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007662 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007663 Examples: >
7664 :echo pow(3, 3)
7665< 27.0 >
7666 :echo pow(2, 16)
7667< 65536.0 >
7668 :echo pow(32, 0.20)
7669< 2.0
7670
7671 Can also be used as a |method|: >
7672 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007673<
7674 Return type: |Number|
7675
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007676
7677prevnonblank({lnum}) *prevnonblank()*
7678 Return the line number of the first line at or above {lnum}
7679 that is not blank. Example: >
7680 let ind = indent(prevnonblank(v:lnum - 1))
7681< When {lnum} is invalid or there is no non-blank line at or
7682 above it, zero is returned.
7683 {lnum} is used like with |getline()|.
7684 Also see |nextnonblank()|.
7685
7686 Can also be used as a |method|: >
7687 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007688<
7689 Return type: |Number|
7690
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007691
7692printf({fmt}, {expr1} ...) *printf()*
7693 Return a String with {fmt}, where "%" items are replaced by
7694 the formatted form of their respective arguments. Example: >
7695 printf("%4d: E%d %.30s", lnum, errno, msg)
7696< May result in:
7697 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7698
7699 When used as a |method| the base is passed as the second
7700 argument: >
7701 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007702<
7703 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007704
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007705 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007706 %s string
7707 %6S string right-aligned in 6 display cells
7708 %6s string right-aligned in 6 bytes
7709 %.9s string truncated to 9 bytes
7710 %c single byte
7711 %d decimal number
7712 %5d decimal number padded with spaces to 5 characters
7713 %x hex number
7714 %04x hex number padded with zeros to at least 4 characters
7715 %X hex number using upper case letters
7716 %o octal number
7717 %08b binary number padded with zeros to at least 8 chars
7718 %f floating point number as 12.23, inf, -inf or nan
7719 %F floating point number as 12.23, INF, -INF or NAN
7720 %e floating point number as 1.23e3, inf, -inf or nan
7721 %E floating point number as 1.23E3, INF, -INF or NAN
7722 %g floating point number, as %f or %e depending on value
7723 %G floating point number, as %F or %E depending on value
7724 %% the % character itself
7725
7726 Conversion specifications start with '%' and end with the
7727 conversion type. All other characters are copied unchanged to
7728 the result.
7729
7730 The "%" starts a conversion specification. The following
7731 arguments appear in sequence:
7732
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007733 % [pos-argument] [flags] [field-width] [.precision] type
7734
7735 pos-argument
7736 At most one positional argument specifier. These
7737 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007738
7739 flags
7740 Zero or more of the following flags:
7741
7742 # The value should be converted to an "alternate
7743 form". For c, d, and s conversions, this option
7744 has no effect. For o conversions, the precision
7745 of the number is increased to force the first
7746 character of the output string to a zero (except
7747 if a zero value is printed with an explicit
7748 precision of zero).
7749 For b and B conversions, a non-zero result has
7750 the string "0b" (or "0B" for B conversions)
7751 prepended to it.
7752 For x and X conversions, a non-zero result has
7753 the string "0x" (or "0X" for X conversions)
7754 prepended to it.
7755
7756 0 (zero) Zero padding. For all conversions the converted
7757 value is padded on the left with zeros rather
7758 than blanks. If a precision is given with a
7759 numeric conversion (d, b, B, o, x, and X), the 0
7760 flag is ignored.
7761
7762 - A negative field width flag; the converted value
7763 is to be left adjusted on the field boundary.
7764 The converted value is padded on the right with
7765 blanks, rather than on the left with blanks or
7766 zeros. A - overrides a 0 if both are given.
7767
7768 ' ' (space) A blank should be left before a positive
7769 number produced by a signed conversion (d).
7770
7771 + A sign must always be placed before a number
7772 produced by a signed conversion. A + overrides
7773 a space if both are used.
7774
7775 field-width
7776 An optional decimal digit string specifying a minimum
7777 field width. If the converted value has fewer bytes
7778 than the field width, it will be padded with spaces on
7779 the left (or right, if the left-adjustment flag has
7780 been given) to fill out the field width. For the S
7781 conversion the count is in cells.
7782
7783 .precision
7784 An optional precision, in the form of a period '.'
7785 followed by an optional digit string. If the digit
7786 string is omitted, the precision is taken as zero.
7787 This gives the minimum number of digits to appear for
7788 d, o, x, and X conversions, the maximum number of
7789 bytes to be printed from a string for s conversions,
7790 or the maximum number of cells to be printed from a
7791 string for S conversions.
7792 For floating point it is the number of digits after
7793 the decimal point.
7794
7795 type
7796 A character that specifies the type of conversion to
7797 be applied, see below.
7798
7799 A field width or precision, or both, may be indicated by an
7800 asterisk '*' instead of a digit string. In this case, a
7801 Number argument supplies the field width or precision. A
7802 negative field width is treated as a left adjustment flag
7803 followed by a positive field width; a negative precision is
7804 treated as though it were missing. Example: >
7805 :echo printf("%d: %.*s", nr, width, line)
7806< This limits the length of the text used from "line" to
7807 "width" bytes.
7808
Dominique Pellé17dca3c2023-12-14 20:36:32 +01007809 If the argument to be formatted is specified using a
7810 positional argument specifier, and a '*' is used to indicate
7811 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007812 precision, the argument(s) to be used must also be specified
7813 using a {n$} positional argument specifier. See |printf-$|.
7814
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007815 The conversion specifiers and their meanings are:
7816
7817 *printf-d* *printf-b* *printf-B* *printf-o*
7818 *printf-x* *printf-X*
7819 dbBoxX The Number argument is converted to signed decimal
7820 (d), unsigned binary (b and B), unsigned octal (o), or
7821 unsigned hexadecimal (x and X) notation. The letters
7822 "abcdef" are used for x conversions; the letters
7823 "ABCDEF" are used for X conversions.
7824 The precision, if any, gives the minimum number of
7825 digits that must appear; if the converted value
7826 requires fewer digits, it is padded on the left with
7827 zeros.
7828 In no case does a non-existent or small field width
7829 cause truncation of a numeric field; if the result of
7830 a conversion is wider than the field width, the field
7831 is expanded to contain the conversion result.
7832 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02007833 The 'l' modifier indicates the argument is a long
7834 integer. The size will be 32 bits or 64 bits
7835 depending on your platform.
7836 The "ll" modifier indicates the argument is 64 bits.
7837 The b and B conversion specifiers never take a width
7838 modifier and always assume their argument is a 64 bit
7839 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007840 Generally, these modifiers are not useful. They are
7841 ignored when type is known from the argument.
7842
7843 i alias for d
7844 D alias for ld
7845 U alias for lu
7846 O alias for lo
7847
7848 *printf-c*
7849 c The Number argument is converted to a byte, and the
7850 resulting character is written.
7851
7852 *printf-s*
7853 s The text of the String argument is used. If a
7854 precision is specified, no more bytes than the number
7855 specified are used.
7856 If the argument is not a String type, it is
7857 automatically converted to text with the same format
7858 as ":echo".
7859 *printf-S*
7860 S The text of the String argument is used. If a
7861 precision is specified, no more display cells than the
7862 number specified are used.
7863
7864 *printf-f* *E807*
7865 f F The Float argument is converted into a string of the
7866 form 123.456. The precision specifies the number of
7867 digits after the decimal point. When the precision is
7868 zero the decimal point is omitted. When the precision
7869 is not specified 6 is used. A really big number
7870 (out of range or dividing by zero) results in "inf"
7871 or "-inf" with %f (INF or -INF with %F).
7872 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
7873 Example: >
7874 echo printf("%.2f", 12.115)
7875< 12.12
7876 Note that roundoff depends on the system libraries.
7877 Use |round()| when in doubt.
7878
7879 *printf-e* *printf-E*
7880 e E The Float argument is converted into a string of the
7881 form 1.234e+03 or 1.234E+03 when using 'E'. The
7882 precision specifies the number of digits after the
7883 decimal point, like with 'f'.
7884
7885 *printf-g* *printf-G*
7886 g G The Float argument is converted like with 'f' if the
7887 value is between 0.001 (inclusive) and 10000000.0
7888 (exclusive). Otherwise 'e' is used for 'g' and 'E'
7889 for 'G'. When no precision is specified superfluous
7890 zeroes and '+' signs are removed, except for the zero
7891 immediately after the decimal point. Thus 10000000.0
7892 results in 1.0e7.
7893
7894 *printf-%*
7895 % A '%' is written. No argument is converted. The
7896 complete conversion specification is "%%".
7897
7898 When a Number argument is expected a String argument is also
7899 accepted and automatically converted.
7900 When a Float or String argument is expected a Number argument
7901 is also accepted and automatically converted.
7902 Any other argument type results in an error message.
7903
7904 *E766* *E767*
7905 The number of {exprN} arguments must exactly match the number
7906 of "%" items. If there are not sufficient or too many
7907 arguments an error is given. Up to 18 arguments can be used.
7908
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007909 *printf-$*
7910 In certain languages, error and informative messages are
7911 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02007912 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007913 having a different word order, positional arguments may be
7914 used to indicate this. For instance: >
7915
h_east596a9f22023-11-21 21:24:23 +09007916 #, c-format
7917 msgid "%s returning %s"
7918 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007919<
h_east596a9f22023-11-21 21:24:23 +09007920 In this example, the sentence has its 2 string arguments
7921 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007922
h_east596a9f22023-11-21 21:24:23 +09007923 echo printf(
7924 "In The Netherlands, vim's creator's name is: %1$s %2$s",
7925 "Bram", "Moolenaar")
7926< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007927
h_east596a9f22023-11-21 21:24:23 +09007928 echo printf(
7929 "In Belgium, vim's creator's name is: %2$s %1$s",
7930 "Bram", "Moolenaar")
7931< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007932
7933 Width (and precision) can be specified using the '*' specifier.
7934 In this case, you must specify the field width position in the
7935 argument list. >
7936
h_east596a9f22023-11-21 21:24:23 +09007937 echo printf("%1$*2$.*3$d", 1, 2, 3)
7938< 001 >
7939 echo printf("%2$*3$.*1$d", 1, 2, 3)
7940< 2 >
7941 echo printf("%3$*1$.*2$d", 1, 2, 3)
7942< 03 >
7943 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
7944< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007945
7946 You can mix specifying the width and/or precision directly
7947 and via positional arguments: >
7948
h_east596a9f22023-11-21 21:24:23 +09007949 echo printf("%1$4.*2$f", 1.4142135, 6)
7950< 1.414214 >
7951 echo printf("%1$*2$.4f", 1.4142135, 6)
7952< 1.4142 >
7953 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
7954< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007955
Christ van Willegenc35fc032024-03-14 18:30:41 +01007956 You will get an overflow error |E1510|, when the field-width
7957 or precision will result in a string longer than 6400 chars.
7958
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007959 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007960 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09007961 echo printf("%s%1$s", "One", "Two")
7962< E1500: Cannot mix positional and non-positional arguments:
7963 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007964
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007965 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007966 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09007967 echo printf("%3$s%1$s", "One", "Two", "Three")
7968< E1501: format argument 2 unused in $-style format:
7969 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007970
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007971 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007972 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09007973 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
7974< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007975
7976 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09007977 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
7978< E1502: Positional argument 2 used as field width reused as
7979 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007980
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007981 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007982 When a positional argument is used, but not the correct number
7983 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09007984 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
7985< E1503: Positional argument 3 out of bounds: %1$d at width
7986 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007987
7988 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09007989 echo printf("%01$*2$.*3$d %4$d", 1, 2)
7990< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
7991 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007992
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007993 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007994 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09007995 echo printf("%1$s %2$s %1$s", "One", "Two")
7996< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007997
7998 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09007999 echo printf("%1$s %2$s %1$d", "One", "Two")
8000< E1504: Positional argument 1 type used inconsistently:
8001 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008002
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008003 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008004 Various other errors that lead to a format string being
8005 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09008006 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
8007< E1505: Invalid format specifier: %1$d at width %2$d is:
8008 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008009
Christ van Willegenea746f92023-10-05 20:48:36 +02008010 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08008011 This internal error indicates that the logic to parse a
8012 positional format argument ran into a problem that couldn't be
8013 otherwise reported. Please file a bug against Vim if you run
8014 into this, copying the exact format string and parameters that
8015 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02008016
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008017 Return type: |String|
8018
Christ van Willegenea746f92023-10-05 20:48:36 +02008019
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008020prompt_getprompt({buf}) *prompt_getprompt()*
8021 Returns the effective prompt text for buffer {buf}. {buf} can
8022 be a buffer name or number. See |prompt-buffer|.
8023
8024 If the buffer doesn't exist or isn't a prompt buffer, an empty
8025 string is returned.
8026
8027 Can also be used as a |method|: >
8028 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008029<
8030 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008031
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008032 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008033
8034
8035prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
8036 Set prompt callback for buffer {buf} to {expr}. When {expr}
8037 is an empty string the callback is removed. This has only
8038 effect if {buf} has 'buftype' set to "prompt".
8039
8040 The callback is invoked when pressing Enter. The current
8041 buffer will always be the prompt buffer. A new line for a
8042 prompt is added before invoking the callback, thus the prompt
8043 for which the callback was invoked will be in the last but one
8044 line.
8045 If the callback wants to add text to the buffer, it must
8046 insert it above the last line, since that is where the current
8047 prompt is. This can also be done asynchronously.
8048 The callback is invoked with one argument, which is the text
8049 that was entered at the prompt. This can be an empty string
8050 if the user only typed Enter.
8051 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008052 func s:TextEntered(text)
8053 if a:text == 'exit' || a:text == 'quit'
8054 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008055 " Reset 'modified' to allow the buffer to be closed.
8056 " We assume there is nothing useful to be saved.
8057 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008058 close
8059 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008060 " Do something useful with "a:text". In this example
8061 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008062 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008063 endif
8064 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008065 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008066
8067< Can also be used as a |method|: >
8068 GetBuffer()->prompt_setcallback(callback)
8069
8070< {only available when compiled with the |+channel| feature}
8071
8072prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
8073 Set a callback for buffer {buf} to {expr}. When {expr} is an
8074 empty string the callback is removed. This has only effect if
8075 {buf} has 'buftype' set to "prompt".
8076
8077 This callback will be invoked when pressing CTRL-C in Insert
8078 mode. Without setting a callback Vim will exit Insert mode,
8079 as in any buffer.
8080
8081 Can also be used as a |method|: >
8082 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008083<
8084 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008085
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008086 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008087
8088prompt_setprompt({buf}, {text}) *prompt_setprompt()*
8089 Set prompt for buffer {buf} to {text}. You most likely want
8090 {text} to end in a space.
8091 The result is only visible if {buf} has 'buftype' set to
8092 "prompt". Example: >
8093 call prompt_setprompt(bufnr(), 'command: ')
8094<
8095 Can also be used as a |method|: >
8096 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008097<
8098 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008099
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008100 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008101
8102prop_ functions are documented here: |text-prop-functions|
8103
8104pum_getpos() *pum_getpos()*
8105 If the popup menu (see |ins-completion-menu|) is not visible,
8106 returns an empty |Dictionary|, otherwise, returns a
8107 |Dictionary| with the following keys:
8108 height nr of items visible
8109 width screen cells
8110 row top screen row (0 first row)
8111 col leftmost screen column (0 first col)
8112 size total nr of items
8113 scrollbar |TRUE| if scrollbar is visible
8114
8115 The values are the same as in |v:event| during
8116 |CompleteChanged|.
8117
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008118 Return type: dict<any>
8119
8120
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008121pumvisible() *pumvisible()*
8122 Returns non-zero when the popup menu is visible, zero
8123 otherwise. See |ins-completion-menu|.
8124 This can be used to avoid some things that would remove the
8125 popup menu.
8126
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008127 Return type: |Number|
8128
8129
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008130py3eval({expr}) *py3eval()*
8131 Evaluate Python expression {expr} and return its result
8132 converted to Vim data structures.
8133 Numbers and strings are returned as they are (strings are
8134 copied though, Unicode strings are additionally converted to
8135 'encoding').
8136 Lists are represented as Vim |List| type.
8137 Dictionaries are represented as Vim |Dictionary| type with
8138 keys converted to strings.
8139 Note that in a `:def` function local variables are not visible
8140 to {expr}.
8141
8142 Can also be used as a |method|: >
8143 GetExpr()->py3eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008144<
8145 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008146
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008147 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008148
8149 *E858* *E859*
8150pyeval({expr}) *pyeval()*
8151 Evaluate Python expression {expr} and return its result
8152 converted to Vim data structures.
8153 Numbers and strings are returned as they are (strings are
8154 copied though).
8155 Lists are represented as Vim |List| type.
8156 Dictionaries are represented as Vim |Dictionary| type,
8157 non-string keys result in error.
8158 Note that in a `:def` function local variables are not visible
8159 to {expr}.
8160
8161 Can also be used as a |method|: >
8162 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008163<
8164 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008165
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008166 {only available when compiled with the |+python| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008167
8168pyxeval({expr}) *pyxeval()*
8169 Evaluate Python expression {expr} and return its result
8170 converted to Vim data structures.
8171 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8172 See also: |pyeval()|, |py3eval()|
8173
8174 Can also be used as a |method|: >
h-east52e7cc22024-07-28 17:03:29 +02008175 GetExpr()->pyxeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008176<
8177 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008178
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008179 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008180 |+python3| feature}
8181
8182rand([{expr}]) *rand()* *random*
8183 Return a pseudo-random Number generated with an xoshiro128**
8184 algorithm using seed {expr}. The returned number is 32 bits,
8185 also on 64 bits systems, for consistency.
8186 {expr} can be initialized by |srand()| and will be updated by
8187 rand(). If {expr} is omitted, an internal seed value is used
8188 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008189 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008190
8191 Examples: >
8192 :echo rand()
8193 :let seed = srand()
8194 :echo rand(seed)
8195 :echo rand(seed) % 16 " random number 0 - 15
8196<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008197 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008198
8199 *E726* *E727*
8200range({expr} [, {max} [, {stride}]]) *range()*
8201 Returns a |List| with Numbers:
8202 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8203 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8204 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8205 {max}] (increasing {expr} with {stride} each time, not
8206 producing a value past {max}).
8207 When the maximum is one before the start the result is an
8208 empty list. When the maximum is more than one before the
8209 start this is an error.
8210 Examples: >
8211 range(4) " [0, 1, 2, 3]
8212 range(2, 4) " [2, 3, 4]
8213 range(2, 9, 3) " [2, 5, 8]
8214 range(2, -2, -1) " [2, 1, 0, -1, -2]
8215 range(0) " []
8216 range(2, 0) " error!
8217<
8218 Can also be used as a |method|: >
8219 GetExpr()->range()
8220<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008221 Return type: list<number>
8222
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008223
K.Takata11df3ae2022-10-19 14:02:40 +01008224readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008225 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008226 If {offset} is specified, read the file from the specified
8227 offset. If it is a negative value, it is used as an offset
8228 from the end of the file. E.g., to read the last 12 bytes: >
8229 readblob('file.bin', -12)
8230< If {size} is specified, only the specified size will be read.
8231 E.g. to read the first 100 bytes of a file: >
8232 readblob('file.bin', 0, 100)
8233< If {size} is -1 or omitted, the whole data starting from
8234 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008235 This can be also used to read the data from a character device
8236 on Unix when {size} is explicitly set. Only if the device
8237 supports seeking {offset} can be used. Otherwise it should be
8238 zero. E.g. to read 10 bytes from a serial console: >
8239 readblob('/dev/ttyS0', 0, 10)
8240< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008241 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008242 When the offset is beyond the end of the file the result is an
8243 empty blob.
8244 When trying to read more bytes than are available the result
8245 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008246 Also see |readfile()| and |writefile()|.
8247
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008248 Return type: |Blob|
8249
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008250
8251readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8252 Return a list with file and directory names in {directory}.
8253 You can also use |glob()| if you don't need to do complicated
8254 things, such as limiting the number of matches.
8255 The list will be sorted (case sensitive), see the {dict}
8256 argument below for changing the sort order.
8257
8258 When {expr} is omitted all entries are included.
8259 When {expr} is given, it is evaluated to check what to do:
8260 If {expr} results in -1 then no further entries will
8261 be handled.
8262 If {expr} results in 0 then this entry will not be
8263 added to the list.
8264 If {expr} results in 1 then this entry will be added
8265 to the list.
8266 The entries "." and ".." are always excluded.
8267 Each time {expr} is evaluated |v:val| is set to the entry name.
8268 When {expr} is a function the name is passed as the argument.
8269 For example, to get a list of files ending in ".txt": >
8270 readdir(dirname, {n -> n =~ '.txt$'})
8271< To skip hidden and backup files: >
8272 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008273< *E857*
8274 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008275 values. Currently this is used to specify if and how sorting
8276 should be performed. The dict can have the following members:
8277
8278 sort How to sort the result returned from the system.
8279 Valid values are:
8280 "none" do not sort (fastest method)
8281 "case" sort case sensitive (byte value of
8282 each character, technically, using
8283 strcmp()) (default)
8284 "icase" sort case insensitive (technically
8285 using strcasecmp())
8286 "collate" sort using the collation order
8287 of the "POSIX" or "C" |locale|
8288 (technically using strcoll())
8289 Other values are silently ignored.
8290
8291 For example, to get a list of all files in the current
8292 directory without sorting the individual entries: >
8293 readdir('.', '1', #{sort: 'none'})
8294< If you want to get a directory tree: >
8295 function! s:tree(dir)
8296 return {a:dir : map(readdir(a:dir),
8297 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008298 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008299 endfunction
8300 echo s:tree(".")
8301<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008302 Returns an empty List on error.
8303
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008304 Can also be used as a |method|: >
8305 GetDirName()->readdir()
8306<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008307 Return type: list<string> or list<any>
8308
8309
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008310readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8311 Extended version of |readdir()|.
8312 Return a list of Dictionaries with file and directory
8313 information in {directory}.
8314 This is useful if you want to get the attributes of file and
8315 directory at the same time as getting a list of a directory.
8316 This is much faster than calling |readdir()| then calling
8317 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8318 each file and directory especially on MS-Windows.
8319 The list will by default be sorted by name (case sensitive),
8320 the sorting can be changed by using the optional {dict}
8321 argument, see |readdir()|.
8322
8323 The Dictionary for file and directory information has the
8324 following items:
8325 group Group name of the entry. (Only on Unix)
8326 name Name of the entry.
8327 perm Permissions of the entry. See |getfperm()|.
8328 size Size of the entry. See |getfsize()|.
8329 time Timestamp of the entry. See |getftime()|.
8330 type Type of the entry.
8331 On Unix, almost same as |getftype()| except:
8332 Symlink to a dir "linkd"
8333 Other symlink "link"
8334 On MS-Windows:
8335 Normal file "file"
8336 Directory "dir"
8337 Junction "junction"
8338 Symlink to a dir "linkd"
8339 Other symlink "link"
8340 Other reparse point "reparse"
8341 user User name of the entry's owner. (Only on Unix)
8342 On Unix, if the entry is a symlink, the Dictionary includes
8343 the information of the target (except the "type" item).
8344 On MS-Windows, it includes the information of the symlink
8345 itself because of performance reasons.
8346
8347 When {expr} is omitted all entries are included.
8348 When {expr} is given, it is evaluated to check what to do:
8349 If {expr} results in -1 then no further entries will
8350 be handled.
8351 If {expr} results in 0 then this entry will not be
8352 added to the list.
8353 If {expr} results in 1 then this entry will be added
8354 to the list.
8355 The entries "." and ".." are always excluded.
8356 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8357 of the entry.
8358 When {expr} is a function the entry is passed as the argument.
8359 For example, to get a list of files ending in ".txt": >
8360 readdirex(dirname, {e -> e.name =~ '.txt$'})
8361<
8362 For example, to get a list of all files in the current
8363 directory without sorting the individual entries: >
8364 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008365<
8366 Can also be used as a |method|: >
8367 GetDirName()->readdirex()
8368<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008369 Return type: list<dict<any>> or list<any>
8370
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008371
8372 *readfile()*
8373readfile({fname} [, {type} [, {max}]])
8374 Read file {fname} and return a |List|, each line of the file
8375 as an item. Lines are broken at NL characters. Macintosh
8376 files separated with CR will result in a single long line
8377 (unless a NL appears somewhere).
8378 All NUL characters are replaced with a NL character.
8379 When {type} contains "b" binary mode is used:
8380 - When the last line ends in a NL an extra empty list item is
8381 added.
8382 - No CR characters are removed.
8383 Otherwise:
8384 - CR characters that appear before a NL are removed.
8385 - Whether the last line ends in a NL or not does not matter.
8386 - When 'encoding' is Unicode any UTF-8 byte order mark is
8387 removed from the text.
8388 When {max} is given this specifies the maximum number of lines
8389 to be read. Useful if you only want to check the first ten
8390 lines of a file: >
8391 :for line in readfile(fname, '', 10)
8392 : if line =~ 'Date' | echo line | endif
8393 :endfor
8394< When {max} is negative -{max} lines from the end of the file
8395 are returned, or as many as there are.
8396 When {max} is zero the result is an empty list.
8397 Note that without {max} the whole file is read into memory.
8398 Also note that there is no recognition of encoding. Read a
8399 file into a buffer if you need to.
8400 Deprecated (use |readblob()| instead): When {type} contains
8401 "B" a |Blob| is returned with the binary data of the file
8402 unmodified.
8403 When the file can't be opened an error message is given and
8404 the result is an empty list.
8405 Also see |writefile()|.
8406
8407 Can also be used as a |method|: >
8408 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008409<
8410 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008411
8412reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8413 {func} is called for every item in {object}, which can be a
8414 |String|, |List| or a |Blob|. {func} is called with two
8415 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008416 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008417
8418 {initial} is the initial result. When omitted, the first item
8419 in {object} is used and {func} is first called for the second
8420 item. If {initial} is not given and {object} is empty no
8421 result can be computed, an E998 error is given.
8422
8423 Examples: >
8424 echo reduce([1, 3, 5], { acc, val -> acc + val })
8425 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8426 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8427 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8428<
8429 Can also be used as a |method|: >
8430 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008431<
8432 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8433 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008434
8435
8436reg_executing() *reg_executing()*
8437 Returns the single letter name of the register being executed.
8438 Returns an empty string when no register is being executed.
8439 See |@|.
8440
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008441 Return type: |String|
8442
8443
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008444reg_recording() *reg_recording()*
8445 Returns the single letter name of the register being recorded.
8446 Returns an empty string when not recording. See |q|.
8447
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008448 Return type: |String|
8449
8450
8451reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008452reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008453reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008454 Return an item that represents a time value. The item is a
8455 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008456 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008457 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008458 string or |reltimefloat()| to convert to a Float. For
8459 example, to see the time spent in function Work(): >
8460 var startTime = reltime()
8461 Work()
8462 echo startTime->reltime()->reltimestr()
8463<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008464 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008465 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008466 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008467 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008468 specified in the argument.
8469 With two arguments it returns the time passed between {start}
8470 and {end}.
8471
8472 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008473 reltime(). If there is an error an empty List is returned in
8474 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008475
8476 Can also be used as a |method|: >
8477 GetStart()->reltime()
8478<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008479 Return type: list<number>
8480
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008481 {only available when compiled with the |+reltime| feature}
8482
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008483
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008484reltimefloat({time}) *reltimefloat()*
8485 Return a Float that represents the time value of {time}.
8486 Example: >
8487 let start = reltime()
8488 call MyFunction()
8489 let seconds = reltimefloat(reltime(start))
8490< See the note of reltimestr() about overhead.
8491 Also see |profiling|.
8492 If there is an error 0.0 is returned in legacy script, in Vim9
8493 script an error is given.
8494
8495 Can also be used as a |method|: >
8496 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008497<
8498 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008499
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008500 {only available when compiled with the |+reltime| feature}
8501
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008502
8503reltimestr({time}) *reltimestr()*
8504 Return a String that represents the time value of {time}.
8505 This is the number of seconds, a dot and the number of
8506 microseconds. Example: >
8507 let start = reltime()
8508 call MyFunction()
8509 echo reltimestr(reltime(start))
8510< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008511 The accuracy depends on the system. Use reltimefloat() for the
8512 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008513 Leading spaces are used to make the string align nicely. You
8514 can use split() to remove it. >
8515 echo split(reltimestr(reltime(start)))[0]
8516< Also see |profiling|.
8517 If there is an error an empty string is returned in legacy
8518 script, in Vim9 script an error is given.
8519
8520 Can also be used as a |method|: >
8521 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008522<
8523 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008524
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008525 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008526
8527 *remote_expr()* *E449*
8528remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008529 Send the {string} to {server}. The {server} argument is a
8530 string, also see |{server}|.
8531
8532 The string is sent as an expression and the result is returned
Christian Brabandt1961caf2024-10-12 11:57:12 +02008533 after evaluation. The result must be a String or a |List|
8534 other types will be converted to String. A |List| is turned
8535 into a String by joining the items with a line break in
8536 between (not at the end), like with join(expr, "\n").
Bram Moolenaar944697a2022-02-20 19:48:20 +00008537
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008538 If {idvar} is present and not empty, it is taken as the name
8539 of a variable and a {serverid} for later use with
8540 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008541
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008542 If {timeout} is given the read times out after this many
8543 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008544
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008545 See also |clientserver| |RemoteReply|.
8546 This function is not available in the |sandbox|.
8547 {only available when compiled with the |+clientserver| feature}
8548 Note: Any errors will cause a local error message to be issued
8549 and the result will be the empty string.
8550
8551 Variables will be evaluated in the global namespace,
8552 independent of a function currently being active. Except
8553 when in debug mode, then local function variables and
8554 arguments can be evaluated.
8555
8556 Examples: >
8557 :echo remote_expr("gvim", "2+2")
8558 :echo remote_expr("gvim1", "b:current_syntax")
8559<
8560 Can also be used as a |method|: >
8561 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008562<
8563 Return type: |String| or list<{type}>
8564
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008565
8566remote_foreground({server}) *remote_foreground()*
8567 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008568 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008569 This works like: >
8570 remote_expr({server}, "foreground()")
8571< Except that on Win32 systems the client does the work, to work
8572 around the problem that the OS doesn't always allow the server
8573 to bring itself to the foreground.
8574 Note: This does not restore the window if it was minimized,
8575 like foreground() does.
8576 This function is not available in the |sandbox|.
8577
8578 Can also be used as a |method|: >
8579 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008580<
8581 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008582
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008583 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008584 Win32 console version}
8585
8586
8587remote_peek({serverid} [, {retvar}]) *remote_peek()*
8588 Returns a positive number if there are available strings
8589 from {serverid}. Copies any reply string into the variable
8590 {retvar} if specified. {retvar} must be a string with the
8591 name of a variable.
8592 Returns zero if none are available.
8593 Returns -1 if something is wrong.
8594 See also |clientserver|.
8595 This function is not available in the |sandbox|.
8596 {only available when compiled with the |+clientserver| feature}
8597 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008598 :let repl = ""
8599 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008600
8601< Can also be used as a |method|: >
8602 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008603<
8604 Return type: |Number|
8605
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008606
8607remote_read({serverid}, [{timeout}]) *remote_read()*
8608 Return the oldest available reply from {serverid} and consume
8609 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008610 reply is available. Returns an empty string, if a reply is
8611 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008612 See also |clientserver|.
8613 This function is not available in the |sandbox|.
8614 {only available when compiled with the |+clientserver| feature}
8615 Example: >
8616 :echo remote_read(id)
8617
8618< Can also be used as a |method|: >
8619 ServerId()->remote_read()
8620<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008621 Return type: |String|
8622
8623
8624remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008625 Send the {string} to {server}. The {server} argument is a
8626 string, also see |{server}|.
8627
8628 The string is sent as input keys and the function returns
8629 immediately. At the Vim server the keys are not mapped
8630 |:map|.
8631
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008632 If {idvar} is present, it is taken as the name of a variable
8633 and a {serverid} for later use with remote_read() is stored
8634 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008635
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008636 See also |clientserver| |RemoteReply|.
8637 This function is not available in the |sandbox|.
8638 {only available when compiled with the |+clientserver| feature}
8639
8640 Note: Any errors will be reported in the server and may mess
8641 up the display.
8642 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008643 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008644 \ remote_read(serverid)
8645
8646 :autocmd NONE RemoteReply *
8647 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008648 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008649 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8650<
8651 Can also be used as a |method|: >
8652 ServerName()->remote_send(keys)
8653<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008654 Return type: |String|
8655
8656
8657remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008658 Become the server {name}. {name} must be a non-empty string.
8659 This fails if already running as a server, when |v:servername|
8660 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008661
8662 Can also be used as a |method|: >
8663 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008664<
8665 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008666
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008667 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008668
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008669
8670remove({list}, {idx}) *remove()*
8671remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008672 Without {end}: Remove the item at {idx} from |List| {list} and
8673 return the item.
8674 With {end}: Remove items from {idx} to {end} (inclusive) and
8675 return a |List| with these items. When {idx} points to the same
8676 item as {end} a list with one item is returned. When {end}
8677 points to an item before {idx} this is an error.
8678 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008679 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008680 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008681 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008682 :call remove(mylist, 0, 9)
8683<
8684 Use |delete()| to remove a file.
8685
8686 Can also be used as a |method|: >
8687 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008688<
8689 Return type: any, depending on {list}
8690
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008691
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008692remove({blob}, {idx})
8693remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008694 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8695 return the byte.
8696 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8697 return a |Blob| with these bytes. When {idx} points to the same
8698 byte as {end} a |Blob| with one byte is returned. When {end}
8699 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008700 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008701 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008702 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008703 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008704<
8705 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008706
8707remove({dict}, {key})
8708 Remove the entry from {dict} with key {key} and return it.
8709 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008710 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008711< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008712 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008713
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008714 Return type: any, depending on {dict}
8715
8716
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008717rename({from}, {to}) *rename()*
8718 Rename the file by the name {from} to the name {to}. This
8719 should also work to move files across file systems. The
8720 result is a Number, which is 0 if the file was renamed
8721 successfully, and non-zero when the renaming failed.
8722 NOTE: If {to} exists it is overwritten without warning.
8723 This function is not available in the |sandbox|.
8724
8725 Can also be used as a |method|: >
8726 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008727<
8728 Return type: |Number|
8729
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008730
8731repeat({expr}, {count}) *repeat()*
8732 Repeat {expr} {count} times and return the concatenated
8733 result. Example: >
8734 :let separator = repeat('-', 80)
8735< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01008736 When {expr} is a |List| or a |Blob| the result is {expr}
8737 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008738 :let longlist = repeat(['a', 'b'], 3)
8739< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
8740
8741 Can also be used as a |method|: >
8742 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008743<
8744 Return type: |String|, |Blob| or list<{type}> depending on
8745 {expr}
8746
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008747
8748resolve({filename}) *resolve()* *E655*
8749 On MS-Windows, when {filename} is a shortcut (a .lnk file),
8750 returns the path the shortcut points to in a simplified form.
8751 When {filename} is a symbolic link or junction point, return
8752 the full path to the target. If the target of junction is
8753 removed, return {filename}.
8754 On Unix, repeat resolving symbolic links in all path
8755 components of {filename} and return the simplified result.
8756 To cope with link cycles, resolving of symbolic links is
8757 stopped after 100 iterations.
8758 On other systems, return the simplified {filename}.
8759 The simplification step is done as by |simplify()|.
8760 resolve() keeps a leading path component specifying the
8761 current directory (provided the result is still a relative
8762 path name) and also keeps a trailing path separator.
8763
8764 Can also be used as a |method|: >
8765 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008766<
8767 Return type: |String|
8768
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008769
8770reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01008771 Reverse the order of items in {object}. {object} can be a
8772 |List|, a |Blob| or a |String|. For a List and a Blob the
8773 items are reversed in-place and {object} is returned.
8774 For a String a new String is returned.
8775 Returns zero if {object} is not a List, Blob or a String.
8776 If you want a List or Blob to remain unmodified make a copy
8777 first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008778 :let revlist = reverse(copy(mylist))
8779< Can also be used as a |method|: >
8780 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008781<
8782 Return type: |String|, |Blob| or list<{type}> depending on
8783 {object}
8784
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008785
8786round({expr}) *round()*
8787 Round off {expr} to the nearest integral value and return it
8788 as a |Float|. If {expr} lies halfway between two integral
8789 values, then use the larger one (away from zero).
8790 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008791 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008792 Examples: >
8793 echo round(0.456)
8794< 0.0 >
8795 echo round(4.5)
8796< 5.0 >
8797 echo round(-4.5)
8798< -5.0
8799
8800 Can also be used as a |method|: >
8801 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008802<
8803 Return type: |Float|
8804
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008805
8806rubyeval({expr}) *rubyeval()*
8807 Evaluate Ruby expression {expr} and return its result
8808 converted to Vim data structures.
8809 Numbers, floats and strings are returned as they are (strings
8810 are copied though).
8811 Arrays are represented as Vim |List| type.
8812 Hashes are represented as Vim |Dictionary| type.
8813 Other objects are represented as strings resulted from their
8814 "Object#to_s" method.
8815 Note that in a `:def` function local variables are not visible
8816 to {expr}.
8817
8818 Can also be used as a |method|: >
8819 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008820<
8821 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008822
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008823 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008824
8825screenattr({row}, {col}) *screenattr()*
8826 Like |screenchar()|, but return the attribute. This is a rather
8827 arbitrary number that can only be used to compare to the
8828 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008829 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008830
8831 Can also be used as a |method|: >
8832 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008833<
8834 Return type: |Number|
8835
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008836
8837screenchar({row}, {col}) *screenchar()*
8838 The result is a Number, which is the character at position
8839 [row, col] on the screen. This works for every possible
8840 screen position, also status lines, window separators and the
8841 command line. The top left position is row one, column one
8842 The character excludes composing characters. For double-byte
8843 encodings it may only be the first byte.
8844 This is mainly to be used for testing.
8845 Returns -1 when row or col is out of range.
8846
8847 Can also be used as a |method|: >
8848 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008849<
8850 Return type: |Number|
8851
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008852
8853screenchars({row}, {col}) *screenchars()*
8854 The result is a |List| of Numbers. The first number is the same
8855 as what |screenchar()| returns. Further numbers are
8856 composing characters on top of the base character.
8857 This is mainly to be used for testing.
8858 Returns an empty List when row or col is out of range.
8859
8860 Can also be used as a |method|: >
8861 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008862<
8863 Return type: list<number> or list<any>
8864
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008865
8866screencol() *screencol()*
8867 The result is a Number, which is the current screen column of
8868 the cursor. The leftmost column has number 1.
8869 This function is mainly used for testing.
8870
8871 Note: Always returns the current screen column, thus if used
8872 in a command (e.g. ":echo screencol()") it will return the
8873 column inside the command line, which is 1 when the command is
8874 executed. To get the cursor position in the file use one of
8875 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008876 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008877 nnoremap <silent> GG :echom screencol()<CR>
8878 nnoremap GG <Cmd>echom screencol()<CR>
8879<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008880 Return type: |Number|
8881
8882
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008883screenpos({winid}, {lnum}, {col}) *screenpos()*
8884 The result is a Dict with the screen position of the text
8885 character in window {winid} at buffer line {lnum} and column
8886 {col}. {col} is a one-based byte index.
8887 The Dict has these members:
8888 row screen row
8889 col first screen column
8890 endcol last screen column
8891 curscol cursor screen column
8892 If the specified position is not visible, all values are zero.
8893 The "endcol" value differs from "col" when the character
8894 occupies more than one screen cell. E.g. for a Tab "col" can
8895 be 1 and "endcol" can be 8.
8896 The "curscol" value is where the cursor would be placed. For
8897 a Tab it would be the same as "endcol", while for a double
8898 width character it would be the same as "col".
8899 The |conceal| feature is ignored here, the column numbers are
8900 as if 'conceallevel' is zero. You can set the cursor to the
8901 right position and use |screencol()| to get the value with
8902 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008903 If the position is in a closed fold the screen position of the
8904 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008905 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008906
8907 Can also be used as a |method|: >
8908 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008909<
8910 Return type: dict<number> or dict<any>
8911
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008912
8913screenrow() *screenrow()*
8914 The result is a Number, which is the current screen row of the
8915 cursor. The top line has number one.
8916 This function is mainly used for testing.
8917 Alternatively you can use |winline()|.
8918
8919 Note: Same restrictions as with |screencol()|.
8920
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008921 Return type: |Number|
8922
8923
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008924screenstring({row}, {col}) *screenstring()*
8925 The result is a String that contains the base character and
8926 any composing characters at position [row, col] on the screen.
8927 This is like |screenchars()| but returning a String with the
8928 characters.
8929 This is mainly to be used for testing.
8930 Returns an empty String when row or col is out of range.
8931
8932 Can also be used as a |method|: >
8933 GetRow()->screenstring(col)
8934<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008935 Return type: |String|
8936
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008937 *search()*
8938search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
8939 Search for regexp pattern {pattern}. The search starts at the
8940 cursor position (you can use |cursor()| to set it).
8941
8942 When a match has been found its line number is returned.
8943 If there is no match a 0 is returned and the cursor doesn't
8944 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01008945 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008946
8947 {flags} is a String, which can contain these character flags:
8948 'b' search Backward instead of forward
8949 'c' accept a match at the Cursor position
8950 'e' move to the End of the match
8951 'n' do Not move the cursor
8952 'p' return number of matching sub-Pattern (see below)
8953 's' Set the ' mark at the previous location of the cursor
8954 'w' Wrap around the end of the file
8955 'W' don't Wrap around the end of the file
8956 'z' start searching at the cursor column instead of zero
8957 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
8958
8959 If the 's' flag is supplied, the ' mark is set, only if the
8960 cursor is moved. The 's' flag cannot be combined with the 'n'
8961 flag.
8962
8963 'ignorecase', 'smartcase' and 'magic' are used.
8964
8965 When the 'z' flag is not given, forward searching always
8966 starts in column zero and then matches before the cursor are
8967 skipped. When the 'c' flag is present in 'cpo' the next
8968 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01008969 search starts one column after the start of the match. This
8970 matters for overlapping matches. See |cpo-c|. You can also
8971 insert "\ze" to change where the match ends, see |/\ze|.
8972
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008973 When searching backwards and the 'z' flag is given then the
8974 search starts in column zero, thus no match in the current
8975 line will be found (unless wrapping around the end of the
8976 file).
8977
8978 When the {stopline} argument is given then the search stops
8979 after searching this line. This is useful to restrict the
8980 search to a range of lines. Examples: >
8981 let match = search('(', 'b', line("w0"))
8982 let end = search('END', '', line("w$"))
8983< When {stopline} is used and it is not zero this also implies
8984 that the search does not wrap around the end of the file.
8985 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01008986 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008987 When the {timeout} argument is given the search stops when
8988 more than this many milliseconds have passed. Thus when
8989 {timeout} is 500 the search stops after half a second.
8990 The value must not be negative. A zero value is like not
8991 giving the argument.
Christian Brabandtd657d3d2024-09-10 21:55:49 +02008992
8993 Note: the timeout is only considered when searching, not
8994 while evaluating the {skip} expression.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008995 {only available when compiled with the |+reltime| feature}
8996
8997 If the {skip} expression is given it is evaluated with the
8998 cursor positioned on the start of a match. If it evaluates to
8999 non-zero this match is skipped. This can be used, for
9000 example, to skip a match in a comment or a string.
9001 {skip} can be a string, which is evaluated as an expression, a
9002 function reference or a lambda.
9003 When {skip} is omitted or empty, every match is accepted.
9004 When evaluating {skip} causes an error the search is aborted
9005 and -1 returned.
9006 *search()-sub-match*
9007 With the 'p' flag the returned value is one more than the
9008 first sub-match in \(\). One if none of them matched but the
9009 whole pattern did match.
9010 To get the column number too use |searchpos()|.
9011
9012 The cursor will be positioned at the match, unless the 'n'
9013 flag is used.
9014
9015 Example (goes over all files in the argument list): >
9016 :let n = 1
9017 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009018 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009019 : " start at the last char in the file and wrap for the
9020 : " first search to find match at start of file
9021 : normal G$
9022 : let flags = "w"
9023 : while search("foo", flags) > 0
9024 : s/foo/bar/g
9025 : let flags = "W"
9026 : endwhile
9027 : update " write the file if modified
9028 : let n = n + 1
9029 :endwhile
9030<
9031 Example for using some flags: >
9032 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
9033< This will search for the keywords "if", "else", and "endif"
9034 under or after the cursor. Because of the 'p' flag, it
9035 returns 1, 2, or 3 depending on which keyword is found, or 0
9036 if the search fails. With the cursor on the first word of the
9037 line:
9038 if (foo == 0) | let foo = foo + 1 | endif ~
9039 the function returns 1. Without the 'c' flag, the function
9040 finds the "endif" and returns 3. The same thing happens
9041 without the 'e' flag if the cursor is on the "f" of "if".
9042 The 'n' flag tells the function not to move the cursor.
9043
9044 Can also be used as a |method|: >
9045 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009046<
9047 Return type: |Number|
9048
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009049
9050searchcount([{options}]) *searchcount()*
9051 Get or update the last search count, like what is displayed
9052 without the "S" flag in 'shortmess'. This works even if
9053 'shortmess' does contain the "S" flag.
9054
9055 This returns a |Dictionary|. The dictionary is empty if the
9056 previous pattern was not set and "pattern" was not specified.
9057
9058 key type meaning ~
9059 current |Number| current position of match;
9060 0 if the cursor position is
9061 before the first match
9062 exact_match |Boolean| 1 if "current" is matched on
9063 "pos", otherwise 0
9064 total |Number| total count of matches found
9065 incomplete |Number| 0: search was fully completed
9066 1: recomputing was timed out
9067 2: max count exceeded
9068
9069 For {options} see further down.
9070
9071 To get the last search count when |n| or |N| was pressed, call
9072 this function with `recompute: 0` . This sometimes returns
9073 wrong information because |n| and |N|'s maximum count is 99.
9074 If it exceeded 99 the result must be max count + 1 (100). If
9075 you want to get correct information, specify `recompute: 1`: >
9076
9077 " result == maxcount + 1 (100) when many matches
9078 let result = searchcount(#{recompute: 0})
9079
9080 " Below returns correct result (recompute defaults
9081 " to 1)
9082 let result = searchcount()
9083<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01009084 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009085 function! LastSearchCount() abort
9086 let result = searchcount(#{recompute: 0})
9087 if empty(result)
9088 return ''
9089 endif
9090 if result.incomplete ==# 1 " timed out
9091 return printf(' /%s [?/??]', @/)
9092 elseif result.incomplete ==# 2 " max count exceeded
9093 if result.total > result.maxcount &&
9094 \ result.current > result.maxcount
9095 return printf(' /%s [>%d/>%d]', @/,
9096 \ result.current, result.total)
9097 elseif result.total > result.maxcount
9098 return printf(' /%s [%d/>%d]', @/,
9099 \ result.current, result.total)
9100 endif
9101 endif
9102 return printf(' /%s [%d/%d]', @/,
9103 \ result.current, result.total)
9104 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009105 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009106
9107 " Or if you want to show the count only when
9108 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009109 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009110 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9111<
9112 You can also update the search count, which can be useful in a
9113 |CursorMoved| or |CursorMovedI| autocommand: >
9114
9115 autocmd CursorMoved,CursorMovedI *
9116 \ let s:searchcount_timer = timer_start(
9117 \ 200, function('s:update_searchcount'))
9118 function! s:update_searchcount(timer) abort
9119 if a:timer ==# s:searchcount_timer
9120 call searchcount(#{
9121 \ recompute: 1, maxcount: 0, timeout: 100})
9122 redrawstatus
9123 endif
9124 endfunction
9125<
9126 This can also be used to count matched texts with specified
9127 pattern in the current buffer using "pattern": >
9128
9129 " Count '\<foo\>' in this buffer
9130 " (Note that it also updates search count)
9131 let result = searchcount(#{pattern: '\<foo\>'})
9132
9133 " To restore old search count by old pattern,
9134 " search again
9135 call searchcount()
9136<
9137 {options} must be a |Dictionary|. It can contain:
9138 key type meaning ~
9139 recompute |Boolean| if |TRUE|, recompute the count
9140 like |n| or |N| was executed.
9141 otherwise returns the last
9142 computed result (when |n| or
9143 |N| was used when "S" is not
9144 in 'shortmess', or this
9145 function was called).
9146 (default: |TRUE|)
9147 pattern |String| recompute if this was given
9148 and different with |@/|.
9149 this works as same as the
9150 below command is executed
9151 before calling this function >
9152 let @/ = pattern
9153< (default: |@/|)
9154 timeout |Number| 0 or negative number is no
9155 timeout. timeout milliseconds
9156 for recomputing the result
9157 (default: 0)
9158 maxcount |Number| 0 or negative number is no
9159 limit. max count of matched
9160 text while recomputing the
9161 result. if search exceeded
9162 total count, "total" value
9163 becomes `maxcount + 1`
9164 (default: 99)
9165 pos |List| `[lnum, col, off]` value
9166 when recomputing the result.
9167 this changes "current" result
9168 value. see |cursor()|,
9169 |getpos()|
9170 (default: cursor's position)
9171
9172 Can also be used as a |method|: >
9173 GetSearchOpts()->searchcount()
9174<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009175 Return type: dict<number>
9176
9177
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009178searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9179 Search for the declaration of {name}.
9180
9181 With a non-zero {global} argument it works like |gD|, find
9182 first match in the file. Otherwise it works like |gd|, find
9183 first match in the function.
9184
9185 With a non-zero {thisblock} argument matches in a {} block
9186 that ends before the cursor position are ignored. Avoids
9187 finding variable declarations only valid in another scope.
9188
9189 Moves the cursor to the found match.
9190 Returns zero for success, non-zero for failure.
9191 Example: >
9192 if searchdecl('myvar') == 0
9193 echo getline('.')
9194 endif
9195<
9196 Can also be used as a |method|: >
9197 GetName()->searchdecl()
9198<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009199 Return type: |Number|
9200
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009201 *searchpair()*
9202searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9203 [, {stopline} [, {timeout}]]]])
9204 Search for the match of a nested start-end pair. This can be
9205 used to find the "endif" that matches an "if", while other
9206 if/endif pairs in between are ignored.
9207 The search starts at the cursor. The default is to search
9208 forward, include 'b' in {flags} to search backward.
9209 If a match is found, the cursor is positioned at it and the
9210 line number is returned. If no match is found 0 or -1 is
9211 returned and the cursor doesn't move. No error message is
9212 given.
9213
9214 {start}, {middle} and {end} are patterns, see |pattern|. They
9215 must not contain \( \) pairs. Use of \%( \) is allowed. When
9216 {middle} is not empty, it is found when searching from either
9217 direction, but only when not in a nested start-end pair. A
9218 typical use is: >
9219 searchpair('\<if\>', '\<else\>', '\<endif\>')
9220< By leaving {middle} empty the "else" is skipped.
9221
9222 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9223 |search()|. Additionally:
9224 'r' Repeat until no more matches found; will find the
9225 outer pair. Implies the 'W' flag.
9226 'm' Return number of matches instead of line number with
9227 the match; will be > 1 when 'r' is used.
9228 Note: it's nearly always a good idea to use the 'W' flag, to
9229 avoid wrapping around the end of the file.
9230
9231 When a match for {start}, {middle} or {end} is found, the
9232 {skip} expression is evaluated with the cursor positioned on
9233 the start of the match. It should return non-zero if this
9234 match is to be skipped. E.g., because it is inside a comment
9235 or a string.
9236 When {skip} is omitted or empty, every match is accepted.
9237 When evaluating {skip} causes an error the search is aborted
9238 and -1 returned.
9239 {skip} can be a string, a lambda, a funcref or a partial.
9240 Anything else makes the function fail.
9241 In a `:def` function when the {skip} argument is a string
9242 constant it is compiled into instructions.
9243
9244 For {stopline} and {timeout} see |search()|.
9245
9246 The value of 'ignorecase' is used. 'magic' is ignored, the
9247 patterns are used like it's on.
9248
9249 The search starts exactly at the cursor. A match with
9250 {start}, {middle} or {end} at the next character, in the
9251 direction of searching, is the first one found. Example: >
9252 if 1
9253 if 2
9254 endif 2
9255 endif 1
9256< When starting at the "if 2", with the cursor on the "i", and
9257 searching forwards, the "endif 2" is found. When starting on
9258 the character just before the "if 2", the "endif 1" will be
9259 found. That's because the "if 2" will be found first, and
9260 then this is considered to be a nested if/endif from "if 2" to
9261 "endif 2".
9262 When searching backwards and {end} is more than one character,
9263 it may be useful to put "\zs" at the end of the pattern, so
9264 that when the cursor is inside a match with the end it finds
9265 the matching start.
9266
9267 Example, to find the "endif" command in a Vim script: >
9268
9269 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9270 \ 'getline(".") =~ "^\\s*\""')
9271
9272< The cursor must be at or after the "if" for which a match is
9273 to be found. Note that single-quote strings are used to avoid
9274 having to double the backslashes. The skip expression only
9275 catches comments at the start of a line, not after a command.
9276 Also, a word "en" or "if" halfway a line is considered a
9277 match.
9278 Another example, to search for the matching "{" of a "}": >
9279
9280 :echo searchpair('{', '', '}', 'bW')
9281
9282< This works when the cursor is at or before the "}" for which a
9283 match is to be found. To reject matches that syntax
9284 highlighting recognized as strings: >
9285
9286 :echo searchpair('{', '', '}', 'bW',
9287 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9288<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009289 Return type: |Number|
9290
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009291 *searchpairpos()*
9292searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9293 [, {stopline} [, {timeout}]]]])
9294 Same as |searchpair()|, but returns a |List| with the line and
9295 column position of the match. The first element of the |List|
9296 is the line number and the second element is the byte index of
9297 the column position of the match. If no match is found,
9298 returns [0, 0]. >
9299
9300 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9301<
9302 See |match-parens| for a bigger and more useful example.
9303
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009304 Return type: list<number>
9305
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009306 *searchpos()*
9307searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9308 Same as |search()|, but returns a |List| with the line and
9309 column position of the match. The first element of the |List|
9310 is the line number and the second element is the byte index of
9311 the column position of the match. If no match is found,
9312 returns [0, 0].
9313 Example: >
9314 :let [lnum, col] = searchpos('mypattern', 'n')
9315
9316< When the 'p' flag is given then there is an extra item with
9317 the sub-pattern match number |search()-sub-match|. Example: >
9318 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9319< In this example "submatch" is 2 when a lowercase letter is
9320 found |/\l|, 3 when an uppercase letter is found |/\u|.
9321
9322 Can also be used as a |method|: >
9323 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009324<
9325 Return type: list<number>
9326
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009327
9328server2client({clientid}, {string}) *server2client()*
9329 Send a reply string to {clientid}. The most recent {clientid}
9330 that sent a string can be retrieved with expand("<client>").
9331 {only available when compiled with the |+clientserver| feature}
9332 Returns zero for success, -1 for failure.
9333 Note:
9334 This id has to be stored before the next command can be
9335 received. I.e. before returning from the received command and
9336 before calling any commands that waits for input.
9337 See also |clientserver|.
9338 Example: >
9339 :echo server2client(expand("<client>"), "HELLO")
9340
9341< Can also be used as a |method|: >
9342 GetClientId()->server2client(string)
9343<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009344 Return type: |Number|
9345
9346
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009347serverlist() *serverlist()*
9348 Return a list of available server names, one per line.
9349 When there are no servers or the information is not available
9350 an empty string is returned. See also |clientserver|.
9351 {only available when compiled with the |+clientserver| feature}
9352 Example: >
9353 :echo serverlist()
9354<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009355 Return type: |String|
9356
9357
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009358setbufline({buf}, {lnum}, {text}) *setbufline()*
9359 Set line {lnum} to {text} in buffer {buf}. This works like
9360 |setline()| for the specified buffer.
9361
9362 This function works only for loaded buffers. First call
9363 |bufload()| if needed.
9364
9365 To insert lines use |appendbufline()|.
9366 Any text properties in {lnum} are cleared.
9367
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009368 {text} can be a string to set one line, or a List of strings
9369 to set multiple lines. If the List extends below the last
9370 line then those lines are added. If the List is empty then
9371 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009372
9373 For the use of {buf}, see |bufname()| above.
9374
9375 {lnum} is used like with |setline()|.
9376 Use "$" to refer to the last line in buffer {buf}.
9377 When {lnum} is just below the last line the {text} will be
9378 added below the last line.
9379
9380 When {buf} is not a valid buffer, the buffer is not loaded or
9381 {lnum} is not valid then 1 is returned. In |Vim9| script an
9382 error is given.
9383 On success 0 is returned.
9384
9385 Can also be used as a |method|, the base is passed as the
9386 third argument: >
9387 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009388<
9389 Return type: |Number|
9390
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009391
9392setbufvar({buf}, {varname}, {val}) *setbufvar()*
9393 Set option or local variable {varname} in buffer {buf} to
9394 {val}.
9395 This also works for a global or local window option, but it
9396 doesn't work for a global or local window variable.
9397 For a local window option the global value is unchanged.
9398 For the use of {buf}, see |bufname()| above.
9399 The {varname} argument is a string.
9400 Note that the variable name without "b:" must be used.
9401 Examples: >
9402 :call setbufvar(1, "&mod", 1)
9403 :call setbufvar("todo", "myvar", "foobar")
9404< This function is not available in the |sandbox|.
9405
9406 Can also be used as a |method|, the base is passed as the
9407 third argument: >
9408 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009409<
9410 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009411
9412
9413setcellwidths({list}) *setcellwidths()*
9414 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009415 tells Vim how wide characters are when displayed in the
9416 terminal, counted in screen cells. The values override
9417 'ambiwidth'. Example: >
9418 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009419 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009420 \ [0x2194, 0x2199, 2],
9421 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009422
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009423< The {list} argument is a List of Lists with each three
9424 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9425 {low} and {high} can be the same, in which case this refers to
9426 one character. Otherwise it is the range of characters from
9427 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009428 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009429
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009430 {width} must be either 1 or 2, indicating the character width
9431 in screen cells. *E1112*
9432 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009433 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009434
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009435 If the new value causes 'fillchars' or 'listchars' to become
9436 invalid it is rejected and an error is given.
9437
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009438 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009439 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009440
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009441< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009442 the effect for known emoji characters. Move the cursor
9443 through the text to check if the cell widths of your terminal
9444 match with what Vim knows about each emoji. If it doesn't
9445 look right you need to adjust the {list} argument.
9446
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009447 Return type: |Number|
9448
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009449
9450setcharpos({expr}, {list}) *setcharpos()*
9451 Same as |setpos()| but uses the specified column number as the
9452 character index instead of the byte index in the line.
9453
9454 Example:
9455 With the text "여보세요" in line 8: >
9456 call setcharpos('.', [0, 8, 4, 0])
9457< positions the cursor on the fourth character '요'. >
9458 call setpos('.', [0, 8, 4, 0])
9459< positions the cursor on the second character '보'.
9460
9461 Can also be used as a |method|: >
9462 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009463<
9464 Return type: |Number|
9465
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009466
9467setcharsearch({dict}) *setcharsearch()*
9468 Set the current character search information to {dict},
9469 which contains one or more of the following entries:
9470
9471 char character which will be used for a subsequent
9472 |,| or |;| command; an empty string clears the
9473 character search
9474 forward direction of character search; 1 for forward,
9475 0 for backward
9476 until type of character search; 1 for a |t| or |T|
9477 character search, 0 for an |f| or |F|
9478 character search
9479
9480 This can be useful to save/restore a user's character search
9481 from a script: >
9482 :let prevsearch = getcharsearch()
9483 :" Perform a command which clobbers user's search
9484 :call setcharsearch(prevsearch)
9485< Also see |getcharsearch()|.
9486
9487 Can also be used as a |method|: >
9488 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009489<
9490 Return type: dict<any>
9491
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009492
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009493setcmdline({str} [, {pos}]) *setcmdline()*
9494 Set the command line to {str} and set the cursor position to
9495 {pos}.
9496 If {pos} is omitted, the cursor is positioned after the text.
9497 Returns 0 when successful, 1 when not editing the command
9498 line.
9499
9500 Can also be used as a |method|: >
9501 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009502<
9503 Return type: |Number|
9504
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009505
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009506setcmdpos({pos}) *setcmdpos()*
9507 Set the cursor position in the command line to byte position
9508 {pos}. The first position is 1.
9509 Use |getcmdpos()| to obtain the current position.
9510 Only works while editing the command line, thus you must use
9511 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9512 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9513 set after the command line is set to the expression. For
9514 |c_CTRL-R_=| it is set after evaluating the expression but
9515 before inserting the resulting text.
9516 When the number is too big the cursor is put at the end of the
9517 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009518 Returns 0 when successful, 1 when not editing the command
9519 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009520
9521 Can also be used as a |method|: >
9522 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009523<
9524 Return type: |Number|
9525
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009526
9527setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9528setcursorcharpos({list})
9529 Same as |cursor()| but uses the specified column number as the
9530 character index instead of the byte index in the line.
9531
9532 Example:
9533 With the text "여보세요" in line 4: >
9534 call setcursorcharpos(4, 3)
9535< positions the cursor on the third character '세'. >
9536 call cursor(4, 3)
9537< positions the cursor on the first character '여'.
9538
9539 Can also be used as a |method|: >
9540 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009541<
9542 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009543
9544
9545setenv({name}, {val}) *setenv()*
9546 Set environment variable {name} to {val}. Example: >
9547 call setenv('HOME', '/home/myhome')
9548
9549< When {val} is |v:null| the environment variable is deleted.
9550 See also |expr-env|.
9551
9552 Can also be used as a |method|, the base is passed as the
9553 second argument: >
9554 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009555<
9556 Return type: |Number|
9557
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009558
9559setfperm({fname}, {mode}) *setfperm()* *chmod*
9560 Set the file permissions for {fname} to {mode}.
9561 {mode} must be a string with 9 characters. It is of the form
9562 "rwxrwxrwx", where each group of "rwx" flags represent, in
9563 turn, the permissions of the owner of the file, the group the
9564 file belongs to, and other users. A '-' character means the
9565 permission is off, any other character means on. Multi-byte
9566 characters are not supported.
9567
9568 For example "rw-r-----" means read-write for the user,
9569 readable by the group, not accessible by others. "xx-x-----"
9570 would do the same thing.
9571
9572 Returns non-zero for success, zero for failure.
9573
9574 Can also be used as a |method|: >
9575 GetFilename()->setfperm(mode)
9576<
9577 To read permissions see |getfperm()|.
9578
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009579 Return type: |Number|
9580
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009581
9582setline({lnum}, {text}) *setline()*
9583 Set line {lnum} of the current buffer to {text}. To insert
9584 lines use |append()|. To set lines in another buffer use
Christian Brabandt946f61c2024-06-17 13:17:58 +02009585 |setbufline()|.
h-east52e7cc22024-07-28 17:03:29 +02009586 Any text properties in {lnum} are cleared. See
9587 |text-prop-cleared|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009588
9589 {lnum} is used like with |getline()|.
9590 When {lnum} is just below the last line the {text} will be
9591 added below the last line.
9592 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009593 converted to a String. When {text} is an empty List then
9594 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009595
9596 If this succeeds, FALSE is returned. If this fails (most likely
9597 because {lnum} is invalid) TRUE is returned.
9598 In |Vim9| script an error is given if {lnum} is invalid.
9599
9600 Example: >
9601 :call setline(5, strftime("%c"))
9602
9603< When {text} is a |List| then line {lnum} and following lines
9604 will be set to the items in the list. Example: >
9605 :call setline(5, ['aaa', 'bbb', 'ccc'])
9606< This is equivalent to: >
9607 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9608 : call setline(n, l)
9609 :endfor
9610
9611< Note: The '[ and '] marks are not set.
9612
9613 Can also be used as a |method|, the base is passed as the
9614 second argument: >
9615 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009616<
9617 Return type: |Number|
9618
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009619
9620setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9621 Create or replace or add to the location list for window {nr}.
9622 {nr} can be the window number or the |window-ID|.
9623 When {nr} is zero the current window is used.
9624
9625 For a location list window, the displayed location list is
9626 modified. For an invalid window number {nr}, -1 is returned.
9627 Otherwise, same as |setqflist()|.
9628 Also see |location-list|.
9629
9630 For {action} see |setqflist-action|.
9631
9632 If the optional {what} dictionary argument is supplied, then
9633 only the items listed in {what} are set. Refer to |setqflist()|
9634 for the list of supported keys in {what}.
9635
9636 Can also be used as a |method|, the base is passed as the
9637 second argument: >
9638 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009639<
9640 Return type: |Number|
9641
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009642
9643setmatches({list} [, {win}]) *setmatches()*
9644 Restores a list of matches saved by |getmatches()| for the
9645 current window. Returns 0 if successful, otherwise -1. All
9646 current matches are cleared before the list is restored. See
9647 example for |getmatches()|.
9648 If {win} is specified, use the window with this number or
9649 window ID instead of the current window.
9650
9651 Can also be used as a |method|: >
9652 GetMatches()->setmatches()
9653<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009654 Return type: |Number|
9655
9656
9657setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009658 Set the position for String {expr}. Possible values:
9659 . the cursor
9660 'x mark x
9661
9662 {list} must be a |List| with four or five numbers:
9663 [bufnum, lnum, col, off]
9664 [bufnum, lnum, col, off, curswant]
9665
9666 "bufnum" is the buffer number. Zero can be used for the
9667 current buffer. When setting an uppercase mark "bufnum" is
9668 used for the mark position. For other marks it specifies the
9669 buffer to set the mark in. You can use the |bufnr()| function
9670 to turn a file name into a buffer number.
9671 For setting the cursor and the ' mark "bufnum" is ignored,
9672 since these are associated with a window, not a buffer.
9673 Does not change the jumplist.
9674
9675 "lnum" and "col" are the position in the buffer. The first
9676 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9677 smaller than 1 then 1 is used. To use the character count
9678 instead of the byte count, use |setcharpos()|.
9679
9680 The "off" number is only used when 'virtualedit' is set. Then
9681 it is the offset in screen columns from the start of the
9682 character. E.g., a position within a <Tab> or after the last
9683 character.
9684
9685 The "curswant" number is only used when setting the cursor
9686 position. It sets the preferred column for when moving the
9687 cursor vertically. When the "curswant" number is missing the
9688 preferred column is not set. When it is present and setting a
9689 mark position it is not used.
9690
9691 Note that for '< and '> changing the line number may result in
9692 the marks to be effectively be swapped, so that '< is always
9693 before '>.
9694
9695 Returns 0 when the position could be set, -1 otherwise.
9696 An error message is given if {expr} is invalid.
9697
9698 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9699
9700 This does not restore the preferred column for moving
9701 vertically; if you set the cursor position with this, |j| and
9702 |k| motions will jump to previous columns! Use |cursor()| to
9703 also set the preferred column. Also see the "curswant" key in
9704 |winrestview()|.
9705
9706 Can also be used as a |method|: >
9707 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009708<
9709 Return type: |Number|
9710
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009711
9712setqflist({list} [, {action} [, {what}]]) *setqflist()*
9713 Create or replace or add to the quickfix list.
9714
9715 If the optional {what} dictionary argument is supplied, then
9716 only the items listed in {what} are set. The first {list}
9717 argument is ignored. See below for the supported items in
9718 {what}.
9719 *setqflist-what*
9720 When {what} is not present, the items in {list} are used. Each
9721 item must be a dictionary. Non-dictionary items in {list} are
9722 ignored. Each dictionary item can contain the following
9723 entries:
9724
9725 bufnr buffer number; must be the number of a valid
9726 buffer
9727 filename name of a file; only used when "bufnr" is not
9728 present or it is invalid.
9729 module name of a module; if given it will be used in
9730 quickfix error window instead of the filename.
9731 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00009732 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009733 pattern search pattern used to locate the error
9734 col column number
9735 vcol when non-zero: "col" is visual column
9736 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00009737 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009738 nr error number
9739 text description of the error
9740 type single-character error type, 'E', 'W', etc.
9741 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +02009742 user_data custom data associated with the item, can be
9743 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009744
9745 The "col", "vcol", "nr", "type" and "text" entries are
9746 optional. Either "lnum" or "pattern" entry can be used to
9747 locate a matching error line.
9748 If the "filename" and "bufnr" entries are not present or
9749 neither the "lnum" or "pattern" entries are present, then the
9750 item will not be handled as an error line.
9751 If both "pattern" and "lnum" are present then "pattern" will
9752 be used.
9753 If the "valid" entry is not supplied, then the valid flag is
9754 set when "bufnr" is a valid buffer or "filename" exists.
9755 If you supply an empty {list}, the quickfix list will be
9756 cleared.
9757 Note that the list is not exactly the same as what
9758 |getqflist()| returns.
9759
9760 {action} values: *setqflist-action* *E927*
9761 'a' The items from {list} are added to the existing
9762 quickfix list. If there is no existing list, then a
9763 new list is created.
9764
9765 'r' The items from the current quickfix list are replaced
9766 with the items from {list}. This can also be used to
9767 clear the list: >
9768 :call setqflist([], 'r')
9769<
Jeremy Fleischman27fbf6e2024-10-14 20:46:27 +02009770 'u' Like 'r', but tries to preserve the current selection
9771 in the quickfix list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009772 'f' All the quickfix lists in the quickfix stack are
9773 freed.
9774
9775 If {action} is not present or is set to ' ', then a new list
9776 is created. The new quickfix list is added after the current
9777 quickfix list in the stack and all the following lists are
9778 freed. To add a new quickfix list at the end of the stack,
9779 set "nr" in {what} to "$".
9780
9781 The following items can be specified in dictionary {what}:
9782 context quickfix list context. See |quickfix-context|
9783 efm errorformat to use when parsing text from
9784 "lines". If this is not present, then the
9785 'errorformat' option value is used.
9786 See |quickfix-parse|
9787 id quickfix list identifier |quickfix-ID|
9788 idx index of the current entry in the quickfix
9789 list specified by 'id' or 'nr'. If set to '$',
9790 then the last entry in the list is set as the
9791 current entry. See |quickfix-index|
9792 items list of quickfix entries. Same as the {list}
9793 argument.
9794 lines use 'errorformat' to parse a list of lines and
9795 add the resulting entries to the quickfix list
9796 {nr} or {id}. Only a |List| value is supported.
9797 See |quickfix-parse|
9798 nr list number in the quickfix stack; zero
9799 means the current quickfix list and "$" means
9800 the last quickfix list.
9801 quickfixtextfunc
9802 function to get the text to display in the
9803 quickfix window. The value can be the name of
9804 a function or a funcref or a lambda. Refer to
9805 |quickfix-window-function| for an explanation
9806 of how to write the function and an example.
9807 title quickfix list title text. See |quickfix-title|
9808 Unsupported keys in {what} are ignored.
9809 If the "nr" item is not present, then the current quickfix list
9810 is modified. When creating a new quickfix list, "nr" can be
9811 set to a value one greater than the quickfix stack size.
9812 When modifying a quickfix list, to guarantee that the correct
9813 list is modified, "id" should be used instead of "nr" to
9814 specify the list.
9815
9816 Examples (See also |setqflist-examples|): >
9817 :call setqflist([], 'r', {'title': 'My search'})
9818 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
9819 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
9820<
9821 Returns zero for success, -1 for failure.
9822
9823 This function can be used to create a quickfix list
9824 independent of the 'errorformat' setting. Use a command like
9825 `:cc 1` to jump to the first position.
9826
9827 Can also be used as a |method|, the base is passed as the
9828 second argument: >
9829 GetErrorlist()->setqflist()
9830<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009831 Return type: |Number|
9832
9833
9834setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009835 Set the register {regname} to {value}.
9836 If {regname} is "" or "@", the unnamed register '"' is used.
9837 The {regname} argument is a string. In |Vim9-script|
9838 {regname} must be one character.
9839
9840 {value} may be any value returned by |getreg()| or
9841 |getreginfo()|, including a |List| or |Dict|.
9842 If {options} contains "a" or {regname} is upper case,
9843 then the value is appended.
9844
9845 {options} can also contain a register type specification:
9846 "c" or "v" |characterwise| mode
9847 "l" or "V" |linewise| mode
9848 "b" or "<CTRL-V>" |blockwise-visual| mode
9849 If a number immediately follows "b" or "<CTRL-V>" then this is
9850 used as the width of the selection - if it is not specified
9851 then the width of the block is set to the number of characters
9852 in the longest line (counting a <Tab> as 1 character).
9853
9854 If {options} contains no register settings, then the default
9855 is to use character mode unless {value} ends in a <NL> for
9856 string {value} and linewise mode for list {value}. Blockwise
9857 mode is never selected automatically.
9858 Returns zero for success, non-zero for failure.
9859
9860 *E883*
9861 Note: you may not use |List| containing more than one item to
9862 set search and expression registers. Lists containing no
9863 items act like empty strings.
9864
9865 Examples: >
9866 :call setreg(v:register, @*)
9867 :call setreg('*', @%, 'ac')
9868 :call setreg('a', "1\n2\n3", 'b5')
9869 :call setreg('"', { 'points_to': 'a'})
9870
9871< This example shows using the functions to save and restore a
9872 register: >
9873 :let var_a = getreginfo()
9874 :call setreg('a', var_a)
9875< or: >
9876 :let var_a = getreg('a', 1, 1)
9877 :let var_amode = getregtype('a')
9878 ....
9879 :call setreg('a', var_a, var_amode)
9880< Note: you may not reliably restore register value
9881 without using the third argument to |getreg()| as without it
9882 newlines are represented as newlines AND Nul bytes are
9883 represented as newlines as well, see |NL-used-for-Nul|.
9884
9885 You can also change the type of a register by appending
9886 nothing: >
9887 :call setreg('a', '', 'al')
9888
9889< Can also be used as a |method|, the base is passed as the
9890 second argument: >
9891 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009892<
9893 Return type: |Number|
9894
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009895
9896settabvar({tabnr}, {varname}, {val}) *settabvar()*
9897 Set tab-local variable {varname} to {val} in tab page {tabnr}.
9898 |t:var|
9899 The {varname} argument is a string.
9900 Note that autocommands are blocked, side effects may not be
9901 triggered, e.g. when setting 'filetype'.
9902 Note that the variable name without "t:" must be used.
9903 Tabs are numbered starting with one.
9904 This function is not available in the |sandbox|.
9905
9906 Can also be used as a |method|, the base is passed as the
9907 third argument: >
9908 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009909<
9910 Return type: |Number|
9911
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009912
9913settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
9914 Set option or local variable {varname} in window {winnr} to
9915 {val}.
9916 Tabs are numbered starting with one. For the current tabpage
9917 use |setwinvar()|.
9918 {winnr} can be the window number or the |window-ID|.
9919 When {winnr} is zero the current window is used.
9920 Note that autocommands are blocked, side effects may not be
9921 triggered, e.g. when setting 'filetype' or 'syntax'.
9922 This also works for a global or local buffer option, but it
9923 doesn't work for a global or local buffer variable.
9924 For a local buffer option the global value is unchanged.
9925 Note that the variable name without "w:" must be used.
9926 Examples: >
9927 :call settabwinvar(1, 1, "&list", 0)
9928 :call settabwinvar(3, 2, "myvar", "foobar")
9929< This function is not available in the |sandbox|.
9930
9931 Can also be used as a |method|, the base is passed as the
9932 fourth argument: >
9933 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009934<
9935 Return type: |Number|
9936
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009937
9938settagstack({nr}, {dict} [, {action}]) *settagstack()*
9939 Modify the tag stack of the window {nr} using {dict}.
9940 {nr} can be the window number or the |window-ID|.
9941
9942 For a list of supported items in {dict}, refer to
9943 |gettagstack()|. "curidx" takes effect before changing the tag
9944 stack.
9945 *E962*
9946 How the tag stack is modified depends on the {action}
9947 argument:
9948 - If {action} is not present or is set to 'r', then the tag
9949 stack is replaced.
9950 - If {action} is set to 'a', then new entries from {dict} are
9951 pushed (added) onto the tag stack.
9952 - If {action} is set to 't', then all the entries from the
9953 current entry in the tag stack or "curidx" in {dict} are
9954 removed and then new entries are pushed to the stack.
9955
9956 The current index is set to one after the length of the tag
9957 stack after the modification.
9958
9959 Returns zero for success, -1 for failure.
9960
9961 Examples (for more examples see |tagstack-examples|):
9962 Empty the tag stack of window 3: >
9963 call settagstack(3, {'items' : []})
9964
9965< Save and restore the tag stack: >
9966 let stack = gettagstack(1003)
9967 " do something else
9968 call settagstack(1003, stack)
9969 unlet stack
9970<
9971 Can also be used as a |method|, the base is passed as the
9972 second argument: >
9973 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009974<
9975 Return type: |Number|
9976
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009977
9978setwinvar({winnr}, {varname}, {val}) *setwinvar()*
9979 Like |settabwinvar()| for the current tab page.
9980 Examples: >
9981 :call setwinvar(1, "&list", 0)
9982 :call setwinvar(2, "myvar", "foobar")
9983
9984< Can also be used as a |method|, the base is passed as the
9985 third argument: >
9986 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009987<
9988 Return type: |Number|
9989
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009990
9991sha256({string}) *sha256()*
9992 Returns a String with 64 hex characters, which is the SHA256
9993 checksum of {string}.
9994
9995 Can also be used as a |method|: >
9996 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009997<
9998 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009999
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010000 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010001
10002shellescape({string} [, {special}]) *shellescape()*
10003 Escape {string} for use as a shell command argument.
10004 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +000010005 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010006 in single quotes and will double up all internal single
10007 quotes.
10008 On MS-Windows, when 'shellslash' is not set, it will enclose
10009 {string} in double quotes and double all double quotes within
10010 {string}.
10011 Otherwise it will enclose {string} in single quotes and
10012 replace all "'" with "'\''".
10013
Enno5faeb602024-05-15 21:54:19 +020010014 The {special} argument adds additional escaping of keywords
10015 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +090010016 number or a non-empty String (|non-zero-arg|), then special
10017 items such as "!", "%", "#" and "<cword>" (as listed in
10018 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +020010019 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010020
10021 The "!" character will be escaped (again with a |non-zero-arg|
10022 {special}) when 'shell' contains "csh" in the tail. That is
10023 because for csh and tcsh "!" is used for history replacement
10024 even when inside single quotes.
10025
10026 With a |non-zero-arg| {special} the <NL> character is also
10027 escaped. When 'shell' containing "csh" in the tail it's
10028 escaped a second time.
10029
10030 The "\" character will be escaped when 'shell' contains "fish"
10031 in the tail. That is because for fish "\" is used as an escape
10032 character inside single quotes.
10033
10034 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010035 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010036< This results in a directory listing for the file under the
10037 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010038 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010039< See also |::S|.
10040
10041 Can also be used as a |method|: >
10042 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010043<
10044 Return type: |String|
10045
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010046
10047shiftwidth([{col}]) *shiftwidth()*
10048 Returns the effective value of 'shiftwidth'. This is the
10049 'shiftwidth' value unless it is zero, in which case it is the
10050 'tabstop' value. This function was introduced with patch
10051 7.3.694 in 2012, everybody should have it by now (however it
10052 did not allow for the optional {col} argument until 8.1.542).
10053
10054 When there is one argument {col} this is used as column number
10055 for which to return the 'shiftwidth' value. This matters for the
10056 'vartabstop' feature. If the 'vartabstop' setting is enabled and
10057 no {col} argument is given, column 1 will be assumed.
10058
10059 Can also be used as a |method|: >
10060 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010061<
10062 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010063
10064sign_ functions are documented here: |sign-functions-details|
10065
10066
10067simplify({filename}) *simplify()*
10068 Simplify the file name as much as possible without changing
10069 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
10070 Unix) are not resolved. If the first path component in
10071 {filename} designates the current directory, this will be
10072 valid for the result as well. A trailing path separator is
10073 not removed either. On Unix "//path" is unchanged, but
10074 "///path" is simplified to "/path" (this follows the Posix
10075 standard).
10076 Example: >
10077 simplify("./dir/.././/file/") == "./file/"
10078< Note: The combination "dir/.." is only removed if "dir" is
10079 a searchable directory or does not exist. On Unix, it is also
10080 removed when "dir" is a symbolic link within the same
10081 directory. In order to resolve all the involved symbolic
10082 links before simplifying the path name, use |resolve()|.
10083
10084 Can also be used as a |method|: >
10085 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010086<
10087 Return type: |String|
10088
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010089
10090sin({expr}) *sin()*
10091 Return the sine of {expr}, measured in radians, as a |Float|.
10092 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010093 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010094 Examples: >
10095 :echo sin(100)
10096< -0.506366 >
10097 :echo sin(-4.01)
10098< 0.763301
10099
10100 Can also be used as a |method|: >
10101 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010102<
10103 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010104
10105
10106sinh({expr}) *sinh()*
10107 Return the hyperbolic sine of {expr} as a |Float| in the range
10108 [-inf, inf].
10109 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010110 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010111 Examples: >
10112 :echo sinh(0.5)
10113< 0.521095 >
10114 :echo sinh(-0.9)
10115< -1.026517
10116
10117 Can also be used as a |method|: >
10118 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010119<
10120 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010121
10122
10123slice({expr}, {start} [, {end}]) *slice()*
10124 Similar to using a |slice| "expr[start : end]", but "end" is
10125 used exclusive. And for a string the indexes are used as
10126 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010127 |vim9script|. Also, composing characters are treated as a
10128 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010129 When {end} is omitted the slice continues to the last item.
10130 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010131 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010132
10133 Can also be used as a |method|: >
10134 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010135<
10136 Return type: list<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010137
10138
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010139sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010140 Sort the items in {list} in-place. Returns {list}.
10141
10142 If you want a list to remain unmodified make a copy first: >
10143 :let sortedlist = sort(copy(mylist))
10144
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010145< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010146 string representation of each item to sort on. Numbers sort
10147 after Strings, |Lists| after Numbers. For sorting text in the
10148 current buffer use |:sort|.
10149
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010150 When {how} is given and it is 'i' then case is ignored.
10151 In legacy script, for backwards compatibility, the value one
10152 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010153
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010154 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010155 locale is used for ordering. Implementation details: strcoll()
10156 is used to compare strings. See |:language| check or set the
10157 collation locale. |v:collate| can also be used to check the
10158 current locale. Sorting using the locale typically ignores
10159 case. Example: >
10160 " ö is sorted similarly to o with English locale.
10161 :language collate en_US.UTF8
10162 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10163< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10164>
10165 " ö is sorted after z with Swedish locale.
10166 :language collate sv_SE.UTF8
10167 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10168< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10169 This does not work properly on Mac.
10170
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010171 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010172 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010173 strtod() function to parse numbers. Strings, Lists, Dicts and
10174 Funcrefs will be considered as being 0). Note that this won't
10175 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010176
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010177 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010178 sorted numerical. This is like 'n' but a string containing
10179 digits will be used as the number they represent.
10180
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010181 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010182 sorted numerical. All values must be a Number or a Float.
10183
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010184 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010185 is called to compare items. The function is invoked with two
10186 items as argument and must return zero if they are equal, 1 or
10187 bigger if the first one sorts after the second one, -1 or
10188 smaller if the first one sorts before the second one.
10189
10190 {dict} is for functions with the "dict" attribute. It will be
10191 used to set the local variable "self". |Dictionary-function|
10192
10193 The sort is stable, items which compare equal (as number or as
10194 string) will keep their relative position. E.g., when sorting
10195 on numbers, text strings will sort next to each other, in the
10196 same order as they were originally.
10197
10198 Can also be used as a |method|: >
10199 mylist->sort()
10200
10201< Also see |uniq()|.
10202
10203 Example: >
10204 func MyCompare(i1, i2)
10205 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10206 endfunc
10207 eval mylist->sort("MyCompare")
10208< A shorter compare version for this specific simple case, which
10209 ignores overflow: >
10210 func MyCompare(i1, i2)
10211 return a:i1 - a:i2
10212 endfunc
10213< For a simple expression you can use a lambda: >
10214 eval mylist->sort({i1, i2 -> i1 - i2})
10215<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010216 Return type: list<{type}>
10217
10218
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010219sound_clear() *sound_clear()*
10220 Stop playing all sounds.
10221
10222 On some Linux systems you may need the libcanberra-pulse
10223 package, otherwise sound may not stop.
10224
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010225 Return type: |Number|
10226
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010227 {only available when compiled with the |+sound| feature}
10228
10229 *sound_playevent()*
10230sound_playevent({name} [, {callback}])
10231 Play a sound identified by {name}. Which event names are
10232 supported depends on the system. Often the XDG sound names
10233 are used. On Ubuntu they may be found in
10234 /usr/share/sounds/freedesktop/stereo. Example: >
10235 call sound_playevent('bell')
10236< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10237 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10238 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010239 On macOS, {name} refers to files located in
10240 /System/Library/Sounds (e.g. "Tink"). It will also work for
10241 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010242
10243 When {callback} is specified it is invoked when the sound is
10244 finished. The first argument is the sound ID, the second
10245 argument is the status:
10246 0 sound was played to the end
10247 1 sound was interrupted
10248 2 error occurred after sound started
10249 Example: >
10250 func Callback(id, status)
10251 echomsg "sound " .. a:id .. " finished with " .. a:status
10252 endfunc
10253 call sound_playevent('bell', 'Callback')
10254
10255< MS-Windows: {callback} doesn't work for this function.
10256
10257 Returns the sound ID, which can be passed to `sound_stop()`.
10258 Returns zero if the sound could not be played.
10259
10260 Can also be used as a |method|: >
10261 GetSoundName()->sound_playevent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010262<
10263 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010264
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010265 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010266
10267 *sound_playfile()*
10268sound_playfile({path} [, {callback}])
10269 Like `sound_playevent()` but play sound file {path}. {path}
10270 must be a full path. On Ubuntu you may find files to play
10271 with this command: >
10272 :!find /usr/share/sounds -type f | grep -v index.theme
10273
10274< Can also be used as a |method|: >
10275 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010276<
10277 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010278
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010279 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010280
10281
10282sound_stop({id}) *sound_stop()*
10283 Stop playing sound {id}. {id} must be previously returned by
10284 `sound_playevent()` or `sound_playfile()`.
10285
10286 On some Linux systems you may need the libcanberra-pulse
10287 package, otherwise sound may not stop.
10288
10289 On MS-Windows, this does not work for event sound started by
10290 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10291
10292 Can also be used as a |method|: >
10293 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010294<
10295 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010296
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010297 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010298
10299 *soundfold()*
10300soundfold({word})
10301 Return the sound-folded equivalent of {word}. Uses the first
10302 language in 'spelllang' for the current window that supports
10303 soundfolding. 'spell' must be set. When no sound folding is
10304 possible the {word} is returned unmodified.
10305 This can be used for making spelling suggestions. Note that
10306 the method can be quite slow.
10307
10308 Can also be used as a |method|: >
10309 GetWord()->soundfold()
10310<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010311 Return type: |String|
10312
10313
10314spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010315 Without argument: The result is the badly spelled word under
10316 or after the cursor. The cursor is moved to the start of the
10317 bad word. When no bad word is found in the cursor line the
10318 result is an empty string and the cursor doesn't move.
10319
10320 With argument: The result is the first word in {sentence} that
10321 is badly spelled. If there are no spelling mistakes the
10322 result is an empty string.
10323
10324 The return value is a list with two items:
10325 - The badly spelled word or an empty string.
10326 - The type of the spelling error:
10327 "bad" spelling mistake
10328 "rare" rare word
10329 "local" word only valid in another region
10330 "caps" word should start with Capital
10331 Example: >
10332 echo spellbadword("the quik brown fox")
10333< ['quik', 'bad'] ~
10334
10335 The spelling information for the current window and the value
10336 of 'spelllang' are used.
10337
10338 Can also be used as a |method|: >
10339 GetText()->spellbadword()
10340<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010341 Return type: list<string>
10342
10343
10344spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010345 Return a |List| with spelling suggestions to replace {word}.
10346 When {max} is given up to this number of suggestions are
10347 returned. Otherwise up to 25 suggestions are returned.
10348
10349 When the {capital} argument is given and it's non-zero only
10350 suggestions with a leading capital will be given. Use this
10351 after a match with 'spellcapcheck'.
10352
10353 {word} can be a badly spelled word followed by other text.
10354 This allows for joining two words that were split. The
10355 suggestions also include the following text, thus you can
10356 replace a line.
10357
10358 {word} may also be a good word. Similar words will then be
10359 returned. {word} itself is not included in the suggestions,
10360 although it may appear capitalized.
10361
10362 The spelling information for the current window is used. The
10363 values of 'spelllang' and 'spellsuggest' are used.
10364
10365 Can also be used as a |method|: >
10366 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010367<
10368 Return type: list<string> or list<any>
10369
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010370
10371split({string} [, {pattern} [, {keepempty}]]) *split()*
10372 Make a |List| out of {string}. When {pattern} is omitted or
Shane Harperc1b39842024-07-17 19:40:40 +020010373 empty each white space separated sequence of characters
10374 becomes an item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010375 Otherwise the string is split where {pattern} matches,
10376 removing the matched characters. 'ignorecase' is not used
10377 here, add \c to ignore case. |/\c|
10378 When the first or last item is empty it is omitted, unless the
10379 {keepempty} argument is given and it's non-zero.
10380 Other empty items are kept when {pattern} matches at least one
10381 character or when {keepempty} is non-zero.
10382 Example: >
10383 :let words = split(getline('.'), '\W\+')
10384< To split a string in individual characters: >
10385 :for c in split(mystring, '\zs')
10386< If you want to keep the separator you can also use '\zs' at
10387 the end of the pattern: >
10388 :echo split('abc:def:ghi', ':\zs')
10389< ['abc:', 'def:', 'ghi'] ~
10390 Splitting a table where the first element can be empty: >
10391 :let items = split(line, ':', 1)
10392< The opposite function is |join()|.
10393
10394 Can also be used as a |method|: >
10395 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010396<
10397 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010398
10399sqrt({expr}) *sqrt()*
10400 Return the non-negative square root of Float {expr} as a
10401 |Float|.
10402 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010403 is negative the result is NaN (Not a Number). Returns 0.0 if
10404 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010405 Examples: >
10406 :echo sqrt(100)
10407< 10.0 >
10408 :echo sqrt(-4.01)
10409< nan
10410 "nan" may be different, it depends on system libraries.
10411
10412 Can also be used as a |method|: >
10413 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010414<
10415 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010416
10417
10418srand([{expr}]) *srand()*
10419 Initialize seed used by |rand()|:
10420 - If {expr} is not given, seed values are initialized by
10421 reading from /dev/urandom, if possible, or using time(NULL)
10422 a.k.a. epoch time otherwise; this only has second accuracy.
10423 - If {expr} is given it must be a Number. It is used to
10424 initialize the seed values. This is useful for testing or
10425 when a predictable sequence is intended.
10426
10427 Examples: >
10428 :let seed = srand()
10429 :let seed = srand(userinput)
10430 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010431<
10432 Return type: list<number>
10433
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010434
10435state([{what}]) *state()*
10436 Return a string which contains characters indicating the
10437 current state. Mostly useful in callbacks that want to do
10438 work that may not always be safe. Roughly this works like:
10439 - callback uses state() to check if work is safe to do.
10440 Yes: then do it right away.
10441 No: add to work queue and add a |SafeState| and/or
10442 |SafeStateAgain| autocommand (|SafeState| triggers at
10443 toplevel, |SafeStateAgain| triggers after handling
10444 messages and callbacks).
10445 - When SafeState or SafeStateAgain is triggered and executes
10446 your autocommand, check with `state()` if the work can be
10447 done now, and if yes remove it from the queue and execute.
10448 Remove the autocommand if the queue is now empty.
10449 Also see |mode()|.
10450
10451 When {what} is given only characters in this string will be
10452 added. E.g, this checks if the screen has scrolled: >
10453 if state('s') == ''
10454 " screen has not scrolled
10455<
10456 These characters indicate the state, generally indicating that
10457 something is busy:
10458 m halfway a mapping, :normal command, feedkeys() or
10459 stuffed command
10460 o operator pending, e.g. after |d|
10461 a Insert mode autocomplete active
10462 x executing an autocommand
10463 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10464 ch_readraw() when reading json
10465 S not triggering SafeState or SafeStateAgain, e.g. after
10466 |f| or a count
10467 c callback invoked, including timer (repeats for
10468 recursiveness up to "ccc")
10469 s screen has scrolled for messages
10470
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010471 Return type: |String|
10472
10473
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010474str2float({string} [, {quoted}]) *str2float()*
10475 Convert String {string} to a Float. This mostly works the
10476 same as when using a floating point number in an expression,
10477 see |floating-point-format|. But it's a bit more permissive.
10478 E.g., "1e40" is accepted, while in an expression you need to
10479 write "1.0e40". The hexadecimal form "0x123" is also
10480 accepted, but not others, like binary or octal.
10481 When {quoted} is present and non-zero then embedded single
10482 quotes before the dot are ignored, thus "1'000.0" is a
10483 thousand.
10484 Text after the number is silently ignored.
10485 The decimal point is always '.', no matter what the locale is
10486 set to. A comma ends the number: "12,345.67" is converted to
10487 12.0. You can strip out thousands separators with
10488 |substitute()|: >
10489 let f = str2float(substitute(text, ',', '', 'g'))
10490<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010491 Returns 0.0 if the conversion fails.
10492
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010493 Can also be used as a |method|: >
10494 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010495<
10496 Return type: |Float|
10497
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010498
10499str2list({string} [, {utf8}]) *str2list()*
10500 Return a list containing the number values which represent
10501 each character in String {string}. Examples: >
10502 str2list(" ") returns [32]
10503 str2list("ABC") returns [65, 66, 67]
10504< |list2str()| does the opposite.
10505
10506 When {utf8} is omitted or zero, the current 'encoding' is used.
10507 When {utf8} is TRUE, always treat the String as UTF-8
10508 characters. With UTF-8 composing characters are handled
10509 properly: >
10510 str2list("á") returns [97, 769]
10511
10512< Can also be used as a |method|: >
10513 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010514<
10515 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010516
10517
10518str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10519 Convert string {string} to a number.
10520 {base} is the conversion base, it can be 2, 8, 10 or 16.
10521 When {quoted} is present and non-zero then embedded single
10522 quotes are ignored, thus "1'000'000" is a million.
10523
10524 When {base} is omitted base 10 is used. This also means that
10525 a leading zero doesn't cause octal conversion to be used, as
10526 with the default String to Number conversion. Example: >
10527 let nr = str2nr('0123')
10528<
10529 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10530 different base the result will be zero. Similarly, when
10531 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10532 {base} is 2 a leading "0b" or "0B" is ignored.
10533 Text after the number is silently ignored.
10534
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010535 Returns 0 if {string} is empty or on error.
10536
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010537 Can also be used as a |method|: >
10538 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010539<
10540 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010541
10542
10543strcharlen({string}) *strcharlen()*
10544 The result is a Number, which is the number of characters
10545 in String {string}. Composing characters are ignored.
10546 |strchars()| can count the number of characters, counting
10547 composing characters separately.
10548
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010549 Returns 0 if {string} is empty or on error.
10550
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010551 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10552
10553 Can also be used as a |method|: >
10554 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010555<
10556 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010557
10558
10559strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10560 Like |strpart()| but using character index and length instead
10561 of byte index and length.
10562 When {skipcc} is omitted or zero, composing characters are
10563 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010564 When {skipcc} set to 1, composing characters are treated as a
10565 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010566 When a character index is used where a character does not
10567 exist it is omitted and counted as one character. For
10568 example: >
10569 strcharpart('abc', -1, 2)
10570< results in 'a'.
10571
Bram Moolenaard592deb2022-06-17 15:42:40 +010010572 Returns an empty string on error.
10573
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010574 Can also be used as a |method|: >
10575 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010576<
10577 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010578
10579
10580strchars({string} [, {skipcc}]) *strchars()*
10581 The result is a Number, which is the number of characters
10582 in String {string}.
10583 When {skipcc} is omitted or zero, composing characters are
10584 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010585 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010586 |strcharlen()| always does this.
10587
Bram Moolenaard592deb2022-06-17 15:42:40 +010010588 Returns zero on error.
10589
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010590 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10591
10592 {skipcc} is only available after 7.4.755. For backward
10593 compatibility, you can define a wrapper function: >
10594 if has("patch-7.4.755")
10595 function s:strchars(str, skipcc)
10596 return strchars(a:str, a:skipcc)
10597 endfunction
10598 else
10599 function s:strchars(str, skipcc)
10600 if a:skipcc
10601 return strlen(substitute(a:str, ".", "x", "g"))
10602 else
10603 return strchars(a:str)
10604 endif
10605 endfunction
10606 endif
10607<
10608 Can also be used as a |method|: >
10609 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010610<
10611 Return type: |Number|
10612
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010613
10614strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10615 The result is a Number, which is the number of display cells
10616 String {string} occupies on the screen when it starts at {col}
10617 (first column is zero). When {col} is omitted zero is used.
10618 Otherwise it is the screen column where to start. This
10619 matters for Tab characters.
10620 The option settings of the current window are used. This
10621 matters for anything that's displayed differently, such as
10622 'tabstop' and 'display'.
10623 When {string} contains characters with East Asian Width Class
10624 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010625 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010626 Also see |strlen()|, |strwidth()| and |strchars()|.
10627
10628 Can also be used as a |method|: >
10629 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010630<
10631 Return type: |Number|
10632
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010633
10634strftime({format} [, {time}]) *strftime()*
10635 The result is a String, which is a formatted date and time, as
10636 specified by the {format} string. The given {time} is used,
10637 or the current time if no time is given. The accepted
10638 {format} depends on your system, thus this is not portable!
10639 See the manual page of the C function strftime() for the
10640 format. The maximum length of the result is 80 characters.
10641 See also |localtime()|, |getftime()| and |strptime()|.
10642 The language can be changed with the |:language| command.
10643 Examples: >
10644 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10645 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10646 :echo strftime("%y%m%d %T") 970427 11:53:55
10647 :echo strftime("%H:%M") 11:55
10648 :echo strftime("%c", getftime("file.c"))
10649 Show mod time of file.c.
10650< Not available on all systems. To check use: >
10651 :if exists("*strftime")
10652
10653< Can also be used as a |method|: >
10654 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010655<
10656 Return type: |String|
10657
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010658
10659strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010660 Get a Number corresponding to the character at {index} in
10661 {str}. This uses a zero-based character index, not a byte
10662 index. Composing characters are considered separate
10663 characters here. Use |nr2char()| to convert the Number to a
10664 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010665 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010666 Also see |strcharpart()| and |strchars()|.
10667
10668 Can also be used as a |method|: >
10669 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010670<
10671 Return type: |Number|
10672
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010673
10674stridx({haystack}, {needle} [, {start}]) *stridx()*
10675 The result is a Number, which gives the byte index in
10676 {haystack} of the first occurrence of the String {needle}.
10677 If {start} is specified, the search starts at index {start}.
10678 This can be used to find a second match: >
10679 :let colon1 = stridx(line, ":")
10680 :let colon2 = stridx(line, ":", colon1 + 1)
10681< The search is done case-sensitive.
10682 For pattern searches use |match()|.
10683 -1 is returned if the {needle} does not occur in {haystack}.
10684 See also |strridx()|.
10685 Examples: >
10686 :echo stridx("An Example", "Example") 3
10687 :echo stridx("Starting point", "Start") 0
10688 :echo stridx("Starting point", "start") -1
10689< *strstr()* *strchr()*
10690 stridx() works similar to the C function strstr(). When used
10691 with a single character it works similar to strchr().
10692
10693 Can also be used as a |method|: >
10694 GetHaystack()->stridx(needle)
10695<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010696 Return type: |Number|
10697
10698
10699string({expr}) *string()*
10700 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010701 Float, String, Blob or a composition of them, then the result
10702 can be parsed back with |eval()|.
10703 {expr} type result ~
10704 String 'string' (single quotes are doubled)
10705 Number 123
10706 Float 123.123456 or 1.123456e8
10707 Funcref function('name')
10708 Blob 0z00112233.44556677.8899
10709 List [item, item]
10710 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000010711 Class class SomeName
10712 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010010713 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020010714 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010715
10716 When a |List| or |Dictionary| has a recursive reference it is
10717 replaced by "[...]" or "{...}". Using eval() on the result
10718 will then fail.
10719
mityu7f0bba22024-03-29 10:14:41 +010010720 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010721 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010010722 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010723
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010724 Can also be used as a |method|: >
10725 mylist->string()
10726
10727< Also see |strtrans()|.
10728
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010729 Return type: |String|
10730
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010731
10732strlen({string}) *strlen()*
10733 The result is a Number, which is the length of the String
10734 {string} in bytes.
10735 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010736 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010737 If you want to count the number of multibyte characters use
10738 |strchars()|.
10739 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
10740
10741 Can also be used as a |method|: >
10742 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010743<
10744 Return type: |Number|
10745
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010746
10747strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
10748 The result is a String, which is part of {src}, starting from
10749 byte {start}, with the byte length {len}.
10750 When {chars} is present and TRUE then {len} is the number of
10751 characters positions (composing characters are not counted
10752 separately, thus "1" means one base character and any
10753 following composing characters).
10754 To count {start} as characters instead of bytes use
10755 |strcharpart()|.
10756
10757 When bytes are selected which do not exist, this doesn't
10758 result in an error, the bytes are simply omitted.
10759 If {len} is missing, the copy continues from {start} till the
10760 end of the {src}. >
10761 strpart("abcdefg", 3, 2) == "de"
10762 strpart("abcdefg", -2, 4) == "ab"
10763 strpart("abcdefg", 5, 4) == "fg"
10764 strpart("abcdefg", 3) == "defg"
10765
10766< Note: To get the first character, {start} must be 0. For
10767 example, to get the character under the cursor: >
10768 strpart(getline("."), col(".") - 1, 1, v:true)
10769<
Bram Moolenaard592deb2022-06-17 15:42:40 +010010770 Returns an empty string on error.
10771
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010772 Can also be used as a |method|: >
10773 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010774<
10775 Return type: |String|
10776
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010777
10778strptime({format}, {timestring}) *strptime()*
10779 The result is a Number, which is a unix timestamp representing
10780 the date and time in {timestring}, which is expected to match
10781 the format specified in {format}.
10782
10783 The accepted {format} depends on your system, thus this is not
10784 portable! See the manual page of the C function strptime()
10785 for the format. Especially avoid "%c". The value of $TZ also
10786 matters.
10787
10788 If the {timestring} cannot be parsed with {format} zero is
10789 returned. If you do not know the format of {timestring} you
10790 can try different {format} values until you get a non-zero
10791 result.
10792
10793 See also |strftime()|.
10794 Examples: >
10795 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
10796< 862156163 >
10797 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
10798< Sun Apr 27 11:53:55 1997 >
10799 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
10800< Sun Apr 27 12:53:55 1997
10801
10802 Can also be used as a |method|: >
10803 GetFormat()->strptime(timestring)
10804<
10805 Not available on all systems. To check use: >
10806 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010807<
10808 Return type: |Number|
10809
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010810
10811strridx({haystack}, {needle} [, {start}]) *strridx()*
10812 The result is a Number, which gives the byte index in
10813 {haystack} of the last occurrence of the String {needle}.
10814 When {start} is specified, matches beyond this index are
10815 ignored. This can be used to find a match before a previous
10816 match: >
10817 :let lastcomma = strridx(line, ",")
10818 :let comma2 = strridx(line, ",", lastcomma - 1)
10819< The search is done case-sensitive.
10820 For pattern searches use |match()|.
10821 -1 is returned if the {needle} does not occur in {haystack}.
10822 If the {needle} is empty the length of {haystack} is returned.
10823 See also |stridx()|. Examples: >
10824 :echo strridx("an angry armadillo", "an") 3
10825< *strrchr()*
10826 When used with a single character it works similar to the C
10827 function strrchr().
10828
10829 Can also be used as a |method|: >
10830 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010831<
10832 Return type: |Number|
10833
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010834
10835strtrans({string}) *strtrans()*
10836 The result is a String, which is {string} with all unprintable
10837 characters translated into printable characters |'isprint'|.
10838 Like they are shown in a window. Example: >
10839 echo strtrans(@a)
10840< This displays a newline in register a as "^@" instead of
10841 starting a new line.
10842
Bram Moolenaard592deb2022-06-17 15:42:40 +010010843 Returns an empty string on error.
10844
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010845 Can also be used as a |method|: >
10846 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010847<
10848 Return type: |String|
10849
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010850
Christian Brabandt67672ef2023-04-24 21:09:54 +010010851strutf16len({string} [, {countcc}]) *strutf16len()*
10852 The result is a Number, which is the number of UTF-16 code
10853 units in String {string} (after converting it to UTF-16).
10854
10855 When {countcc} is TRUE, composing characters are counted
10856 separately.
10857 When {countcc} is omitted or FALSE, composing characters are
10858 ignored.
10859
10860 Returns zero on error.
10861
10862 Also see |strlen()| and |strcharlen()|.
10863 Examples: >
10864 echo strutf16len('a') returns 1
10865 echo strutf16len('©') returns 1
10866 echo strutf16len('😊') returns 2
10867 echo strutf16len('ą́') returns 1
10868 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090010869<
Christian Brabandt67672ef2023-04-24 21:09:54 +010010870 Can also be used as a |method|: >
10871 GetText()->strutf16len()
10872<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010873 Return type: |Number|
10874
10875
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010876strwidth({string}) *strwidth()*
10877 The result is a Number, which is the number of display cells
10878 String {string} occupies. A Tab character is counted as one
10879 cell, alternatively use |strdisplaywidth()|.
10880 When {string} contains characters with East Asian Width Class
10881 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010882 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010883 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
10884
10885 Can also be used as a |method|: >
10886 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010887<
10888 Return type: |Number|
10889
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010890
10891submatch({nr} [, {list}]) *submatch()* *E935*
10892 Only for an expression in a |:substitute| command or
10893 substitute() function.
10894 Returns the {nr}'th submatch of the matched text. When {nr}
10895 is 0 the whole matched text is returned.
10896 Note that a NL in the string can stand for a line break of a
10897 multi-line match or a NUL character in the text.
10898 Also see |sub-replace-expression|.
10899
10900 If {list} is present and non-zero then submatch() returns
10901 a list of strings, similar to |getline()| with two arguments.
10902 NL characters in the text represent NUL characters in the
10903 text.
10904 Only returns more than one item for |:substitute|, inside
10905 |substitute()| this list will always contain one or zero
10906 items, since there are no real line breaks.
10907
10908 When substitute() is used recursively only the submatches in
10909 the current (deepest) call can be obtained.
10910
Bram Moolenaard592deb2022-06-17 15:42:40 +010010911 Returns an empty string or list on error.
10912
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010913 Examples: >
10914 :s/\d\+/\=submatch(0) + 1/
10915 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
10916< This finds the first number in the line and adds one to it.
10917 A line break is included as a newline character.
10918
10919 Can also be used as a |method|: >
10920 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010921<
10922 Return type: |String| or list<string> depending on {list}
10923
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010924
10925substitute({string}, {pat}, {sub}, {flags}) *substitute()*
10926 The result is a String, which is a copy of {string}, in which
10927 the first match of {pat} is replaced with {sub}.
10928 When {flags} is "g", all matches of {pat} in {string} are
10929 replaced. Otherwise {flags} should be "".
10930
10931 This works like the ":substitute" command (without any flags).
10932 But the matching with {pat} is always done like the 'magic'
10933 option is set and 'cpoptions' is empty (to make scripts
10934 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
10935 if you want to ignore or match case and ignore 'ignorecase'.
10936 'smartcase' is not used. See |string-match| for how {pat} is
10937 used.
10938
10939 A "~" in {sub} is not replaced with the previous {sub}.
10940 Note that some codes in {sub} have a special meaning
10941 |sub-replace-special|. For example, to replace something with
10942 "\n" (two characters), use "\\\\n" or '\\n'.
10943
10944 When {pat} does not match in {string}, {string} is returned
10945 unmodified.
10946
10947 Example: >
10948 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
10949< This removes the last component of the 'path' option. >
10950 :echo substitute("testing", ".*", "\\U\\0", "")
10951< results in "TESTING".
10952
10953 When {sub} starts with "\=", the remainder is interpreted as
10954 an expression. See |sub-replace-expression|. Example: >
10955 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010956 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010957
10958< When {sub} is a Funcref that function is called, with one
10959 optional argument. Example: >
10960 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
10961< The optional argument is a list which contains the whole
10962 matched string and up to nine submatches, like what
10963 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010964 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010965
Bram Moolenaard592deb2022-06-17 15:42:40 +010010966< Returns an empty string on error.
10967
10968 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010969 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010970<
10971 Return type: |String|
10972
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010973
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000010974swapfilelist() *swapfilelist()*
10975 Returns a list of swap file names, like what "vim -r" shows.
10976 See the |-r| command argument. The 'directory' option is used
10977 for the directories to inspect. If you only want to get a
10978 list of swap files in the current directory then temporarily
10979 set 'directory' to a dot: >
10980 let save_dir = &directory
10981 let &directory = '.'
10982 let swapfiles = swapfilelist()
10983 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010984<
10985 Return type: list<string>
10986
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000010987
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010988swapinfo({fname}) *swapinfo()*
10989 The result is a dictionary, which holds information about the
10990 swapfile {fname}. The available fields are:
10991 version Vim version
10992 user user name
10993 host host name
10994 fname original file name
10995 pid PID of the Vim process that created the swap
10996 file
10997 mtime last modification time in seconds
10998 inode Optional: INODE number of the file
10999 dirty 1 if file was modified, 0 if not
11000 Note that "user" and "host" are truncated to at most 39 bytes.
11001 In case of failure an "error" item is added with the reason:
11002 Cannot open file: file not found or in accessible
11003 Cannot read file: cannot read first block
11004 Not a swap file: does not contain correct block ID
11005 Magic number mismatch: Info in first block is invalid
11006
11007 Can also be used as a |method|: >
11008 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011009<
11010 Return type: dict<any> or dict<string>
11011
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011012
11013swapname({buf}) *swapname()*
11014 The result is the swap file path of the buffer {expr}.
11015 For the use of {buf}, see |bufname()| above.
11016 If buffer {buf} is the current buffer, the result is equal to
11017 |:swapname| (unless there is no swap file).
11018 If buffer {buf} has no swap file, returns an empty string.
11019
11020 Can also be used as a |method|: >
11021 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011022<
11023 Return type: |String|
11024
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011025
11026synID({lnum}, {col}, {trans}) *synID()*
11027 The result is a Number, which is the syntax ID at the position
11028 {lnum} and {col} in the current window.
11029 The syntax ID can be used with |synIDattr()| and
11030 |synIDtrans()| to obtain syntax information about text.
11031
11032 {col} is 1 for the leftmost column, {lnum} is 1 for the first
11033 line. 'synmaxcol' applies, in a longer line zero is returned.
11034 Note that when the position is after the last character,
11035 that's where the cursor can be in Insert mode, synID() returns
11036 zero. {lnum} is used like with |getline()|.
11037
11038 When {trans} is |TRUE|, transparent items are reduced to the
11039 item that they reveal. This is useful when wanting to know
11040 the effective color. When {trans} is |FALSE|, the transparent
11041 item is returned. This is useful when wanting to know which
11042 syntax item is effective (e.g. inside parens).
11043 Warning: This function can be very slow. Best speed is
11044 obtained by going through the file in forward direction.
11045
Bram Moolenaard592deb2022-06-17 15:42:40 +010011046 Returns zero on error.
11047
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011048 Example (echoes the name of the syntax item under the cursor): >
11049 :echo synIDattr(synID(line("."), col("."), 1), "name")
11050<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011051 Return type: |Number|
11052
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011053
11054synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
11055 The result is a String, which is the {what} attribute of
11056 syntax ID {synID}. This can be used to obtain information
11057 about a syntax item.
11058 {mode} can be "gui", "cterm" or "term", to get the attributes
11059 for that mode. When {mode} is omitted, or an invalid value is
11060 used, the attributes for the currently active highlighting are
11061 used (GUI, cterm or term).
11062 Use synIDtrans() to follow linked highlight groups.
11063 {what} result
11064 "name" the name of the syntax item
11065 "fg" foreground color (GUI: color name used to set
11066 the color, cterm: color number as a string,
11067 term: empty string)
11068 "bg" background color (as with "fg")
11069 "font" font name (only available in the GUI)
11070 |highlight-font|
11071 "sp" special color for the GUI (as with "fg")
11072 |highlight-guisp|
11073 "ul" underline color for cterm: number as a string
11074 "fg#" like "fg", but for the GUI and the GUI is
11075 running the name in "#RRGGBB" form
11076 "bg#" like "fg#" for "bg"
11077 "sp#" like "fg#" for "sp"
11078 "bold" "1" if bold
11079 "italic" "1" if italic
11080 "reverse" "1" if reverse
11081 "inverse" "1" if inverse (= reverse)
11082 "standout" "1" if standout
11083 "underline" "1" if underlined
11084 "undercurl" "1" if undercurled
11085 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010011086 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011087
Bram Moolenaard592deb2022-06-17 15:42:40 +010011088 Returns an empty string on error.
11089
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011090 Example (echoes the color of the syntax item under the
11091 cursor): >
11092 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
11093<
11094 Can also be used as a |method|: >
11095 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011096<
11097 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011098
11099
11100synIDtrans({synID}) *synIDtrans()*
11101 The result is a Number, which is the translated syntax ID of
11102 {synID}. This is the syntax group ID of what is being used to
11103 highlight the character. Highlight links given with
11104 ":highlight link" are followed.
11105
Bram Moolenaard592deb2022-06-17 15:42:40 +010011106 Returns zero on error.
11107
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011108 Can also be used as a |method|: >
11109 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011110<
11111 Return type: |Number|
11112
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011113
11114synconcealed({lnum}, {col}) *synconcealed()*
11115 The result is a |List| with currently three items:
11116 1. The first item in the list is 0 if the character at the
11117 position {lnum} and {col} is not part of a concealable
11118 region, 1 if it is. {lnum} is used like with |getline()|.
11119 2. The second item in the list is a string. If the first item
11120 is 1, the second item contains the text which will be
11121 displayed in place of the concealed text, depending on the
11122 current setting of 'conceallevel' and 'listchars'.
11123 3. The third and final item in the list is a number
11124 representing the specific syntax region matched in the
11125 line. When the character is not concealed the value is
11126 zero. This allows detection of the beginning of a new
11127 concealable region if there are two consecutive regions
11128 with the same replacement character. For an example, if
11129 the text is "123456" and both "23" and "45" are concealed
11130 and replaced by the character "X", then:
11131 call returns ~
11132 synconcealed(lnum, 1) [0, '', 0]
11133 synconcealed(lnum, 2) [1, 'X', 1]
11134 synconcealed(lnum, 3) [1, 'X', 1]
11135 synconcealed(lnum, 4) [1, 'X', 2]
11136 synconcealed(lnum, 5) [1, 'X', 2]
11137 synconcealed(lnum, 6) [0, '', 0]
11138
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011139 Note: Doesn't consider |matchadd()| highlighting items,
11140 since syntax and matching highlighting are two different
11141 mechanisms |syntax-vs-match|.
h-east52e7cc22024-07-28 17:03:29 +020011142
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011143 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011144
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011145
11146synstack({lnum}, {col}) *synstack()*
11147 Return a |List|, which is the stack of syntax items at the
11148 position {lnum} and {col} in the current window. {lnum} is
11149 used like with |getline()|. Each item in the List is an ID
11150 like what |synID()| returns.
11151 The first item in the List is the outer region, following are
11152 items contained in that one. The last one is what |synID()|
11153 returns, unless not the whole item is highlighted or it is a
11154 transparent item.
11155 This function is useful for debugging a syntax file.
11156 Example that shows the syntax stack under the cursor: >
11157 for id in synstack(line("."), col("."))
11158 echo synIDattr(id, "name")
11159 endfor
11160< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011161 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011162 character in a line and the first column in an empty line are
11163 valid positions.
11164
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011165 Return type: list<number> or list<any>
11166
11167
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011168system({expr} [, {input}]) *system()* *E677*
11169 Get the output of the shell command {expr} as a |String|. See
11170 |systemlist()| to get the output as a |List|.
11171
11172 When {input} is given and is a |String| this string is written
11173 to a file and passed as stdin to the command. The string is
11174 written as-is, you need to take care of using the correct line
11175 separators yourself.
11176 If {input} is given and is a |List| it is written to the file
11177 in a way |writefile()| does with {binary} set to "b" (i.e.
11178 with a newline between each list item with newlines inside
11179 list items converted to NULs).
11180 When {input} is given and is a number that is a valid id for
11181 an existing buffer then the content of the buffer is written
11182 to the file line by line, each line terminated by a NL and
11183 NULs characters where the text has a NL.
11184
11185 Pipes are not used, the 'shelltemp' option is not used.
11186
11187 When prepended by |:silent| the terminal will not be set to
11188 cooked mode. This is meant to be used for commands that do
11189 not need the user to type. It avoids stray characters showing
11190 up on the screen which require |CTRL-L| to remove. >
11191 :silent let f = system('ls *.vim')
11192<
11193 Note: Use |shellescape()| or |::S| with |expand()| or
11194 |fnamemodify()| to escape special characters in a command
11195 argument. Newlines in {expr} may cause the command to fail.
11196 The characters in 'shellquote' and 'shellxquote' may also
11197 cause trouble.
11198 This is not to be used for interactive commands.
11199
11200 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011201 :let files = system('ls ' .. shellescape(expand('%:h')))
11202 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011203
11204< To make the result more system-independent, the shell output
11205 is filtered to replace <CR> with <NL> for Macintosh, and
11206 <CR><NL> with <NL> for DOS-like systems.
11207 To avoid the string being truncated at a NUL, all NUL
11208 characters are replaced with SOH (0x01).
11209
11210 The command executed is constructed using several options:
11211 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11212 ({tmp} is an automatically generated file name).
11213 For Unix, braces are put around {expr} to allow for
11214 concatenated commands.
11215
11216 The command will be executed in "cooked" mode, so that a
11217 CTRL-C will interrupt the command (on Unix at least).
11218
11219 The resulting error code can be found in |v:shell_error|.
11220 This function will fail in |restricted-mode|.
11221
11222 Note that any wrong value in the options mentioned above may
11223 make the function fail. It has also been reported to fail
11224 when using a security agent application.
11225 Unlike ":!cmd" there is no automatic check for changed files.
11226 Use |:checktime| to force a check.
11227
11228 Can also be used as a |method|: >
11229 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011230<
11231 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011232
11233
11234systemlist({expr} [, {input}]) *systemlist()*
11235 Same as |system()|, but returns a |List| with lines (parts of
11236 output separated by NL) with NULs transformed into NLs. Output
11237 is the same as |readfile()| will output with {binary} argument
11238 set to "b", except that there is no extra empty item when the
11239 result ends in a NL.
11240 Note that on MS-Windows you may get trailing CR characters.
11241
11242 To see the difference between "echo hello" and "echo -n hello"
11243 use |system()| and |split()|: >
11244 echo system('echo hello')->split('\n', 1)
11245<
11246 Returns an empty string on error.
11247
11248 Can also be used as a |method|: >
11249 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011250<
11251 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011252
11253
11254tabpagebuflist([{arg}]) *tabpagebuflist()*
11255 The result is a |List|, where each item is the number of the
11256 buffer associated with each window in the current tab page.
11257 {arg} specifies the number of the tab page to be used. When
11258 omitted the current tab page is used.
11259 When {arg} is invalid the number zero is returned.
11260 To get a list of all buffers in all tabs use this: >
11261 let buflist = []
11262 for i in range(tabpagenr('$'))
11263 call extend(buflist, tabpagebuflist(i + 1))
11264 endfor
11265< Note that a buffer may appear in more than one window.
11266
11267 Can also be used as a |method|: >
11268 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011269<
11270 Return type: list<number>
11271
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011272
11273tabpagenr([{arg}]) *tabpagenr()*
11274 The result is a Number, which is the number of the current
11275 tab page. The first tab page has number 1.
11276
11277 The optional argument {arg} supports the following values:
11278 $ the number of the last tab page (the tab page
11279 count).
11280 # the number of the last accessed tab page
11281 (where |g<Tab>| goes to). if there is no
11282 previous tab page 0 is returned.
11283 The number can be used with the |:tab| command.
11284
Bram Moolenaard592deb2022-06-17 15:42:40 +010011285 Returns zero on error.
11286
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011287 Return type: |Number|
11288
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011289
11290tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11291 Like |winnr()| but for tab page {tabarg}.
11292 {tabarg} specifies the number of tab page to be used.
11293 {arg} is used like with |winnr()|:
11294 - When omitted the current window number is returned. This is
11295 the window which will be used when going to this tab page.
11296 - When "$" the number of windows is returned.
11297 - When "#" the previous window nr is returned.
11298 Useful examples: >
11299 tabpagewinnr(1) " current window of tab page 1
11300 tabpagewinnr(4, '$') " number of windows in tab page 4
11301< When {tabarg} is invalid zero is returned.
11302
11303 Can also be used as a |method|: >
11304 GetTabpage()->tabpagewinnr()
11305<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011306 Return type: |Number|
11307
11308
11309tagfiles() *tagfiles()*
11310 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011311 for the current buffer. This is the 'tags' option expanded.
11312
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011313 Return type: list<string> or list<any>
11314
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011315
11316taglist({expr} [, {filename}]) *taglist()*
11317 Returns a |List| of tags matching the regular expression {expr}.
11318
11319 If {filename} is passed it is used to prioritize the results
11320 in the same way that |:tselect| does. See |tag-priority|.
11321 {filename} should be the full path of the file.
11322
11323 Each list item is a dictionary with at least the following
11324 entries:
11325 name Name of the tag.
11326 filename Name of the file where the tag is
11327 defined. It is either relative to the
11328 current directory or a full path.
11329 cmd Ex command used to locate the tag in
11330 the file.
11331 kind Type of the tag. The value for this
11332 entry depends on the language specific
11333 kind values. Only available when
11334 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011335 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011336 static A file specific tag. Refer to
11337 |static-tag| for more information.
11338 More entries may be present, depending on the content of the
11339 tags file: access, implementation, inherits and signature.
11340 Refer to the ctags documentation for information about these
11341 fields. For C code the fields "struct", "class" and "enum"
11342 may appear, they give the name of the entity the tag is
11343 contained in.
11344
11345 The ex-command "cmd" can be either an ex search pattern, a
11346 line number or a line number followed by a byte number.
11347
11348 If there are no matching tags, then an empty list is returned.
11349
11350 To get an exact tag match, the anchors '^' and '$' should be
11351 used in {expr}. This also make the function work faster.
11352 Refer to |tag-regexp| for more information about the tag
11353 search regular expression pattern.
11354
11355 Refer to |'tags'| for information about how the tags file is
11356 located by Vim. Refer to |tags-file-format| for the format of
11357 the tags file generated by the different ctags tools.
11358
11359 Can also be used as a |method|: >
11360 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011361<
11362 Return type: list<dict<any>> or list<any>
11363
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011364
11365tan({expr}) *tan()*
11366 Return the tangent of {expr}, measured in radians, as a |Float|
11367 in the range [-inf, inf].
11368 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011369 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011370 Examples: >
11371 :echo tan(10)
11372< 0.648361 >
11373 :echo tan(-4.01)
11374< -1.181502
11375
11376 Can also be used as a |method|: >
11377 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011378<
11379 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011380
11381
11382tanh({expr}) *tanh()*
11383 Return the hyperbolic tangent of {expr} as a |Float| in the
11384 range [-1, 1].
11385 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011386 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011387 Examples: >
11388 :echo tanh(0.5)
11389< 0.462117 >
11390 :echo tanh(-1)
11391< -0.761594
11392
11393 Can also be used as a |method|: >
11394 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011395<
11396 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011397
11398
11399tempname() *tempname()* *temp-file-name*
11400 The result is a String, which is the name of a file that
11401 doesn't exist. It can be used for a temporary file. The name
11402 is different for at least 26 consecutive calls. Example: >
11403 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011404 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011405< For Unix, the file will be in a private directory |tempfile|
11406 that is recursively deleted when Vim exits, on other systems
11407 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011408 For MS-Windows forward slashes are used when the 'shellslash'
11409 option is set, or when 'shellcmdflag' starts with '-' and
11410 'shell' does not contain powershell or pwsh.
11411
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011412 Return type: |String|
11413
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011414
11415term_ functions are documented here: |terminal-function-details|
11416
11417
11418terminalprops() *terminalprops()*
11419 Returns a |Dictionary| with properties of the terminal that Vim
11420 detected from the response to |t_RV| request. See
11421 |v:termresponse| for the response itself. If |v:termresponse|
11422 is empty most values here will be 'u' for unknown.
11423 cursor_style whether sending |t_RS| works **
11424 cursor_blink_mode whether sending |t_RC| works **
11425 underline_rgb whether |t_8u| works **
11426 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011427 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011428
11429 ** value 'u' for unknown, 'y' for yes, 'n' for no
11430
11431 If the |+termresponse| feature is missing then the result is
11432 an empty dictionary.
11433
11434 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11435 current cursor style.
11436 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11437 request the cursor blink status.
11438 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11439 is not empty, Vim will detect the working of sending |t_RS|
11440 and |t_RC| on startup.
11441
11442 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11443 This avoids sending it to xterm, which would clear the colors.
11444
11445 For "mouse" the value 'u' is unknown
11446
11447 Also see:
11448 - 'ambiwidth' - detected by using |t_u7|.
11449 - |v:termstyleresp| and |v:termblinkresp| for the response to
11450 |t_RS| and |t_RC|.
11451
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011452 Return type: dict<string>
11453
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011454
11455test_ functions are documented here: |test-functions-details|
11456
11457
11458 *timer_info()*
11459timer_info([{id}])
11460 Return a list with information about timers.
11461 When {id} is given only information about this timer is
11462 returned. When timer {id} does not exist an empty list is
11463 returned.
11464 When {id} is omitted information about all timers is returned.
11465
11466 For each timer the information is stored in a |Dictionary| with
11467 these items:
11468 "id" the timer ID
11469 "time" time the timer was started with
11470 "remaining" time until the timer fires
11471 "repeat" number of times the timer will still fire;
11472 -1 means forever
11473 "callback" the callback
11474 "paused" 1 if the timer is paused, 0 otherwise
11475
11476 Can also be used as a |method|: >
11477 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011478<
11479 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011480
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011481 {only available when compiled with the |+timers| feature}
11482
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011483
11484timer_pause({timer}, {paused}) *timer_pause()*
11485 Pause or unpause a timer. A paused timer does not invoke its
11486 callback when its time expires. Unpausing a timer may cause
11487 the callback to be invoked almost immediately if enough time
11488 has passed.
11489
11490 Pausing a timer is useful to avoid the callback to be called
11491 for a short time.
11492
11493 If {paused} evaluates to a non-zero Number or a non-empty
11494 String, then the timer is paused, otherwise it is unpaused.
11495 See |non-zero-arg|.
11496
11497 Can also be used as a |method|: >
11498 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011499<
11500 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011501
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011502 {only available when compiled with the |+timers| feature}
11503
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011504
11505 *timer_start()* *timer* *timers*
11506timer_start({time}, {callback} [, {options}])
11507 Create a timer and return the timer ID.
11508
11509 {time} is the waiting time in milliseconds. This is the
11510 minimum time before invoking the callback. When the system is
11511 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011512 Zero can be used to execute the callback when Vim is back in
11513 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011514
11515 {callback} is the function to call. It can be the name of a
11516 function or a |Funcref|. It is called with one argument, which
11517 is the timer ID. The callback is only invoked when Vim is
11518 waiting for input.
11519 If you want to show a message look at |popup_notification()|
11520 to avoid interfering with what the user is doing.
11521
11522 {options} is a dictionary. Supported entries:
11523 "repeat" Number of times to repeat calling the
11524 callback. -1 means forever. When not present
11525 the callback will be called once.
11526 If the timer causes an error three times in a
11527 row the repeat is cancelled. This avoids that
11528 Vim becomes unusable because of all the error
11529 messages.
11530
Bram Moolenaard592deb2022-06-17 15:42:40 +010011531 Returns -1 on error.
11532
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011533 Example: >
11534 func MyHandler(timer)
11535 echo 'Handler called'
11536 endfunc
11537 let timer = timer_start(500, 'MyHandler',
11538 \ {'repeat': 3})
11539< This will invoke MyHandler() three times at 500 msec
11540 intervals.
11541
11542 Can also be used as a |method|: >
11543 GetMsec()->timer_start(callback)
11544
11545< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011546
11547 Return type: |Number|
11548
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011549 {only available when compiled with the |+timers| feature}
11550
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011551
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011552timer_stop({timer}) *timer_stop()*
11553 Stop a timer. The timer callback will no longer be invoked.
11554 {timer} is an ID returned by timer_start(), thus it must be a
11555 Number. If {timer} does not exist there is no error.
11556
11557 Can also be used as a |method|: >
11558 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011559<
11560 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011561
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011562 {only available when compiled with the |+timers| feature}
11563
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011564
11565timer_stopall() *timer_stopall()*
11566 Stop all timers. The timer callbacks will no longer be
11567 invoked. Useful if a timer is misbehaving. If there are no
11568 timers there is no error.
11569
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011570 Return type: |Number|
11571
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011572 {only available when compiled with the |+timers| feature}
11573
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011574
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011575tolower({expr}) *tolower()*
11576 The result is a copy of the String given, with all uppercase
11577 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011578 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011579
11580 Can also be used as a |method|: >
11581 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011582<
11583 Return type: |String|
11584
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011585
11586toupper({expr}) *toupper()*
11587 The result is a copy of the String given, with all lowercase
11588 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011589 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011590
11591 Can also be used as a |method|: >
11592 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011593<
11594 Return type: |String|
11595
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011596
11597tr({src}, {fromstr}, {tostr}) *tr()*
11598 The result is a copy of the {src} string with all characters
11599 which appear in {fromstr} replaced by the character in that
11600 position in the {tostr} string. Thus the first character in
11601 {fromstr} is translated into the first character in {tostr}
11602 and so on. Exactly like the unix "tr" command.
11603 This code also deals with multibyte characters properly.
11604
Bram Moolenaard592deb2022-06-17 15:42:40 +010011605 Returns an empty string on error.
11606
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011607 Examples: >
11608 echo tr("hello there", "ht", "HT")
11609< returns "Hello THere" >
11610 echo tr("<blob>", "<>", "{}")
11611< returns "{blob}"
11612
11613 Can also be used as a |method|: >
11614 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011615<
11616 Return type: |String|
11617
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011618
11619trim({text} [, {mask} [, {dir}]]) *trim()*
11620 Return {text} as a String where any character in {mask} is
11621 removed from the beginning and/or end of {text}.
11622
Illia Bobyr80799172023-10-17 18:00:50 +020011623 If {mask} is not given, or is an empty string, {mask} is all
11624 characters up to 0x20, which includes Tab, space, NL and CR,
11625 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011626
11627 The optional {dir} argument specifies where to remove the
11628 characters:
11629 0 remove from the beginning and end of {text}
11630 1 remove only at the beginning of {text}
11631 2 remove only at the end of {text}
11632 When omitted both ends are trimmed.
11633
11634 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011635 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011636
11637 Examples: >
11638 echo trim(" some text ")
11639< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011640 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011641< returns "RESERVE_TAIL" >
11642 echo trim("rm<Xrm<>X>rrm", "rm<>")
11643< returns "Xrm<>X" (characters in the middle are not removed) >
11644 echo trim(" vim ", " ", 2)
11645< returns " vim"
11646
11647 Can also be used as a |method|: >
11648 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011649<
11650 Return type: |String|
11651
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011652
11653trunc({expr}) *trunc()*
11654 Return the largest integral value with magnitude less than or
11655 equal to {expr} as a |Float| (truncate towards zero).
11656 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011657 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011658 Examples: >
11659 echo trunc(1.456)
11660< 1.0 >
11661 echo trunc(-5.456)
11662< -5.0 >
11663 echo trunc(4.0)
11664< 4.0
11665
11666 Can also be used as a |method|: >
11667 Compute()->trunc()
11668<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011669 Return type: |Float|
11670
11671
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011672 *type()*
11673type({expr}) The result is a Number representing the type of {expr}.
11674 Instead of using the number directly, it is better to use the
11675 v:t_ variable that has the value:
11676 Number: 0 |v:t_number|
11677 String: 1 |v:t_string|
11678 Funcref: 2 |v:t_func|
11679 List: 3 |v:t_list|
11680 Dictionary: 4 |v:t_dict|
11681 Float: 5 |v:t_float|
11682 Boolean: 6 |v:t_bool| (v:false and v:true)
11683 None: 7 |v:t_none| (v:null and v:none)
11684 Job: 8 |v:t_job|
11685 Channel: 9 |v:t_channel|
11686 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090011687 Class: 12 |v:t_class|
11688 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010011689 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011690 Enum: 15 |v:t_enum|
11691 EnumValue: 16 |v:t_enumvalue|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011692 For backward compatibility, this method can be used: >
11693 :if type(myvar) == type(0)
11694 :if type(myvar) == type("")
11695 :if type(myvar) == type(function("tr"))
11696 :if type(myvar) == type([])
11697 :if type(myvar) == type({})
11698 :if type(myvar) == type(0.0)
11699 :if type(myvar) == type(v:false)
11700 :if type(myvar) == type(v:none)
11701< To check if the v:t_ variables exist use this: >
11702 :if exists('v:t_number')
11703
11704< Can also be used as a |method|: >
11705 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011706<
11707 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011708
11709
11710typename({expr}) *typename()*
11711 Return a string representation of the type of {expr}.
11712 Example: >
11713 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000011714< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011715
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011716 Return type: |String|
11717
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011718
11719undofile({name}) *undofile()*
11720 Return the name of the undo file that would be used for a file
11721 with name {name} when writing. This uses the 'undodir'
11722 option, finding directories that exist. It does not check if
11723 the undo file exists.
11724 {name} is always expanded to the full path, since that is what
11725 is used internally.
11726 If {name} is empty undofile() returns an empty string, since a
11727 buffer without a file name will not write an undo file.
11728 Useful in combination with |:wundo| and |:rundo|.
11729 When compiled without the |+persistent_undo| option this always
11730 returns an empty string.
11731
11732 Can also be used as a |method|: >
11733 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011734<
11735 Return type: |String|
11736
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011737
Devin J. Pohly5fee1112023-04-23 20:26:59 -050011738undotree([{buf}]) *undotree()*
11739 Return the current state of the undo tree for the current
11740 buffer, or for a specific buffer if {buf} is given. The
11741 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011742 "seq_last" The highest undo sequence number used.
11743 "seq_cur" The sequence number of the current position in
11744 the undo tree. This differs from "seq_last"
11745 when some changes were undone.
11746 "time_cur" Time last used for |:earlier| and related
11747 commands. Use |strftime()| to convert to
11748 something readable.
11749 "save_last" Number of the last file write. Zero when no
11750 write yet.
11751 "save_cur" Number of the current position in the undo
11752 tree.
11753 "synced" Non-zero when the last undo block was synced.
11754 This happens when waiting from input from the
11755 user. See |undo-blocks|.
11756 "entries" A list of dictionaries with information about
11757 undo blocks.
11758
11759 The first item in the "entries" list is the oldest undo item.
11760 Each List item is a |Dictionary| with these items:
11761 "seq" Undo sequence number. Same as what appears in
11762 |:undolist|.
11763 "time" Timestamp when the change happened. Use
11764 |strftime()| to convert to something readable.
11765 "newhead" Only appears in the item that is the last one
11766 that was added. This marks the last change
11767 and where further changes will be added.
11768 "curhead" Only appears in the item that is the last one
11769 that was undone. This marks the current
11770 position in the undo tree, the block that will
11771 be used by a redo command. When nothing was
11772 undone after the last change this item will
11773 not appear anywhere.
11774 "save" Only appears on the last block before a file
11775 write. The number is the write count. The
11776 first write has number 1, the last one the
11777 "save_last" mentioned above.
11778 "alt" Alternate entry. This is again a List of undo
11779 blocks. Each item may again have an "alt"
11780 item.
11781
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011782 Return type: dict<any>
11783
11784
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011785uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
11786 Remove second and succeeding copies of repeated adjacent
11787 {list} items in-place. Returns {list}. If you want a list
11788 to remain unmodified make a copy first: >
11789 :let newlist = uniq(copy(mylist))
11790< The default compare function uses the string representation of
11791 each item. For the use of {func} and {dict} see |sort()|.
11792
Bram Moolenaard592deb2022-06-17 15:42:40 +010011793 Returns zero if {list} is not a |List|.
11794
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011795 Can also be used as a |method|: >
11796 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010011797<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011798 Return type: list<{type}>
11799
11800
Christian Brabandt67672ef2023-04-24 21:09:54 +010011801 *utf16idx()*
11802utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011803 Same as |charidx()| but returns the UTF-16 code unit index of
11804 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010011805
11806 When {charidx} is present and TRUE, {idx} is used as the
11807 character index in the String {string} instead of as the byte
11808 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010011809 An {idx} in the middle of a UTF-8 sequence is rounded
11810 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010011811
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011812 Returns -1 if the arguments are invalid or if there are less
11813 than {idx} bytes in {string}. If there are exactly {idx} bytes
11814 the length of the string in UTF-16 code units is returned.
11815
Christian Brabandt67672ef2023-04-24 21:09:54 +010011816 See |byteidx()| and |byteidxcomp()| for getting the byte index
11817 from the UTF-16 index and |charidx()| for getting the
11818 character index from the UTF-16 index.
11819 Refer to |string-offset-encoding| for more information.
11820 Examples: >
11821 echo utf16idx('a😊😊', 3) returns 2
11822 echo utf16idx('a😊😊', 7) returns 4
11823 echo utf16idx('a😊😊', 1, 0, 1) returns 2
11824 echo utf16idx('a😊😊', 2, 0, 1) returns 4
11825 echo utf16idx('aą́c', 6) returns 2
11826 echo utf16idx('aą́c', 6, 1) returns 4
11827 echo utf16idx('a😊😊', 9) returns -1
11828<
11829 Can also be used as a |method|: >
11830 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011831<
11832 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010011833
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011834
11835values({dict}) *values()*
11836 Return a |List| with all the values of {dict}. The |List| is
11837 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011838 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011839
11840 Can also be used as a |method|: >
11841 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011842<
11843 Return type: list<any>
11844
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011845
zeertzjq825cf812023-08-17 22:55:25 +020011846virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011847 The result is a Number, which is the screen column of the file
11848 position given with {expr}. That is, the last screen position
11849 occupied by the character at that position, when the screen
11850 would be of unlimited width. When there is a <Tab> at the
11851 position, the returned Number will be the column at the end of
11852 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
11853 set to 8, it returns 8. |conceal| is ignored.
11854 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011855
zeertzjq02f3eba2024-06-12 20:45:24 +020011856 For the use of {expr} see |getpos()| and |col()|.
zeertzjqd353d272024-06-13 23:00:25 +080011857 When {expr} is "$", it means the end of the cursor line, so
11858 the result is the number of cells in the cursor line plus one.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011859
11860 When 'virtualedit' is used {expr} can be [lnum, col, off],
11861 where "off" is the offset in screen columns from the start of
11862 the character. E.g., a position within a <Tab> or after the
11863 last character. When "off" is omitted zero is used. When
11864 Virtual editing is active in the current mode, a position
11865 beyond the end of the line can be returned. Also see
11866 |'virtualedit'|
11867
zeertzjq825cf812023-08-17 22:55:25 +020011868 If {list} is present and non-zero then virtcol() returns a
11869 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010011870 character.
11871
zeertzjq825cf812023-08-17 22:55:25 +020011872 With the optional {winid} argument the values are obtained for
11873 that window instead of the current window.
11874
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011875 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +020011876
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011877 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010011878 " With text "foo^Lbar" and cursor on the "^L":
11879
11880 virtcol(".") " returns 5
11881 virtcol(".", 1) " returns [4, 5]
11882 virtcol("$") " returns 9
11883
11884 " With text " there", with 't at 'h':
11885
11886 virtcol("'t") " returns 6
zeertzjq02f3eba2024-06-12 20:45:24 +020011887<
11888 The first column is 1. 0 or [0, 0] is returned for an error.
11889
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011890 A more advanced example that echoes the maximum length of
11891 all lines: >
11892 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
11893
11894< Can also be used as a |method|: >
11895 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011896<
11897 Return type: |Number|
11898
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011899
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011900virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
11901 The result is a Number, which is the byte index of the
11902 character in window {winid} at buffer line {lnum} and virtual
11903 column {col}.
11904
zeertzjqb583eda2023-10-14 11:32:28 +020011905 If buffer line {lnum} is an empty line, 0 is returned.
11906
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011907 If {col} is greater than the last virtual column in line
11908 {lnum}, then the byte index of the character at the last
11909 virtual column is returned.
11910
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020011911 For a multi-byte character, the column number of the first
11912 byte in the character is returned.
11913
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011914 The {winid} argument can be the window number or the
11915 |window-ID|. If this is zero, then the current window is used.
11916
11917 Returns -1 if the window {winid} doesn't exist or the buffer
11918 line {lnum} or virtual column {col} is invalid.
11919
11920 See also |screenpos()|, |virtcol()| and |col()|.
11921
11922 Can also be used as a |method|: >
11923 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011924<
11925 Return type: |Number|
11926
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011927
11928visualmode([{expr}]) *visualmode()*
11929 The result is a String, which describes the last Visual mode
11930 used in the current buffer. Initially it returns an empty
11931 string, but once Visual mode has been used, it returns "v",
11932 "V", or "<CTRL-V>" (a single CTRL-V character) for
11933 character-wise, line-wise, or block-wise Visual mode
11934 respectively.
11935 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011936 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011937< This enters the same Visual mode as before. It is also useful
11938 in scripts if you wish to act differently depending on the
11939 Visual mode that was used.
11940 If Visual mode is active, use |mode()| to get the Visual mode
11941 (e.g., in a |:vmap|).
11942 If {expr} is supplied and it evaluates to a non-zero Number or
11943 a non-empty String, then the Visual mode will be cleared and
11944 the old value is returned. See |non-zero-arg|.
11945
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011946 Return type: |String|
11947
11948
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011949wildmenumode() *wildmenumode()*
11950 Returns |TRUE| when the wildmenu is active and |FALSE|
11951 otherwise. See 'wildmenu' and 'wildmode'.
11952 This can be used in mappings to handle the 'wildcharm' option
11953 gracefully. (Makes only sense with |mapmode-c| mappings).
11954
11955 For example to make <c-j> work like <down> in wildmode, use: >
11956 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
11957<
Milly6c2fc372024-10-16 22:11:17 +020011958 (Note: this needs the 'wildcharm' option set appropriately).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011959
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011960 Return type: |Number|
11961
11962
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011963win_execute({id}, {command} [, {silent}]) *win_execute()*
11964 Like `execute()` but in the context of window {id}.
11965 The window will temporarily be made the current window,
11966 without triggering autocommands or changing directory. When
11967 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010011968 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011969 Example: >
11970 call win_execute(winid, 'set syntax=python')
11971< Doing the same with `setwinvar()` would not trigger
11972 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011973 *E994*
11974 Not all commands are allowed in popup windows.
11975 When window {id} does not exist then no error is given and
11976 an empty string is returned.
11977
11978 Can also be used as a |method|, the base is passed as the
11979 second argument: >
11980 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011981<
11982 Return type: |String|
11983
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011984
11985win_findbuf({bufnr}) *win_findbuf()*
11986 Returns a |List| with |window-ID|s for windows that contain
11987 buffer {bufnr}. When there is none the list is empty.
11988
11989 Can also be used as a |method|: >
11990 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011991<
11992 Return type: list<number> or list<any>
11993
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011994
11995win_getid([{win} [, {tab}]]) *win_getid()*
11996 Get the |window-ID| for the specified window.
11997 When {win} is missing use the current window.
11998 With {win} this is the window number. The top window has
11999 number 1.
12000 Without {tab} use the current tab, otherwise the tab with
12001 number {tab}. The first tab has number one.
12002 Return zero if the window cannot be found.
12003
12004 Can also be used as a |method|: >
12005 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012006<
12007 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012008
12009
12010win_gettype([{nr}]) *win_gettype()*
12011 Return the type of the window:
12012 "autocmd" autocommand window. Temporary window
12013 used to execute autocommands.
12014 "command" command-line window |cmdwin|
12015 (empty) normal window
12016 "loclist" |location-list-window|
12017 "popup" popup window |popup|
12018 "preview" preview window |preview-window|
12019 "quickfix" |quickfix-window|
12020 "unknown" window {nr} not found
12021
12022 When {nr} is omitted return the type of the current window.
12023 When {nr} is given return the type of this window by number or
12024 |window-ID|.
12025
12026 Also see the 'buftype' option. When running a terminal in a
12027 popup window then 'buftype' is "terminal" and win_gettype()
12028 returns "popup".
12029
12030 Can also be used as a |method|: >
12031 GetWinid()->win_gettype()
12032<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012033 Return type: |String|
12034
12035
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012036win_gotoid({expr}) *win_gotoid()*
12037 Go to window with ID {expr}. This may also change the current
12038 tabpage.
12039 Return TRUE if successful, FALSE if the window cannot be found.
12040
12041 Can also be used as a |method|: >
12042 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012043<
12044 Return type: |Number|
12045
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012046
12047win_id2tabwin({expr}) *win_id2tabwin()*
12048 Return a list with the tab number and window number of window
12049 with ID {expr}: [tabnr, winnr].
12050 Return [0, 0] if the window cannot be found.
12051
12052 Can also be used as a |method|: >
12053 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012054<
12055 Return type: list<number>
12056
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012057
12058win_id2win({expr}) *win_id2win()*
12059 Return the window number of window with ID {expr}.
12060 Return 0 if the window cannot be found in the current tabpage.
12061
12062 Can also be used as a |method|: >
12063 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012064<
12065 Return type: |Number|
12066
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012067
Daniel Steinbergee630312022-01-10 13:36:34 +000012068win_move_separator({nr}, {offset}) *win_move_separator()*
12069 Move window {nr}'s vertical separator (i.e., the right border)
12070 by {offset} columns, as if being dragged by the mouse. {nr}
12071 can be a window number or |window-ID|. A positive {offset}
12072 moves right and a negative {offset} moves left. Moving a
12073 window's vertical separator will change the width of the
12074 window and the width of other windows adjacent to the vertical
12075 separator. The magnitude of movement may be smaller than
12076 specified (e.g., as a consequence of maintaining
12077 'winminwidth'). Returns TRUE if the window can be found and
12078 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012079 This will fail for the rightmost window and a full-width
12080 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012081 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000012082
12083 Can also be used as a |method|: >
12084 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012085<
12086 Return type: |Number|
12087
Daniel Steinbergee630312022-01-10 13:36:34 +000012088
12089win_move_statusline({nr}, {offset}) *win_move_statusline()*
12090 Move window {nr}'s status line (i.e., the bottom border) by
12091 {offset} rows, as if being dragged by the mouse. {nr} can be a
12092 window number or |window-ID|. A positive {offset} moves down
12093 and a negative {offset} moves up. Moving a window's status
12094 line will change the height of the window and the height of
12095 other windows adjacent to the status line. The magnitude of
12096 movement may be smaller than specified (e.g., as a consequence
12097 of maintaining 'winminheight'). Returns TRUE if the window can
12098 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012099 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000012100
12101 Can also be used as a |method|: >
12102 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012103<
12104 Return type: |Number|
12105
Daniel Steinbergee630312022-01-10 13:36:34 +000012106
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012107win_screenpos({nr}) *win_screenpos()*
12108 Return the screen position of window {nr} as a list with two
12109 numbers: [row, col]. The first window always has position
12110 [1, 1], unless there is a tabline, then it is [2, 1].
12111 {nr} can be the window number or the |window-ID|. Use zero
12112 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012113 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012114
12115 Can also be used as a |method|: >
12116 GetWinid()->win_screenpos()
12117<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012118 Return type: list<number>
12119
12120
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012121win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012122 Temporarily switch to window {target}, then move window {nr}
12123 to a new split adjacent to {target}.
12124 Unlike commands such as |:split|, no new windows are created
12125 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012126
12127 Both {nr} and {target} can be window numbers or |window-ID|s.
12128 Both must be in the current tab page.
12129
12130 Returns zero for success, non-zero for failure.
12131
12132 {options} is a |Dictionary| with the following optional entries:
12133 "vertical" When TRUE, the split is created vertically,
12134 like with |:vsplit|.
12135 "rightbelow" When TRUE, the split is made below or to the
12136 right (if vertical). When FALSE, it is done
12137 above or to the left (if vertical). When not
12138 present, the values of 'splitbelow' and
12139 'splitright' are used.
12140
12141 Can also be used as a |method|: >
12142 GetWinid()->win_splitmove(target)
12143<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012144 Return type: |Number|
12145
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012146
12147 *winbufnr()*
12148winbufnr({nr}) The result is a Number, which is the number of the buffer
12149 associated with window {nr}. {nr} can be the window number or
12150 the |window-ID|.
12151 When {nr} is zero, the number of the buffer in the current
12152 window is returned.
12153 When window {nr} doesn't exist, -1 is returned.
12154 Example: >
12155 :echo "The file in the current window is " . bufname(winbufnr(0))
12156<
12157 Can also be used as a |method|: >
12158 FindWindow()->winbufnr()->bufname()
12159<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012160 Return type: |Number|
12161
12162
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012163 *wincol()*
12164wincol() The result is a Number, which is the virtual column of the
12165 cursor in the window. This is counting screen cells from the
12166 left side of the window. The leftmost column is one.
12167
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012168 Return type: |Number|
12169
12170
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012171 *windowsversion()*
12172windowsversion()
12173 The result is a String. For MS-Windows it indicates the OS
12174 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12175 Windows XP is "5.1". For non-MS-Windows systems the result is
12176 an empty string.
12177
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012178 Return type: |String|
12179
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012180winheight({nr}) *winheight()*
12181 The result is a Number, which is the height of window {nr}.
12182 {nr} can be the window number or the |window-ID|.
12183 When {nr} is zero, the height of the current window is
12184 returned. When window {nr} doesn't exist, -1 is returned.
12185 An existing window always has a height of zero or more.
12186 This excludes any window toolbar line.
12187 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012188 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012189
12190< Can also be used as a |method|: >
12191 GetWinid()->winheight()
12192<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012193 Return type: |Number|
12194
12195
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012196winlayout([{tabnr}]) *winlayout()*
12197 The result is a nested List containing the layout of windows
12198 in a tabpage.
12199
12200 Without {tabnr} use the current tabpage, otherwise the tabpage
12201 with number {tabnr}. If the tabpage {tabnr} is not found,
12202 returns an empty list.
12203
12204 For a leaf window, it returns:
12205 ['leaf', {winid}]
12206 For horizontally split windows, which form a column, it
12207 returns:
12208 ['col', [{nested list of windows}]]
12209 For vertically split windows, which form a row, it returns:
12210 ['row', [{nested list of windows}]]
12211
12212 Example: >
12213 " Only one window in the tab page
12214 :echo winlayout()
12215 ['leaf', 1000]
12216 " Two horizontally split windows
12217 :echo winlayout()
12218 ['col', [['leaf', 1000], ['leaf', 1001]]]
12219 " The second tab page, with three horizontally split
12220 " windows, with two vertically split windows in the
12221 " middle window
12222 :echo winlayout(2)
12223 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12224 ['leaf', 1001]]], ['leaf', 1000]]]
12225<
12226 Can also be used as a |method|: >
12227 GetTabnr()->winlayout()
12228<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012229 Return type: list<any>
12230
12231
12232winline() *winline()*
12233 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012234 in the window. This is counting screen lines from the top of
12235 the window. The first line is one.
12236 If the cursor was moved the view on the file will be updated
12237 first, this may cause a scroll.
12238
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012239 Return type: |Number|
12240
12241
12242winnr([{arg}]) *winnr()*
12243 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012244 window. The top window has number 1.
12245 Returns zero for a popup window.
12246
12247 The optional argument {arg} supports the following values:
12248 $ the number of the last window (the window
12249 count).
12250 # the number of the last accessed window (where
12251 |CTRL-W_p| goes to). If there is no previous
12252 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012253 returned. May refer to the current window in
12254 some cases (e.g. when evaluating 'statusline'
12255 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012256 {N}j the number of the Nth window below the
12257 current window (where |CTRL-W_j| goes to).
12258 {N}k the number of the Nth window above the current
12259 window (where |CTRL-W_k| goes to).
12260 {N}h the number of the Nth window left of the
12261 current window (where |CTRL-W_h| goes to).
12262 {N}l the number of the Nth window right of the
12263 current window (where |CTRL-W_l| goes to).
12264 The number can be used with |CTRL-W_w| and ":wincmd w"
12265 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012266 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012267 Also see |tabpagewinnr()| and |win_getid()|.
12268 Examples: >
12269 let window_count = winnr('$')
12270 let prev_window = winnr('#')
12271 let wnum = winnr('3k')
12272
12273< Can also be used as a |method|: >
12274 GetWinval()->winnr()
12275<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012276 Return type: |Number|
12277
12278
12279winrestcmd() *winrestcmd()*
12280 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012281 the current window sizes. Only works properly when no windows
12282 are opened or closed and the current window and tab page is
12283 unchanged.
12284 Example: >
12285 :let cmd = winrestcmd()
12286 :call MessWithWindowSizes()
12287 :exe cmd
12288<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012289 Return type: |String|
12290
12291
12292winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012293 Uses the |Dictionary| returned by |winsaveview()| to restore
12294 the view of the current window.
12295 Note: The {dict} does not have to contain all values, that are
12296 returned by |winsaveview()|. If values are missing, those
12297 settings won't be restored. So you can use: >
12298 :call winrestview({'curswant': 4})
12299<
12300 This will only set the curswant value (the column the cursor
12301 wants to move on vertical movements) of the cursor to column 5
12302 (yes, that is 5), while all other settings will remain the
12303 same. This is useful, if you set the cursor position manually.
12304
12305 If you have changed the values the result is unpredictable.
12306 If the window size changed the result won't be the same.
12307
12308 Can also be used as a |method|: >
12309 GetView()->winrestview()
12310<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012311 Return type: |Number|
12312
12313
12314winsaveview() *winsaveview()*
12315 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012316 the view of the current window. Use |winrestview()| to
12317 restore the view.
12318 This is useful if you have a mapping that jumps around in the
12319 buffer and you want to go back to the original view.
12320 This does not save fold information. Use the 'foldenable'
12321 option to temporarily switch off folding, so that folds are
12322 not opened when moving around. This may have side effects.
12323 The return value includes:
12324 lnum cursor line number
12325 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012326 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012327 returns)
12328 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012329 curswant column for vertical movement (Note:
12330 the first column is zero, as opposed
12331 to what |getcurpos()| returns). After
12332 |$| command it will be a very large
12333 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012334 topline first line in the window
12335 topfill filler lines, only in diff mode
12336 leftcol first column displayed; only used when
12337 'wrap' is off
12338 skipcol columns skipped
12339 Note that no option values are saved.
12340
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012341 Return type: dict<number>
12342
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012343
12344winwidth({nr}) *winwidth()*
12345 The result is a Number, which is the width of window {nr}.
12346 {nr} can be the window number or the |window-ID|.
12347 When {nr} is zero, the width of the current window is
12348 returned. When window {nr} doesn't exist, -1 is returned.
12349 An existing window always has a width of zero or more.
12350 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012351 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012352 :if winwidth(0) <= 50
12353 : 50 wincmd |
12354 :endif
12355< For getting the terminal or screen size, see the 'columns'
12356 option.
12357
12358 Can also be used as a |method|: >
12359 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012360<
12361 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012362
12363
12364wordcount() *wordcount()*
12365 The result is a dictionary of byte/chars/word statistics for
12366 the current buffer. This is the same info as provided by
12367 |g_CTRL-G|
12368 The return value includes:
12369 bytes Number of bytes in the buffer
12370 chars Number of chars in the buffer
12371 words Number of words in the buffer
12372 cursor_bytes Number of bytes before cursor position
12373 (not in Visual mode)
12374 cursor_chars Number of chars before cursor position
12375 (not in Visual mode)
12376 cursor_words Number of words before cursor position
12377 (not in Visual mode)
12378 visual_bytes Number of bytes visually selected
12379 (only in Visual mode)
12380 visual_chars Number of chars visually selected
12381 (only in Visual mode)
12382 visual_words Number of words visually selected
12383 (only in Visual mode)
12384
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012385 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012386
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012387
12388writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012389 When {object} is a |List| write it to file {fname}. Each list
12390 item is separated with a NL. Each list item must be a String
12391 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012392 All NL characters are replaced with a NUL character.
12393 Inserting CR characters needs to be done before passing {list}
12394 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012395
12396 When {object} is a |Blob| write the bytes to file {fname}
12397 unmodified, also when binary mode is not specified.
12398
12399 {flags} must be a String. These characters are recognized:
12400
12401 'b' Binary mode is used: There will not be a NL after the
12402 last list item. An empty item at the end does cause the
12403 last line in the file to end in a NL.
12404
12405 'a' Append mode is used, lines are appended to the file: >
12406 :call writefile(["foo"], "event.log", "a")
12407 :call writefile(["bar"], "event.log", "a")
12408<
12409 'D' Delete the file when the current function ends. This
12410 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012411 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012412< Fails when not in a function. Also see |:defer|.
12413
12414 's' fsync() is called after writing the file. This flushes
12415 the file to disk, if possible. This takes more time but
12416 avoids losing the file if the system crashes.
12417
12418 'S' fsync() is not called, even when 'fsync' is set.
12419
12420 When {flags} does not contain "S" or "s" then fsync() is
12421 called if the 'fsync' option is set.
12422
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012423 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012424
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012425 When the write fails -1 is returned, otherwise 0. There is an
12426 error message if the file can't be created or when writing
12427 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012428
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012429 Also see |readfile()|.
12430 To copy a file byte for byte: >
12431 :let fl = readfile("foo", "b")
12432 :call writefile(fl, "foocopy", "b")
12433
12434< Can also be used as a |method|: >
12435 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012436<
12437 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012438
12439
12440xor({expr}, {expr}) *xor()*
12441 Bitwise XOR on the two arguments. The arguments are converted
12442 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012443 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012444 Example: >
12445 :let bits = xor(bits, 0x80)
12446<
12447 Can also be used as a |method|: >
12448 :let bits = bits->xor(0x80)
12449<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012450 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012451
12452==============================================================================
124533. Feature list *feature-list*
12454
12455There are three types of features:
124561. Features that are only supported when they have been enabled when Vim
12457 was compiled |+feature-list|. Example: >
12458 :if has("cindent")
12459< *gui_running*
124602. Features that are only supported when certain conditions have been met.
12461 Example: >
12462 :if has("gui_running")
12463< *has-patch*
124643. Beyond a certain version or at a certain version and including a specific
12465 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12466 later, or it is version 7.4 and patch 248 was included. Example: >
12467 :if has("patch-7.4.248")
12468< Note that it's possible for patch 248 to be omitted even though 249 is
12469 included. Only happens when cherry-picking patches.
12470 Note that this form only works for patch 7.4.237 and later, before that
12471 you need to check for the patch and the v:version. Example (checking
12472 version 6.2.148 or later): >
12473 :if v:version > 602 || (v:version == 602 && has("patch148"))
12474
12475Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12476use: `if exists('+shellslash')`
12477
12478
12479acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012480all_builtin_terms Compiled with all builtin terminals enabled. (always
12481 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012482amiga Amiga version of Vim.
12483arabic Compiled with Arabic support |Arabic|.
12484arp Compiled with ARP support (Amiga).
12485autocmd Compiled with autocommand support. (always true)
12486autochdir Compiled with support for 'autochdir'
12487autoservername Automatically enable |clientserver|
12488balloon_eval Compiled with |balloon-eval| support.
12489balloon_multiline GUI supports multiline balloons.
12490beos BeOS version of Vim.
12491browse Compiled with |:browse| support, and browse() will
12492 work.
12493browsefilter Compiled with support for |browsefilter|.
12494bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012495builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012496byte_offset Compiled with support for 'o' in 'statusline'
12497channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012498cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012499clientserver Compiled with remote invocation support |clientserver|.
12500clipboard Compiled with 'clipboard' support.
12501clipboard_working Compiled with 'clipboard' support and it can be used.
12502cmdline_compl Compiled with |cmdline-completion| support.
12503cmdline_hist Compiled with |cmdline-history| support.
12504cmdline_info Compiled with 'showcmd' and 'ruler' support.
12505comments Compiled with |'comments'| support.
12506compatible Compiled to be very Vi compatible.
12507conpty Platform where |ConPTY| can be used.
12508cryptv Compiled with encryption support |encryption|.
12509cscope Compiled with |cscope| support.
12510cursorbind Compiled with |'cursorbind'| (always true)
12511debug Compiled with "DEBUG" defined.
12512dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012513dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012514dialog_gui Compiled with GUI dialog support.
12515diff Compiled with |vimdiff| and 'diff' support.
12516digraphs Compiled with support for digraphs.
12517directx Compiled with support for DirectX and 'renderoptions'.
12518dnd Compiled with support for the "~ register |quote_~|.
12519drop_file Compiled with |drop_file| support.
12520ebcdic Compiled on a machine with ebcdic character set.
12521emacs_tags Compiled with support for Emacs tags.
12522eval Compiled with expression evaluation support. Always
12523 true, of course!
12524ex_extra |+ex_extra| (always true)
12525extra_search Compiled with support for |'incsearch'| and
12526 |'hlsearch'|
12527farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012528file_in_path Compiled with support for |gf| and |<cfile>| (always
12529 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012530filterpipe When 'shelltemp' is off pipes are used for shell
12531 read/write/filter commands
12532find_in_path Compiled with support for include file searches
12533 |+find_in_path|.
12534float Compiled with support for |Float|.
12535fname_case Case in file names matters (for Amiga and MS-Windows
12536 this is not present).
12537folding Compiled with |folding| support.
12538footer Compiled with GUI footer support. |gui-footer|
12539fork Compiled to use fork()/exec() instead of system().
12540gettext Compiled with message translation |multi-lang|
12541gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012542gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012543gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12544gui_gtk Compiled with GTK+ GUI (any version).
12545gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12546gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12547gui_haiku Compiled with Haiku GUI.
12548gui_mac Compiled with Macintosh GUI.
12549gui_motif Compiled with Motif GUI.
12550gui_photon Compiled with Photon GUI.
12551gui_running Vim is running in the GUI, or it will start soon.
12552gui_win32 Compiled with MS-Windows Win32 GUI.
12553gui_win32s idem, and Win32s system being used (Windows 3.1)
12554haiku Haiku version of Vim.
12555hangul_input Compiled with Hangul input support. |hangul|
12556hpux HP-UX version of Vim.
12557iconv Can use iconv() for conversion.
12558insert_expand Compiled with support for CTRL-X expansion commands in
12559 Insert mode. (always true)
12560job Compiled with support for |channel| and |job|
12561ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012562jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012563keymap Compiled with 'keymap' support.
12564lambda Compiled with |lambda| support.
12565langmap Compiled with 'langmap' support.
12566libcall Compiled with |libcall()| support.
12567linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12568 'breakindent' support.
12569linux Linux version of Vim.
12570lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012571 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012572listcmds Compiled with commands for the buffer list |:files|
12573 and the argument list |arglist|.
12574localmap Compiled with local mappings and abbr. |:map-local|
12575lua Compiled with Lua interface |Lua|.
12576mac Any Macintosh version of Vim cf. osx
12577macunix Synonym for osxdarwin
12578menu Compiled with support for |:menu|.
12579mksession Compiled with support for |:mksession|.
12580modify_fname Compiled with file name modifiers. |filename-modifiers|
12581 (always true)
12582mouse Compiled with support for mouse.
12583mouse_dec Compiled with support for Dec terminal mouse.
12584mouse_gpm Compiled with support for gpm (Linux console mouse)
12585mouse_gpm_enabled GPM mouse is working
12586mouse_netterm Compiled with support for netterm mouse.
12587mouse_pterm Compiled with support for qnx pterm mouse.
12588mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12589mouse_sgr Compiled with support for sgr mouse.
12590mouse_urxvt Compiled with support for urxvt mouse.
12591mouse_xterm Compiled with support for xterm mouse.
12592mouseshape Compiled with support for 'mouseshape'.
12593multi_byte Compiled with support for 'encoding' (always true)
12594multi_byte_encoding 'encoding' is set to a multibyte encoding.
12595multi_byte_ime Compiled with support for IME input method.
12596multi_lang Compiled with support for multiple languages.
12597mzscheme Compiled with MzScheme interface |mzscheme|.
12598nanotime Compiled with sub-second time stamp checks.
12599netbeans_enabled Compiled with support for |netbeans| and connected.
12600netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012601num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012602ole Compiled with OLE automation support for Win32.
12603osx Compiled for macOS cf. mac
12604osxdarwin Compiled for macOS, with |mac-darwin-feature|
12605packages Compiled with |packages| support.
12606path_extra Compiled with up/downwards search in 'path' and 'tags'
12607perl Compiled with Perl interface.
12608persistent_undo Compiled with support for persistent undo history.
12609postscript Compiled with PostScript file printing.
12610printer Compiled with |:hardcopy| support.
12611profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012612prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012613python Python 2.x interface available. |has-python|
12614python_compiled Compiled with Python 2.x interface. |has-python|
12615python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12616python3 Python 3.x interface available. |has-python|
12617python3_compiled Compiled with Python 3.x interface. |has-python|
12618python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012619python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012620pythonx Python 2.x and/or 3.x interface available. |python_x|
12621qnx QNX version of Vim.
12622quickfix Compiled with |quickfix| support.
12623reltime Compiled with |reltime()| support.
12624rightleft Compiled with 'rightleft' support.
12625ruby Compiled with Ruby interface |ruby|.
12626scrollbind Compiled with 'scrollbind' support. (always true)
12627showcmd Compiled with 'showcmd' support.
12628signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012629smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012630sodium Compiled with libsodium for better crypt support
12631sound Compiled with sound support, e.g. `sound_playevent()`
12632spell Compiled with spell checking support |spell|.
12633startuptime Compiled with |--startuptime| support.
12634statusline Compiled with support for 'statusline', 'rulerformat'
12635 and special formats of 'titlestring' and 'iconstring'.
12636sun SunOS version of Vim.
12637sun_workshop Support for Sun |workshop| has been removed.
12638syntax Compiled with syntax highlighting support |syntax|.
12639syntax_items There are active syntax highlighting items for the
12640 current buffer.
12641system Compiled to use system() instead of fork()/exec().
12642tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012643 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012644tag_old_static Support for old static tags was removed, see
12645 |tag-old-static|.
12646tcl Compiled with Tcl interface.
12647termguicolors Compiled with true color in terminal support.
12648terminal Compiled with |terminal| support.
12649terminfo Compiled with terminfo instead of termcap.
12650termresponse Compiled with support for |t_RV| and |v:termresponse|.
12651textobjects Compiled with support for |text-objects|.
12652textprop Compiled with support for |text-properties|.
12653tgetent Compiled with tgetent support, able to use a termcap
12654 or terminfo file.
12655timers Compiled with |timer_start()| support.
12656title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012657 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012658toolbar Compiled with support for |gui-toolbar|.
12659ttyin input is a terminal (tty)
12660ttyout output is a terminal (tty)
12661unix Unix version of Vim. *+unix*
12662unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
12663user_commands User-defined commands. (always true)
12664vartabs Compiled with variable tabstop support |'vartabstop'|.
12665vcon Win32: Virtual console support is working, can use
12666 'termguicolors'. Also see |+vtp|.
12667vertsplit Compiled with vertically split windows |:vsplit|.
12668 (always true)
12669vim_starting True while initial source'ing takes place. |startup|
12670 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000012671vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012672viminfo Compiled with viminfo support.
12673vimscript-1 Compiled Vim script version 1 support
12674vimscript-2 Compiled Vim script version 2 support
12675vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010012676vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012677virtualedit Compiled with 'virtualedit' option. (always true)
12678visual Compiled with Visual mode. (always true)
12679visualextra Compiled with extra Visual mode commands. (always
12680 true) |blockwise-operators|.
12681vms VMS version of Vim.
12682vreplace Compiled with |gR| and |gr| commands. (always true)
12683vtp Compiled for vcon support |+vtp| (check vcon to find
12684 out if it works in the current console).
12685wildignore Compiled with 'wildignore' option.
12686wildmenu Compiled with 'wildmenu' option.
12687win16 old version for MS-Windows 3.1 (always false)
12688win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
12689 64 bits)
12690win32unix Win32 version of Vim, using Unix files (Cygwin)
12691win64 Win64 version of Vim (MS-Windows 64 bit).
12692win95 Win32 version for MS-Windows 95/98/ME (always false)
12693winaltkeys Compiled with 'winaltkeys' option.
12694windows Compiled with support for more than one window.
12695 (always true)
12696writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020012697xattr Compiled with extended attributes support |xattr|
12698 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012699xfontset Compiled with X fontset support |xfontset|.
12700xim Compiled with X input method support |xim|.
12701xpm Compiled with pixmap support.
12702xpm_w32 Compiled with pixmap support for Win32. (Only for
12703 backward compatibility. Use "xpm" instead.)
12704xsmp Compiled with X session management support.
12705xsmp_interact Compiled with interactive X session management support.
12706xterm_clipboard Compiled with support for xterm clipboard.
12707xterm_save Compiled with support for saving and restoring the
12708 xterm screen.
12709x11 Compiled with X11 support.
12710
12711
12712==============================================================================
127134. Matching a pattern in a String *string-match*
12714
12715This is common between several functions. A regexp pattern as explained at
12716|pattern| is normally used to find a match in the buffer lines. When a
12717pattern is used to find a match in a String, almost everything works in the
12718same way. The difference is that a String is handled like it is one line.
12719When it contains a "\n" character, this is not seen as a line break for the
12720pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
12721>
12722 :let a = "aaaa\nxxxx"
12723 :echo matchstr(a, "..\n..")
12724 aa
12725 xx
12726 :echo matchstr(a, "a.x")
12727 a
12728 x
12729
12730Don't forget that "^" will only match at the first character of the String and
12731"$" at the last character of the string. They don't match after or before a
12732"\n".
12733
12734 vim:tw=78:ts=8:noet:ft=help:norl: