blob: 8f2d132e2940d9fb52fede88b2fa36a7d8dcfeb9 [file] [log] [blame]
zeertzjq02f3eba2024-06-12 20:45:24 +02001*builtin.txt* For Vim version 9.1. Last change: 2024 Jun 12
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}
31appendbufline({expr}, {lnum}, {text})
32 Number append {text} below line {lnum}
33 in buffer {expr}
34argc([{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
70blob2list({blob}) List convert {blob} into a list of numbers
71browse({save}, {title}, {initdir}, {default})
72 String put up a file requester
73browsedir({title}, {initdir}) String put up a directory requester
74bufadd({name}) Number add a buffer to the buffer list
75bufexists({buf}) Number |TRUE| if buffer {buf} exists
76buflisted({buf}) Number |TRUE| if buffer {buf} is listed
77bufload({buf}) Number load buffer {buf} if not loaded yet
78bufloaded({buf}) Number |TRUE| if buffer {buf} is loaded
79bufname([{buf}]) String Name of the buffer {buf}
80bufnr([{buf} [, {create}]]) Number Number of the buffer {buf}
81bufwinid({buf}) Number window ID of buffer {buf}
82bufwinnr({buf}) Number window number of buffer {buf}
83byte2line({byte}) Number line number at byte count {byte}
Christian Brabandt67672ef2023-04-24 21:09:54 +010084byteidx({expr}, {nr} [, {utf16}])
85 Number byte index of {nr}'th char in {expr}
86byteidxcomp({expr}, {nr} [, {utf16}])
87 Number byte index of {nr}'th char in {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000088call({func}, {arglist} [, {dict}])
89 any call {func} with arguments {arglist}
90ceil({expr}) Float round {expr} up
91ch_canread({handle}) Number check if there is something to read
92ch_close({handle}) none close {handle}
93ch_close_in({handle}) none close in part of {handle}
94ch_evalexpr({handle}, {expr} [, {options}])
95 any evaluate {expr} on JSON {handle}
96ch_evalraw({handle}, {string} [, {options}])
97 any evaluate {string} on raw {handle}
98ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
99ch_getjob({channel}) Job get the Job of {channel}
100ch_info({handle}) String info about channel {handle}
101ch_log({msg} [, {handle}]) none write {msg} in the channel log file
102ch_logfile({fname} [, {mode}]) none start logging channel activity
103ch_open({address} [, {options}])
104 Channel open a channel to {address}
105ch_read({handle} [, {options}]) String read from {handle}
106ch_readblob({handle} [, {options}])
107 Blob read Blob from {handle}
108ch_readraw({handle} [, {options}])
109 String read raw from {handle}
110ch_sendexpr({handle}, {expr} [, {options}])
111 any send {expr} over JSON {handle}
112ch_sendraw({handle}, {expr} [, {options}])
113 any send {expr} over raw {handle}
114ch_setoptions({handle}, {options})
115 none set options for {handle}
116ch_status({handle} [, {options}])
117 String status of channel {handle}
118changenr() Number current change number
119char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr}
120charclass({string}) Number character class of {string}
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000121charcol({expr} [, {winid}]) Number column number of cursor or mark
Christian Brabandt67672ef2023-04-24 21:09:54 +0100122charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000123 Number char index of byte {idx} in {string}
124chdir({dir}) String change current working directory
125cindent({lnum}) Number C indent for line {lnum}
126clearmatches([{win}]) none clear all matches
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000127col({expr} [, {winid}]) Number column byte index of cursor or mark
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000128complete({startcol}, {matches}) none set Insert mode completion
129complete_add({expr}) Number add completion match
130complete_check() Number check for key typed during completion
131complete_info([{what}]) Dict get current completion information
132confirm({msg} [, {choices} [, {default} [, {type}]]])
133 Number number of choice picked by user
134copy({expr}) any make a shallow copy of {expr}
135cos({expr}) Float cosine of {expr}
136cosh({expr}) Float hyperbolic cosine of {expr}
137count({comp}, {expr} [, {ic} [, {start}]])
138 Number count how many {expr} are in {comp}
139cscope_connection([{num}, {dbpath} [, {prepend}]])
140 Number checks existence of cscope connection
141cursor({lnum}, {col} [, {off}])
142 Number move cursor to {lnum}, {col}, {off}
143cursor({list}) Number move cursor to position in {list}
144debugbreak({pid}) Number interrupt process being debugged
145deepcopy({expr} [, {noref}]) any make a full copy of {expr}
146delete({fname} [, {flags}]) Number delete the file or directory {fname}
147deletebufline({buf}, {first} [, {last}])
148 Number delete lines from buffer {buf}
149did_filetype() Number |TRUE| if FileType autocmd event used
Yegappan Lakshmananfa378352024-02-01 22:05:27 +0100150diff({fromlist}, {tolist} [, {options}])
151 List diff two Lists of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000152diff_filler({lnum}) Number diff filler lines about {lnum}
153diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
154digraph_get({chars}) String get the |digraph| of {chars}
155digraph_getlist([{listall}]) List get all |digraph|s
156digraph_set({chars}, {digraph}) Boolean register |digraph|
157digraph_setlist({digraphlist}) Boolean register multiple |digraph|s
158echoraw({expr}) none output {expr} as-is
159empty({expr}) Number |TRUE| if {expr} is empty
160environ() Dict return environment variables
Sean Dewarb0efa492023-07-08 10:35:19 +0100161err_teapot([{expr}]) none give E418, or E503 if {expr} is |TRUE|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000162escape({string}, {chars}) String escape {chars} in {string} with '\'
163eval({string}) any evaluate {string} into its value
164eventhandler() Number |TRUE| if inside an event handler
165executable({expr}) Number 1 if executable {expr} exists
166execute({command}) String execute {command} and get the output
167exepath({expr}) String full path of the command {expr}
168exists({expr}) Number |TRUE| if {expr} exists
169exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
170exp({expr}) Float exponential of {expr}
171expand({expr} [, {nosuf} [, {list}]])
172 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100173expandcmd({string} [, {options}])
174 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000175extend({expr1}, {expr2} [, {expr3}])
176 List/Dict insert items of {expr2} into {expr1}
177extendnew({expr1}, {expr2} [, {expr3}])
178 List/Dict like |extend()| but creates a new
179 List or Dictionary
180feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
Shougo Matsushita60c87432024-06-03 22:59:27 +0200181filecopy({from}, {to}) Number |TRUE| if copying file {from} to {to}
182 worked
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000183filereadable({file}) Number |TRUE| if {file} is a readable file
184filewritable({file}) Number |TRUE| if {file} is a writable file
185filter({expr1}, {expr2}) List/Dict/Blob/String
186 remove items from {expr1} where
187 {expr2} is 0
188finddir({name} [, {path} [, {count}]])
189 String find directory {name} in {path}
190findfile({name} [, {path} [, {count}]])
191 String find file {name} in {path}
192flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
193flattennew({list} [, {maxdepth}])
194 List flatten a copy of {list}
195float2nr({expr}) Number convert Float {expr} to a Number
196floor({expr}) Float round {expr} down
197fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
198fnameescape({fname}) String escape special characters in {fname}
199fnamemodify({fname}, {mods}) String modify file name
200foldclosed({lnum}) Number first line of fold at {lnum} if closed
201foldclosedend({lnum}) Number last line of fold at {lnum} if closed
202foldlevel({lnum}) Number fold level at {lnum}
203foldtext() String line displayed for closed fold
204foldtextresult({lnum}) String text for closed fold at {lnum}
Ernie Raele79e2072024-01-13 11:47:33 +0100205foreach({expr1}, {expr2}) List/Dict/Blob/String
206 for each item in {expr1} call {expr2}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000207foreground() Number bring the Vim window to the foreground
Bram Moolenaaraa534142022-09-15 21:46:02 +0100208fullcommand({name} [, {vim9}]) String get full command from {name}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000209funcref({name} [, {arglist}] [, {dict}])
210 Funcref reference to function {name}
211function({name} [, {arglist}] [, {dict}])
212 Funcref named reference to function {name}
213garbagecollect([{atexit}]) none free memory, breaking cyclic references
214get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
215get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
216get({func}, {what}) any get property of funcref/partial {func}
217getbufinfo([{buf}]) List information about buffers
218getbufline({buf}, {lnum} [, {end}])
219 List lines {lnum} to {end} of buffer {buf}
Bram Moolenaarce30ccc2022-11-21 19:57:04 +0000220getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000221getbufvar({buf}, {varname} [, {def}])
222 any variable {varname} in buffer {buf}
Kota Kato66bb9ae2023-01-17 18:31:56 +0000223getcellwidths() List get character cell width overrides
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000224getchangelist([{buf}]) List list of change list items
Doug Kearns9cd9e752024-04-07 17:42:17 +0200225getchar([{expr}]) Number or String
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000226 get one character from the user
227getcharmod() Number modifiers for the last typed character
228getcharpos({expr}) List position of cursor, mark, etc.
229getcharsearch() Dict last character search
Doug Kearns9cd9e752024-04-07 17:42:17 +0200230getcharstr([{expr}]) String get one character from the user
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100231getcmdcompltype() String return the type of the current
232 command-line completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000233getcmdline() String return the current command-line
234getcmdpos() Number return cursor position in command-line
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100235getcmdscreenpos() Number return cursor screen position in
236 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000237getcmdtype() String return current command-line type
238getcmdwintype() String return current command-line window type
239getcompletion({pat}, {type} [, {filtered}])
240 List list of cmdline completion matches
241getcurpos([{winnr}]) List position of the cursor
242getcursorcharpos([{winnr}]) List character position of the cursor
243getcwd([{winnr} [, {tabnr}]]) String get the current working directory
244getenv({name}) String return environment variable
245getfontname([{name}]) String name of font being used
246getfperm({fname}) String file permissions of file {fname}
247getfsize({fname}) Number size in bytes of file {fname}
248getftime({fname}) Number last modification time of file
249getftype({fname}) String description of type of file {fname}
250getimstatus() Number |TRUE| if the IME status is active
251getjumplist([{winnr} [, {tabnr}]])
252 List list of jump list items
253getline({lnum}) String line {lnum} of current buffer
254getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
255getloclist({nr}) List list of location list items
256getloclist({nr}, {what}) Dict get specific location list properties
257getmarklist([{buf}]) List list of global/local marks
258getmatches([{win}]) List list of current matches
259getmousepos() Dict last known mouse position
Bram Moolenaar24dc19c2022-11-14 19:49:15 +0000260getmouseshape() String current mouse shape name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000261getpid() Number process ID of Vim
262getpos({expr}) List position of cursor, mark, etc.
263getqflist() List list of quickfix items
264getqflist({what}) Dict get specific quickfix list properties
265getreg([{regname} [, 1 [, {list}]]])
266 String or List contents of a register
267getreginfo([{regname}]) Dict information about a register
Shougo Matsushita19b71882024-02-28 22:48:12 +0100268getregion({pos1}, {pos2} [, {opts}])
Shougo Matsushita3f905ab2024-02-21 00:02:45 +0100269 List get the text from {pos1} to {pos2}
Shougo Matsushitab4757e62024-05-07 20:49:24 +0200270getregionpos({pos1}, {pos2} [, {opts}])
271 List get a list of positions for a region
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000272getregtype([{regname}]) String type of a register
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +0100273getscriptinfo([{opts}]) List list of sourced scripts
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000274gettabinfo([{expr}]) List list of tab pages
275gettabvar({nr}, {varname} [, {def}])
276 any variable {varname} in tab {nr} or {def}
277gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
278 any {name} in {winnr} in tab page {tabnr}
279gettagstack([{nr}]) Dict get the tag stack of window {nr}
280gettext({text}) String lookup translation of {text}
281getwininfo([{winid}]) List list of info about each window
Bram Moolenaar938ae282023-02-20 20:44:55 +0000282getwinpos([{timeout}]) List X and Y coord in pixels of Vim window
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000283getwinposx() Number X coord in pixels of the Vim window
284getwinposy() Number Y coord in pixels of the Vim window
285getwinvar({nr}, {varname} [, {def}])
286 any variable {varname} in window {nr}
287glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
288 any expand file wildcards in {expr}
289glob2regpat({expr}) String convert a glob pat into a search pat
290globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
291 String do glob({expr}) for all dirs in {path}
292has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
293has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
294haslocaldir([{winnr} [, {tabnr}]])
295 Number |TRUE| if the window executed |:lcd|
296 or |:tcd|
297hasmapto({what} [, {mode} [, {abbr}]])
298 Number |TRUE| if mapping to {what} exists
299histadd({history}, {item}) Number add an item to a history
300histdel({history} [, {item}]) Number remove an item from a history
301histget({history} [, {index}]) String get the item {index} from a history
302histnr({history}) Number highest index of a history
303hlID({name}) Number syntax ID of highlight group {name}
304hlexists({name}) Number |TRUE| if highlight group {name} exists
305hlget([{name} [, {resolve}]]) List get highlight group attributes
306hlset({list}) Number set highlight group attributes
307hostname() String name of the machine Vim is running on
308iconv({expr}, {from}, {to}) String convert encoding of {expr}
309indent({lnum}) Number indent of line {lnum}
310index({object}, {expr} [, {start} [, {ic}]])
311 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100312indexof({object}, {expr} [, {opts}]])
313 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000314input({prompt} [, {text} [, {completion}]])
315 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100316inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000317 String like input() but in a GUI dialog
318inputlist({textlist}) Number let the user pick from a choice list
319inputrestore() Number restore typeahead
320inputsave() Number save and clear typeahead
321inputsecret({prompt} [, {text}]) String like input() but hiding the text
322insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
LemonBoyafe04662023-08-23 21:08:11 +0200323instanceof({object}, {class}) Number |TRUE| if {object} is an instance of {class}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000324interrupt() none interrupt script execution
325invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100326isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000327isdirectory({directory}) Number |TRUE| if {directory} is a directory
328isinf({expr}) Number determine if {expr} is infinity value
329 (positive or negative)
330islocked({expr}) Number |TRUE| if {expr} is locked
331isnan({expr}) Number |TRUE| if {expr} is NaN
332items({dict}) List key-value pairs in {dict}
333job_getchannel({job}) Channel get the channel handle for {job}
334job_info([{job}]) Dict get information about {job}
335job_setoptions({job}, {options}) none set options for {job}
336job_start({command} [, {options}])
337 Job start a job
338job_status({job}) String get the status of {job}
339job_stop({job} [, {how}]) Number stop {job}
340join({list} [, {sep}]) String join {list} items into one String
341js_decode({string}) any decode JS style JSON
342js_encode({expr}) String encode JS style JSON
343json_decode({string}) any decode JSON
344json_encode({expr}) String encode JSON
345keys({dict}) List keys in {dict}
zeertzjqcdc83932022-09-12 13:38:41 +0100346keytrans({string}) String translate internal keycodes to a form
347 that can be used by |:map|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000348len({expr}) Number the length of {expr}
349libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
350libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
351line({expr} [, {winid}]) Number line nr of cursor, last line or mark
352line2byte({lnum}) Number byte count of line {lnum}
353lispindent({lnum}) Number Lisp indent for line {lnum}
354list2blob({list}) Blob turn {list} of numbers into a Blob
355list2str({list} [, {utf8}]) String turn {list} of numbers into a String
356listener_add({callback} [, {buf}])
357 Number add a callback to listen to changes
358listener_flush([{buf}]) none invoke listener callbacks
359listener_remove({id}) none remove a listener callback
360localtime() Number current time
361log({expr}) Float natural logarithm (base e) of {expr}
362log10({expr}) Float logarithm of Float {expr} to base 10
363luaeval({expr} [, {expr}]) any evaluate |Lua| expression
364map({expr1}, {expr2}) List/Dict/Blob/String
365 change each item in {expr1} to {expr2}
366maparg({name} [, {mode} [, {abbr} [, {dict}]]])
367 String or Dict
368 rhs of mapping {name} in mode {mode}
369mapcheck({name} [, {mode} [, {abbr}]])
370 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100371maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000372mapnew({expr1}, {expr2}) List/Dict/Blob/String
373 like |map()| but creates a new List or
374 Dictionary
375mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
376match({expr}, {pat} [, {start} [, {count}]])
377 Number position where {pat} matches in {expr}
378matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
379 Number highlight {pattern} with {group}
380matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
381 Number highlight positions with {group}
382matcharg({nr}) List arguments of |:match|
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100383matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict})
384 List all the {pat} matches in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000385matchdelete({id} [, {win}]) Number delete match identified by {id}
386matchend({expr}, {pat} [, {start} [, {count}]])
387 Number position where {pat} ends in {expr}
388matchfuzzy({list}, {str} [, {dict}])
389 List fuzzy match {str} in {list}
390matchfuzzypos({list}, {str} [, {dict}])
391 List fuzzy match {str} in {list}
392matchlist({expr}, {pat} [, {start} [, {count}]])
393 List match and submatches of {pat} in {expr}
394matchstr({expr}, {pat} [, {start} [, {count}]])
395 String {count}'th match of {pat} in {expr}
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100396matchstrlist({list}, {pat} [, {dict})
397 List all the {pat} matches in {list}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000398matchstrpos({expr}, {pat} [, {start} [, {count}]])
399 List {count}'th match of {pat} in {expr}
400max({expr}) Number maximum value of items in {expr}
401menu_info({name} [, {mode}]) Dict get menu item information
402min({expr}) Number minimum value of items in {expr}
Bram Moolenaar938ae282023-02-20 20:44:55 +0000403mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000404 Number create directory {name}
Doug Kearns9cd9e752024-04-07 17:42:17 +0200405mode([{expr}]) String current editing mode
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000406mzeval({expr}) any evaluate |MzScheme| expression
407nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
408nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
409or({expr}, {expr}) Number bitwise OR
410pathshorten({expr} [, {len}]) String shorten directory names in a path
411perleval({expr}) any evaluate |Perl| expression
412popup_atcursor({what}, {options}) Number create popup window near the cursor
413popup_beval({what}, {options}) Number create popup window for 'ballooneval'
414popup_clear() none close all popup windows
415popup_close({id} [, {result}]) none close popup window {id}
416popup_create({what}, {options}) Number create a popup window
417popup_dialog({what}, {options}) Number create a popup window used as a dialog
418popup_filter_menu({id}, {key}) Number filter for a menu popup window
419popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100420popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000421popup_findinfo() Number get window ID of info popup window
422popup_findpreview() Number get window ID of preview popup window
423popup_getoptions({id}) Dict get options of popup window {id}
424popup_getpos({id}) Dict get position of popup window {id}
425popup_hide({id}) none hide popup menu {id}
426popup_list() List get a list of window IDs of all popups
427popup_locate({row}, {col}) Number get window ID of popup at position
428popup_menu({what}, {options}) Number create a popup window used as a menu
429popup_move({id}, {options}) none set position of popup window {id}
430popup_notification({what}, {options})
431 Number create a notification popup window
432popup_setoptions({id}, {options})
433 none set options for popup window {id}
434popup_settext({id}, {text}) none set the text of popup window {id}
435popup_show({id}) none unhide popup window {id}
436pow({x}, {y}) Float {x} to the power of {y}
437prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
438printf({fmt}, {expr1}...) String format text
439prompt_getprompt({buf}) String get prompt text
440prompt_setcallback({buf}, {expr}) none set prompt callback function
441prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
442prompt_setprompt({buf}, {text}) none set prompt text
443prop_add({lnum}, {col}, {props}) none add one text property
444prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
445 none add multiple text properties
446prop_clear({lnum} [, {lnum-end} [, {props}]])
447 none remove all text properties
448prop_find({props} [, {direction}])
449 Dict search for a text property
450prop_list({lnum} [, {props}]) List text properties in {lnum}
451prop_remove({props} [, {lnum} [, {lnum-end}]])
452 Number remove a text property
453prop_type_add({name}, {props}) none define a new property type
454prop_type_change({name}, {props})
455 none change an existing property type
456prop_type_delete({name} [, {props}])
457 none delete a property type
458prop_type_get({name} [, {props}])
459 Dict get property type values
460prop_type_list([{props}]) List get list of property types
461pum_getpos() Dict position and size of pum if visible
462pumvisible() Number whether popup menu is visible
463py3eval({expr}) any evaluate |python3| expression
464pyeval({expr}) any evaluate |Python| expression
465pyxeval({expr}) any evaluate |python_x| expression
466rand([{expr}]) Number get pseudo-random number
467range({expr} [, {max} [, {stride}]])
468 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100469readblob({fname} [, {offset} [, {size}]])
470 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000471readdir({dir} [, {expr} [, {dict}]])
472 List file names in {dir} selected by {expr}
473readdirex({dir} [, {expr} [, {dict}]])
474 List file info in {dir} selected by {expr}
475readfile({fname} [, {type} [, {max}]])
476 List get list of lines from file {fname}
477reduce({object}, {func} [, {initial}])
478 any reduce {object} using {func}
479reg_executing() String get the executing register name
480reg_recording() String get the recording register name
481reltime([{start} [, {end}]]) List get time value
482reltimefloat({time}) Float turn the time value into a Float
483reltimestr({time}) String turn time value into a String
484remote_expr({server}, {string} [, {idvar} [, {timeout}]])
485 String send expression
486remote_foreground({server}) Number bring Vim server to the foreground
487remote_peek({serverid} [, {retvar}])
488 Number check for reply string
489remote_read({serverid} [, {timeout}])
490 String read reply string
491remote_send({server}, {string} [, {idvar}])
492 String send key sequence
493remote_startserver({name}) none become server {name}
494remove({list}, {idx} [, {end}]) any/List
495 remove items {idx}-{end} from {list}
496remove({blob}, {idx} [, {end}]) Number/Blob
497 remove bytes {idx}-{end} from {blob}
498remove({dict}, {key}) any remove entry {key} from {dict}
499rename({from}, {to}) Number rename (move) file from {from} to {to}
Bakudankun375141e2022-09-09 18:46:47 +0100500repeat({expr}, {count}) List/Blob/String
501 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000502resolve({filename}) String get filename a shortcut points to
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +0100503reverse({obj}) List/Blob/String
504 reverse {obj}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000505round({expr}) Float round off {expr}
506rubyeval({expr}) any evaluate |Ruby| expression
507screenattr({row}, {col}) Number attribute at screen position
508screenchar({row}, {col}) Number character at screen position
509screenchars({row}, {col}) List List of characters at screen position
510screencol() Number current cursor column
511screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
512screenrow() Number current cursor row
513screenstring({row}, {col}) String characters at screen position
514search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
515 Number search for {pattern}
516searchcount([{options}]) Dict get or update search stats
517searchdecl({name} [, {global} [, {thisblock}]])
518 Number search for variable declaration
519searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
520 Number search for other end of start/end pair
521searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
522 List search for other end of start/end pair
523searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
524 List search for {pattern}
525server2client({clientid}, {string})
526 Number send reply string
527serverlist() String get a list of available servers
528setbufline({expr}, {lnum}, {text})
529 Number set line {lnum} to {text} in buffer
530 {expr}
531setbufvar({buf}, {varname}, {val})
532 none set {varname} in buffer {buf} to {val}
533setcellwidths({list}) none set character cell width overrides
534setcharpos({expr}, {list}) Number set the {expr} position to {list}
535setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100536setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000537setcmdpos({pos}) Number set cursor position in command-line
538setcursorcharpos({list}) Number move cursor to position in {list}
539setenv({name}, {val}) none set environment variable
540setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
541setline({lnum}, {line}) Number set line {lnum} to {line}
542setloclist({nr}, {list} [, {action}])
543 Number modify location list using {list}
544setloclist({nr}, {list}, {action}, {what})
545 Number modify specific location list props
546setmatches({list} [, {win}]) Number restore a list of matches
547setpos({expr}, {list}) Number set the {expr} position to {list}
548setqflist({list} [, {action}]) Number modify quickfix list using {list}
549setqflist({list}, {action}, {what})
550 Number modify specific quickfix list props
551setreg({n}, {v} [, {opt}]) Number set register to value and type
552settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
553settabwinvar({tabnr}, {winnr}, {varname}, {val})
554 none set {varname} in window {winnr} in tab
555 page {tabnr} to {val}
556settagstack({nr}, {dict} [, {action}])
557 Number modify tag stack using {dict}
558setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
559sha256({string}) String SHA256 checksum of {string}
560shellescape({string} [, {special}])
561 String escape {string} for use as shell
562 command argument
563shiftwidth([{col}]) Number effective value of 'shiftwidth'
564sign_define({name} [, {dict}]) Number define or update a sign
565sign_define({list}) List define or update a list of signs
566sign_getdefined([{name}]) List get a list of defined signs
567sign_getplaced([{buf} [, {dict}]])
568 List get a list of placed signs
569sign_jump({id}, {group}, {buf})
570 Number jump to a sign
571sign_place({id}, {group}, {name}, {buf} [, {dict}])
572 Number place a sign
573sign_placelist({list}) List place a list of signs
574sign_undefine([{name}]) Number undefine a sign
575sign_undefine({list}) List undefine a list of signs
576sign_unplace({group} [, {dict}])
577 Number unplace a sign
578sign_unplacelist({list}) List unplace a list of signs
579simplify({filename}) String simplify filename as much as possible
580sin({expr}) Float sine of {expr}
581sinh({expr}) Float hyperbolic sine of {expr}
582slice({expr}, {start} [, {end}]) String, List or Blob
583 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000584sort({list} [, {how} [, {dict}]])
585 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000586sound_clear() none stop playing all sounds
587sound_playevent({name} [, {callback}])
588 Number play an event sound
589sound_playfile({path} [, {callback}])
590 Number play sound file {path}
591sound_stop({id}) none stop playing sound {id}
592soundfold({word}) String sound-fold {word}
593spellbadword() String badly spelled word at cursor
594spellsuggest({word} [, {max} [, {capital}]])
595 List spelling suggestions
596split({expr} [, {pat} [, {keepempty}]])
597 List make |List| from {pat} separated {expr}
598sqrt({expr}) Float square root of {expr}
599srand([{expr}]) List get seed for |rand()|
600state([{what}]) String current state of Vim
601str2float({expr} [, {quoted}]) Float convert String to Float
602str2list({expr} [, {utf8}]) List convert each character of {expr} to
603 ASCII/UTF-8 value
604str2nr({expr} [, {base} [, {quoted}]])
605 Number convert String to Number
606strcharlen({expr}) Number character length of the String {expr}
607strcharpart({str}, {start} [, {len} [, {skipcc}]])
608 String {len} characters of {str} at
609 character {start}
610strchars({expr} [, {skipcc}]) Number character count of the String {expr}
611strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
612strftime({format} [, {time}]) String format time with a specified format
613strgetchar({str}, {index}) Number get char {index} from {str}
614stridx({haystack}, {needle} [, {start}])
615 Number index of {needle} in {haystack}
616string({expr}) String String representation of {expr} value
617strlen({expr}) Number length of the String {expr}
618strpart({str}, {start} [, {len} [, {chars}]])
619 String {len} bytes/chars of {str} at
620 byte {start}
621strptime({format}, {timestring})
622 Number Convert {timestring} to unix timestamp
623strridx({haystack}, {needle} [, {start}])
624 Number last index of {needle} in {haystack}
625strtrans({expr}) String translate string to make it printable
Christian Brabandt67672ef2023-04-24 21:09:54 +0100626strutf16len({string} [, {countcc}])
627 Number number of UTF-16 code units in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000628strwidth({expr}) Number display cell length of the String {expr}
629submatch({nr} [, {list}]) String or List
630 specific match in ":s" or substitute()
631substitute({expr}, {pat}, {sub}, {flags})
632 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000633swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000634swapinfo({fname}) Dict information about swap file {fname}
635swapname({buf}) String swap file of buffer {buf}
636synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
637synIDattr({synID}, {what} [, {mode}])
638 String attribute {what} of syntax ID {synID}
639synIDtrans({synID}) Number translated syntax ID of {synID}
640synconcealed({lnum}, {col}) List info about concealing
641synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
642system({expr} [, {input}]) String output of shell command/filter {expr}
643systemlist({expr} [, {input}]) List output of shell command/filter {expr}
644tabpagebuflist([{arg}]) List list of buffer numbers in tab page
645tabpagenr([{arg}]) Number number of current or last tab page
646tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
647tagfiles() List tags files used
648taglist({expr} [, {filename}]) List list of tags matching {expr}
649tan({expr}) Float tangent of {expr}
650tanh({expr}) Float hyperbolic tangent of {expr}
651tempname() String name for a temporary file
652term_dumpdiff({filename}, {filename} [, {options}])
653 Number display difference between two dumps
654term_dumpload({filename} [, {options}])
655 Number displaying a screen dump
656term_dumpwrite({buf}, {filename} [, {options}])
657 none dump terminal window contents
658term_getaltscreen({buf}) Number get the alternate screen flag
659term_getansicolors({buf}) List get ANSI palette in GUI color mode
660term_getattr({attr}, {what}) Number get the value of attribute {what}
661term_getcursor({buf}) List get the cursor position of a terminal
662term_getjob({buf}) Job get the job associated with a terminal
663term_getline({buf}, {row}) String get a line of text from a terminal
664term_getscrolled({buf}) Number get the scroll count of a terminal
665term_getsize({buf}) List get the size of a terminal
666term_getstatus({buf}) String get the status of a terminal
667term_gettitle({buf}) String get the title of a terminal
668term_gettty({buf}, [{input}]) String get the tty name of a terminal
669term_list() List get the list of terminal buffers
670term_scrape({buf}, {row}) List get row of a terminal screen
671term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
672term_setansicolors({buf}, {colors})
673 none set ANSI palette in GUI color mode
674term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
675term_setkill({buf}, {how}) none set signal to stop job in terminal
676term_setrestore({buf}, {command}) none set command to restore terminal
677term_setsize({buf}, {rows}, {cols})
678 none set the size of a terminal
679term_start({cmd} [, {options}]) Number open a terminal window and run a job
680term_wait({buf} [, {time}]) Number wait for screen to be updated
681terminalprops() Dict properties of the terminal
682test_alloc_fail({id}, {countdown}, {repeat})
683 none make memory allocation fail
684test_autochdir() none enable 'autochdir' during startup
685test_feedinput({string}) none add key sequence to input buffer
686test_garbagecollect_now() none free memory right now for testing
687test_garbagecollect_soon() none free memory soon for testing
688test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000689test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000690test_ignore_error({expr}) none ignore a specific error
Christopher Plewright20b795e2022-12-20 20:01:58 +0000691test_mswin_event({event}, {args})
692 bool generate MS-Windows event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000693test_null_blob() Blob null value for testing
694test_null_channel() Channel null value for testing
695test_null_dict() Dict null value for testing
696test_null_function() Funcref null value for testing
697test_null_job() Job null value for testing
698test_null_list() List null value for testing
699test_null_partial() Funcref null value for testing
700test_null_string() String null value for testing
701test_option_not_set({name}) none reset flag indicating option was set
702test_override({expr}, {val}) none test with Vim internal overrides
703test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000704test_setmouse({row}, {col}) none set the mouse position for testing
705test_settime({expr}) none set current time for testing
Doug Kearns9cd9e752024-04-07 17:42:17 +0200706test_srand_seed([{seed}]) none set seed for testing srand()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000707test_unknown() any unknown value for testing
708test_void() any void value for testing
709timer_info([{id}]) List information about timers
710timer_pause({id}, {pause}) none pause or unpause a timer
711timer_start({time}, {callback} [, {options}])
712 Number create a timer
713timer_stop({timer}) none stop a timer
714timer_stopall() none stop all timers
715tolower({expr}) String the String {expr} switched to lowercase
716toupper({expr}) String the String {expr} switched to uppercase
717tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
718 to chars in {tostr}
719trim({text} [, {mask} [, {dir}]])
720 String trim characters in {mask} from {text}
721trunc({expr}) Float truncate Float {expr}
722type({expr}) Number type of value {expr}
723typename({expr}) String representation of the type of {expr}
724undofile({name}) String undo file name for {name}
Devin J. Pohly5fee1112023-04-23 20:26:59 -0500725undotree([{buf}]) List undo file tree for buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000726uniq({list} [, {func} [, {dict}]])
727 List remove adjacent duplicates from a list
Christian Brabandt67672ef2023-04-24 21:09:54 +0100728utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
729 Number UTF-16 index of byte {idx} in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000730values({dict}) List values in {dict}
zeertzjq825cf812023-08-17 22:55:25 +0200731virtcol({expr} [, {list} [, {winid}])
732 Number or List
LemonBoy0f7a3e12022-05-26 12:10:37 +0100733 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100734virtcol2col({winid}, {lnum}, {col})
735 Number byte index of a character on screen
Doug Kearns9cd9e752024-04-07 17:42:17 +0200736visualmode([{expr}]) String last visual mode used
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000737wildmenumode() Number whether 'wildmenu' mode is active
738win_execute({id}, {command} [, {silent}])
739 String execute {command} in window {id}
740win_findbuf({bufnr}) List find windows containing {bufnr}
741win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
742win_gettype([{nr}]) String type of window {nr}
743win_gotoid({expr}) Number go to window with ID {expr}
744win_id2tabwin({expr}) List get tab and window nr from window ID
745win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000746win_move_separator({nr}) Number move window vertical separator
747win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000748win_screenpos({nr}) List get screen position of window {nr}
749win_splitmove({nr}, {target} [, {options}])
750 Number move window {nr} to split of {target}
751winbufnr({nr}) Number buffer number of window {nr}
752wincol() Number window column of the cursor
753windowsversion() String MS-Windows OS version
754winheight({nr}) Number height of window {nr}
755winlayout([{tabnr}]) List layout of windows in tab {tabnr}
756winline() Number window line of the cursor
757winnr([{expr}]) Number number of current window
758winrestcmd() String returns command to restore window sizes
759winrestview({dict}) none restore view of current window
760winsaveview() Dict save view of current window
761winwidth({nr}) Number width of window {nr}
762wordcount() Dict get byte/char/word statistics
763writefile({object}, {fname} [, {flags}])
764 Number write |Blob| or |List| of lines to file
765xor({expr}, {expr}) Number bitwise XOR
766
767==============================================================================
7682. Details *builtin-function-details*
769
770Not all functions are here, some have been moved to a help file covering the
771specific functionality.
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200772Return type specifies the type for |Vim9-script|, see |vim9-types|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000773
774abs({expr}) *abs()*
775 Return the absolute value of {expr}. When {expr} evaluates to
776 a |Float| abs() returns a |Float|. When {expr} can be
777 converted to a |Number| abs() returns a |Number|. Otherwise
778 abs() gives an error message and returns -1.
779 Examples: >
780 echo abs(1.456)
781< 1.456 >
782 echo abs(-5.456)
783< 5.456 >
784 echo abs(-4)
785< 4
786
787 Can also be used as a |method|: >
788 Compute()->abs()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200789<
790 Return type: |Number| or |Float| depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000791
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000792
793acos({expr}) *acos()*
794 Return the arc cosine of {expr} measured in radians, as a
795 |Float| in the range of [0, pi].
796 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100797 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000798 Examples: >
799 :echo acos(0)
800< 1.570796 >
801 :echo acos(-0.5)
802< 2.094395
803
804 Can also be used as a |method|: >
805 Compute()->acos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200806<
807 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000808
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000809
810add({object}, {expr}) *add()*
811 Append the item {expr} to |List| or |Blob| {object}. Returns
812 the resulting |List| or |Blob|. Examples: >
813 :let alist = add([1, 2, 3], item)
814 :call add(mylist, "woodstock")
815< Note that when {expr} is a |List| it is appended as a single
816 item. Use |extend()| to concatenate |Lists|.
817 When {object} is a |Blob| then {expr} must be a number.
818 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100819 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000820
821 Can also be used as a |method|: >
822 mylist->add(val1)->add(val2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200823<
824 Return type: list<{type}> (depending on the given |List|) or
825 |Blob|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000826
827
828and({expr}, {expr}) *and()*
829 Bitwise AND on the two arguments. The arguments are converted
830 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100831 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000832 Example: >
833 :let flag = and(bits, 0x80)
834< Can also be used as a |method|: >
835 :let flag = bits->and(0x80)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200836<
837 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000838
839
840append({lnum}, {text}) *append()*
841 When {text} is a |List|: Append each item of the |List| as a
842 text line below line {lnum} in the current buffer.
843 Otherwise append {text} as one text line below line {lnum} in
844 the current buffer.
845 Any type of item is accepted and converted to a String.
846 {lnum} can be zero to insert a line before the first one.
847 {lnum} is used like with |getline()|.
848 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000849 0 for success. When {text} is an empty list zero is returned,
850 no matter the value of {lnum}.
851 In |Vim9| script an invalid argument or negative number
852 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000853 :let failed = append(line('$'), "# THE END")
854 :let failed = append(0, ["Chapter 1", "the beginning"])
855
856< Can also be used as a |method| after a List, the base is
857 passed as the second argument: >
858 mylist->append(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200859<
860 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000861
862
863appendbufline({buf}, {lnum}, {text}) *appendbufline()*
864 Like |append()| but append the text in buffer {buf}.
865
866 This function works only for loaded buffers. First call
867 |bufload()| if needed.
868
869 For the use of {buf}, see |bufname()|.
870
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000871 {lnum} is the line number to append below. Note that using
872 |line()| would use the current buffer, not the one appending
873 to. Use "$" to append at the end of the buffer. Other string
874 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000875
876 On success 0 is returned, on failure 1 is returned.
877 In |Vim9| script an error is given for an invalid {lnum}.
878
879 If {buf} is not a valid buffer or {lnum} is not valid, an
880 error message is given. Example: >
881 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000882< However, when {text} is an empty list then no error is given
883 for an invalid {lnum}, since {lnum} isn't actually used.
884
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000885 Can also be used as a |method| after a List, the base is
886 passed as the second argument: >
887 mylist->appendbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200888<
889 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000890
891
892argc([{winid}]) *argc()*
893 The result is the number of files in the argument list. See
894 |arglist|.
895 If {winid} is not supplied, the argument list of the current
896 window is used.
897 If {winid} is -1, the global argument list is used.
898 Otherwise {winid} specifies the window of which the argument
899 list is used: either the window number or the window ID.
900 Returns -1 if the {winid} argument is invalid.
901
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200902 Return type: |Number|
903
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000904 *argidx()*
905argidx() The result is the current index in the argument list. 0 is
906 the first file. argc() - 1 is the last one. See |arglist|.
907
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200908 Return type: |Number|
909
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000910 *arglistid()*
911arglistid([{winnr} [, {tabnr}]])
912 Return the argument list ID. This is a number which
913 identifies the argument list being used. Zero is used for the
914 global argument list. See |arglist|.
915 Returns -1 if the arguments are invalid.
916
917 Without arguments use the current window.
918 With {winnr} only use this window in the current tab page.
919 With {winnr} and {tabnr} use the window in the specified tab
920 page.
921 {winnr} can be the window number or the |window-ID|.
922
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200923 Return type: |Number|
924
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000925 *argv()*
926argv([{nr} [, {winid}]])
927 The result is the {nr}th file in the argument list. See
928 |arglist|. "argv(0)" is the first one. Example: >
929 :let i = 0
930 :while i < argc()
931 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000932 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000933 : let i = i + 1
934 :endwhile
935< Without the {nr} argument, or when {nr} is -1, a |List| with
936 the whole |arglist| is returned.
937
938 The {winid} argument specifies the window ID, see |argc()|.
939 For the Vim command line arguments see |v:argv|.
940
Bram Moolenaar016188f2022-06-06 20:52:59 +0100941 Returns an empty string if {nr}th argument is not present in
942 the argument list. Returns an empty List if the {winid}
943 argument is invalid.
944
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200945 Return type: |String|
946
947
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000948asin({expr}) *asin()*
949 Return the arc sine of {expr} measured in radians, as a |Float|
950 in the range of [-pi/2, pi/2].
951 {expr} must evaluate to a |Float| or a |Number| in the range
952 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100953 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
954 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000955 Examples: >
956 :echo asin(0.8)
957< 0.927295 >
958 :echo asin(-0.5)
959< -0.523599
960
961 Can also be used as a |method|: >
962 Compute()->asin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200963<
964 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000965
966assert_ functions are documented here: |assert-functions-details|
967
968
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000969atan({expr}) *atan()*
970 Return the principal value of the arc tangent of {expr}, in
971 the range [-pi/2, +pi/2] radians, as a |Float|.
972 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100973 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000974 Examples: >
975 :echo atan(100)
976< 1.560797 >
977 :echo atan(-4.01)
978< -1.326405
979
980 Can also be used as a |method|: >
981 Compute()->atan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200982<
983 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000984
985
986atan2({expr1}, {expr2}) *atan2()*
987 Return the arc tangent of {expr1} / {expr2}, measured in
988 radians, as a |Float| in the range [-pi, pi].
989 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100990 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
991 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000992 Examples: >
993 :echo atan2(-1, 1)
994< -0.785398 >
995 :echo atan2(1, -1)
996< 2.356194
997
998 Can also be used as a |method|: >
999 Compute()->atan2(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001000<
1001 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001002
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001003
1004autocmd_add({acmds}) *autocmd_add()*
1005 Adds a List of autocmds and autocmd groups.
1006
1007 The {acmds} argument is a List where each item is a Dict with
1008 the following optional items:
1009 bufnr buffer number to add a buffer-local autocmd.
1010 If this item is specified, then the "pattern"
1011 item is ignored.
1012 cmd Ex command to execute for this autocmd event
1013 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001014 This can be either a String with a single
1015 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001016 group autocmd group name. Refer to |autocmd-groups|.
1017 If this group doesn't exist then it is
1018 created. If not specified or empty, then the
1019 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001020 nested boolean flag, set to v:true to add a nested
1021 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +01001022 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001023 which executes only once. Refer to
1024 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001025 pattern autocmd pattern string. Refer to
1026 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001027 present, then this item is ignored. This can
1028 be a String with a single pattern or a List of
1029 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001030 replace boolean flag, set to v:true to remove all the
1031 commands associated with the specified autocmd
1032 event and group and add the {cmd}. This is
1033 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +01001034 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001035
1036 Returns v:true on success and v:false on failure.
1037 Examples: >
1038 " Create a buffer-local autocmd for buffer 5
1039 let acmd = {}
1040 let acmd.group = 'MyGroup'
1041 let acmd.event = 'BufEnter'
1042 let acmd.bufnr = 5
1043 let acmd.cmd = 'call BufEnterFunc()'
1044 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00001045<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001046 Can also be used as a |method|: >
1047 GetAutocmdList()->autocmd_add()
1048<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001049 Return type: |vim9-boolean|
1050
1051
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001052autocmd_delete({acmds}) *autocmd_delete()*
1053 Deletes a List of autocmds and autocmd groups.
1054
1055 The {acmds} argument is a List where each item is a Dict with
1056 the following optional items:
1057 bufnr buffer number to delete a buffer-local autocmd.
1058 If this item is specified, then the "pattern"
1059 item is ignored.
1060 cmd Ex command for this autocmd event
1061 event autocmd event name. Refer to |autocmd-events|.
1062 If '*' then all the autocmd events in this
1063 group are deleted.
1064 group autocmd group name. Refer to |autocmd-groups|.
1065 If not specified or empty, then the default
1066 group is used.
1067 nested set to v:true for a nested autocmd.
1068 Refer to |autocmd-nested|.
1069 once set to v:true for an autocmd which executes
1070 only once. Refer to |autocmd-once|.
1071 pattern autocmd pattern string. Refer to
1072 |autocmd-patterns|. If "bufnr" item is
1073 present, then this item is ignored.
1074
1075 If only {group} is specified in a {acmds} entry and {event},
1076 {pattern} and {cmd} are not specified, then that autocmd group
1077 is deleted.
1078
Bram Moolenaar016188f2022-06-06 20:52:59 +01001079 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001080 Examples: >
1081 " :autocmd! BufLeave *.vim
1082 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1083 call autocmd_delete([acmd]})
1084 " :autocmd! MyGroup1 BufLeave
1085 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1086 call autocmd_delete([acmd])
1087 " :autocmd! MyGroup2 BufEnter *.c
1088 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1089 \ pattern: '*.c'}
1090 " :autocmd! MyGroup2 * *.c
1091 let acmd = #{group: 'MyGroup2', event: '*',
1092 \ pattern: '*.c'}
1093 call autocmd_delete([acmd])
1094 " :autocmd! MyGroup3
1095 let acmd = #{group: 'MyGroup3'}
1096 call autocmd_delete([acmd])
1097<
1098 Can also be used as a |method|: >
1099 GetAutocmdList()->autocmd_delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001100<
1101 Return type: |vim9-boolean|
1102
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001103
1104autocmd_get([{opts}]) *autocmd_get()*
1105 Returns a |List| of autocmds. If {opts} is not supplied, then
1106 returns the autocmds for all the events in all the groups.
1107
1108 The optional {opts} Dict argument supports the following
1109 items:
1110 group Autocmd group name. If specified, returns only
1111 the autocmds defined in this group. If the
1112 specified group doesn't exist, results in an
1113 error message. If set to an empty string,
1114 then the default autocmd group is used.
1115 event Autocmd event name. If specified, returns only
1116 the autocmds defined for this event. If set
1117 to "*", then returns autocmds for all the
1118 events. If the specified event doesn't exist,
1119 results in an error message.
1120 pattern Autocmd pattern. If specified, returns only
1121 the autocmds defined for this pattern.
1122 A combination of the above three times can be supplied in
1123 {opts}.
1124
1125 Each Dict in the returned List contains the following items:
1126 bufnr For buffer-local autocmds, buffer number where
1127 the autocmd is defined.
1128 cmd Command executed for this autocmd.
1129 event Autocmd event name.
1130 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001131 nested Boolean flag, set to v:true for a nested
1132 autocmd. See |autocmd-nested|.
1133 once Boolean flag, set to v:true, if the autocmd
1134 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001135 pattern Autocmd pattern. For a buffer-local
1136 autocmd, this will be of the form "<buffer=n>".
1137 If there are multiple commands for an autocmd event in a
1138 group, then separate items are returned for each command.
1139
Bram Moolenaar016188f2022-06-06 20:52:59 +01001140 Returns an empty List if an autocmd with the specified group
1141 or event or pattern is not found.
1142
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001143 Examples: >
1144 " :autocmd MyGroup
1145 echo autocmd_get(#{group: 'Mygroup'})
1146 " :autocmd G BufUnload
1147 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1148 " :autocmd G * *.ts
1149 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1150 echo autocmd_get(acmd)
1151 " :autocmd Syntax
1152 echo autocmd_get(#{event: 'Syntax'})
1153 " :autocmd G BufEnter *.ts
1154 let acmd = #{group: 'G', event: 'BufEnter',
1155 \ pattern: '*.ts'}
1156 echo autocmd_get(acmd)
1157<
1158 Can also be used as a |method|: >
1159 Getopts()->autocmd_get()
1160<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001161 Return type: list<dict<any>>
1162
1163
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001164balloon_gettext() *balloon_gettext()*
1165 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001166 not used for the List. Returns an empty string if balloon
1167 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001168
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001169 Return type: |String|
1170
1171
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001172balloon_show({expr}) *balloon_show()*
1173 Show {expr} inside the balloon. For the GUI {expr} is used as
1174 a string. For a terminal {expr} can be a list, which contains
1175 the lines of the balloon. If {expr} is not a list it will be
1176 split with |balloon_split()|.
1177 If {expr} is an empty string any existing balloon is removed.
1178
1179 Example: >
1180 func GetBalloonContent()
1181 " ... initiate getting the content
1182 return ''
1183 endfunc
1184 set balloonexpr=GetBalloonContent()
1185
1186 func BalloonCallback(result)
1187 call balloon_show(a:result)
1188 endfunc
1189< Can also be used as a |method|: >
1190 GetText()->balloon_show()
1191<
1192 The intended use is that fetching the content of the balloon
1193 is initiated from 'balloonexpr'. It will invoke an
1194 asynchronous method, in which a callback invokes
1195 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001196 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001197
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001198 When showing a balloon is not possible then nothing happens,
1199 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001200 {only available when compiled with the |+balloon_eval| or
1201 |+balloon_eval_term| feature}
1202
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001203 Return type: |Number|
1204
1205
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001206balloon_split({msg}) *balloon_split()*
1207 Split String {msg} into lines to be displayed in a balloon.
1208 The splits are made for the current window size and optimize
1209 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001210 Returns a |List| with the split lines. Returns an empty List
1211 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001212 Can also be used as a |method|: >
1213 GetText()->balloon_split()->balloon_show()
1214
1215< {only available when compiled with the |+balloon_eval_term|
1216 feature}
1217
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001218 Return type: list<any> or list<string>
1219
1220
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001221blob2list({blob}) *blob2list()*
1222 Return a List containing the number value of each byte in Blob
1223 {blob}. Examples: >
1224 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1225 blob2list(0z) returns []
1226< Returns an empty List on error. |list2blob()| does the
1227 opposite.
1228
1229 Can also be used as a |method|: >
1230 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001231<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001232 Return type: list<any> or list<number>
1233
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001234 *browse()*
1235browse({save}, {title}, {initdir}, {default})
1236 Put up a file requester. This only works when "has("browse")"
1237 returns |TRUE| (only in some GUI versions).
1238 The input fields are:
1239 {save} when |TRUE|, select file to write
1240 {title} title for the requester
1241 {initdir} directory to start browsing in
1242 {default} default file name
1243 An empty string is returned when the "Cancel" button is hit,
1244 something went wrong, or browsing is not possible.
1245
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001246 Return type: |String|
1247
1248
1249browsedir({title}, {initdir}) *browsedir()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001250 Put up a directory requester. This only works when
1251 "has("browse")" returns |TRUE| (only in some GUI versions).
1252 On systems where a directory browser is not supported a file
1253 browser is used. In that case: select a file in the directory
1254 to be used.
1255 The input fields are:
1256 {title} title for the requester
1257 {initdir} directory to start browsing in
1258 When the "Cancel" button is hit, something went wrong, or
1259 browsing is not possible, an empty string is returned.
1260
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001261 Return type: |String|
1262
1263
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001264bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001265 Add a buffer to the buffer list with name {name} (must be a
1266 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001267 If a buffer for file {name} already exists, return that buffer
1268 number. Otherwise return the buffer number of the newly
1269 created buffer. When {name} is an empty string then a new
1270 buffer is always created.
1271 The buffer will not have 'buflisted' set and not be loaded
1272 yet. To add some text to the buffer use this: >
1273 let bufnr = bufadd('someName')
1274 call bufload(bufnr)
1275 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001276< Returns 0 on error.
1277 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001278 let bufnr = 'somename'->bufadd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001279<
1280 Return type: |Number|
1281
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001282
1283bufexists({buf}) *bufexists()*
1284 The result is a Number, which is |TRUE| if a buffer called
1285 {buf} exists.
1286 If the {buf} argument is a number, buffer numbers are used.
1287 Number zero is the alternate buffer for the current window.
1288
1289 If the {buf} argument is a string it must match a buffer name
1290 exactly. The name can be:
1291 - Relative to the current directory.
1292 - A full path.
1293 - The name of a buffer with 'buftype' set to "nofile".
1294 - A URL name.
1295 Unlisted buffers will be found.
1296 Note that help files are listed by their short name in the
1297 output of |:buffers|, but bufexists() requires using their
1298 long name to be able to find them.
1299 bufexists() may report a buffer exists, but to use the name
1300 with a |:buffer| command you may need to use |expand()|. Esp
1301 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1302 Use "bufexists(0)" to test for the existence of an alternate
1303 file name.
1304
1305 Can also be used as a |method|: >
1306 let exists = 'somename'->bufexists()
1307<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001308 Return type: |Number|
1309
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001310 Obsolete name: buffer_exists(). *buffer_exists()*
1311
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001312
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001313buflisted({buf}) *buflisted()*
1314 The result is a Number, which is |TRUE| if a buffer called
1315 {buf} exists and is listed (has the 'buflisted' option set).
1316 The {buf} argument is used like with |bufexists()|.
1317
1318 Can also be used as a |method|: >
1319 let listed = 'somename'->buflisted()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001320<
1321 Return type: |Number|
1322
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001323
1324bufload({buf}) *bufload()*
1325 Ensure the buffer {buf} is loaded. When the buffer name
1326 refers to an existing file then the file is read. Otherwise
1327 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001328 then there is no change. If the buffer is not related to a
Daniel Steinbergc2bd2052023-08-09 12:10:59 -04001329 file then no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001330 If there is an existing swap file for the file of the buffer,
1331 there will be no dialog, the buffer will be loaded anyway.
1332 The {buf} argument is used like with |bufexists()|.
1333
1334 Can also be used as a |method|: >
1335 eval 'somename'->bufload()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001336<
1337 Return type: |Number|
1338
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001339
1340bufloaded({buf}) *bufloaded()*
1341 The result is a Number, which is |TRUE| if a buffer called
1342 {buf} exists and is loaded (shown in a window or hidden).
1343 The {buf} argument is used like with |bufexists()|.
1344
1345 Can also be used as a |method|: >
1346 let loaded = 'somename'->bufloaded()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001347<
1348 Return type: |Number|
1349
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001350
1351bufname([{buf}]) *bufname()*
1352 The result is the name of a buffer. Mostly as it is displayed
1353 by the `:ls` command, but not using special names such as
1354 "[No Name]".
1355 If {buf} is omitted the current buffer is used.
1356 If {buf} is a Number, that buffer number's name is given.
1357 Number zero is the alternate buffer for the current window.
1358 If {buf} is a String, it is used as a |file-pattern| to match
1359 with the buffer names. This is always done like 'magic' is
1360 set and 'cpoptions' is empty. When there is more than one
1361 match an empty string is returned.
1362 "" or "%" can be used for the current buffer, "#" for the
1363 alternate buffer.
1364 A full match is preferred, otherwise a match at the start, end
1365 or middle of the buffer name is accepted. If you only want a
1366 full match then put "^" at the start and "$" at the end of the
1367 pattern.
1368 Listed buffers are found first. If there is a single match
1369 with a listed buffer, that one is returned. Next unlisted
1370 buffers are searched for.
1371 If the {buf} is a String, but you want to use it as a buffer
1372 number, force it to be a Number by adding zero to it: >
1373 :echo bufname("3" + 0)
1374< Can also be used as a |method|: >
1375 echo bufnr->bufname()
1376
1377< If the buffer doesn't exist, or doesn't have a name, an empty
1378 string is returned. >
1379 bufname("#") alternate buffer name
1380 bufname(3) name of buffer 3
1381 bufname("%") name of current buffer
1382 bufname("file2") name of buffer where "file2" matches.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001383<
1384 Return type: |String|
1385 *buffer_name()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001386 Obsolete name: buffer_name().
1387
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001388
1389bufnr([{buf} [, {create}]]) *bufnr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001390 The result is the number of a buffer, as it is displayed by
1391 the `:ls` command. For the use of {buf}, see |bufname()|
1392 above.
1393
1394 If the buffer doesn't exist, -1 is returned. Or, if the
1395 {create} argument is present and TRUE, a new, unlisted,
1396 buffer is created and its number is returned. Example: >
1397 let newbuf = bufnr('Scratch001', 1)
1398< Using an empty name uses the current buffer. To create a new
1399 buffer with an empty name use |bufadd()|.
1400
1401 bufnr("$") is the last buffer: >
1402 :let last_buffer = bufnr("$")
1403< The result is a Number, which is the highest buffer number
1404 of existing buffers. Note that not all buffers with a smaller
1405 number necessarily exist, because ":bwipeout" may have removed
1406 them. Use bufexists() to test for the existence of a buffer.
1407
1408 Can also be used as a |method|: >
1409 echo bufref->bufnr()
1410<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001411 Return type: |Number|
1412
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001413 Obsolete name: buffer_number(). *buffer_number()*
1414 *last_buffer_nr()*
1415 Obsolete name for bufnr("$"): last_buffer_nr().
1416
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001417
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001418bufwinid({buf}) *bufwinid()*
1419 The result is a Number, which is the |window-ID| of the first
1420 window associated with buffer {buf}. For the use of {buf},
1421 see |bufname()| above. If buffer {buf} doesn't exist or
1422 there is no such window, -1 is returned. Example: >
1423
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001424 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001425<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001426 Only deals with the current tab page. See |win_findbuf()| for
1427 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001428
1429 Can also be used as a |method|: >
1430 FindBuffer()->bufwinid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001431<
1432 Return type: |Number|
1433
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001434
1435bufwinnr({buf}) *bufwinnr()*
1436 Like |bufwinid()| but return the window number instead of the
1437 |window-ID|.
1438 If buffer {buf} doesn't exist or there is no such window, -1
1439 is returned. Example: >
1440
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001441 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001442
1443< The number can be used with |CTRL-W_w| and ":wincmd w"
1444 |:wincmd|.
1445
1446 Can also be used as a |method|: >
1447 FindBuffer()->bufwinnr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001448<
1449 Return type: |Number|
1450
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001451
1452byte2line({byte}) *byte2line()*
1453 Return the line number that contains the character at byte
1454 count {byte} in the current buffer. This includes the
1455 end-of-line character, depending on the 'fileformat' option
1456 for the current buffer. The first character has byte count
1457 one.
1458 Also see |line2byte()|, |go| and |:goto|.
1459
Bram Moolenaar016188f2022-06-06 20:52:59 +01001460 Returns -1 if the {byte} value is invalid.
1461
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001462 Can also be used as a |method|: >
1463 GetOffset()->byte2line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001464<
1465 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001466
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001467 {not available when compiled without the |+byte_offset|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001468 feature}
1469
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001470
Christian Brabandt67672ef2023-04-24 21:09:54 +01001471byteidx({expr}, {nr} [, {utf16}]) *byteidx()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001472 Return byte index of the {nr}'th character in the String
1473 {expr}. Use zero for the first character, it then returns
1474 zero.
1475 If there are no multibyte characters the returned value is
1476 equal to {nr}.
1477 Composing characters are not counted separately, their byte
1478 length is added to the preceding base character. See
1479 |byteidxcomp()| below for counting composing characters
1480 separately.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001481 When {utf16} is present and TRUE, {nr} is used as the UTF-16
1482 index in the String {expr} instead of as the character index.
1483 The UTF-16 index is the index in the string when it is encoded
1484 with 16-bit words. If the specified UTF-16 index is in the
1485 middle of a character (e.g. in a 4-byte character), then the
1486 byte index of the first byte in the character is returned.
1487 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001488 Example : >
1489 echo matchstr(str, ".", byteidx(str, 3))
1490< will display the fourth character. Another way to do the
1491 same: >
1492 let s = strpart(str, byteidx(str, 3))
1493 echo strpart(s, 0, byteidx(s, 1))
1494< Also see |strgetchar()| and |strcharpart()|.
1495
1496 If there are less than {nr} characters -1 is returned.
1497 If there are exactly {nr} characters the length of the string
1498 in bytes is returned.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001499 See |charidx()| and |utf16idx()| for getting the character and
1500 UTF-16 index respectively from the byte index.
1501 Examples: >
1502 echo byteidx('a😊😊', 2) returns 5
1503 echo byteidx('a😊😊', 2, 1) returns 1
1504 echo byteidx('a😊😊', 3, 1) returns 5
1505<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001506 Can also be used as a |method|: >
1507 GetName()->byteidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001508<
1509 Return type: |Number|
1510
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001511
Christian Brabandt67672ef2023-04-24 21:09:54 +01001512byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001513 Like byteidx(), except that a composing character is counted
1514 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001515 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001516 echo byteidx(s, 1)
1517 echo byteidxcomp(s, 1)
1518 echo byteidxcomp(s, 2)
1519< The first and third echo result in 3 ('e' plus composing
1520 character is 3 bytes), the second echo results in 1 ('e' is
1521 one byte).
1522 Only works differently from byteidx() when 'encoding' is set
1523 to a Unicode encoding.
1524
1525 Can also be used as a |method|: >
1526 GetName()->byteidxcomp(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001527<
1528 Return type: |Number|
1529
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001530
1531call({func}, {arglist} [, {dict}]) *call()* *E699*
1532 Call function {func} with the items in |List| {arglist} as
1533 arguments.
1534 {func} can either be a |Funcref| or the name of a function.
1535 a:firstline and a:lastline are set to the cursor line.
1536 Returns the return value of the called function.
1537 {dict} is for functions with the "dict" attribute. It will be
1538 used to set the local variable "self". |Dictionary-function|
1539
1540 Can also be used as a |method|: >
1541 GetFunc()->call([arg, arg], dict)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001542<
1543 Return type: any, depending on {func}
1544
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001545
1546ceil({expr}) *ceil()*
1547 Return the smallest integral value greater than or equal to
1548 {expr} as a |Float| (round up).
1549 {expr} must evaluate to a |Float| or a |Number|.
1550 Examples: >
1551 echo ceil(1.456)
1552< 2.0 >
1553 echo ceil(-5.456)
1554< -5.0 >
1555 echo ceil(4.0)
1556< 4.0
1557
Bram Moolenaar016188f2022-06-06 20:52:59 +01001558 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1559
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001560 Can also be used as a |method|: >
1561 Compute()->ceil()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001562<
1563 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001564
1565
1566ch_ functions are documented here: |channel-functions-details|
1567
1568
1569changenr() *changenr()*
1570 Return the number of the most recent change. This is the same
1571 number as what is displayed with |:undolist| and can be used
1572 with the |:undo| command.
1573 When a change was made it is the number of that change. After
1574 redo it is the number of the redone change. After undo it is
1575 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001576 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001577
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001578 Return type: |Number|
1579
1580
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001581char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001582 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001583 Examples: >
1584 char2nr(" ") returns 32
1585 char2nr("ABC") returns 65
1586< When {utf8} is omitted or zero, the current 'encoding' is used.
1587 Example for "utf-8": >
1588 char2nr("á") returns 225
1589 char2nr("á"[0]) returns 195
1590< When {utf8} is TRUE, always treat as UTF-8 characters.
1591 A combining character is a separate character.
1592 |nr2char()| does the opposite.
1593 To turn a string into a list of character numbers: >
1594 let str = "ABC"
1595 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1596< Result: [65, 66, 67]
1597
Bram Moolenaar016188f2022-06-06 20:52:59 +01001598 Returns 0 if {string} is not a |String|.
1599
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001600 Can also be used as a |method|: >
1601 GetChar()->char2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001602<
1603 Return type: |Number|
1604
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001605
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001606charclass({string}) *charclass()*
1607 Return the character class of the first character in {string}.
1608 The character class is one of:
1609 0 blank
1610 1 punctuation
1611 2 word character
1612 3 emoji
1613 other specific Unicode class
1614 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001615 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001616
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001617 Return type: |Number|
1618
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001619
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001620charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001621 Same as |col()| but returns the character index of the column
1622 position given with {expr} instead of the byte position.
1623
1624 Example:
1625 With the cursor on '세' in line 5 with text "여보세요": >
1626 charcol('.') returns 3
1627 col('.') returns 7
1628
1629< Can also be used as a |method|: >
1630 GetPos()->col()
1631<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001632 Return type: |Number|
1633
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001634 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001635charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001636 Return the character index of the byte at {idx} in {string}.
1637 The index of the first character is zero.
1638 If there are no multibyte characters the returned value is
1639 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001640
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001641 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001642 are not counted separately, their byte length is added to the
1643 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001644 When {countcc} is |TRUE|, then composing characters are
1645 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001646
1647 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1648 index in the String {expr} instead of as the byte index.
1649
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001650 Returns -1 if the arguments are invalid or if there are less
1651 than {idx} bytes. If there are exactly {idx} bytes the length
1652 of the string in characters is returned.
1653
1654 An error is given and -1 is returned if the first argument is
1655 not a string, the second argument is not a number or when the
1656 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001657
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001658 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001659 from the character index and |utf16idx()| for getting the
1660 UTF-16 index from the character index.
1661 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001662 Examples: >
1663 echo charidx('áb́ć', 3) returns 1
1664 echo charidx('áb́ć', 6, 1) returns 4
1665 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001666 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001667<
1668 Can also be used as a |method|: >
1669 GetName()->charidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001670<
1671 Return type: |Number|
1672
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001673
1674chdir({dir}) *chdir()*
1675 Change the current working directory to {dir}. The scope of
1676 the directory change depends on the directory of the current
1677 window:
1678 - If the current window has a window-local directory
1679 (|:lcd|), then changes the window local directory.
1680 - Otherwise, if the current tabpage has a local
1681 directory (|:tcd|) then changes the tabpage local
1682 directory.
1683 - Otherwise, changes the global directory.
1684 {dir} must be a String.
1685 If successful, returns the previous working directory. Pass
1686 this to another chdir() to restore the directory.
1687 On failure, returns an empty string.
1688
1689 Example: >
1690 let save_dir = chdir(newdir)
1691 if save_dir != ""
1692 " ... do some work
1693 call chdir(save_dir)
1694 endif
1695
1696< Can also be used as a |method|: >
1697 GetDir()->chdir()
1698<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001699 Return type: |String|
1700
1701
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001702cindent({lnum}) *cindent()*
1703 Get the amount of indent for line {lnum} according the C
1704 indenting rules, as with 'cindent'.
1705 The indent is counted in spaces, the value of 'tabstop' is
1706 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001707 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001708 See |C-indenting|.
1709
1710 Can also be used as a |method|: >
1711 GetLnum()->cindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001712<
1713 Return type: |Number|
1714
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001715
1716clearmatches([{win}]) *clearmatches()*
1717 Clears all matches previously defined for the current window
1718 by |matchadd()| and the |:match| commands.
1719 If {win} is specified, use the window with this number or
1720 window ID instead of the current window.
1721
1722 Can also be used as a |method|: >
1723 GetWin()->clearmatches()
1724<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001725 Return type: |Number|
1726
1727
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001728col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001729 The result is a Number, which is the byte index of the column
zeertzjq02f3eba2024-06-12 20:45:24 +02001730 position given with {expr}.
1731 For accepted positions see |getpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001732 Additionally {expr} can be [lnum, col]: a |List| with the line
1733 and column number. Most useful when the column is "$", to get
1734 the last column of a specific line. When "lnum" or "col" is
1735 out of range then col() returns zero.
zeertzjq02f3eba2024-06-12 20:45:24 +02001736
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001737 With the optional {winid} argument the values are obtained for
1738 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02001739
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001740 To get the line number use |line()|. To get both use
1741 |getpos()|.
1742 For the screen column position use |virtcol()|. For the
1743 character position use |charcol()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02001744
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001745 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +02001746
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001747 Examples: >
1748 col(".") column of cursor
1749 col("$") length of cursor line plus one
1750 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001751 col("'" .. markname) column of mark markname
zeertzjq02f3eba2024-06-12 20:45:24 +02001752<
1753 The first column is 1. Returns 0 if {expr} is invalid or when
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001754 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001755 For an uppercase mark the column may actually be in another
1756 buffer.
1757 For the cursor position, when 'virtualedit' is active, the
1758 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001759 line. Also, when using a <Cmd> mapping the cursor isn't
1760 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001761 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001762
1763< Can also be used as a |method|: >
1764 GetPos()->col()
1765<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001766 Return type: |Number|
1767
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001768
1769complete({startcol}, {matches}) *complete()* *E785*
1770 Set the matches for Insert mode completion.
1771 Can only be used in Insert mode. You need to use a mapping
1772 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1773 or with an expression mapping.
1774 {startcol} is the byte offset in the line where the completed
1775 text start. The text up to the cursor is the original text
1776 that will be replaced by the matches. Use col('.') for an
1777 empty string. "col('.') - 1" will replace one character by a
1778 match.
1779 {matches} must be a |List|. Each |List| item is one match.
1780 See |complete-items| for the kind of items that are possible.
1781 "longest" in 'completeopt' is ignored.
1782 Note that the after calling this function you need to avoid
1783 inserting anything that would cause completion to stop.
1784 The match can be selected with CTRL-N and CTRL-P as usual with
1785 Insert mode completion. The popup menu will appear if
1786 specified, see |ins-completion-menu|.
1787 Example: >
1788 inoremap <F5> <C-R>=ListMonths()<CR>
1789
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001790 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001791 call complete(col('.'), ['January', 'February', 'March',
1792 \ 'April', 'May', 'June', 'July', 'August', 'September',
1793 \ 'October', 'November', 'December'])
1794 return ''
1795 endfunc
1796< This isn't very useful, but it shows how it works. Note that
1797 an empty string is returned to avoid a zero being inserted.
1798
1799 Can also be used as a |method|, the base is passed as the
1800 second argument: >
1801 GetMatches()->complete(col('.'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001802<
1803 Return type: |Number|
1804
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001805
1806complete_add({expr}) *complete_add()*
1807 Add {expr} to the list of matches. Only to be used by the
1808 function specified with the 'completefunc' option.
1809 Returns 0 for failure (empty string or out of memory),
1810 1 when the match was added, 2 when the match was already in
1811 the list.
1812 See |complete-functions| for an explanation of {expr}. It is
1813 the same as one item in the list that 'omnifunc' would return.
1814
1815 Can also be used as a |method|: >
1816 GetMoreMatches()->complete_add()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001817<
1818 Return type: |Number|
1819
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001820
1821complete_check() *complete_check()*
1822 Check for a key typed while looking for completion matches.
1823 This is to be used when looking for matches takes some time.
1824 Returns |TRUE| when searching for matches is to be aborted,
1825 zero otherwise.
1826 Only to be used by the function specified with the
1827 'completefunc' option.
1828
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001829 Return type: |Number|
1830
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001831
1832complete_info([{what}]) *complete_info()*
1833 Returns a |Dictionary| with information about Insert mode
1834 completion. See |ins-completion|.
1835 The items are:
1836 mode Current completion mode name string.
1837 See |complete_info_mode| for the values.
1838 pum_visible |TRUE| if popup menu is visible.
1839 See |pumvisible()|.
1840 items List of completion matches. Each item is a
1841 dictionary containing the entries "word",
1842 "abbr", "menu", "kind", "info" and "user_data".
1843 See |complete-items|.
1844 selected Selected item index. First index is zero.
1845 Index is -1 if no item is selected (showing
1846 typed text only, or the last completion after
1847 no item is selected when using the <Up> or
1848 <Down> keys)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01001849 inserted Inserted string. [NOT IMPLEMENTED YET]
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001850
1851 *complete_info_mode*
1852 mode values are:
1853 "" Not in completion mode
1854 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1855 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1856 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1857 |i_CTRL-X_CTRL-Y|
1858 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1859 "files" File names |i_CTRL-X_CTRL-F|
1860 "tags" Tags |i_CTRL-X_CTRL-]|
1861 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1862 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1863 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1864 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1865 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1866 "function" User defined completion |i_CTRL-X_CTRL-U|
1867 "omni" Omni completion |i_CTRL-X_CTRL-O|
1868 "spell" Spelling suggestions |i_CTRL-X_s|
1869 "eval" |complete()| completion
1870 "unknown" Other internal modes
1871
1872 If the optional {what} list argument is supplied, then only
1873 the items listed in {what} are returned. Unsupported items in
1874 {what} are silently ignored.
1875
1876 To get the position and size of the popup menu, see
1877 |pum_getpos()|. It's also available in |v:event| during the
1878 |CompleteChanged| event.
1879
Bram Moolenaar016188f2022-06-06 20:52:59 +01001880 Returns an empty |Dictionary| on error.
1881
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001882 Examples: >
1883 " Get all items
1884 call complete_info()
1885 " Get only 'mode'
1886 call complete_info(['mode'])
1887 " Get only 'mode' and 'pum_visible'
1888 call complete_info(['mode', 'pum_visible'])
1889
1890< Can also be used as a |method|: >
1891 GetItems()->complete_info()
1892<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001893 Return type: dict<any>
1894
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001895 *confirm()*
1896confirm({msg} [, {choices} [, {default} [, {type}]]])
1897 confirm() offers the user a dialog, from which a choice can be
1898 made. It returns the number of the choice. For the first
1899 choice this is 1.
1900 Note: confirm() is only supported when compiled with dialog
glepnirdf461152024-04-04 22:23:29 +02001901 support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001902
1903 {msg} is displayed in a |dialog| with {choices} as the
1904 alternatives. When {choices} is missing or empty, "&OK" is
1905 used (and translated).
1906 {msg} is a String, use '\n' to include a newline. Only on
1907 some systems the string is wrapped when it doesn't fit.
1908
1909 {choices} is a String, with the individual choices separated
1910 by '\n', e.g. >
1911 confirm("Save changes?", "&Yes\n&No\n&Cancel")
1912< The letter after the '&' is the shortcut key for that choice.
1913 Thus you can type 'c' to select "Cancel". The shortcut does
1914 not need to be the first letter: >
1915 confirm("file has been modified", "&Save\nSave &All")
1916< For the console, the first letter of each choice is used as
1917 the default shortcut key. Case is ignored.
1918
1919 The optional {default} argument is the number of the choice
1920 that is made if the user hits <CR>. Use 1 to make the first
1921 choice the default one. Use 0 to not set a default. If
1922 {default} is omitted, 1 is used.
1923
1924 The optional {type} String argument gives the type of dialog.
1925 This is only used for the icon of the GTK, Mac, Motif and
1926 Win32 GUI. It can be one of these values: "Error",
1927 "Question", "Info", "Warning" or "Generic". Only the first
1928 character is relevant. When {type} is omitted, "Generic" is
1929 used.
1930
1931 If the user aborts the dialog by pressing <Esc>, CTRL-C,
1932 or another valid interrupt key, confirm() returns 0.
1933
1934 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01001935 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001936 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01001937 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001938 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001939 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001940 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001941 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001942 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01001943 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001944< In a GUI dialog, buttons are used. The layout of the buttons
1945 depends on the 'v' flag in 'guioptions'. If it is included,
1946 the buttons are always put vertically. Otherwise, confirm()
1947 tries to put the buttons in one horizontal line. If they
1948 don't fit, a vertical layout is used anyway. For some systems
1949 the horizontal layout is always used.
1950
1951 Can also be used as a |method|in: >
1952 BuildMessage()->confirm("&Yes\n&No")
1953<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001954 Return type: |Number|
1955
1956
1957copy({expr}) *copy()*
1958 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001959 different from using {expr} directly.
1960 When {expr} is a |List| a shallow copy is created. This means
1961 that the original |List| can be changed without changing the
1962 copy, and vice versa. But the items are identical, thus
1963 changing an item changes the contents of both |Lists|.
1964 A |Dictionary| is copied in a similar way as a |List|.
1965 Also see |deepcopy()|.
1966 Can also be used as a |method|: >
1967 mylist->copy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001968<
1969 Return type: any, depending on {expr}
1970
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001971
1972cos({expr}) *cos()*
1973 Return the cosine of {expr}, measured in radians, as a |Float|.
1974 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001975 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001976 Examples: >
1977 :echo cos(100)
1978< 0.862319 >
1979 :echo cos(-4.01)
1980< -0.646043
1981
1982 Can also be used as a |method|: >
1983 Compute()->cos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001984<
1985 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001986
1987
1988cosh({expr}) *cosh()*
1989 Return the hyperbolic cosine of {expr} as a |Float| in the range
1990 [1, inf].
1991 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001992 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001993 Examples: >
1994 :echo cosh(0.5)
1995< 1.127626 >
1996 :echo cosh(-0.5)
1997< -1.127626
1998
1999 Can also be used as a |method|: >
2000 Compute()->cosh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002001<
2002 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002003
2004
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07002005count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002006 Return the number of times an item with value {expr} appears
2007 in |String|, |List| or |Dictionary| {comp}.
2008
2009 If {start} is given then start with the item with this index.
2010 {start} can only be used with a |List|.
2011
2012 When {ic} is given and it's |TRUE| then case is ignored.
2013
2014 When {comp} is a string then the number of not overlapping
2015 occurrences of {expr} is returned. Zero is returned when
2016 {expr} is an empty string.
2017
2018 Can also be used as a |method|: >
2019 mylist->count(val)
2020<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002021 Return type: |Number|
2022
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002023 *cscope_connection()*
2024cscope_connection([{num} , {dbpath} [, {prepend}]])
2025 Checks for the existence of a |cscope| connection. If no
2026 parameters are specified, then the function returns:
2027 0, if cscope was not available (not compiled in), or
2028 if there are no cscope connections;
2029 1, if there is at least one cscope connection.
2030
2031 If parameters are specified, then the value of {num}
2032 determines how existence of a cscope connection is checked:
2033
2034 {num} Description of existence check
2035 ----- ------------------------------
2036 0 Same as no parameters (e.g., "cscope_connection()").
2037 1 Ignore {prepend}, and use partial string matches for
2038 {dbpath}.
2039 2 Ignore {prepend}, and use exact string matches for
2040 {dbpath}.
2041 3 Use {prepend}, use partial string matches for both
2042 {dbpath} and {prepend}.
2043 4 Use {prepend}, use exact string matches for both
2044 {dbpath} and {prepend}.
2045
2046 Note: All string comparisons are case sensitive!
2047
2048 Examples. Suppose we had the following (from ":cs show"): >
2049
2050 # pid database name prepend path
2051 0 27664 cscope.out /usr/local
2052<
2053 Invocation Return Val ~
2054 ---------- ---------- >
2055 cscope_connection() 1
2056 cscope_connection(1, "out") 1
2057 cscope_connection(2, "out") 0
2058 cscope_connection(3, "out") 0
2059 cscope_connection(3, "out", "local") 1
2060 cscope_connection(4, "out") 0
2061 cscope_connection(4, "out", "local") 0
2062 cscope_connection(4, "cscope.out", "/usr/local") 1
2063<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002064 Return type: |Number|
2065
2066
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002067cursor({lnum}, {col} [, {off}]) *cursor()*
2068cursor({list})
2069 Positions the cursor at the column (byte count) {col} in the
2070 line {lnum}. The first column is one.
2071
2072 When there is one argument {list} this is used as a |List|
2073 with two, three or four item:
2074 [{lnum}, {col}]
2075 [{lnum}, {col}, {off}]
2076 [{lnum}, {col}, {off}, {curswant}]
2077 This is like the return value of |getpos()| or |getcurpos()|,
2078 but without the first item.
2079
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01002080 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002081 |setcursorcharpos()|.
2082
2083 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01002084 {lnum} is used like with |getline()|, except that if {lnum} is
2085 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002086 If {lnum} is greater than the number of lines in the buffer,
2087 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002088 If {col} is greater than the number of bytes in the line,
2089 the cursor will be positioned at the last character in the
2090 line.
2091 If {col} is zero, the cursor will stay in the current column.
2092 If {curswant} is given it is used to set the preferred column
2093 for vertical movement. Otherwise {col} is used.
2094
2095 When 'virtualedit' is used {off} specifies the offset in
2096 screen columns from the start of the character. E.g., a
2097 position within a <Tab> or after the last character.
2098 Returns 0 when the position could be set, -1 otherwise.
2099
2100 Can also be used as a |method|: >
2101 GetCursorPos()->cursor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002102<
2103 Return type: |Number|
2104
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002105
2106debugbreak({pid}) *debugbreak()*
2107 Specifically used to interrupt a program being debugged. It
2108 will cause process {pid} to get a SIGTRAP. Behavior for other
2109 processes is undefined. See |terminal-debugger|.
2110 {only available on MS-Windows}
2111
Bram Moolenaar016188f2022-06-06 20:52:59 +01002112 Returns |TRUE| if successfully interrupted the program.
2113 Otherwise returns |FALSE|.
2114
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002115 Can also be used as a |method|: >
2116 GetPid()->debugbreak()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002117<
2118 Return type: |Number|
2119
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002120
2121deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
2122 Make a copy of {expr}. For Numbers and Strings this isn't
2123 different from using {expr} directly.
2124 When {expr} is a |List| a full copy is created. This means
2125 that the original |List| can be changed without changing the
2126 copy, and vice versa. When an item is a |List| or
2127 |Dictionary|, a copy for it is made, recursively. Thus
2128 changing an item in the copy does not change the contents of
2129 the original |List|.
2130 A |Dictionary| is copied in a similar way as a |List|.
2131
2132 When {noref} is omitted or zero a contained |List| or
2133 |Dictionary| is only copied once. All references point to
2134 this single copy. With {noref} set to 1 every occurrence of a
2135 |List| or |Dictionary| results in a new copy. This also means
2136 that a cyclic reference causes deepcopy() to fail.
2137 *E724*
2138 Nesting is possible up to 100 levels. When there is an item
2139 that refers back to a higher level making a deep copy with
2140 {noref} set to 1 will fail.
2141 Also see |copy()|.
2142
2143 Can also be used as a |method|: >
2144 GetObject()->deepcopy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002145<
2146 Return type: any, depending on {expr}
2147
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002148
2149delete({fname} [, {flags}]) *delete()*
2150 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002151 name {fname}.
2152
2153 This also works when {fname} is a symbolic link. The symbolic
2154 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002155
2156 When {flags} is "d": Deletes the directory by the name
2157 {fname}. This fails when directory {fname} is not empty.
2158
2159 When {flags} is "rf": Deletes the directory by the name
2160 {fname} and everything in it, recursively. BE CAREFUL!
2161 Note: on MS-Windows it is not possible to delete a directory
2162 that is being used.
2163
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002164 The result is a Number, which is 0/false if the delete
2165 operation was successful and -1/true when the deletion failed
2166 or partly failed.
2167
2168 Use |remove()| to delete an item from a |List|.
2169 To delete a line from the buffer use |:delete| or
2170 |deletebufline()|.
2171
2172 Can also be used as a |method|: >
2173 GetName()->delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002174<
2175 Return type: |Number|
2176
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002177
2178deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2179 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2180 If {last} is omitted then delete line {first} only.
2181 On success 0 is returned, on failure 1 is returned.
2182
2183 This function works only for loaded buffers. First call
2184 |bufload()| if needed.
2185
2186 For the use of {buf}, see |bufname()| above.
2187
2188 {first} and {last} are used like with |getline()|. Note that
2189 when using |line()| this refers to the current buffer. Use "$"
2190 to refer to the last line in buffer {buf}.
2191
2192 Can also be used as a |method|: >
2193 GetBuffer()->deletebufline(1)
2194<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002195 Return type: |Number|
2196
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002197 *did_filetype()*
2198did_filetype() Returns |TRUE| when autocommands are being executed and the
2199 FileType event has been triggered at least once. Can be used
2200 to avoid triggering the FileType event again in the scripts
2201 that detect the file type. |FileType|
2202 Returns |FALSE| when `:setf FALLBACK` was used.
2203 When editing another file, the counter is reset, thus this
2204 really checks if the FileType event has been triggered for the
2205 current buffer. This allows an autocommand that starts
2206 editing another buffer to set 'filetype' and load a syntax
2207 file.
2208
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002209 Return type: |Number|
2210
2211
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002212diff({fromlist}, {tolist} [, {options}]) *diff()*
2213 Returns a String or a List containing the diff between the
2214 strings in {fromlist} and {tolist}. Uses the Vim internal
2215 diff library to compute the diff.
2216
2217 *E106*
2218 The optional "output" item in {options} specifies the returned
2219 diff format. The following values are supported:
2220 indices Return a List of the starting and ending
2221 indices and a count of the strings in each
2222 diff hunk.
2223 unified Return the unified diff output as a String.
2224 This is the default.
2225
2226 If the "output" item in {options} is "indices", then a List is
2227 returned. Each List item contains a Dict with the following
2228 items for each diff hunk:
2229 from_idx start index in {fromlist} for this diff hunk.
2230 from_count number of strings in {fromlist} that are
2231 added/removed/modified in this diff hunk.
2232 to_idx start index in {tolist} for this diff hunk.
2233 to_count number of strings in {tolist} that are
2234 added/removed/modified in this diff hunk.
2235
2236 The {options} Dict argument also specifies diff options
2237 (similar to 'diffopt') and supports the following items:
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002238 algorithm Dict specifying the diff algorithm to
2239 use. Supported boolean items are
2240 "myers", "minimal", "patience" and
2241 "histogram".
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002242 context diff context length. Default is 0.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002243 iblank ignore changes where lines are all
2244 blank.
2245 icase ignore changes in case of text.
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002246 indent-heuristic use the indent heuristic for the
2247 internal diff library.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002248 iwhite ignore changes in amount of white
2249 space.
2250 iwhiteall ignore all white space changes.
2251 iwhiteeol ignore white space changes at end of
2252 line.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002253 For more information about these options, refer to 'diffopt'.
2254
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002255 To compute the unified diff, all the items in {fromlist} are
2256 concatenated into a string using a newline separator and the
2257 same for {tolist}. The unified diff output uses line numbers.
2258
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002259 Returns an empty List or String if {fromlist} and {tolist} are
2260 identical.
2261
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002262 Examples: >
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002263 :echo diff(['abc'], ['xxx'])
2264 @@ -1 +1 @@
2265 -abc
2266 +xxx
2267
2268 :echo diff(['abc'], ['xxx'], {'output': 'indices'})
2269 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}]
2270 :echo diff(readfile('oldfile'), readfile('newfile'))
2271 :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$'))
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002272<
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002273 For more examples, refer to |diff-func-examples|
2274
2275 Can also be used as a |method|: >
2276 GetFromList->diff(to_list)
2277<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002278 Return type: |String| or list<dict<number>> or list<any>
2279 depending on {options}
2280
2281
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002282diff_filler({lnum}) *diff_filler()*
2283 Returns the number of filler lines above line {lnum}.
2284 These are the lines that were inserted at this point in
2285 another diff'ed window. These filler lines are shown in the
2286 display but don't exist in the buffer.
2287 {lnum} is used like with |getline()|. Thus "." is the current
2288 line, "'m" mark m, etc.
2289 Returns 0 if the current window is not in diff mode.
2290
2291 Can also be used as a |method|: >
2292 GetLnum()->diff_filler()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002293<
2294 Return type: |Number|
2295
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002296
2297diff_hlID({lnum}, {col}) *diff_hlID()*
2298 Returns the highlight ID for diff mode at line {lnum} column
2299 {col} (byte index). When the current line does not have a
2300 diff change zero is returned.
2301 {lnum} is used like with |getline()|. Thus "." is the current
2302 line, "'m" mark m, etc.
2303 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2304 line.
2305 The highlight ID can be used with |synIDattr()| to obtain
2306 syntax information about the highlighting.
2307
2308 Can also be used as a |method|: >
2309 GetLnum()->diff_hlID(col)
2310<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002311 Return type: |Number|
2312
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002313
2314digraph_get({chars}) *digraph_get()* *E1214*
2315 Return the digraph of {chars}. This should be a string with
2316 exactly two characters. If {chars} are not just two
2317 characters, or the digraph of {chars} does not exist, an error
2318 is given and an empty string is returned.
2319
2320 The character will be converted from Unicode to 'encoding'
2321 when needed. This does require the conversion to be
2322 available, it might fail.
2323
2324 Also see |digraph_getlist()|.
2325
2326 Examples: >
2327 " Get a built-in digraph
2328 :echo digraph_get('00') " Returns '∞'
2329
2330 " Get a user-defined digraph
2331 :call digraph_set('aa', 'あ')
2332 :echo digraph_get('aa') " Returns 'あ'
2333<
2334 Can also be used as a |method|: >
2335 GetChars()->digraph_get()
2336<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002337 Return type: |String|
2338
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002339 This function works only when compiled with the |+digraphs|
2340 feature. If this feature is disabled, this function will
2341 display an error message.
2342
2343
2344digraph_getlist([{listall}]) *digraph_getlist()*
2345 Return a list of digraphs. If the {listall} argument is given
2346 and it is TRUE, return all digraphs, including the default
2347 digraphs. Otherwise, return only user-defined digraphs.
2348
2349 The characters will be converted from Unicode to 'encoding'
2350 when needed. This does require the conservation to be
2351 available, it might fail.
2352
2353 Also see |digraph_get()|.
2354
2355 Examples: >
2356 " Get user-defined digraphs
2357 :echo digraph_getlist()
2358
2359 " Get all the digraphs, including default digraphs
2360 :echo digraph_getlist(1)
2361<
2362 Can also be used as a |method|: >
2363 GetNumber()->digraph_getlist()
2364<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002365 Return type: list<list<string>>
2366
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002367 This function works only when compiled with the |+digraphs|
2368 feature. If this feature is disabled, this function will
2369 display an error message.
2370
2371
Bram Moolenaara2baa732022-02-04 16:09:54 +00002372digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002373 Add digraph {chars} to the list. {chars} must be a string
2374 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002375 encoded character. *E1215*
2376 Be careful, composing characters are NOT ignored. This
2377 function is similar to |:digraphs| command, but useful to add
2378 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002379
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002380 The function returns v:true if |digraph| is registered. If
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002381 this fails an error message is given and v:false is returned.
2382
2383 If you want to define multiple digraphs at once, you can use
2384 |digraph_setlist()|.
2385
2386 Example: >
2387 call digraph_set(' ', 'あ')
2388<
2389 Can be used as a |method|: >
2390 GetString()->digraph_set('あ')
2391<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002392 Return type: |vim9-boolean|
2393
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002394 This function works only when compiled with the |+digraphs|
2395 feature. If this feature is disabled, this function will
2396 display an error message.
2397
2398
2399digraph_setlist({digraphlist}) *digraph_setlist()*
2400 Similar to |digraph_set()| but this function can add multiple
2401 digraphs at once. {digraphlist} is a list composed of lists,
2402 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002403 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002404 Example: >
2405 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2406<
2407 It is similar to the following: >
2408 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2409 call digraph_set(chars, digraph)
2410 endfor
2411< Except that the function returns after the first error,
2412 following digraphs will not be added.
2413
2414 Can be used as a |method|: >
2415 GetList()->digraph_setlist()
2416<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002417 Return type: |vim9-boolean|
2418
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002419 This function works only when compiled with the |+digraphs|
2420 feature. If this feature is disabled, this function will
2421 display an error message.
2422
2423
2424echoraw({string}) *echoraw()*
2425 Output {string} as-is, including unprintable characters.
2426 This can be used to output a terminal code. For example, to
2427 disable modifyOtherKeys: >
2428 call echoraw(&t_TE)
2429< and to enable it again: >
2430 call echoraw(&t_TI)
2431< Use with care, you can mess up the terminal this way.
2432
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002433 Return type: |Number|
2434
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002435
2436empty({expr}) *empty()*
2437 Return the Number 1 if {expr} is empty, zero otherwise.
2438 - A |List| or |Dictionary| is empty when it does not have any
2439 items.
2440 - A |String| is empty when its length is zero.
2441 - A |Number| and |Float| are empty when their value is zero.
2442 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2443 - A |Job| is empty when it failed to start.
2444 - A |Channel| is empty when it is closed.
2445 - A |Blob| is empty when its length is zero.
mityu7f0bba22024-03-29 10:14:41 +01002446 - An |Object| is empty, when the empty() method in the object
2447 (if present) returns true. |object-empty()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002448
2449 For a long |List| this is much faster than comparing the
2450 length with zero.
2451
2452 Can also be used as a |method|: >
2453 mylist->empty()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002454<
2455 Return type: |Number|
2456
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002457
2458environ() *environ()*
2459 Return all of environment variables as dictionary. You can
2460 check if an environment variable exists like this: >
2461 :echo has_key(environ(), 'HOME')
2462< Note that the variable name may be CamelCase; to ignore case
2463 use this: >
2464 :echo index(keys(environ()), 'HOME', 0, 1) != -1
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002465<
2466 Return type: dict<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002467
Bram Moolenaar416bd912023-07-07 23:19:18 +01002468
2469err_teapot([{expr}]) *err_teapot()*
2470 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002471 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002472 If {expr} is present and it is TRUE error 503 is given,
2473 indicating that coffee is temporarily not available.
2474 If {expr} is present it must be a String.
2475
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002476 Return type: |Number|
2477
Bram Moolenaar416bd912023-07-07 23:19:18 +01002478
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002479escape({string}, {chars}) *escape()*
2480 Escape the characters in {chars} that occur in {string} with a
2481 backslash. Example: >
2482 :echo escape('c:\program files\vim', ' \')
2483< results in: >
2484 c:\\program\ files\\vim
2485< Also see |shellescape()| and |fnameescape()|.
2486
2487 Can also be used as a |method|: >
2488 GetText()->escape(' \')
2489<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002490 Return type: |String|
2491
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002492 *eval()*
2493eval({string}) Evaluate {string} and return the result. Especially useful to
2494 turn the result of |string()| back into the original value.
2495 This works for Numbers, Floats, Strings, Blobs and composites
2496 of them. Also works for |Funcref|s that refer to existing
Aliaksei Budavei95740222024-04-04 23:05:33 +03002497 functions. In |Vim9| script, it can be used to obtain |enum|
2498 values from their fully qualified names.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002499
2500 Can also be used as a |method|: >
2501 argv->join()->eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002502<
2503 Return type: any, depending on {string}
2504
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002505
2506eventhandler() *eventhandler()*
2507 Returns 1 when inside an event handler. That is that Vim got
2508 interrupted while waiting for the user to type a character,
2509 e.g., when dropping a file on Vim. This means interactive
2510 commands cannot be used. Otherwise zero is returned.
2511
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002512 Return type: |Number|
2513
2514
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002515executable({expr}) *executable()*
2516 This function checks if an executable with the name {expr}
2517 exists. {expr} must be the name of the program without any
2518 arguments.
2519 executable() uses the value of $PATH and/or the normal
2520 searchpath for programs. *PATHEXT*
2521 On MS-Windows the ".exe", ".bat", etc. can optionally be
2522 included. Then the extensions in $PATHEXT are tried. Thus if
2523 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2524 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2525 by itself can be used in $PATHEXT to try using the name
2526 without an extension. When 'shell' looks like a Unix shell,
2527 then the name is also tried without adding an extension.
2528 On MS-Windows it only checks if the file exists and is not a
2529 directory, not if it's really executable.
2530 On MS-Windows an executable in the same directory as Vim is
Yasuhiro Matsumoto05cf63e2022-05-03 11:02:28 +01002531 normally found. Since this directory is added to $PATH it
2532 should also work to execute it |win32-PATH|. This can be
2533 disabled by setting the $NoDefaultCurrentDirectoryInExePath
2534 environment variable. *NoDefaultCurrentDirectoryInExePath*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002535 The result is a Number:
2536 1 exists
2537 0 does not exist
2538 -1 not implemented on this system
2539 |exepath()| can be used to get the full path of an executable.
2540
2541 Can also be used as a |method|: >
2542 GetCommand()->executable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002543<
2544 Return type: |Number|
2545
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002546
2547execute({command} [, {silent}]) *execute()*
2548 Execute an Ex command or commands and return the output as a
2549 string.
2550 {command} can be a string or a List. In case of a List the
2551 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002552 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002553 redir => var
2554 {command}
2555 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002556< Except that line continuation in {command} is not recognized.
2557
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002558 The optional {silent} argument can have these values:
2559 "" no `:silent` used
2560 "silent" `:silent` used
2561 "silent!" `:silent!` used
2562 The default is "silent". Note that with "silent!", unlike
2563 `:redir`, error messages are dropped. When using an external
2564 command the screen may be messed up, use `system()` instead.
2565 *E930*
2566 It is not possible to use `:redir` anywhere in {command}.
2567
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002568 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002569 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002570
2571< To execute a command in another window than the current one
2572 use `win_execute()`.
2573
2574 When used recursively the output of the recursive call is not
2575 included in the output of the higher level call.
2576
2577 Can also be used as a |method|: >
2578 GetCommand()->execute()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002579<
2580 Return type: |Number|
2581
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002582
2583exepath({expr}) *exepath()*
2584 If {expr} is an executable and is either an absolute path, a
2585 relative path or found in $PATH, return the full path.
2586 Note that the current directory is used when {expr} starts
2587 with "./", which may be a problem for Vim: >
2588 echo exepath(v:progpath)
2589< If {expr} cannot be found in $PATH or is not executable then
2590 an empty string is returned.
2591
2592 Can also be used as a |method|: >
2593 GetCommand()->exepath()
2594<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002595 Return type: |String|
2596
2597
2598exists({expr}) *exists()*
2599 The result is a Number, which is |TRUE| if {expr} is defined,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002600 zero otherwise.
2601
2602 Note: In a compiled |:def| function the evaluation is done at
2603 runtime. Use `exists_compiled()` to evaluate the expression
2604 at compile time.
2605
2606 For checking for a supported feature use |has()|.
2607 For checking if a file exists use |filereadable()|.
2608
2609 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002610 varname internal variable (see
2611 dict.key |internal-variables|). Also works
2612 list[i] for |curly-braces-names|, |Dictionary|
Yegappan Lakshmanana2ebb6e2024-02-25 08:40:10 +01002613 import.Func entries, |List| items, class and
2614 class.Func object methods, imported items, etc.
2615 object.Func Does not work for local variables in a
2616 class.varname compiled `:def` function.
2617 object.varname Also works for a function in |Vim9|
Bram Moolenaar944697a2022-02-20 19:48:20 +00002618 script, since it can be used as a
2619 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002620 Beware that evaluating an index may
2621 cause an error message for an invalid
2622 expression. E.g.: >
2623 :let l = [1, 2, 3]
2624 :echo exists("l[5]")
2625< 0 >
2626 :echo exists("l[xx]")
2627< E121: Undefined variable: xx
2628 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002629 &option-name Vim option (only checks if it exists,
2630 not if it really works)
2631 +option-name Vim option that works.
2632 $ENVNAME environment variable (could also be
2633 done by comparing with an empty
2634 string)
2635 *funcname built-in function (see |functions|)
2636 or user defined function (see
2637 |user-functions|) that is implemented.
2638 Also works for a variable that is a
2639 Funcref.
2640 ?funcname built-in function that could be
2641 implemented; to be used to check if
2642 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002643 :cmdname Ex command: built-in command, user
2644 command or command modifier |:command|.
2645 Returns:
2646 1 for match with start of a command
2647 2 full match with a command
2648 3 matches several user commands
2649 To check for a supported command
2650 always check the return value to be 2.
2651 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002652 :3match The |:3match| command (but you
2653 probably should not use it, it is
2654 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002655 #event autocommand defined for this event
2656 #event#pattern autocommand defined for this event and
2657 pattern (the pattern is taken
2658 literally and compared to the
2659 autocommand patterns character by
2660 character)
2661 #group autocommand group exists
2662 #group#event autocommand defined for this group and
2663 event.
2664 #group#event#pattern
2665 autocommand defined for this group,
2666 event and pattern.
2667 ##event autocommand for this event is
2668 supported.
2669
2670 Examples: >
2671 exists("&shortname")
2672 exists("$HOSTNAME")
2673 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002674 exists("*s:MyFunc") " only for legacy script
2675 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002676 exists("bufcount")
2677 exists(":Make")
2678 exists("#CursorHold")
2679 exists("#BufReadPre#*.gz")
2680 exists("#filetypeindent")
2681 exists("#filetypeindent#FileType")
2682 exists("#filetypeindent#FileType#*")
2683 exists("##ColorScheme")
2684< There must be no space between the symbol (&/$/*/#) and the
2685 name.
2686 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002687 a few cases this is ignored. That may become stricter in the
2688 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002689 Working example: >
2690 exists(":make")
2691< NOT working example: >
2692 exists(":make install")
2693
2694< Note that the argument must be a string, not the name of the
2695 variable itself. For example: >
2696 exists(bufcount)
2697< This doesn't check for existence of the "bufcount" variable,
2698 but gets the value of "bufcount", and checks if that exists.
2699
2700 Can also be used as a |method|: >
2701 Varname()->exists()
2702<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002703 Return type: |String|
2704
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002705
2706exists_compiled({expr}) *exists_compiled()*
2707 Like `exists()` but evaluated at compile time. This is useful
2708 to skip a block where a function is used that would otherwise
2709 give an error: >
2710 if exists_compiled('*ThatFunction')
2711 ThatFunction('works')
2712 endif
2713< If `exists()` were used then a compilation error would be
2714 given if ThatFunction() is not defined.
2715
2716 {expr} must be a literal string. *E1232*
2717 Can only be used in a |:def| function. *E1233*
2718 This does not work to check for arguments or local variables.
2719
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002720 Return type: |String|
2721
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002722
2723exp({expr}) *exp()*
2724 Return the exponential of {expr} as a |Float| in the range
2725 [0, inf].
2726 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002727 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002728 Examples: >
2729 :echo exp(2)
2730< 7.389056 >
2731 :echo exp(-1)
2732< 0.367879
2733
2734 Can also be used as a |method|: >
2735 Compute()->exp()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002736<
2737 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002738
2739
2740expand({string} [, {nosuf} [, {list}]]) *expand()*
2741 Expand wildcards and the following special keywords in
2742 {string}. 'wildignorecase' applies.
2743
2744 If {list} is given and it is |TRUE|, a List will be returned.
2745 Otherwise the result is a String and when there are several
2746 matches, they are separated by <NL> characters. [Note: in
2747 version 5.0 a space was used, which caused problems when a
2748 file name contains a space]
2749
2750 If the expansion fails, the result is an empty string. A name
2751 for a non-existing file is not included, unless {string} does
2752 not start with '%', '#' or '<', see below.
2753
Christian Brabandtec9c3262024-02-21 20:40:05 +01002754 For a |:terminal| window '%' expands to a '!' followed by
h-east53753f62024-05-05 18:42:31 +02002755 the command or shell that is run. |terminal-bufname|
Christian Brabandtec9c3262024-02-21 20:40:05 +01002756
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002757 When {string} starts with '%', '#' or '<', the expansion is
2758 done like for the |cmdline-special| variables with their
2759 associated modifiers. Here is a short overview:
2760
2761 % current file name
2762 # alternate file name
2763 #n alternate file name n
2764 <cfile> file name under the cursor
2765 <afile> autocmd file name
2766 <abuf> autocmd buffer number (as a String!)
2767 <amatch> autocmd matched name
2768 <cexpr> C expression under the cursor
2769 <sfile> sourced script file or function name
2770 <slnum> sourced script line number or function
2771 line number
2772 <sflnum> script file line number, also when in
2773 a function
2774 <SID> "<SNR>123_" where "123" is the
2775 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002776 <script> sourced script file, or script file
2777 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002778 <stack> call stack
2779 <cword> word under the cursor
2780 <cWORD> WORD under the cursor
2781 <client> the {clientid} of the last received
2782 message |server2client()|
2783 Modifiers:
2784 :p expand to full path
2785 :h head (last path component removed)
2786 :t tail (last path component only)
2787 :r root (one extension removed)
2788 :e extension only
2789
2790 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002791 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002792< Note that when expanding a string that starts with '%', '#' or
2793 '<', any following text is ignored. This does NOT work: >
2794 :let doesntwork = expand("%:h.bak")
2795< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002796 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002797< Also note that expanding "<cfile>" and others only returns the
2798 referenced file name without further expansion. If "<cfile>"
2799 is "~/.cshrc", you need to do another expand() to have the
2800 "~/" expanded into the path of the home directory: >
2801 :echo expand(expand("<cfile>"))
2802<
2803 There cannot be white space between the variables and the
2804 following modifier. The |fnamemodify()| function can be used
2805 to modify normal file names.
2806
2807 When using '%' or '#', and the current or alternate file name
2808 is not defined, an empty string is used. Using "%:p" in a
2809 buffer with no name, results in the current directory, with a
2810 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002811 When 'verbose' is set then expanding '%', '#' and <> items
2812 will result in an error message if the argument cannot be
2813 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002814
2815 When {string} does not start with '%', '#' or '<', it is
2816 expanded like a file name is expanded on the command line.
2817 'suffixes' and 'wildignore' are used, unless the optional
2818 {nosuf} argument is given and it is |TRUE|.
2819 Names for non-existing files are included. The "**" item can
2820 be used to search in a directory tree. For example, to find
2821 all "README" files in the current directory and below: >
2822 :echo expand("**/README")
2823<
2824 expand() can also be used to expand variables and environment
2825 variables that are only known in a shell. But this can be
2826 slow, because a shell may be used to do the expansion. See
2827 |expr-env-expand|.
2828 The expanded variable is still handled like a list of file
2829 names. When an environment variable cannot be expanded, it is
2830 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2831 "$FOOBAR".
2832
2833 See |glob()| for finding existing files. See |system()| for
2834 getting the raw output of an external command.
2835
2836 Can also be used as a |method|: >
2837 Getpattern()->expand()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002838<
2839 Return type: |String| or list<string> depending on {list}
2840
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002841
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002842expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002843 Expand special items in String {string} like what is done for
2844 an Ex command such as `:edit`. This expands special keywords,
2845 like with |expand()|, and environment variables, anywhere in
2846 {string}. "~user" and "~/path" are only expanded at the
2847 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002848
2849 The following items are supported in the {options} Dict
2850 argument:
2851 errmsg If set to TRUE, error messages are displayed
2852 if an error is encountered during expansion.
2853 By default, error messages are not displayed.
2854
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002855 Returns the expanded string. If an error is encountered
2856 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002857
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002858 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002859 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002860 make /path/runtime/doc/builtin.o
2861 :echo expandcmd('make %<.o', {'errmsg': v:true})
2862<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002863 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002864 GetCommand()->expandcmd()
2865<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002866 Return type: |String| or list<string> depending on {list}
2867
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002868extend({expr1}, {expr2} [, {expr3}]) *extend()*
2869 {expr1} and {expr2} must be both |Lists| or both
2870 |Dictionaries|.
2871
2872 If they are |Lists|: Append {expr2} to {expr1}.
2873 If {expr3} is given insert the items of {expr2} before the
2874 item with index {expr3} in {expr1}. When {expr3} is zero
2875 insert before the first item. When {expr3} is equal to
2876 len({expr1}) then {expr2} is appended.
2877 Examples: >
2878 :echo sort(extend(mylist, [7, 5]))
2879 :call extend(mylist, [2, 3], 1)
2880< When {expr1} is the same List as {expr2} then the number of
2881 items copied is equal to the original length of the List.
2882 E.g., when {expr3} is 1 you get N new copies of the first item
2883 (where N is the original length of the List).
2884 Use |add()| to concatenate one item to a list. To concatenate
2885 two lists into a new list use the + operator: >
2886 :let newlist = [1, 2, 3] + [4, 5]
2887<
2888 If they are |Dictionaries|:
2889 Add all entries from {expr2} to {expr1}.
2890 If a key exists in both {expr1} and {expr2} then {expr3} is
2891 used to decide what to do:
2892 {expr3} = "keep": keep the value of {expr1}
2893 {expr3} = "force": use the value of {expr2}
2894 {expr3} = "error": give an error message *E737*
2895 When {expr3} is omitted then "force" is assumed.
2896
2897 {expr1} is changed when {expr2} is not empty. If necessary
2898 make a copy of {expr1} first.
2899 {expr2} remains unchanged.
2900 When {expr1} is locked and {expr2} is not empty the operation
2901 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002902 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002903
2904 Can also be used as a |method|: >
2905 mylist->extend(otherlist)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002906<
2907 Return type: list<{type}> or dict<{type}> depending on {expr1}
2908 and {expr2}, in case of error: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002909
2910
2911extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
2912 Like |extend()| but instead of adding items to {expr1} a new
2913 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00002914 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002915
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002916 Return type: list<{type}> or dict<{type}> depending on {expr1}
2917 and {expr2}, in case of error: |Number|
2918
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002919
2920feedkeys({string} [, {mode}]) *feedkeys()*
2921 Characters in {string} are queued for processing as if they
2922 come from a mapping or were typed by the user.
2923
2924 By default the string is added to the end of the typeahead
2925 buffer, thus if a mapping is still being executed the
2926 characters come after them. Use the 'i' flag to insert before
2927 other characters, they will be executed next, before any
2928 characters from a mapping.
2929
2930 The function does not wait for processing of keys contained in
2931 {string}.
2932
2933 To include special keys into {string}, use double-quotes
2934 and "\..." notation |expr-quote|. For example,
2935 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
2936 feedkeys('\<CR>') pushes 5 characters.
2937 A special code that might be useful is <Ignore>, it exits the
2938 wait for a character without doing anything. *<Ignore>*
2939
2940 {mode} is a String, which can contain these character flags:
2941 'm' Remap keys. This is default. If {mode} is absent,
2942 keys are remapped.
2943 'n' Do not remap keys.
2944 't' Handle keys as if typed; otherwise they are handled as
2945 if coming from a mapping. This matters for undo,
2946 opening folds, etc.
2947 'L' Lowlevel input. Only works for Unix or when using the
2948 GUI. Keys are used as if they were coming from the
2949 terminal. Other flags are not used. *E980*
2950 When a CTRL-C interrupts and 't' is included it sets
2951 the internal "got_int" flag.
2952 'i' Insert the string instead of appending (see above).
2953 'x' Execute commands until typeahead is empty. This is
2954 similar to using ":normal!". You can call feedkeys()
2955 several times without 'x' and then one time with 'x'
2956 (possibly with an empty {string}) to execute all the
2957 typeahead. Note that when Vim ends in Insert mode it
2958 will behave as if <Esc> is typed, to avoid getting
2959 stuck, waiting for a character to be typed before the
2960 script continues.
2961 Note that if you manage to call feedkeys() while
2962 executing commands, thus calling it recursively, then
2963 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00002964 'c' Remove any script context when executing, so that
2965 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01002966 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01002967 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002968 '!' When used with 'x' will not end Insert mode. Can be
2969 used in a test when a timer is set to exit Insert mode
2970 a little later. Useful for testing CursorHoldI.
2971
2972 Return value is always 0.
2973
2974 Can also be used as a |method|: >
2975 GetInput()->feedkeys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002976<
2977 Return type: |String| or list<string> depending on {list}
2978
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002979
Shougo Matsushita60c87432024-06-03 22:59:27 +02002980filecopy({from}, {to}) *filecopy()*
2981 Copy the file pointed to by the name {from} to {to}. The
2982 result is a Number, which is |TRUE| if the file was copied
2983 successfully, and |FALSE| when it failed.
2984 If a file with name {to} already exists, it will fail.
2985 Note that it does not handle directories (yet).
2986
2987 This function is not available in the |sandbox|.
2988
2989 Can also be used as a |method|: >
2990 GetOldName()->filecopy(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002991<
2992 Return type: |Number|
2993
Shougo Matsushita60c87432024-06-03 22:59:27 +02002994
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002995filereadable({file}) *filereadable()*
2996 The result is a Number, which is |TRUE| when a file with the
2997 name {file} exists, and can be read. If {file} doesn't exist,
2998 or is a directory, the result is |FALSE|. {file} is any
2999 expression, which is used as a String.
3000 If you don't care about the file being readable you can use
3001 |glob()|.
3002 {file} is used as-is, you may want to expand wildcards first: >
3003 echo filereadable('~/.vimrc')
3004 0
3005 echo filereadable(expand('~/.vimrc'))
3006 1
3007
3008< Can also be used as a |method|: >
3009 GetName()->filereadable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003010<
3011 Return type: |Number|
3012
3013 *file_readable()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003014 Obsolete name: file_readable().
3015
3016
3017filewritable({file}) *filewritable()*
3018 The result is a Number, which is 1 when a file with the
3019 name {file} exists, and can be written. If {file} doesn't
3020 exist, or is not writable, the result is 0. If {file} is a
3021 directory, and we can write to it, the result is 2.
3022
3023 Can also be used as a |method|: >
3024 GetName()->filewritable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003025<
3026 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003027
3028
3029filter({expr1}, {expr2}) *filter()*
3030 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3031 For each item in {expr1} evaluate {expr2} and when the result
3032 is zero or false remove the item from the |List| or
3033 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003034 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003035
3036 {expr2} must be a |string| or |Funcref|.
3037
3038 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3039 of the current item. For a |Dictionary| |v:key| has the key
3040 of the current item and for a |List| |v:key| has the index of
3041 the current item. For a |Blob| |v:key| has the index of the
3042 current byte. For a |String| |v:key| has the index of the
3043 current character.
3044 Examples: >
3045 call filter(mylist, 'v:val !~ "OLD"')
3046< Removes the items where "OLD" appears. >
3047 call filter(mydict, 'v:key >= 8')
3048< Removes the items with a key below 8. >
3049 call filter(var, 0)
3050< Removes all the items, thus clears the |List| or |Dictionary|.
3051
3052 Note that {expr2} is the result of expression and is then
3053 used as an expression again. Often it is good to use a
3054 |literal-string| to avoid having to double backslashes.
3055
3056 If {expr2} is a |Funcref| it must take two arguments:
3057 1. the key or the index of the current item.
3058 2. the value of the current item.
3059 The function must return |TRUE| if the item should be kept.
3060 Example that keeps the odd items of a list: >
3061 func Odd(idx, val)
3062 return a:idx % 2 == 1
3063 endfunc
3064 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003065< It is shorter when using a |lambda|. In |Vim9| syntax: >
3066 call filter(myList, (idx, val) => idx * val <= 42)
3067< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003068 call filter(myList, {idx, val -> idx * val <= 42})
3069< If you do not use "val" you can leave it out: >
3070 call filter(myList, {idx -> idx % 2 == 1})
3071<
3072 In |Vim9| script the result must be true, false, zero or one.
3073 Other values will result in a type error.
3074
3075 For a |List| and a |Dictionary| the operation is done
3076 in-place. If you want it to remain unmodified make a copy
3077 first: >
3078 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
3079
3080< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00003081 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003082 When an error is encountered while evaluating {expr2} no
3083 further items in {expr1} are processed.
3084 When {expr2} is a Funcref errors inside a function are ignored,
3085 unless it was defined with the "abort" flag.
3086
3087 Can also be used as a |method|: >
3088 mylist->filter(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003089<
3090 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
3091 depending on {expr1}
3092
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003093
3094finddir({name} [, {path} [, {count}]]) *finddir()*
3095 Find directory {name} in {path}. Supports both downwards and
3096 upwards recursive directory searches. See |file-searching|
3097 for the syntax of {path}.
3098
3099 Returns the path of the first found match. When the found
3100 directory is below the current directory a relative path is
3101 returned. Otherwise a full path is returned.
3102 If {path} is omitted or empty then 'path' is used.
3103
3104 If the optional {count} is given, find {count}'s occurrence of
3105 {name} in {path} instead of the first one.
3106 When {count} is negative return all the matches in a |List|.
3107
Bram Moolenaar016188f2022-06-06 20:52:59 +01003108 Returns an empty string if the directory is not found.
3109
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003110 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003111
3112 Can also be used as a |method|: >
3113 GetName()->finddir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003114<
3115 Return type: |String|
3116
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003117
3118findfile({name} [, {path} [, {count}]]) *findfile()*
3119 Just like |finddir()|, but find a file instead of a directory.
3120 Uses 'suffixesadd'.
3121 Example: >
3122 :echo findfile("tags.vim", ".;")
3123< Searches from the directory of the current file upwards until
3124 it finds the file "tags.vim".
3125
3126 Can also be used as a |method|: >
3127 GetName()->findfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003128<
3129 Return type: |String|
3130
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003131
3132flatten({list} [, {maxdepth}]) *flatten()*
3133 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
3134 the result is a |List| without nesting, as if {maxdepth} is
3135 a very large number.
3136 The {list} is changed in place, use |flattennew()| if you do
3137 not want that.
3138 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00003139 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003140 *E900*
3141 {maxdepth} means how deep in nested lists changes are made.
3142 {list} is not modified when {maxdepth} is 0.
3143 {maxdepth} must be positive number.
3144
3145 If there is an error the number zero is returned.
3146
3147 Example: >
3148 :echo flatten([1, [2, [3, 4]], 5])
3149< [1, 2, 3, 4, 5] >
3150 :echo flatten([1, [2, [3, 4]], 5], 1)
3151< [1, 2, [3, 4], 5]
3152
3153 Can also be used as a |method|: >
3154 mylist->flatten()
3155<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003156 Return type: list<{type}>
3157
3158
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003159flattennew({list} [, {maxdepth}]) *flattennew()*
3160 Like |flatten()| but first make a copy of {list}.
3161
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003162 Return type: list<{type}>
3163
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003164
3165float2nr({expr}) *float2nr()*
3166 Convert {expr} to a Number by omitting the part after the
3167 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00003168 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003169 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003170 When the value of {expr} is out of range for a |Number| the
3171 result is truncated to 0x7fffffff or -0x7fffffff (or when
3172 64-bit Number support is enabled, 0x7fffffffffffffff or
3173 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
3174 64-bit Number support is enabled, -0x8000000000000000).
3175 Examples: >
3176 echo float2nr(3.95)
3177< 3 >
3178 echo float2nr(-23.45)
3179< -23 >
3180 echo float2nr(1.0e100)
3181< 2147483647 (or 9223372036854775807) >
3182 echo float2nr(-1.0e150)
3183< -2147483647 (or -9223372036854775807) >
3184 echo float2nr(1.0e-100)
3185< 0
3186
3187 Can also be used as a |method|: >
3188 Compute()->float2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003189<
3190 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003191
3192
3193floor({expr}) *floor()*
3194 Return the largest integral value less than or equal to
3195 {expr} as a |Float| (round down).
3196 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003197 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003198 Examples: >
3199 echo floor(1.856)
3200< 1.0 >
3201 echo floor(-5.456)
3202< -6.0 >
3203 echo floor(4.0)
3204< 4.0
3205
3206 Can also be used as a |method|: >
3207 Compute()->floor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003208<
3209 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003210
3211
3212fmod({expr1}, {expr2}) *fmod()*
3213 Return the remainder of {expr1} / {expr2}, even if the
3214 division is not representable. Returns {expr1} - i * {expr2}
3215 for some integer i such that if {expr2} is non-zero, the
3216 result has the same sign as {expr1} and magnitude less than
3217 the magnitude of {expr2}. If {expr2} is zero, the value
3218 returned is zero. The value returned is a |Float|.
3219 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003220 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
3221 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003222 Examples: >
3223 :echo fmod(12.33, 1.22)
3224< 0.13 >
3225 :echo fmod(-12.33, 1.22)
3226< -0.13
3227
3228 Can also be used as a |method|: >
3229 Compute()->fmod(1.22)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003230<
3231 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003232
3233
3234fnameescape({string}) *fnameescape()*
3235 Escape {string} for use as file name command argument. All
3236 characters that have a special meaning, such as '%' and '|'
3237 are escaped with a backslash.
3238 For most systems the characters escaped are
3239 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3240 appears in a filename, it depends on the value of 'isfname'.
3241 A leading '+' and '>' is also escaped (special after |:edit|
3242 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01003243 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003244 Example: >
3245 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003246 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003247< results in executing: >
3248 edit \+some\ str\%nge\|name
3249<
3250 Can also be used as a |method|: >
3251 GetName()->fnameescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003252<
3253 Return type: |String|
3254
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003255
3256fnamemodify({fname}, {mods}) *fnamemodify()*
3257 Modify file name {fname} according to {mods}. {mods} is a
3258 string of characters like it is used for file names on the
3259 command line. See |filename-modifiers|.
3260 Example: >
3261 :echo fnamemodify("main.c", ":p:h")
3262< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01003263 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01003264< If {mods} is empty or an unsupported modifier is used then
3265 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01003266 When {fname} is empty then with {mods} ":h" returns ".", so
3267 that `:cd` can be used with it. This is different from
3268 expand('%:h') without a buffer name, which returns an empty
3269 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003270 Note: Environment variables don't work in {fname}, use
3271 |expand()| first then.
3272
3273 Can also be used as a |method|: >
3274 GetName()->fnamemodify(':p:h')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003275<
3276 Return type: |String|
3277
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003278
3279foldclosed({lnum}) *foldclosed()*
3280 The result is a Number. If the line {lnum} is in a closed
3281 fold, the result is the number of the first line in that fold.
3282 If the line {lnum} is not in a closed fold, -1 is returned.
3283 {lnum} is used like with |getline()|. Thus "." is the current
3284 line, "'m" mark m, etc.
3285
3286 Can also be used as a |method|: >
3287 GetLnum()->foldclosed()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003288<
3289 Return type: |Number|
3290
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003291
3292foldclosedend({lnum}) *foldclosedend()*
3293 The result is a Number. If the line {lnum} is in a closed
3294 fold, the result is the number of the last line in that fold.
3295 If the line {lnum} is not in a closed fold, -1 is returned.
3296 {lnum} is used like with |getline()|. Thus "." is the current
3297 line, "'m" mark m, etc.
3298
3299 Can also be used as a |method|: >
3300 GetLnum()->foldclosedend()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003301<
3302 Return type: |Number|
3303
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003304
3305foldlevel({lnum}) *foldlevel()*
3306 The result is a Number, which is the foldlevel of line {lnum}
3307 in the current buffer. For nested folds the deepest level is
3308 returned. If there is no fold at line {lnum}, zero is
3309 returned. It doesn't matter if the folds are open or closed.
3310 When used while updating folds (from 'foldexpr') -1 is
3311 returned for lines where folds are still to be updated and the
3312 foldlevel is unknown. As a special case the level of the
3313 previous line is usually available.
3314 {lnum} is used like with |getline()|. Thus "." is the current
3315 line, "'m" mark m, etc.
3316
3317 Can also be used as a |method|: >
3318 GetLnum()->foldlevel()
3319<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003320 Return type: |Number|
3321
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003322 *foldtext()*
3323foldtext() Returns a String, to be displayed for a closed fold. This is
3324 the default function used for the 'foldtext' option and should
3325 only be called from evaluating 'foldtext'. It uses the
3326 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3327 The returned string looks like this: >
3328 +-- 45 lines: abcdef
3329< The number of leading dashes depends on the foldlevel. The
3330 "45" is the number of lines in the fold. "abcdef" is the text
3331 in the first non-blank line of the fold. Leading white space,
3332 "//" or "/*" and the text from the 'foldmarker' and
3333 'commentstring' options is removed.
3334 When used to draw the actual foldtext, the rest of the line
3335 will be filled with the fold char from the 'fillchars'
3336 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003337 Returns an empty string when there is no fold.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003338
3339 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003340 {not available when compiled without the |+folding| feature}
3341
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003342
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003343foldtextresult({lnum}) *foldtextresult()*
3344 Returns the text that is displayed for the closed fold at line
3345 {lnum}. Evaluates 'foldtext' in the appropriate context.
3346 When there is no closed fold at {lnum} an empty string is
3347 returned.
3348 {lnum} is used like with |getline()|. Thus "." is the current
3349 line, "'m" mark m, etc.
3350 Useful when exporting folded text, e.g., to HTML.
3351 {not available when compiled without the |+folding| feature}
3352
3353
3354 Can also be used as a |method|: >
3355 GetLnum()->foldtextresult()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003356<
3357 Return type: |String|
3358
Ernie Raele79e2072024-01-13 11:47:33 +01003359
3360foreach({expr1}, {expr2}) *foreach()*
3361 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3362 For each item in {expr1} execute {expr2}. {expr1} is not
erraelc92b8be2024-01-14 10:11:07 -08003363 modified; its values may be, as with |:lockvar| 1. |E741|
Ernie Raele79e2072024-01-13 11:47:33 +01003364 See |map()| and |filter()| to modify {expr1}.
3365
3366 {expr2} must be a |string| or |Funcref|.
3367
3368 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3369 of the current item. For a |Dictionary| |v:key| has the key
3370 of the current item and for a |List| |v:key| has the index of
3371 the current item. For a |Blob| |v:key| has the index of the
3372 current byte. For a |String| |v:key| has the index of the
3373 current character.
3374 Examples: >
3375 call foreach(mylist, 'used[v:val] = true')
3376< This records the items that are in the {expr1} list.
3377
3378 Note that {expr2} is the result of expression and is then used
3379 as a command. Often it is good to use a |literal-string| to
3380 avoid having to double backslashes.
3381
3382 If {expr2} is a |Funcref| it must take two arguments:
3383 1. the key or the index of the current item.
3384 2. the value of the current item.
3385 With a legacy script lambda you don't get an error if it only
3386 accepts one argument, but with a Vim9 lambda you get "E1106:
3387 One argument too many", the number of arguments must match.
3388 If the function returns a value, it is ignored.
3389
3390 Returns {expr1} in all cases.
3391 When an error is encountered while executing {expr2} no
3392 further items in {expr1} are processed.
3393 When {expr2} is a Funcref errors inside a function are ignored,
3394 unless it was defined with the "abort" flag.
3395
3396 Can also be used as a |method|: >
3397 mylist->foreach(expr2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003398<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003399 Return type: |String|, |Blob| list<{type}> or dict<{type}>
3400 depending on {expr1}
3401
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003402 *foreground()*
3403foreground() Move the Vim window to the foreground. Useful when sent from
3404 a client to a Vim server. |remote_send()|
3405 On Win32 systems this might not work, the OS does not always
3406 allow a window to bring itself to the foreground. Use
3407 |remote_foreground()| instead.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003408
3409 Return type: |Number|
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003410 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003411 Win32 console version}
3412
Bram Moolenaaraa534142022-09-15 21:46:02 +01003413fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003414 Get the full command name from a short abbreviated command
3415 name; see |20.2| for details on command abbreviations.
3416
3417 The string argument {name} may start with a `:` and can
3418 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003419 Returns an empty string if a command doesn't exist, if it's
3420 ambiguous (for user-defined commands) or cannot be shortened
3421 this way. |vim9-no-shorten|
3422
3423 Without the {vim9} argument uses the current script version.
3424 If {vim9} is present and FALSE then legacy script rules are
3425 used. When {vim9} is present and TRUE then Vim9 rules are
3426 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003427
3428 For example `fullcommand('s')`, `fullcommand('sub')`,
3429 `fullcommand(':%substitute')` all return "substitute".
3430
3431 Can also be used as a |method|: >
3432 GetName()->fullcommand()
3433<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003434 Return type: |String|
3435
3436
3437funcref({name} [, {arglist}] [, {dict}]) *funcref()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003438 Just like |function()|, but the returned Funcref will lookup
3439 the function by reference, not by name. This matters when the
3440 function {name} is redefined later.
3441
3442 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003443 It only works for an autoloaded function if it has already
3444 been loaded (to avoid mistakenly loading the autoload script
3445 when only intending to use the function name, use |function()|
3446 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003447 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003448
3449 Can also be used as a |method|: >
3450 GetFuncname()->funcref([arg])
3451<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003452 Return type: func(...): any or |Number| on error
3453
Dominique Pellee764d1b2023-03-12 21:20:59 +00003454 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003455function({name} [, {arglist}] [, {dict}])
3456 Return a |Funcref| variable that refers to function {name}.
3457 {name} can be the name of a user defined function or an
3458 internal function.
3459
3460 {name} can also be a Funcref or a partial. When it is a
3461 partial the dict stored in it will be used and the {dict}
3462 argument is not allowed. E.g.: >
3463 let FuncWithArg = function(dict.Func, [arg])
3464 let Broken = function(dict.Func, [arg], dict)
3465<
3466 When using the Funcref the function will be found by {name},
3467 also when it was redefined later. Use |funcref()| to keep the
3468 same function.
3469
3470 When {arglist} or {dict} is present this creates a partial.
3471 That means the argument list and/or the dictionary is stored in
3472 the Funcref and will be used when the Funcref is called.
3473
3474 The arguments are passed to the function in front of other
3475 arguments, but after any argument from |method|. Example: >
3476 func Callback(arg1, arg2, name)
3477 ...
3478 let Partial = function('Callback', ['one', 'two'])
3479 ...
3480 call Partial('name')
3481< Invokes the function as with: >
3482 call Callback('one', 'two', 'name')
3483
3484< With a |method|: >
3485 func Callback(one, two, three)
3486 ...
3487 let Partial = function('Callback', ['two'])
3488 ...
3489 eval 'one'->Partial('three')
3490< Invokes the function as with: >
3491 call Callback('one', 'two', 'three')
3492
3493< The function() call can be nested to add more arguments to the
3494 Funcref. The extra arguments are appended to the list of
3495 arguments. Example: >
3496 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003497 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003498 let Func = function('Callback', ['one'])
3499 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003500 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003501 call Func2('name')
3502< Invokes the function as with: >
3503 call Callback('one', 'two', 'name')
3504
3505< The Dictionary is only useful when calling a "dict" function.
3506 In that case the {dict} is passed in as "self". Example: >
3507 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003508 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003509 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003510 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003511 let context = {"name": "example"}
3512 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003513 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003514 call Func() " will echo: called for example
3515< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003516 arguments, these two are equivalent, if Callback() is defined
3517 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003518 let Func = function('Callback', context)
3519 let Func = context.Callback
3520
3521< The argument list and the Dictionary can be combined: >
3522 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003523 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003524 let context = {"name": "example"}
3525 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003526 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003527 call Func(500)
3528< Invokes the function as with: >
3529 call context.Callback('one', 500)
3530<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003531 Returns 0 on error.
3532
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003533 Can also be used as a |method|: >
3534 GetFuncname()->function([arg])
3535
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003536<
3537 Return type: func(...): any or |Number| on error
3538
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003539
3540garbagecollect([{atexit}]) *garbagecollect()*
3541 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3542 that have circular references.
3543
3544 There is hardly ever a need to invoke this function, as it is
3545 automatically done when Vim runs out of memory or is waiting
3546 for the user to press a key after 'updatetime'. Items without
3547 circular references are always freed when they become unused.
3548 This is useful if you have deleted a very big |List| and/or
3549 |Dictionary| with circular references in a script that runs
3550 for a long time.
3551
3552 When the optional {atexit} argument is one, garbage
3553 collection will also be done when exiting Vim, if it wasn't
3554 done before. This is useful when checking for memory leaks.
3555
3556 The garbage collection is not done immediately but only when
3557 it's safe to perform. This is when waiting for the user to
3558 type a character. To force garbage collection immediately use
3559 |test_garbagecollect_now()|.
3560
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003561 Return type: |String|
3562
3563
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003564get({list}, {idx} [, {default}]) *get()*
3565 Get item {idx} from |List| {list}. When this item is not
3566 available return {default}. Return zero when {default} is
3567 omitted.
3568 Preferably used as a |method|: >
3569 mylist->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003570<
3571 Return type: any, depending on {list}
3572
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003573get({blob}, {idx} [, {default}])
3574 Get byte {idx} from |Blob| {blob}. When this byte is not
3575 available return {default}. Return -1 when {default} is
3576 omitted.
3577 Preferably used as a |method|: >
3578 myblob->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003579<
3580 Return type: |Number|
3581
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003582get({dict}, {key} [, {default}])
3583 Get item with key {key} from |Dictionary| {dict}. When this
3584 item is not available return {default}. Return zero when
3585 {default} is omitted. Useful example: >
3586 let val = get(g:, 'var_name', 'default')
3587< This gets the value of g:var_name if it exists, and uses
3588 'default' when it does not exist.
3589 Preferably used as a |method|: >
3590 mydict->get(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003591<
3592 Return type: any, depending on {list}
3593
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003594get({func}, {what})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00003595 Get item {what} from Funcref {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003596 {what} are:
3597 "name" The function name
3598 "func" The function
3599 "dict" The dictionary
3600 "args" The list with arguments
Bram Moolenaar016188f2022-06-06 20:52:59 +01003601 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003602 Preferably used as a |method|: >
3603 myfunc->get(what)
3604<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003605 Return type: any, depending on {func}
3606
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003607 *getbufinfo()*
3608getbufinfo([{buf}])
3609getbufinfo([{dict}])
3610 Get information about buffers as a List of Dictionaries.
3611
3612 Without an argument information about all the buffers is
3613 returned.
3614
3615 When the argument is a |Dictionary| only the buffers matching
3616 the specified criteria are returned. The following keys can
3617 be specified in {dict}:
3618 buflisted include only listed buffers.
3619 bufloaded include only loaded buffers.
3620 bufmodified include only modified buffers.
3621
3622 Otherwise, {buf} specifies a particular buffer to return
3623 information for. For the use of {buf}, see |bufname()|
3624 above. If the buffer is found the returned List has one item.
3625 Otherwise the result is an empty list.
3626
3627 Each returned List item is a dictionary with the following
3628 entries:
3629 bufnr Buffer number.
3630 changed TRUE if the buffer is modified.
3631 changedtick Number of changes made to the buffer.
Sean Dewar1fb41032023-08-16 17:15:05 +01003632 command TRUE if the buffer belongs to the
3633 command-line window |cmdwin|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003634 hidden TRUE if the buffer is hidden.
3635 lastused Timestamp in seconds, like
3636 |localtime()|, when the buffer was
3637 last used.
3638 {only with the |+viminfo| feature}
3639 listed TRUE if the buffer is listed.
3640 lnum Line number used for the buffer when
3641 opened in the current window.
3642 Only valid if the buffer has been
3643 displayed in the window in the past.
3644 If you want the line number of the
3645 last known cursor position in a given
3646 window, use |line()|: >
3647 :echo line('.', {winid})
3648<
3649 linecount Number of lines in the buffer (only
3650 valid when loaded)
3651 loaded TRUE if the buffer is loaded.
3652 name Full path to the file in the buffer.
3653 signs List of signs placed in the buffer.
3654 Each list item is a dictionary with
3655 the following fields:
3656 id sign identifier
3657 lnum line number
3658 name sign name
3659 variables A reference to the dictionary with
3660 buffer-local variables.
3661 windows List of |window-ID|s that display this
3662 buffer
3663 popups List of popup |window-ID|s that
3664 display this buffer
3665
3666 Examples: >
3667 for buf in getbufinfo()
3668 echo buf.name
3669 endfor
3670 for buf in getbufinfo({'buflisted':1})
3671 if buf.changed
3672 ....
3673 endif
3674 endfor
3675<
3676 To get buffer-local options use: >
3677 getbufvar({bufnr}, '&option_name')
3678<
3679 Can also be used as a |method|: >
3680 GetBufnr()->getbufinfo()
3681<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003682 Return type: list<dict<any>>
3683
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003684
3685 *getbufline()*
3686getbufline({buf}, {lnum} [, {end}])
3687 Return a |List| with the lines starting from {lnum} to {end}
3688 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003689 |List| with only the line {lnum} is returned. See
3690 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003691
3692 For the use of {buf}, see |bufname()| above.
3693
3694 For {lnum} and {end} "$" can be used for the last line of the
3695 buffer. Otherwise a number must be used.
3696
3697 When {lnum} is smaller than 1 or bigger than the number of
3698 lines in the buffer, an empty |List| is returned.
3699
3700 When {end} is greater than the number of lines in the buffer,
3701 it is treated as {end} is set to the number of lines in the
3702 buffer. When {end} is before {lnum} an empty |List| is
3703 returned.
3704
3705 This function works only for loaded buffers. For unloaded and
3706 non-existing buffers, an empty |List| is returned.
3707
3708 Example: >
3709 :let lines = getbufline(bufnr("myfile"), 1, "$")
3710
3711< Can also be used as a |method|: >
3712 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003713<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003714 Return type: list<string>
3715
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003716 *getbufoneline()*
3717getbufoneline({buf}, {lnum})
3718 Just like `getbufline()` but only get one line and return it
3719 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003720
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003721 Return type: |String|
3722
3723
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003724getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3725 The result is the value of option or local buffer variable
3726 {varname} in buffer {buf}. Note that the name without "b:"
3727 must be used.
3728 The {varname} argument is a string.
3729 When {varname} is empty returns a |Dictionary| with all the
3730 buffer-local variables.
3731 When {varname} is equal to "&" returns a |Dictionary| with all
3732 the buffer-local options.
3733 Otherwise, when {varname} starts with "&" returns the value of
3734 a buffer-local option.
3735 This also works for a global or buffer-local option, but it
3736 doesn't work for a global variable, window-local variable or
3737 window-local option.
3738 For the use of {buf}, see |bufname()| above.
3739 When the buffer or variable doesn't exist {def} or an empty
3740 string is returned, there is no error message.
3741 Examples: >
3742 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003743 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003744
3745< Can also be used as a |method|: >
3746 GetBufnr()->getbufvar(varname)
3747<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003748 Return type: any, depending on {varname}
3749
3750
Kota Kato66bb9ae2023-01-17 18:31:56 +00003751getcellwidths() *getcellwidths()*
3752 Returns a |List| of cell widths of character ranges overridden
3753 by |setcellwidths()|. The format is equal to the argument of
3754 |setcellwidths()|. If no character ranges have their cell
3755 widths overridden, an empty List is returned.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003756<
3757 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003758
3759
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003760getchangelist([{buf}]) *getchangelist()*
3761 Returns the |changelist| for the buffer {buf}. For the use
3762 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3763 exist, an empty list is returned.
3764
3765 The returned list contains two entries: a list with the change
3766 locations and the current position in the list. Each
3767 entry in the change list is a dictionary with the following
3768 entries:
3769 col column number
3770 coladd column offset for 'virtualedit'
3771 lnum line number
3772 If buffer {buf} is the current buffer, then the current
3773 position refers to the position in the list. For other
3774 buffers, it is set to the length of the list.
3775
3776 Can also be used as a |method|: >
3777 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003778<
3779 Return type: list<any>
3780
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003781
Doug Kearns9cd9e752024-04-07 17:42:17 +02003782getchar([{expr}]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003783 Get a single character from the user or input stream.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003784 If {expr} is omitted, wait until a character is available.
3785 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003786 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003787 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003788 not consumed. Return zero if no character available.
3789 If you prefer always getting a string use |getcharstr()|.
3790
Doug Kearns9cd9e752024-04-07 17:42:17 +02003791 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003792 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003793 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003794 Otherwise a String is returned with the encoded character.
3795 For a special key it's a String with a sequence of bytes
3796 starting with 0x80 (decimal: 128). This is the same value as
3797 the String "\<Key>", e.g., "\<Left>". The returned value is
3798 also a String when a modifier (shift, control, alt) was used
3799 that is not included in the character.
3800
Doug Kearns9cd9e752024-04-07 17:42:17 +02003801 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003802 while Vim waits to see if this is the start of an escape
3803 sequence.
3804
Doug Kearns9cd9e752024-04-07 17:42:17 +02003805 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003806 one-byte character it is the character itself as a number.
3807 Use nr2char() to convert it to a String.
3808
3809 Use getcharmod() to obtain any additional modifiers.
3810
3811 When the user clicks a mouse button, the mouse event will be
3812 returned. The position can then be found in |v:mouse_col|,
3813 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3814 |getmousepos()| can also be used. Mouse move events will be
3815 ignored.
3816 This example positions the mouse as it would normally happen: >
3817 let c = getchar()
3818 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003819 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003820 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003821 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003822 endif
3823<
3824 When using bracketed paste only the first character is
3825 returned, the rest of the pasted text is dropped.
3826 |xterm-bracketed-paste|.
3827
3828 There is no prompt, you will somehow have to make clear to the
3829 user that a character has to be typed. The screen is not
3830 redrawn, e.g. when resizing the window. When using a popup
3831 window it should work better with a |popup-filter|.
3832
3833 There is no mapping for the character.
3834 Key codes are replaced, thus when the user presses the <Del>
3835 key you get the code for the <Del> key, not the raw character
3836 sequence. Examples: >
3837 getchar() == "\<Del>"
3838 getchar() == "\<S-Left>"
3839< This example redefines "f" to ignore case: >
3840 :nmap f :call FindChar()<CR>
3841 :function FindChar()
3842 : let c = nr2char(getchar())
3843 : while col('.') < col('$') - 1
3844 : normal l
3845 : if getline('.')[col('.') - 1] ==? c
3846 : break
3847 : endif
3848 : endwhile
3849 :endfunction
3850<
3851 You may also receive synthetic characters, such as
3852 |<CursorHold>|. Often you will want to ignore this and get
3853 another character: >
3854 :function GetKey()
3855 : let c = getchar()
3856 : while c == "\<CursorHold>"
3857 : let c = getchar()
3858 : endwhile
3859 : return c
3860 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003861<
3862 Return type: |Number| or |String|
3863
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003864
3865getcharmod() *getcharmod()*
3866 The result is a Number which is the state of the modifiers for
3867 the last obtained character with getchar() or in another way.
3868 These values are added together:
3869 2 shift
3870 4 control
3871 8 alt (meta)
3872 16 meta (when it's different from ALT)
3873 32 mouse double click
3874 64 mouse triple click
3875 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01003876 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003877 Only the modifiers that have not been included in the
3878 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01003879 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003880
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003881 Return type: |Number|
3882
3883
3884getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003885 Get the position for String {expr}. Same as |getpos()| but the
3886 column number in the returned List is a character index
3887 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00003888 If |getpos()| returns a very large column number, equal to
3889 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003890 of the last character.
3891
3892 Example:
3893 With the cursor on '세' in line 5 with text "여보세요": >
3894 getcharpos('.') returns [0, 5, 3, 0]
3895 getpos('.') returns [0, 5, 7, 0]
3896<
3897 Can also be used as a |method|: >
3898 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003899<
3900 Return type: list<number>
3901
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003902
3903getcharsearch() *getcharsearch()*
3904 Return the current character search information as a {dict}
3905 with the following entries:
3906
3907 char character previously used for a character
3908 search (|t|, |f|, |T|, or |F|); empty string
3909 if no character search has been performed
3910 forward direction of character search; 1 for forward,
3911 0 for backward
3912 until type of character search; 1 for a |t| or |T|
3913 character search, 0 for an |f| or |F|
3914 character search
3915
3916 This can be useful to always have |;| and |,| search
3917 forward/backward regardless of the direction of the previous
3918 character search: >
3919 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
3920 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
3921< Also see |setcharsearch()|.
3922
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003923 Return type: dict<any>
3924
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003925
Doug Kearns9cd9e752024-04-07 17:42:17 +02003926getcharstr([{expr}]) *getcharstr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003927 Get a single character from the user or input stream as a
3928 string.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003929 If {expr} is omitted, wait until a character is available.
3930 If {expr} is 0 or false, only get a character when one is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003931 available. Return an empty string otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003932 If {expr} is 1 or true, only check if a character is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003933 available, it is not consumed. Return an empty string
3934 if no character is available.
3935 Otherwise this works like |getchar()|, except that a number
3936 result is converted to a string.
3937
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003938 Return type: |String|
3939
3940
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003941getcmdcompltype() *getcmdcompltype()*
3942 Return the type of the current command-line completion.
3943 Only works when the command line is being edited, thus
3944 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01003945 See |:command-completion| for the return string.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003946 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
3947 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003948 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003949
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003950 Return type: |String|
3951
3952
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003953getcmdline() *getcmdline()*
3954 Return the current command-line. Only works when the command
3955 line is being edited, thus requires use of |c_CTRL-\_e| or
3956 |c_CTRL-R_=|.
3957 Example: >
3958 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003959< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()| and
3960 |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003961 Returns an empty string when entering a password or using
3962 |inputsecret()|.
3963
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003964 Return type: |String|
3965
3966
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003967getcmdpos() *getcmdpos()*
3968 Return the position of the cursor in the command line as a
3969 byte count. The first column is 1.
3970 Only works when editing the command line, thus requires use of
3971 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3972 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003973 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
3974 |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003975
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003976 Return type: |Number|
3977
3978
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003979getcmdscreenpos() *getcmdscreenpos()*
3980 Return the screen position of the cursor in the command line
3981 as a byte count. The first column is 1.
3982 Instead of |getcmdpos()|, it adds the prompt position.
3983 Only works when editing the command line, thus requires use of
3984 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3985 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003986 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
3987 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003988
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003989 Return type: |Number|
3990
3991
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003992getcmdtype() *getcmdtype()*
3993 Return the current command-line type. Possible return values
3994 are:
3995 : normal Ex command
3996 > debug mode command |debug-mode|
3997 / forward search command
3998 ? backward search command
3999 @ |input()| command
4000 - |:insert| or |:append| command
4001 = |i_CTRL-R_=|
4002 Only works when editing the command line, thus requires use of
4003 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4004 Returns an empty string otherwise.
4005 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4006
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004007 Return type: |String|
4008
4009
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004010getcmdwintype() *getcmdwintype()*
4011 Return the current |command-line-window| type. Possible return
4012 values are the same as |getcmdtype()|. Returns an empty string
4013 when not in the command-line window.
4014
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004015 Return type: |String|
4016
4017
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004018getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4019 Return a list of command-line completion matches. The String
4020 {type} argument specifies what for. The following completion
4021 types are supported:
4022
4023 arglist file names in argument list
4024 augroup autocmd groups
4025 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004026 behave |:behave| suboptions
4027 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004028 color color schemes
4029 command Ex command
4030 cmdline |cmdline-completion| result
4031 compiler compilers
4032 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004033 custom,{func} custom completion, defined via {func}
4034 customlist,{func} custom completion, defined via {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004035 diff_buffer |:diffget| and |:diffput| completion
4036 dir directory names
4037 environment environment variable names
4038 event autocommand events
4039 expression Vim expression
4040 file file and directory names
4041 file_in_path file and directory names in |'path'|
4042 filetype filetype names |'filetype'|
4043 function function name
4044 help help subjects
4045 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004046 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004047 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004048 locale locale names (as output of locale -a)
4049 mapclear buffer argument
4050 mapping mapping name
4051 menu menus
4052 messages |:messages| suboptions
4053 option options
4054 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004055 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004056 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004057 shellcmd Shell command
4058 sign |:sign| suboptions
4059 syntax syntax file names |'syntax'|
4060 syntime |:syntime| suboptions
4061 tag tags
4062 tag_listfiles tags, file names
4063 user user names
4064 var user variables
4065
4066 If {pat} is an empty string, then all the matches are
4067 returned. Otherwise only items matching {pat} are returned.
4068 See |wildcards| for the use of special characters in {pat}.
4069
4070 If the optional {filtered} flag is set to 1, then 'wildignore'
4071 is applied to filter the results. Otherwise all the matches
4072 are returned. The 'wildignorecase' option always applies.
4073
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004074 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4075 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004076 regular expression matching is used. Thus this function
4077 follows the user preference, what happens on the command line.
4078 If you do not want this you can make 'wildoptions' empty
4079 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004080
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004081 If {type} is "cmdline", then the |cmdline-completion| result is
4082 returned. For example, to complete the possible values after
4083 a ":call" command: >
4084 echo getcompletion('call ', 'cmdline')
4085<
4086 If there are no matches, an empty list is returned. An
4087 invalid value for {type} produces an error.
4088
4089 Can also be used as a |method|: >
4090 GetPattern()->getcompletion('color')
4091<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004092 Return type: list<string>
4093
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004094 *getcurpos()*
4095getcurpos([{winid}])
4096 Get the position of the cursor. This is like getpos('.'), but
4097 includes an extra "curswant" item in the list:
4098 [0, lnum, col, off, curswant] ~
4099 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004100 cursor vertically. After |$| command it will be a very large
4101 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004102 |getpos()|.
4103 The first "bufnum" item is always zero. The byte position of
4104 the cursor is returned in 'col'. To get the character
4105 position, use |getcursorcharpos()|.
4106
4107 The optional {winid} argument can specify the window. It can
4108 be the window number or the |window-ID|. The last known
4109 cursor position is returned, this may be invalid for the
4110 current value of the buffer if it is not the current window.
4111 If {winid} is invalid a list with zeroes is returned.
4112
4113 This can be used to save and restore the cursor position: >
4114 let save_cursor = getcurpos()
4115 MoveTheCursorAround
4116 call setpos('.', save_cursor)
4117< Note that this only works within the window. See
4118 |winrestview()| for restoring more state.
4119
4120 Can also be used as a |method|: >
4121 GetWinid()->getcurpos()
4122<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004123 Return type: list<number>
4124
4125
4126getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004127 Same as |getcurpos()| but the column number in the returned
4128 List is a character index instead of a byte index.
4129
4130 Example:
4131 With the cursor on '보' in line 3 with text "여보세요": >
4132 getcursorcharpos() returns [0, 3, 2, 0, 3]
4133 getcurpos() returns [0, 3, 4, 0, 3]
4134<
4135 Can also be used as a |method|: >
4136 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004137<
4138 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004139
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004140
4141getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004142 The result is a String, which is the name of the current
4143 working directory. 'autochdir' is ignored.
4144
4145 With {winnr} return the local current directory of this window
4146 in the current tab page. {winnr} can be the window number or
4147 the |window-ID|.
4148 If {winnr} is -1 return the name of the global working
4149 directory. See also |haslocaldir()|.
4150
4151 With {winnr} and {tabnr} return the local current directory of
4152 the window in the specified tab page. If {winnr} is -1 return
4153 the working directory of the tabpage.
4154 If {winnr} is zero use the current window, if {tabnr} is zero
4155 use the current tabpage.
4156 Without any arguments, return the actual working directory of
4157 the current window.
4158 Return an empty string if the arguments are invalid.
4159
4160 Examples: >
4161 " Get the working directory of the current window
4162 :echo getcwd()
4163 :echo getcwd(0)
4164 :echo getcwd(0, 0)
4165 " Get the working directory of window 3 in tabpage 2
4166 :echo getcwd(3, 2)
4167 " Get the global working directory
4168 :echo getcwd(-1)
4169 " Get the working directory of tabpage 3
4170 :echo getcwd(-1, 3)
4171 " Get the working directory of current tabpage
4172 :echo getcwd(-1, 0)
4173
4174< Can also be used as a |method|: >
4175 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004176<
4177 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004178
4179getenv({name}) *getenv()*
4180 Return the value of environment variable {name}. The {name}
4181 argument is a string, without a leading '$'. Example: >
4182 myHome = getenv('HOME')
4183
4184< When the variable does not exist |v:null| is returned. That
4185 is different from a variable set to an empty string, although
4186 some systems interpret the empty value as the variable being
4187 deleted. See also |expr-env|.
4188
4189 Can also be used as a |method|: >
4190 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004191<
4192 Return type: |String| or |Number|
4193
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004194
4195getfontname([{name}]) *getfontname()*
4196 Without an argument returns the name of the normal font being
4197 used. Like what is used for the Normal highlight group
4198 |hl-Normal|.
4199 With an argument a check is done whether String {name} is a
4200 valid font name. If not then an empty string is returned.
4201 Otherwise the actual font name is returned, or {name} if the
4202 GUI does not support obtaining the real name.
4203 Only works when the GUI is running, thus not in your vimrc or
4204 gvimrc file. Use the |GUIEnter| autocommand to use this
4205 function just after the GUI has started.
4206 Note that the GTK GUI accepts any font name, thus checking for
4207 a valid name does not work.
4208
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004209 Return type: |String|
4210
4211
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004212getfperm({fname}) *getfperm()*
4213 The result is a String, which is the read, write, and execute
4214 permissions of the given file {fname}.
4215 If {fname} does not exist or its directory cannot be read, an
4216 empty string is returned.
4217 The result is of the form "rwxrwxrwx", where each group of
4218 "rwx" flags represent, in turn, the permissions of the owner
4219 of the file, the group the file belongs to, and other users.
4220 If a user does not have a given permission the flag for this
4221 is replaced with the string "-". Examples: >
4222 :echo getfperm("/etc/passwd")
4223 :echo getfperm(expand("~/.vimrc"))
4224< This will hopefully (from a security point of view) display
4225 the string "rw-r--r--" or even "rw-------".
4226
4227 Can also be used as a |method|: >
4228 GetFilename()->getfperm()
4229<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004230 Return type: |String|
4231
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004232 For setting permissions use |setfperm()|.
4233
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004234
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004235getfsize({fname}) *getfsize()*
4236 The result is a Number, which is the size in bytes of the
4237 given file {fname}.
4238 If {fname} is a directory, 0 is returned.
4239 If the file {fname} can't be found, -1 is returned.
4240 If the size of {fname} is too big to fit in a Number then -2
4241 is returned.
4242
4243 Can also be used as a |method|: >
4244 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004245<
4246 Return type: |Number|
4247
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004248
4249getftime({fname}) *getftime()*
4250 The result is a Number, which is the last modification time of
4251 the given file {fname}. The value is measured as seconds
4252 since 1st Jan 1970, and may be passed to strftime(). See also
4253 |localtime()| and |strftime()|.
4254 If the file {fname} can't be found -1 is returned.
4255
4256 Can also be used as a |method|: >
4257 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004258<
4259 Return type: |Number|
4260
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004261
4262getftype({fname}) *getftype()*
4263 The result is a String, which is a description of the kind of
4264 file of the given file {fname}.
4265 If {fname} does not exist an empty string is returned.
4266 Here is a table over different kinds of files and their
4267 results:
4268 Normal file "file"
4269 Directory "dir"
4270 Symbolic link "link"
4271 Block device "bdev"
4272 Character device "cdev"
4273 Socket "socket"
4274 FIFO "fifo"
4275 All other "other"
4276 Example: >
4277 getftype("/home")
4278< Note that a type such as "link" will only be returned on
4279 systems that support it. On some systems only "dir" and
4280 "file" are returned. On MS-Windows a symbolic link to a
4281 directory returns "dir" instead of "link".
4282
4283 Can also be used as a |method|: >
4284 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004285<
4286 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004287
4288getimstatus() *getimstatus()*
4289 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004290 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004291 See 'imstatusfunc'.
4292
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004293 Return type: |Number|
4294
4295
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004296getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4297 Returns the |jumplist| for the specified window.
4298
4299 Without arguments use the current window.
4300 With {winnr} only use this window in the current tab page.
4301 {winnr} can also be a |window-ID|.
4302 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004303 page. If {winnr} or {tabnr} is invalid, an empty list is
4304 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004305
4306 The returned list contains two entries: a list with the jump
4307 locations and the last used jump position number in the list.
4308 Each entry in the jump location list is a dictionary with
4309 the following entries:
4310 bufnr buffer number
4311 col column number
4312 coladd column offset for 'virtualedit'
4313 filename filename if available
4314 lnum line number
4315
4316 Can also be used as a |method|: >
4317 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004318<
4319 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004320
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004321 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004322getline({lnum} [, {end}])
4323 Without {end} the result is a String, which is line {lnum}
4324 from the current buffer. Example: >
4325 getline(1)
4326< When {lnum} is a String that doesn't start with a
4327 digit, |line()| is called to translate the String into a Number.
4328 To get the line under the cursor: >
4329 getline(".")
4330< When {lnum} is a number smaller than 1 or bigger than the
4331 number of lines in the buffer, an empty string is returned.
4332
4333 When {end} is given the result is a |List| where each item is
4334 a line from the current buffer in the range {lnum} to {end},
4335 including line {end}.
4336 {end} is used in the same way as {lnum}.
4337 Non-existing lines are silently omitted.
4338 When {end} is before {lnum} an empty |List| is returned.
4339 Example: >
4340 :let start = line('.')
4341 :let end = search("^$") - 1
4342 :let lines = getline(start, end)
4343
4344< Can also be used as a |method|: >
4345 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004346<
4347 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004348
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004349 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004350 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004351
4352getloclist({nr} [, {what}]) *getloclist()*
4353 Returns a |List| with all the entries in the location list for
4354 window {nr}. {nr} can be the window number or the |window-ID|.
4355 When {nr} is zero the current window is used.
4356
4357 For a location list window, the displayed location list is
4358 returned. For an invalid window number {nr}, an empty list is
4359 returned. Otherwise, same as |getqflist()|.
4360
4361 If the optional {what} dictionary argument is supplied, then
4362 returns the items listed in {what} as a dictionary. Refer to
4363 |getqflist()| for the supported items in {what}.
4364
4365 In addition to the items supported by |getqflist()| in {what},
4366 the following item is supported by |getloclist()|:
4367
4368 filewinid id of the window used to display files
4369 from the location list. This field is
4370 applicable only when called from a
4371 location list window. See
4372 |location-list-file-window| for more
4373 details.
4374
4375 Returns a |Dictionary| with default values if there is no
4376 location list for the window {nr}.
4377 Returns an empty Dictionary if window {nr} does not exist.
4378
4379 Examples (See also |getqflist-examples|): >
4380 :echo getloclist(3, {'all': 0})
4381 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004382<
4383 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004384
4385
4386getmarklist([{buf}]) *getmarklist()*
4387 Without the {buf} argument returns a |List| with information
4388 about all the global marks. |mark|
4389
4390 If the optional {buf} argument is specified, returns the
4391 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004392 see |bufname()|. If {buf} is invalid, an empty list is
4393 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004394
4395 Each item in the returned List is a |Dict| with the following:
4396 mark name of the mark prefixed by "'"
4397 pos a |List| with the position of the mark:
4398 [bufnum, lnum, col, off]
4399 Refer to |getpos()| for more information.
4400 file file name
4401
4402 Refer to |getpos()| for getting information about a specific
4403 mark.
4404
4405 Can also be used as a |method|: >
4406 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004407<
4408 Return type: list<dict<any>> or list<any>
4409
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004410
4411getmatches([{win}]) *getmatches()*
4412 Returns a |List| with all matches previously defined for the
4413 current window by |matchadd()| and the |:match| commands.
4414 |getmatches()| is useful in combination with |setmatches()|,
4415 as |setmatches()| can restore a list of matches saved by
4416 |getmatches()|.
4417 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004418 window ID instead of the current window. If {win} is invalid,
4419 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004420 Example: >
4421 :echo getmatches()
4422< [{'group': 'MyGroup1', 'pattern': 'TODO',
4423 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4424 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4425 :let m = getmatches()
4426 :call clearmatches()
4427 :echo getmatches()
4428< [] >
4429 :call setmatches(m)
4430 :echo getmatches()
4431< [{'group': 'MyGroup1', 'pattern': 'TODO',
4432 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4433 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4434 :unlet m
4435<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004436 Return type: list<dict<any>> or list<any>
4437
4438
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004439getmousepos() *getmousepos()*
4440 Returns a |Dictionary| with the last known position of the
4441 mouse. This can be used in a mapping for a mouse click or in
4442 a filter of a popup window. The items are:
4443 screenrow screen row
4444 screencol screen column
4445 winid Window ID of the click
4446 winrow row inside "winid"
4447 wincol column inside "winid"
4448 line text line inside "winid"
4449 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004450 coladd offset (in screen columns) from the
4451 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004452 All numbers are 1-based.
4453
4454 If not over a window, e.g. when in the command line, then only
4455 "screenrow" and "screencol" are valid, the others are zero.
4456
4457 When on the status line below a window or the vertical
4458 separator right of a window, the "line" and "column" values
4459 are zero.
4460
4461 When the position is after the text then "column" is the
4462 length of the text in bytes plus one.
4463
4464 If the mouse is over a popup window then that window is used.
4465
4466 When using |getchar()| the Vim variables |v:mouse_lnum|,
4467 |v:mouse_col| and |v:mouse_winid| also provide these values.
4468
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004469 Return type: dict<number>
4470
4471
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004472getmouseshape() *getmouseshape()*
4473 Returns the name of the currently showing mouse pointer.
4474 When the |+mouseshape| feature is not supported or the shape
4475 is unknown an empty string is returned.
4476 This function is mainly intended for testing.
4477
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004478 Return type: |String|
4479
4480
4481getpid() *getpid()*
4482 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004483 On Unix and MS-Windows this is a unique number, until Vim
4484 exits.
4485
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004486 Return type: |Number|
4487
4488
4489getpos({expr}) *getpos()*
zeertzjq02f3eba2024-06-12 20:45:24 +02004490 Get the position for String {expr}.
4491 The accepted values for {expr} are: *E1209*
4492 . The cursor position.
4493 $ The last line in the current buffer.
4494 'x Position of mark x (if the mark is not set, 0 is
4495 returned).
4496 w0 First line visible in current window (one if the
4497 display isn't updated, e.g. in silent Ex mode).
4498 w$ Last line visible in current window (this is one
4499 less than "w0" if no lines are visible).
4500 v When not in Visual mode, returns the cursor
4501 position. In Visual mode, returns the other end
4502 of the Visual area. A good way to think about
4503 this is that in Visual mode "v" and "." complement
4504 each other. While "." refers to the cursor
4505 position, "v" refers to where |v_o| would move the
4506 cursor. As a result, you can use "v" and "."
4507 together to work on all of a selection in
4508 characterwise Visual mode. If the cursor is at
4509 the end of a characterwise Visual area, "v" refers
4510 to the start of the same Visual area. And if the
4511 cursor is at the start of a characterwise Visual
4512 area, "v" refers to the end of the same Visual
4513 area. "v" differs from |'<| and |'>| in that it's
4514 updated right away.
4515 Note that a mark in another file can be used. The line number
4516 then applies to another buffer.
4517
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004518 The result is a |List| with four numbers:
4519 [bufnum, lnum, col, off]
4520 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4521 is the buffer number of the mark.
4522 "lnum" and "col" are the position in the buffer. The first
4523 column is 1.
4524 The "off" number is zero, unless 'virtualedit' is used. Then
4525 it is the offset in screen columns from the start of the
4526 character. E.g., a position within a <Tab> or after the last
4527 character.
zeertzjq02f3eba2024-06-12 20:45:24 +02004528
4529 For getting the cursor position see |getcurpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004530 The column number in the returned List is the byte position
4531 within the line. To get the character position in the line,
4532 use |getcharpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02004533
4534 Note that for '< and '> Visual mode matters: when it is "V"
4535 (visual line mode) the column of '< is zero and the column of
4536 '> is a large number equal to |v:maxcol|.
naohiro ono56200ee2022-01-01 14:59:44 +00004537 A very large column number equal to |v:maxcol| can be returned,
4538 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004539 If {expr} is invalid, returns a list with all zeros.
zeertzjq02f3eba2024-06-12 20:45:24 +02004540
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004541 This can be used to save and restore the position of a mark: >
4542 let save_a_mark = getpos("'a")
4543 ...
4544 call setpos("'a", save_a_mark)
zeertzjq02f3eba2024-06-12 20:45:24 +02004545
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004546< Also see |getcharpos()|, |getcurpos()| and |setpos()|.
4547
4548 Can also be used as a |method|: >
4549 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004550<
4551 Return type: list<number>
4552
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004553
4554getqflist([{what}]) *getqflist()*
4555 Returns a |List| with all the current quickfix errors. Each
4556 list item is a dictionary with these entries:
4557 bufnr number of buffer that has the file name, use
4558 bufname() to get the name
4559 module module name
4560 lnum line number in the buffer (first line is 1)
4561 end_lnum
4562 end of line number if the item is multiline
4563 col column number (first column is 1)
4564 end_col end of column number if the item has range
4565 vcol |TRUE|: "col" is visual column
4566 |FALSE|: "col" is byte index
4567 nr error number
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004568 pattern search list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004569 text description of the error
4570 type type of the error, 'E', '1', etc.
4571 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004572 user_data
4573 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004574 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004575
4576 When there is no error list or it's empty, an empty list is
4577 returned. Quickfix list entries with a non-existing buffer
4578 number are returned with "bufnr" set to zero (Note: some
4579 functions accept buffer number zero for the alternate buffer,
4580 you may need to explicitly check for zero).
4581
4582 Useful application: Find pattern matches in multiple files and
4583 do something with them: >
4584 :vimgrep /theword/jg *.c
4585 :for d in getqflist()
4586 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4587 :endfor
4588<
4589 If the optional {what} dictionary argument is supplied, then
4590 returns only the items listed in {what} as a dictionary. The
4591 following string items are supported in {what}:
4592 changedtick get the total number of changes made
4593 to the list |quickfix-changedtick|
4594 context get the |quickfix-context|
4595 efm errorformat to use when parsing "lines". If
4596 not present, then the 'errorformat' option
4597 value is used.
4598 id get information for the quickfix list with
4599 |quickfix-ID|; zero means the id for the
4600 current list or the list specified by "nr"
4601 idx get information for the quickfix entry at this
4602 index in the list specified by 'id' or 'nr'.
4603 If set to zero, then uses the current entry.
4604 See |quickfix-index|
4605 items quickfix list entries
4606 lines parse a list of lines using 'efm' and return
4607 the resulting entries. Only a |List| type is
4608 accepted. The current quickfix list is not
4609 modified. See |quickfix-parse|.
4610 nr get information for this quickfix list; zero
4611 means the current quickfix list and "$" means
4612 the last quickfix list
4613 qfbufnr number of the buffer displayed in the quickfix
4614 window. Returns 0 if the quickfix buffer is
4615 not present. See |quickfix-buffer|.
4616 size number of entries in the quickfix list
4617 title get the list title |quickfix-title|
4618 winid get the quickfix |window-ID|
4619 all all of the above quickfix properties
4620 Non-string items in {what} are ignored. To get the value of a
4621 particular item, set it to zero.
4622 If "nr" is not present then the current quickfix list is used.
4623 If both "nr" and a non-zero "id" are specified, then the list
4624 specified by "id" is used.
4625 To get the number of lists in the quickfix stack, set "nr" to
4626 "$" in {what}. The "nr" value in the returned dictionary
4627 contains the quickfix stack size.
4628 When "lines" is specified, all the other items except "efm"
4629 are ignored. The returned dictionary contains the entry
4630 "items" with the list of entries.
4631
4632 The returned dictionary contains the following entries:
4633 changedtick total number of changes made to the
4634 list |quickfix-changedtick|
4635 context quickfix list context. See |quickfix-context|
4636 If not present, set to "".
4637 id quickfix list ID |quickfix-ID|. If not
4638 present, set to 0.
4639 idx index of the quickfix entry in the list. If not
4640 present, set to 0.
4641 items quickfix list entries. If not present, set to
4642 an empty list.
4643 nr quickfix list number. If not present, set to 0
4644 qfbufnr number of the buffer displayed in the quickfix
4645 window. If not present, set to 0.
4646 size number of entries in the quickfix list. If not
4647 present, set to 0.
4648 title quickfix list title text. If not present, set
4649 to "".
4650 winid quickfix |window-ID|. If not present, set to 0
4651
4652 Examples (See also |getqflist-examples|): >
4653 :echo getqflist({'all': 1})
4654 :echo getqflist({'nr': 2, 'title': 1})
4655 :echo getqflist({'lines' : ["F1:10:L10"]})
4656<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004657 Return type: list<dict<any>> or list<any>
4658
4659
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004660getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4661 The result is a String, which is the contents of register
4662 {regname}. Example: >
4663 :let cliptext = getreg('*')
4664< When register {regname} was not set the result is an empty
4665 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004666 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004667
4668 getreg('=') returns the last evaluated value of the expression
4669 register. (For use in maps.)
4670 getreg('=', 1) returns the expression itself, so that it can
4671 be restored with |setreg()|. For other registers the extra
4672 argument is ignored, thus you can always give it.
4673
4674 If {list} is present and |TRUE|, the result type is changed
4675 to |List|. Each list item is one text line. Use it if you care
4676 about zero bytes possibly present inside register: without
4677 third argument both NLs and zero bytes are represented as NLs
4678 (see |NL-used-for-Nul|).
4679 When the register was not set an empty list is returned.
4680
4681 If {regname} is "", the unnamed register '"' is used.
4682 If {regname} is not specified, |v:register| is used.
4683 In |Vim9-script| {regname} must be one character.
4684
4685 Can also be used as a |method|: >
4686 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004687<
4688 Return type: |String|
4689
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004690
4691getreginfo([{regname}]) *getreginfo()*
4692 Returns detailed information about register {regname} as a
4693 Dictionary with the following entries:
4694 regcontents List of lines contained in register
4695 {regname}, like
4696 |getreg|({regname}, 1, 1).
4697 regtype the type of register {regname}, as in
4698 |getregtype()|.
4699 isunnamed Boolean flag, v:true if this register
4700 is currently pointed to by the unnamed
4701 register.
4702 points_to for the unnamed register, gives the
4703 single letter name of the register
4704 currently pointed to (see |quotequote|).
4705 For example, after deleting a line
4706 with `dd`, this field will be "1",
4707 which is the register that got the
4708 deleted text.
4709
4710 The {regname} argument is a string. If {regname} is invalid
4711 or not set, an empty Dictionary will be returned.
4712 If {regname} is "" or "@", the unnamed register '"' is used.
4713 If {regname} is not specified, |v:register| is used.
4714 The returned Dictionary can be passed to |setreg()|.
4715 In |Vim9-script| {regname} must be one character.
4716
4717 Can also be used as a |method|: >
4718 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004719<
4720 Return type: dict<any>
4721
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004722
Shougo Matsushita19b71882024-02-28 22:48:12 +01004723getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004724 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01004725 buffer.
4726
4727 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004728 See |getpos()| for the format of the list. It's possible
4729 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01004730 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01004731
4732 The optional argument {opts} is a Dict and supports the
4733 following items:
4734
zeertzjqafc22952024-05-24 19:07:12 +02004735 type Specify the region's selection type.
4736 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02004737 except that the width can be omitted
4738 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02004739 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01004740
zeertzjq87410ab2024-03-02 06:00:23 +08004741 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02004742 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08004743 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01004744
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004745 You can get the last selection type by |visualmode()|.
4746 If Visual mode is active, use |mode()| to get the Visual mode
4747 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08004748 This function is useful to get text starting and ending in
4749 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004750
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004751 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004752 Note that:
4753 - Order of {pos1} and {pos2} doesn't matter, it will always
4754 return content from the upper left position to the lower
4755 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08004756 - If 'virtualedit' is enabled and the region is past the end
4757 of the lines, resulting lines are padded with spaces.
4758 - If the region is blockwise and it starts or ends in the
4759 middle of a multi-cell character, it is not included but
4760 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004761 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01004762 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004763 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01004764 - It is evaluated in current window context, which makes a
4765 difference if the buffer is displayed in a window with
4766 different 'virtualedit' or 'list' values.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004767
4768 Examples: >
4769 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01004770 \ <Cmd>echow getregion(
4771 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004772<
4773 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01004774 getpos('.')->getregion(getpos("'a"))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004775
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004776<
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004777getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
4778 Same as |getregion()|, but returns a list of positions
4779 describing the buffer text segments bound by {pos1} and
4780 {pos2}.
4781 The segments are a pair of positions for every line: >
4782 [[{start_pos}, {end_pos}], ...]
4783<
4784 The position is a |List| with four numbers:
4785 [bufnum, lnum, col, off]
4786 "bufnum" is the buffer number.
4787 "lnum" and "col" are the position in the buffer. The first
4788 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02004789 If the "off" number of a starting position is non-zero, it is
4790 the offset in screen columns from the start of the character.
4791 E.g., a position within a <Tab> or after the last character.
4792 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02004793 the offset of the character's first cell not included in the
4794 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004795
zeertzjq2b09de92024-05-24 07:48:51 +02004796 Apart from the options supported by |getregion()|, {opts} also
4797 supports the following:
4798
4799 eol If |TRUE|, indicate positions beyond
4800 the end of a line with "col" values
4801 one more than the length of the line.
4802 If |FALSE|, positions are limited
4803 within their lines, and if a line is
4804 empty or the selection is entirely
4805 beyond the end of a line, a "col"
4806 value of 0 is used for both positions.
4807 (default: |FALSE|)
4808
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004809 Can also be used as a |method|: >
4810 getpos('.')->getregionpos(getpos("'a"))
4811<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004812 Return type: list<string>
4813
4814
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004815getregtype([{regname}]) *getregtype()*
4816 The result is a String, which is type of register {regname}.
4817 The value will be one of:
4818 "v" for |characterwise| text
4819 "V" for |linewise| text
4820 "<CTRL-V>{width}" for |blockwise-visual| text
4821 "" for an empty or unknown register
4822 <CTRL-V> is one character with value 0x16.
4823 The {regname} argument is a string. If {regname} is "", the
4824 unnamed register '"' is used. If {regname} is not specified,
4825 |v:register| is used.
4826 In |Vim9-script| {regname} must be one character.
4827
4828 Can also be used as a |method|: >
4829 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004830<
4831 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004832
Bram Moolenaar71badf92023-04-22 22:40:14 +01004833getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004834 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01004835 scripts in the order they were sourced, like what
4836 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004837
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004838 The optional Dict argument {opts} supports the following
4839 optional items:
4840 name Script name match pattern. If specified,
4841 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01004842 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004843 "name" are returned.
4844 sid Script ID |<SID>|. If specified, only
4845 information about the script with ID "sid" is
4846 returned and "name" is ignored.
4847
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004848 Each item in the returned List is a |Dict| with the following
4849 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004850 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01004851 `import autoload` but was not actually sourced
4852 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004853 functions List of script-local function names defined in
4854 the script. Present only when a particular
4855 script is specified using the "sid" item in
4856 {opts}.
4857 name Vim script file name.
4858 sid Script ID |<SID>|.
4859 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01004860 this script name links to, if any, otherwise
4861 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004862 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00004863 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004864 specified using the "sid" item in {opts}.
4865 Note that this is a copy, the value of
4866 script-local variables cannot be changed using
4867 this dictionary.
h_east59858792023-10-25 22:47:05 +09004868 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01004869
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004870 Examples: >
4871 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08004872 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004873<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004874 Return type: list<dict<any>>
4875
4876
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004877gettabinfo([{tabnr}]) *gettabinfo()*
4878 If {tabnr} is not specified, then information about all the
4879 tab pages is returned as a |List|. Each List item is a
4880 |Dictionary|. Otherwise, {tabnr} specifies the tab page
4881 number and information about that one is returned. If the tab
4882 page does not exist an empty List is returned.
4883
4884 Each List item is a |Dictionary| with the following entries:
4885 tabnr tab page number.
4886 variables a reference to the dictionary with
4887 tabpage-local variables
4888 windows List of |window-ID|s in the tab page.
4889
4890 Can also be used as a |method|: >
4891 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004892<
4893 Return type: list<dict<any>>
4894
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004895
4896gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
4897 Get the value of a tab-local variable {varname} in tab page
4898 {tabnr}. |t:var|
4899 Tabs are numbered starting with one.
4900 The {varname} argument is a string. When {varname} is empty a
4901 dictionary with all tab-local variables is returned.
4902 Note that the name without "t:" must be used.
4903 When the tab or variable doesn't exist {def} or an empty
4904 string is returned, there is no error message.
4905
4906 Can also be used as a |method|: >
4907 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004908<
4909 Return type: any, depending on {varname}
4910
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004911
4912gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
4913 Get the value of window-local variable {varname} in window
4914 {winnr} in tab page {tabnr}.
4915 The {varname} argument is a string. When {varname} is empty a
4916 dictionary with all window-local variables is returned.
4917 When {varname} is equal to "&" get the values of all
4918 window-local options in a |Dictionary|.
4919 Otherwise, when {varname} starts with "&" get the value of a
4920 window-local option.
4921 Note that {varname} must be the name without "w:".
4922 Tabs are numbered starting with one. For the current tabpage
4923 use |getwinvar()|.
4924 {winnr} can be the window number or the |window-ID|.
4925 When {winnr} is zero the current window is used.
4926 This also works for a global option, buffer-local option and
4927 window-local option, but it doesn't work for a global variable
4928 or buffer-local variable.
4929 When the tab, window or variable doesn't exist {def} or an
4930 empty string is returned, there is no error message.
4931 Examples: >
4932 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004933 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004934<
4935 To obtain all window-local variables use: >
4936 gettabwinvar({tabnr}, {winnr}, '&')
4937
4938< Can also be used as a |method|: >
4939 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004940<
4941 Return type: any, depending on {varname}
4942
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004943
4944gettagstack([{winnr}]) *gettagstack()*
4945 The result is a Dict, which is the tag stack of window {winnr}.
4946 {winnr} can be the window number or the |window-ID|.
4947 When {winnr} is not specified, the current window is used.
4948 When window {winnr} doesn't exist, an empty Dict is returned.
4949
4950 The returned dictionary contains the following entries:
4951 curidx Current index in the stack. When at
4952 top of the stack, set to (length + 1).
4953 Index of bottom of the stack is 1.
4954 items List of items in the stack. Each item
4955 is a dictionary containing the
4956 entries described below.
4957 length Number of entries in the stack.
4958
4959 Each item in the stack is a dictionary with the following
4960 entries:
4961 bufnr buffer number of the current jump
4962 from cursor position before the tag jump.
4963 See |getpos()| for the format of the
4964 returned list.
4965 matchnr current matching tag number. Used when
4966 multiple matching tags are found for a
4967 name.
4968 tagname name of the tag
4969
4970 See |tagstack| for more information about the tag stack.
4971
4972 Can also be used as a |method|: >
4973 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004974<
4975 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004976
4977
4978gettext({text}) *gettext()*
4979 Translate String {text} if possible.
4980 This is mainly for use in the distributed Vim scripts. When
4981 generating message translations the {text} is extracted by
4982 xgettext, the translator can add the translated message in the
4983 .po file and Vim will lookup the translation when gettext() is
4984 called.
4985 For {text} double quoted strings are preferred, because
4986 xgettext does not understand escaping in single quoted
4987 strings.
4988
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004989 Return type: |String|
4990
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004991
4992getwininfo([{winid}]) *getwininfo()*
4993 Returns information about windows as a |List| with Dictionaries.
4994
4995 If {winid} is given Information about the window with that ID
4996 is returned, as a |List| with one item. If the window does not
4997 exist the result is an empty list.
4998
4999 Without {winid} information about all the windows in all the
5000 tab pages is returned.
5001
5002 Each List item is a |Dictionary| with the following entries:
5003 botline last complete displayed buffer line
5004 bufnr number of buffer in the window
5005 height window height (excluding winbar)
5006 loclist 1 if showing a location list
5007 {only with the +quickfix feature}
5008 quickfix 1 if quickfix or location list window
5009 {only with the +quickfix feature}
5010 terminal 1 if a terminal window
5011 {only with the +terminal feature}
5012 tabnr tab page number
5013 topline first displayed buffer line
5014 variables a reference to the dictionary with
5015 window-local variables
5016 width window width
5017 winbar 1 if the window has a toolbar, 0
5018 otherwise
5019 wincol leftmost screen column of the window;
5020 "col" from |win_screenpos()|
5021 textoff number of columns occupied by any
5022 'foldcolumn', 'signcolumn' and line
5023 number in front of the text
5024 winid |window-ID|
5025 winnr window number
5026 winrow topmost screen line of the window;
5027 "row" from |win_screenpos()|
5028
5029 Can also be used as a |method|: >
5030 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005031<
5032 Return type: list<dict<any>>
5033
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005034
5035getwinpos([{timeout}]) *getwinpos()*
5036 The result is a |List| with two numbers, the result of
5037 |getwinposx()| and |getwinposy()| combined:
5038 [x-pos, y-pos]
5039 {timeout} can be used to specify how long to wait in msec for
5040 a response from the terminal. When omitted 100 msec is used.
5041 Use a longer time for a remote terminal.
5042 When using a value less than 10 and no response is received
5043 within that time, a previously reported position is returned,
5044 if available. This can be used to poll for the position and
5045 do some work in the meantime: >
5046 while 1
5047 let res = getwinpos(1)
5048 if res[0] >= 0
5049 break
5050 endif
5051 " Do some work here
5052 endwhile
5053<
5054
5055 Can also be used as a |method|: >
5056 GetTimeout()->getwinpos()
5057<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005058 Return type: list<number>
5059
5060
5061getwinposx() *getwinposx()*
5062 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005063 the left hand side of the GUI Vim window. Also works for an
5064 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005065 The result will be -1 if the information is not available
5066 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005067 The value can be used with `:winpos`.
5068
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005069 Return type: |Number|
5070
5071
5072getwinposy() *getwinposy()*
5073 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005074 the top of the GUI Vim window. Also works for an xterm (uses
5075 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005076 The result will be -1 if the information is not available
5077 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005078 The value can be used with `:winpos`.
5079
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005080 Return type: |Number|
5081
5082
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005083getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5084 Like |gettabwinvar()| for the current tabpage.
5085 Examples: >
5086 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005087 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005088
5089< Can also be used as a |method|: >
5090 GetWinnr()->getwinvar(varname)
5091<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005092 Return type: any, depending on {varname}
5093
5094
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005095glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5096 Expand the file wildcards in {expr}. See |wildcards| for the
5097 use of special characters.
5098
5099 Unless the optional {nosuf} argument is given and is |TRUE|,
5100 the 'suffixes' and 'wildignore' options apply: Names matching
5101 one of the patterns in 'wildignore' will be skipped and
5102 'suffixes' affect the ordering of matches.
5103 'wildignorecase' always applies.
5104
5105 When {list} is present and it is |TRUE| the result is a |List|
5106 with all matching files. The advantage of using a List is,
5107 you also get filenames containing newlines correctly.
5108 Otherwise the result is a String and when there are several
5109 matches, they are separated by <NL> characters.
5110
5111 If the expansion fails, the result is an empty String or List.
5112
5113 You can also use |readdir()| if you need to do complicated
5114 things, such as limiting the number of matches.
5115
5116 A name for a non-existing file is not included. A symbolic
5117 link is only included if it points to an existing file.
5118 However, when the {alllinks} argument is present and it is
5119 |TRUE| then all symbolic links are included.
5120
5121 For most systems backticks can be used to get files names from
5122 any external command. Example: >
5123 :let tagfiles = glob("`find . -name tags -print`")
5124 :let &tags = substitute(tagfiles, "\n", ",", "g")
5125< The result of the program inside the backticks should be one
5126 item per line. Spaces inside an item are allowed.
5127
5128 See |expand()| for expanding special Vim variables. See
5129 |system()| for getting the raw output of an external command.
5130
5131 Can also be used as a |method|: >
5132 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005133<
5134 Return type: |String| or list<string> or list<any> depending
5135 on {list}
5136
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005137
5138glob2regpat({string}) *glob2regpat()*
5139 Convert a file pattern, as used by glob(), into a search
5140 pattern. The result can be used to match with a string that
5141 is a file name. E.g. >
5142 if filename =~ glob2regpat('Make*.mak')
5143< This is equivalent to: >
5144 if filename =~ '^Make.*\.mak$'
5145< When {string} is an empty string the result is "^$", match an
5146 empty string.
5147 Note that the result depends on the system. On MS-Windows
5148 a backslash usually means a path separator.
5149
5150 Can also be used as a |method|: >
5151 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005152<
5153 Return type: |String|
5154
5155 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005156globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5157 Perform glob() for String {expr} on all directories in {path}
5158 and concatenate the results. Example: >
5159 :echo globpath(&rtp, "syntax/c.vim")
5160<
5161 {path} is a comma-separated list of directory names. Each
5162 directory name is prepended to {expr} and expanded like with
5163 |glob()|. A path separator is inserted when needed.
5164 To add a comma inside a directory name escape it with a
5165 backslash. Note that on MS-Windows a directory may have a
5166 trailing backslash, remove it if you put a comma after it.
5167 If the expansion fails for one of the directories, there is no
5168 error message.
5169
5170 Unless the optional {nosuf} argument is given and is |TRUE|,
5171 the 'suffixes' and 'wildignore' options apply: Names matching
5172 one of the patterns in 'wildignore' will be skipped and
5173 'suffixes' affect the ordering of matches.
5174
5175 When {list} is present and it is |TRUE| the result is a |List|
5176 with all matching files. The advantage of using a List is, you
5177 also get filenames containing newlines correctly. Otherwise
5178 the result is a String and when there are several matches,
5179 they are separated by <NL> characters. Example: >
5180 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5181<
5182 {alllinks} is used as with |glob()|.
5183
5184 The "**" item can be used to search in a directory tree.
5185 For example, to find all "README.txt" files in the directories
5186 in 'runtimepath' and below: >
5187 :echo globpath(&rtp, "**/README.txt")
5188< Upwards search and limiting the depth of "**" is not
5189 supported, thus using 'path' will not always work properly.
5190
5191 Can also be used as a |method|, the base is passed as the
5192 second argument: >
5193 GetExpr()->globpath(&rtp)
5194<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005195 Return type: |String| or list<string> or list<any> depending
5196 on {list}
5197
5198
5199has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005200 When {check} is omitted or is zero: The result is a Number,
5201 which is 1 if the feature {feature} is supported, zero
5202 otherwise. The {feature} argument is a string, case is
5203 ignored. See |feature-list| below.
5204
5205 When {check} is present and not zero: The result is a Number,
5206 which is 1 if the feature {feature} could ever be supported,
5207 zero otherwise. This is useful to check for a typo in
5208 {feature} and to detect dead code. Keep in mind that an older
5209 Vim version will not know about a feature added later and
5210 features that have been abandoned will not be known by the
5211 current Vim version.
5212
5213 Also see |exists()| and |exists_compiled()|.
5214
5215 Note that to skip code that has a syntax error when the
5216 feature is not available, Vim may skip the rest of the line
5217 and miss a following `endif`. Therefore put the `endif` on a
5218 separate line: >
5219 if has('feature')
5220 let x = this->breaks->without->the->feature
5221 endif
5222< If the `endif` would be moved to the second line as "| endif" it
5223 would not be found.
5224
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005225 Return type: |Number|
5226
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005227
5228has_key({dict}, {key}) *has_key()*
5229 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005230 has an entry with key {key}. FALSE otherwise.
5231 The {key} argument is a string. In |Vim9| script a number is
5232 also accepted (and converted to a string) but no other types.
5233 In legacy script the usual automatic conversion to string is
5234 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005235
5236 Can also be used as a |method|: >
5237 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005238<
5239 Return type: |Number|
5240
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005241
5242haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5243 The result is a Number:
5244 1 when the window has set a local directory via |:lcd|
5245 2 when the tab-page has set a local directory via |:tcd|
5246 0 otherwise.
5247
5248 Without arguments use the current window.
5249 With {winnr} use this window in the current tab page.
5250 With {winnr} and {tabnr} use the window in the specified tab
5251 page.
5252 {winnr} can be the window number or the |window-ID|.
5253 If {winnr} is -1 it is ignored and only the tabpage is used.
5254 Return 0 if the arguments are invalid.
5255 Examples: >
5256 if haslocaldir() == 1
5257 " window local directory case
5258 elseif haslocaldir() == 2
5259 " tab-local directory case
5260 else
5261 " global directory case
5262 endif
5263
5264 " current window
5265 :echo haslocaldir()
5266 :echo haslocaldir(0)
5267 :echo haslocaldir(0, 0)
5268 " window n in current tab page
5269 :echo haslocaldir(n)
5270 :echo haslocaldir(n, 0)
5271 " window n in tab page m
5272 :echo haslocaldir(n, m)
5273 " tab page m
5274 :echo haslocaldir(-1, m)
5275<
5276 Can also be used as a |method|: >
5277 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005278<
5279 Return type: |Number|
5280
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005281
5282hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5283 The result is a Number, which is TRUE if there is a mapping
5284 that contains {what} in somewhere in the rhs (what it is
5285 mapped to) and this mapping exists in one of the modes
5286 indicated by {mode}.
5287 The arguments {what} and {mode} are strings.
5288 When {abbr} is there and it is |TRUE| use abbreviations
5289 instead of mappings. Don't forget to specify Insert and/or
5290 Command-line mode.
5291 Both the global mappings and the mappings local to the current
5292 buffer are checked for a match.
5293 If no matching mapping is found FALSE is returned.
5294 The following characters are recognized in {mode}:
5295 n Normal mode
5296 v Visual and Select mode
5297 x Visual mode
5298 s Select mode
5299 o Operator-pending mode
5300 i Insert mode
5301 l Language-Argument ("r", "f", "t", etc.)
5302 c Command-line mode
5303 When {mode} is omitted, "nvo" is used.
5304
5305 This function is useful to check if a mapping already exists
5306 to a function in a Vim script. Example: >
5307 :if !hasmapto('\ABCdoit')
5308 : map <Leader>d \ABCdoit
5309 :endif
5310< This installs the mapping to "\ABCdoit" only if there isn't
5311 already a mapping to "\ABCdoit".
5312
5313 Can also be used as a |method|: >
5314 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005315<
5316 Return type: |Number|
5317
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005318
5319histadd({history}, {item}) *histadd()*
5320 Add the String {item} to the history {history} which can be
5321 one of: *hist-names*
5322 "cmd" or ":" command line history
5323 "search" or "/" search pattern history
5324 "expr" or "=" typed expression history
5325 "input" or "@" input line history
5326 "debug" or ">" debug command history
5327 empty the current or last used history
5328 The {history} string does not need to be the whole name, one
5329 character is sufficient.
5330 If {item} does already exist in the history, it will be
5331 shifted to become the newest entry.
5332 The result is a Number: TRUE if the operation was successful,
5333 otherwise FALSE is returned.
5334
5335 Example: >
5336 :call histadd("input", strftime("%Y %b %d"))
5337 :let date=input("Enter date: ")
5338< This function is not available in the |sandbox|.
5339
5340 Can also be used as a |method|, the base is passed as the
5341 second argument: >
5342 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005343<
5344 Return type: |Number|
5345
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005346
5347histdel({history} [, {item}]) *histdel()*
5348 Clear {history}, i.e. delete all its entries. See |hist-names|
5349 for the possible values of {history}.
5350
5351 If the parameter {item} evaluates to a String, it is used as a
5352 regular expression. All entries matching that expression will
5353 be removed from the history (if there are any).
5354 Upper/lowercase must match, unless "\c" is used |/\c|.
5355 If {item} evaluates to a Number, it will be interpreted as
5356 an index, see |:history-indexing|. The respective entry will
5357 be removed if it exists.
5358
5359 The result is TRUE for a successful operation, otherwise FALSE
5360 is returned.
5361
5362 Examples:
5363 Clear expression register history: >
5364 :call histdel("expr")
5365<
5366 Remove all entries starting with "*" from the search history: >
5367 :call histdel("/", '^\*')
5368<
5369 The following three are equivalent: >
5370 :call histdel("search", histnr("search"))
5371 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005372 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005373<
5374 To delete the last search pattern and use the last-but-one for
5375 the "n" command and 'hlsearch': >
5376 :call histdel("search", -1)
5377 :let @/ = histget("search", -1)
5378<
5379 Can also be used as a |method|: >
5380 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005381<
5382 Return type: |Number|
5383
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005384
5385histget({history} [, {index}]) *histget()*
5386 The result is a String, the entry with Number {index} from
5387 {history}. See |hist-names| for the possible values of
5388 {history}, and |:history-indexing| for {index}. If there is
5389 no such entry, an empty String is returned. When {index} is
5390 omitted, the most recent item from the history is used.
5391
5392 Examples:
5393 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005394 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005395
5396< Define an Ex command ":H {num}" that supports re-execution of
5397 the {num}th entry from the output of |:history|. >
5398 :command -nargs=1 H execute histget("cmd", 0+<args>)
5399<
5400 Can also be used as a |method|: >
5401 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005402<
5403 Return type: |String|
5404
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005405
5406histnr({history}) *histnr()*
5407 The result is the Number of the current entry in {history}.
5408 See |hist-names| for the possible values of {history}.
5409 If an error occurred, -1 is returned.
5410
5411 Example: >
5412 :let inp_index = histnr("expr")
5413
5414< Can also be used as a |method|: >
5415 GetHistory()->histnr()
5416<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005417 Return type: |Number|
5418
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005419hlexists({name}) *hlexists()*
5420 The result is a Number, which is TRUE if a highlight group
5421 called {name} exists. This is when the group has been
5422 defined in some way. Not necessarily when highlighting has
5423 been defined for it, it may also have been used for a syntax
5424 item.
5425 *highlight_exists()*
5426 Obsolete name: highlight_exists().
5427
5428 Can also be used as a |method|: >
5429 GetName()->hlexists()
5430<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005431 Return type: |Number|
5432
5433
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005434hlget([{name} [, {resolve}]]) *hlget()*
5435 Returns a List of all the highlight group attributes. If the
5436 optional {name} is specified, then returns a List with only
5437 the attributes of the specified highlight group. Returns an
5438 empty List if the highlight group {name} is not present.
5439
5440 If the optional {resolve} argument is set to v:true and the
5441 highlight group {name} is linked to another group, then the
5442 link is resolved recursively and the attributes of the
5443 resolved highlight group are returned.
5444
5445 Each entry in the returned List is a Dictionary with the
5446 following items:
5447 cleared boolean flag, set to v:true if the highlight
5448 group attributes are cleared or not yet
5449 specified. See |highlight-clear|.
5450 cterm cterm attributes. See |highlight-cterm|.
5451 ctermbg cterm background color.
5452 See |highlight-ctermbg|.
5453 ctermfg cterm foreground color.
5454 See |highlight-ctermfg|.
5455 ctermul cterm underline color. See |highlight-ctermul|.
5456 default boolean flag, set to v:true if the highlight
5457 group link is a default link. See
5458 |highlight-default|.
5459 font highlight group font. See |highlight-font|.
5460 gui gui attributes. See |highlight-gui|.
5461 guibg gui background color. See |highlight-guibg|.
5462 guifg gui foreground color. See |highlight-guifg|.
5463 guisp gui special color. See |highlight-guisp|.
5464 id highlight group ID.
5465 linksto linked highlight group name.
5466 See |:highlight-link|.
5467 name highlight group name. See |group-name|.
5468 start start terminal keycode. See |highlight-start|.
5469 stop stop terminal keycode. See |highlight-stop|.
5470 term term attributes. See |highlight-term|.
5471
5472 The 'term', 'cterm' and 'gui' items in the above Dictionary
5473 have a dictionary value with the following optional boolean
5474 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5475 'reverse', 'inverse' and 'strikethrough'.
5476
5477 Example(s): >
5478 :echo hlget()
5479 :echo hlget('ModeMsg')
5480 :echo hlget('Number', v:true)
5481<
5482 Can also be used as a |method|: >
5483 GetName()->hlget()
5484<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005485 Return type: list<dict<any>>
5486
5487
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005488hlset({list}) *hlset()*
5489 Creates or modifies the attributes of a List of highlight
5490 groups. Each item in {list} is a dictionary containing the
5491 attributes of a highlight group. See |hlget()| for the list of
5492 supported items in this dictionary.
5493
5494 In addition to the items described in |hlget()|, the following
5495 additional items are supported in the dictionary:
5496
5497 force boolean flag to force the creation of
5498 a link for an existing highlight group
5499 with attributes.
5500
5501 The highlight group is identified using the 'name' item and
5502 the 'id' item (if supplied) is ignored. If a highlight group
5503 with a specified name doesn't exist, then it is created.
5504 Otherwise the attributes of an existing highlight group are
5505 modified.
5506
5507 If an empty dictionary value is used for the 'term' or 'cterm'
5508 or 'gui' entries, then the corresponding attributes are
5509 cleared. If the 'cleared' item is set to v:true, then all the
5510 attributes of the highlight group are cleared.
5511
5512 The 'linksto' item can be used to link a highlight group to
5513 another highlight group. See |:highlight-link|.
5514
5515 Returns zero for success, -1 for failure.
5516
5517 Example(s): >
5518 " add bold attribute to the Visual highlight group
5519 :call hlset([#{name: 'Visual',
5520 \ term: #{reverse: 1 , bold: 1}}])
5521 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5522 :let l = hlget()
5523 :call hlset(l)
5524 " clear the Search highlight group
5525 :call hlset([#{name: 'Search', cleared: v:true}])
5526 " clear the 'term' attributes for a highlight group
5527 :call hlset([#{name: 'Title', term: {}}])
5528 " create the MyHlg group linking it to DiffAdd
5529 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5530 " remove the MyHlg group link
5531 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5532 " clear the attributes and a link
5533 :call hlset([#{name: 'MyHlg', cleared: v:true,
5534 \ linksto: 'NONE'}])
5535<
5536 Can also be used as a |method|: >
5537 GetAttrList()->hlset()
5538<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005539 Return type: |Number|
5540
5541hlID({name}) *hlID()*
5542 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005543 with name {name}. When the highlight group doesn't exist,
5544 zero is returned.
5545 This can be used to retrieve information about the highlight
5546 group. For example, to get the background color of the
5547 "Comment" group: >
5548 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5549< *highlightID()*
5550 Obsolete name: highlightID().
5551
5552 Can also be used as a |method|: >
5553 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005554<
5555 Return type: |Number|
5556
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005557
5558hostname() *hostname()*
5559 The result is a String, which is the name of the machine on
5560 which Vim is currently running. Machine names greater than
5561 256 characters long are truncated.
5562
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005563 Return type: |String|
5564
5565
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005566iconv({string}, {from}, {to}) *iconv()*
5567 The result is a String, which is the text {string} converted
5568 from encoding {from} to encoding {to}.
5569 When the conversion completely fails an empty string is
5570 returned. When some characters could not be converted they
5571 are replaced with "?".
5572 The encoding names are whatever the iconv() library function
5573 can accept, see ":!man 3 iconv".
5574 Most conversions require Vim to be compiled with the |+iconv|
5575 feature. Otherwise only UTF-8 to latin1 conversion and back
5576 can be done.
5577 This can be used to display messages with special characters,
5578 no matter what 'encoding' is set to. Write the message in
5579 UTF-8 and use: >
5580 echo iconv(utf8_str, "utf-8", &enc)
5581< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5582 from/to UCS-2 is automatically changed to use UTF-8. You
5583 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5584
5585 Can also be used as a |method|: >
5586 GetText()->iconv('latin1', 'utf-8')
5587<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005588 Return type: |String|
5589
5590
5591indent({lnum}) *indent()*
5592 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005593 current buffer. The indent is counted in spaces, the value
5594 of 'tabstop' is relevant. {lnum} is used just like in
5595 |getline()|.
5596 When {lnum} is invalid -1 is returned. In |Vim9| script an
5597 error is given.
5598
5599 Can also be used as a |method|: >
5600 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005601<
5602 Return type: |Number|
5603
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005604
5605index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005606 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005607 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005608
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005609 If {object} is a |List| return the lowest index where the item
5610 has a value equal to {expr}. There is no automatic
5611 conversion, so the String "4" is different from the Number 4.
5612 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005613 of 'ignorecase' is not used here, case matters as indicated by
5614 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005615
5616 If {object} is |Blob| return the lowest index where the byte
5617 value is equal to {expr}.
5618
5619 If {start} is given then start looking at the item with index
5620 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005621
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005622 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5623 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005624
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005625 -1 is returned when {expr} is not found in {object}.
5626 Example: >
5627 :let idx = index(words, "the")
5628 :if index(numbers, 123) >= 0
5629
5630< Can also be used as a |method|: >
5631 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005632<
5633 Return type: |Number|
5634
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005635
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005636indexof({object}, {expr} [, {opts}]) *indexof()*
5637 Returns the index of an item in {object} where {expr} is
5638 v:true. {object} must be a |List| or a |Blob|.
5639
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005640 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005641 List until the expression is v:true and return the index of
5642 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005643
5644 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005645 Blob until the expression is v:true and return the index of
5646 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005647
5648 {expr} must be a |string| or |Funcref|.
5649
5650 If {expr} is a |string|: If {object} is a |List|, inside
5651 {expr} |v:key| has the index of the current List item and
5652 |v:val| has the value of the item. If {object} is a |Blob|,
5653 inside {expr} |v:key| has the index of the current byte and
5654 |v:val| has the byte value.
5655
5656 If {expr} is a |Funcref| it must take two arguments:
5657 1. the key or the index of the current item.
5658 2. the value of the current item.
5659 The function must return |TRUE| if the item is found and the
5660 search should stop.
5661
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005662 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005663 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005664 startidx start evaluating {expr} at the item with this
5665 index; may be negative for an item relative to
5666 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005667 Returns -1 when {expr} evaluates to v:false for all the items.
5668 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005669 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
5670 :echo indexof(l, "v:val.n == 20")
5671 :echo indexof(l, {i, v -> v.n == 30})
5672 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005673
5674< Can also be used as a |method|: >
5675 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005676<
5677 Return type: |Number|
5678
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005679
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005680input({prompt} [, {text} [, {completion}]]) *input()*
5681 The result is a String, which is whatever the user typed on
5682 the command-line. The {prompt} argument is either a prompt
5683 string, or a blank string (for no prompt). A '\n' can be used
5684 in the prompt to start a new line.
5685 The highlighting set with |:echohl| is used for the prompt.
5686 The input is entered just like a command-line, with the same
5687 editing commands and mappings. There is a separate history
5688 for lines typed for input().
5689 Example: >
5690 :if input("Coffee or beer? ") == "beer"
5691 : echo "Cheers!"
5692 :endif
5693<
5694 If the optional {text} argument is present and not empty, this
5695 is used for the default reply, as if the user typed this.
5696 Example: >
5697 :let color = input("Color? ", "white")
5698
5699< The optional {completion} argument specifies the type of
5700 completion supported for the input. Without it completion is
5701 not performed. The supported completion types are the same as
5702 that can be supplied to a user-defined command using the
5703 "-complete=" argument. Refer to |:command-completion| for
5704 more information. Example: >
5705 let fname = input("File: ", "", "file")
5706<
5707 NOTE: This function must not be used in a startup file, for
5708 the versions that only run in GUI mode (e.g., the Win32 GUI).
5709 Note: When input() is called from within a mapping it will
5710 consume remaining characters from that mapping, because a
5711 mapping is handled like the characters were typed.
5712 Use |inputsave()| before input() and |inputrestore()|
5713 after input() to avoid that. Another solution is to avoid
5714 that further characters follow in the mapping, e.g., by using
5715 |:execute| or |:normal|.
5716
5717 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005718 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005719 :function GetFoo()
5720 : call inputsave()
5721 : let g:Foo = input("enter search pattern: ")
5722 : call inputrestore()
5723 :endfunction
5724
5725< Can also be used as a |method|: >
5726 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005727<
5728 Return type: |String|
5729
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005730
5731inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
5732 Like |input()|, but when the GUI is running and text dialogs
5733 are supported, a dialog window pops up to input the text.
5734 Example: >
5735 :let n = inputdialog("value for shiftwidth", shiftwidth())
5736 :if n != ""
5737 : let &sw = n
5738 :endif
5739< When the dialog is cancelled {cancelreturn} is returned. When
5740 omitted an empty string is returned.
5741 Hitting <Enter> works like pressing the OK button. Hitting
5742 <Esc> works like pressing the Cancel button.
5743 NOTE: Command-line completion is not supported.
5744
5745 Can also be used as a |method|: >
5746 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005747<
5748 Return type: |String|
5749
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005750
5751inputlist({textlist}) *inputlist()*
5752 {textlist} must be a |List| of strings. This |List| is
5753 displayed, one string per line. The user will be prompted to
5754 enter a number, which is returned.
5755 The user can also select an item by clicking on it with the
5756 mouse, if the mouse is enabled in the command line ('mouse' is
5757 "a" or includes "c"). For the first string 0 is returned.
5758 When clicking above the first item a negative number is
5759 returned. When clicking on the prompt one more than the
5760 length of {textlist} is returned.
5761 Make sure {textlist} has less than 'lines' entries, otherwise
5762 it won't work. It's a good idea to put the entry number at
5763 the start of the string. And put a prompt in the first item.
5764 Example: >
5765 let color = inputlist(['Select color:', '1. red',
5766 \ '2. green', '3. blue'])
5767
5768< Can also be used as a |method|: >
5769 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005770<
5771 Return type: |Number|
5772
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005773
5774inputrestore() *inputrestore()*
5775 Restore typeahead that was saved with a previous |inputsave()|.
5776 Should be called the same number of times inputsave() is
5777 called. Calling it more often is harmless though.
5778 Returns TRUE when there is nothing to restore, FALSE otherwise.
5779
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005780 Return type: |Number|
5781
5782
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005783inputsave() *inputsave()*
5784 Preserve typeahead (also from mappings) and clear it, so that
5785 a following prompt gets input from the user. Should be
5786 followed by a matching inputrestore() after the prompt. Can
5787 be used several times, in which case there must be just as
5788 many inputrestore() calls.
5789 Returns TRUE when out of memory, FALSE otherwise.
5790
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005791 Return type: |Number|
5792
5793
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005794inputsecret({prompt} [, {text}]) *inputsecret()*
5795 This function acts much like the |input()| function with but
5796 two exceptions:
5797 a) the user's response will be displayed as a sequence of
5798 asterisks ("*") thereby keeping the entry secret, and
5799 b) the user's response will not be recorded on the input
5800 |history| stack.
5801 The result is a String, which is whatever the user actually
5802 typed on the command-line in response to the issued prompt.
5803 NOTE: Command-line completion is not supported.
5804
5805 Can also be used as a |method|: >
5806 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005807<
5808 Return type: |String|
5809
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005810
5811insert({object}, {item} [, {idx}]) *insert()*
5812 When {object} is a |List| or a |Blob| insert {item} at the start
5813 of it.
5814
5815 If {idx} is specified insert {item} before the item with index
5816 {idx}. If {idx} is zero it goes before the first item, just
5817 like omitting {idx}. A negative {idx} is also possible, see
5818 |list-index|. -1 inserts just before the last item.
5819
5820 Returns the resulting |List| or |Blob|. Examples: >
5821 :let mylist = insert([2, 3, 5], 1)
5822 :call insert(mylist, 4, -1)
5823 :call insert(mylist, 6, len(mylist))
5824< The last example can be done simpler with |add()|.
5825 Note that when {item} is a |List| it is inserted as a single
5826 item. Use |extend()| to concatenate |Lists|.
5827
5828 Can also be used as a |method|: >
5829 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005830<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005831 Return type: |Number|
5832
5833
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005834 *instanceof()* *E614* *E616* *E693*
5835instanceof({object}, {class})
5836 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01005837 argument is a direct or indirect instance of a |Class|,
5838 |Interface|, or class |:type| alias specified by {class}.
5839 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005840 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02005841 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01005842 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02005843
5844< Can also be used as a |method|: >
5845 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005846<
5847 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02005848
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005849interrupt() *interrupt()*
5850 Interrupt script execution. It works more or less like the
5851 user typing CTRL-C, most commands won't execute and control
5852 returns to the user. This is useful to abort execution
5853 from lower down, e.g. in an autocommand. Example: >
5854 :function s:check_typoname(file)
5855 : if fnamemodify(a:file, ':t') == '['
5856 : echomsg 'Maybe typo'
5857 : call interrupt()
5858 : endif
5859 :endfunction
5860 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005861<
5862 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005863
5864invert({expr}) *invert()*
5865 Bitwise invert. The argument is converted to a number. A
5866 List, Dict or Float argument causes an error. Example: >
5867 :let bits = invert(bits)
5868< Can also be used as a |method|: >
5869 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005870<
5871 Return type: |Number|
5872
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005873
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005874isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01005875 The result is a Number, which is |TRUE| when {path} is an
5876 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005877 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01005878 On MS-Windows, it is considered absolute when it starts with an
5879 optional drive prefix and is followed by a '\' or '/'. UNC paths
5880 are always absolute.
5881 Example: >
5882 echo isabsolutepath('/usr/share/') " 1
5883 echo isabsolutepath('./foobar') " 0
5884 echo isabsolutepath('C:\Windows') " 1
5885 echo isabsolutepath('foobar') " 0
5886 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005887<
LemonBoydca1d402022-04-28 15:26:33 +01005888 Can also be used as a |method|: >
5889 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005890<
5891 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01005892
5893
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005894isdirectory({directory}) *isdirectory()*
5895 The result is a Number, which is |TRUE| when a directory
5896 with the name {directory} exists. If {directory} doesn't
5897 exist, or isn't a directory, the result is |FALSE|. {directory}
5898 is any expression, which is used as a String.
5899
5900 Can also be used as a |method|: >
5901 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005902<
5903 Return type: |Number|
5904
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005905
5906isinf({expr}) *isinf()*
5907 Return 1 if {expr} is a positive infinity, or -1 a negative
5908 infinity, otherwise 0. >
5909 :echo isinf(1.0 / 0.0)
5910< 1 >
5911 :echo isinf(-1.0 / 0.0)
5912< -1
5913
5914 Can also be used as a |method|: >
5915 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005916<
5917 Return type: |Number|
5918
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005919
5920islocked({expr}) *islocked()* *E786*
5921 The result is a Number, which is |TRUE| when {expr} is the
5922 name of a locked variable.
5923 The string argument {expr} must be the name of a variable,
5924 |List| item or |Dictionary| entry, not the variable itself!
5925 Example: >
5926 :let alist = [0, ['a', 'b'], 2, 3]
5927 :lockvar 1 alist
5928 :echo islocked('alist') " 1
5929 :echo islocked('alist[1]') " 0
5930
Bram Moolenaar9da17d72022-02-09 21:50:44 +00005931< When {expr} is a variable that does not exist -1 is returned.
5932 If {expr} uses a range, list or dict index that is out of
5933 range or does not exist you get an error message. Use
5934 |exists()| to check for existence.
5935 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005936
5937 Can also be used as a |method|: >
5938 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005939<
5940 Return type: |Number|
5941
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005942
5943isnan({expr}) *isnan()*
5944 Return |TRUE| if {expr} is a float with value NaN. >
5945 echo isnan(0.0 / 0.0)
5946< 1
5947
5948 Can also be used as a |method|: >
5949 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005950<
5951 Return type: |Number|
5952
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005953
5954items({dict}) *items()*
5955 Return a |List| with all the key-value pairs of {dict}. Each
5956 |List| item is a list with two items: the key of a {dict}
5957 entry and the value of this entry. The |List| is in arbitrary
5958 order. Also see |keys()| and |values()|.
5959 Example: >
5960 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005961 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005962 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01005963<
5964 A List or a String argument is also supported. In these
5965 cases, items() returns a List with the index and the value at
5966 the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005967
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01005968 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005969 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005970<
5971 Return type: list<list<any>> or list<any>
5972
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005973
5974job_ functions are documented here: |job-functions-details|
5975
5976
5977join({list} [, {sep}]) *join()*
5978 Join the items in {list} together into one String.
5979 When {sep} is specified it is put in between the items. If
5980 {sep} is omitted a single space is used.
5981 Note that {sep} is not added at the end. You might want to
5982 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005983 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005984< String items are used as-is. |Lists| and |Dictionaries| are
5985 converted into a string like with |string()|.
5986 The opposite function is |split()|.
5987
5988 Can also be used as a |method|: >
5989 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005990<
5991 Return type: |String|
5992
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005993
5994js_decode({string}) *js_decode()*
5995 This is similar to |json_decode()| with these differences:
5996 - Object key names do not have to be in quotes.
5997 - Strings can be in single quotes.
5998 - Empty items in an array (between two commas) are allowed and
5999 result in v:none items.
6000
6001 Can also be used as a |method|: >
6002 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006003<
6004 Return type: any, depending on {varname}
6005
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006006
6007js_encode({expr}) *js_encode()*
6008 This is similar to |json_encode()| with these differences:
6009 - Object key names are not in quotes.
6010 - v:none items in an array result in an empty item between
6011 commas.
6012 For example, the Vim object:
6013 [1,v:none,{"one":1},v:none] ~
6014 Will be encoded as:
6015 [1,,{one:1},,] ~
6016 While json_encode() would produce:
6017 [1,null,{"one":1},null] ~
6018 This encoding is valid for JavaScript. It is more efficient
6019 than JSON, especially when using an array with optional items.
6020
6021 Can also be used as a |method|: >
6022 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006023<
6024 Return type: |String|
6025
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006026
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006027json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006028 This parses a JSON formatted string and returns the equivalent
6029 in Vim values. See |json_encode()| for the relation between
6030 JSON and Vim values.
6031 The decoding is permissive:
6032 - A trailing comma in an array and object is ignored, e.g.
6033 "[1, 2, ]" is the same as "[1, 2]".
6034 - Integer keys are accepted in objects, e.g. {1:2} is the
6035 same as {"1":2}.
6036 - More floating point numbers are recognized, e.g. "1." for
6037 "1.0", or "001.2" for "1.2". Special floating point values
6038 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6039 are accepted.
6040 - Leading zeroes in integer numbers are ignored, e.g. "012"
6041 for "12" or "-012" for "-12".
6042 - Capitalization is ignored in literal names null, true or
6043 false, e.g. "NULL" for "null", "True" for "true".
6044 - Control characters U+0000 through U+001F which are not
6045 escaped in strings are accepted, e.g. " " (tab
6046 character in string) for "\t".
6047 - An empty JSON expression or made of only spaces is accepted
6048 and results in v:none.
6049 - Backslash in an invalid 2-character sequence escape is
6050 ignored, e.g. "\a" is decoded as "a".
6051 - A correct surrogate pair in JSON strings should normally be
6052 a 12 character sequence such as "\uD834\uDD1E", but
6053 json_decode() silently accepts truncated surrogate pairs
6054 such as "\uD834" or "\uD834\u"
6055 *E938*
6056 A duplicate key in an object, valid in rfc7159, is not
6057 accepted by json_decode() as the result must be a valid Vim
6058 type, e.g. this fails: {"a":"b", "a":"c"}
6059
6060 Can also be used as a |method|: >
6061 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006062<
6063 Return type: any, depending on {varname}
6064
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006065
6066json_encode({expr}) *json_encode()*
6067 Encode {expr} as JSON and return this as a string.
6068 The encoding is specified in:
6069 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006070 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006071 |Number| decimal number
6072 |Float| floating point number
6073 Float nan "NaN"
6074 Float inf "Infinity"
6075 Float -inf "-Infinity"
6076 |String| in double quotes (possibly null)
6077 |Funcref| not possible, error
6078 |List| as an array (possibly null); when
6079 used recursively: []
6080 |Dict| as an object (possibly null); when
6081 used recursively: {}
6082 |Blob| as an array of the individual bytes
6083 v:false "false"
6084 v:true "true"
6085 v:none "null"
6086 v:null "null"
6087 Note that NaN and Infinity are passed on as values. This is
6088 missing in the JSON standard, but several implementations do
6089 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006090 If a string contains an illegal character then the replacement
6091 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006092
6093 Can also be used as a |method|: >
6094 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006095<
6096 Return type: |String|
6097
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006098
6099keys({dict}) *keys()*
6100 Return a |List| with all the keys of {dict}. The |List| is in
6101 arbitrary order. Also see |items()| and |values()|.
6102
6103 Can also be used as a |method|: >
6104 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006105<
6106 Return type: list<string>
6107
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006108
zeertzjqcdc83932022-09-12 13:38:41 +01006109keytrans({string}) *keytrans()*
6110 Turn the internal byte representation of keys into a form that
6111 can be used for |:map|. E.g. >
6112 :let xx = "\<C-Home>"
6113 :echo keytrans(xx)
6114< <C-Home>
6115
6116 Can also be used as a |method|: >
6117 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006118<
6119 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006120
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006121
6122len({expr}) *len()* *E701*
6123 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006124 When {expr} is a String or a Number the length in bytes is
6125 used, as with |strlen()|.
6126 When {expr} is a |List| the number of items in the |List| is
6127 returned.
6128 When {expr} is a |Blob| the number of bytes is returned.
6129 When {expr} is a |Dictionary| the number of entries in the
6130 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006131 When {expr} is an |Object|, invokes the len() method in the
6132 object (if present) to get the length (|object-len()|).
6133 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006134
6135 Can also be used as a |method|: >
6136 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006137<
6138 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006139
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006140
6141 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006142libcall({libname}, {funcname}, {argument})
6143 Call function {funcname} in the run-time library {libname}
6144 with single argument {argument}.
6145 This is useful to call functions in a library that you
6146 especially made to be used with Vim. Since only one argument
6147 is possible, calling standard library functions is rather
6148 limited.
6149 The result is the String returned by the function. If the
6150 function returns NULL, this will appear as an empty string ""
6151 to Vim.
6152 If the function returns a number, use libcallnr()!
6153 If {argument} is a number, it is passed to the function as an
6154 int; if {argument} is a string, it is passed as a
6155 null-terminated string.
6156 This function will fail in |restricted-mode|.
6157
6158 libcall() allows you to write your own 'plug-in' extensions to
6159 Vim without having to recompile the program. It is NOT a
6160 means to call system functions! If you try to do so Vim will
6161 very probably crash.
6162
6163 For Win32, the functions you write must be placed in a DLL
6164 and use the normal C calling convention (NOT Pascal which is
6165 used in Windows System DLLs). The function must take exactly
6166 one parameter, either a character pointer or a long integer,
6167 and must return a character pointer or NULL. The character
6168 pointer returned must point to memory that will remain valid
6169 after the function has returned (e.g. in static data in the
6170 DLL). If it points to allocated memory, that memory will
6171 leak away. Using a static buffer in the function should work,
6172 it's then freed when the DLL is unloaded.
6173
6174 WARNING: If the function returns a non-valid pointer, Vim may
6175 crash! This also happens if the function returns a number,
6176 because Vim thinks it's a pointer.
6177 For Win32 systems, {libname} should be the filename of the DLL
6178 without the ".DLL" suffix. A full path is only required if
6179 the DLL is not in the usual places.
6180 For Unix: When compiling your own plugins, remember that the
6181 object code must be compiled as position-independent ('PIC').
6182 {only in Win32 and some Unix versions, when the |+libcall|
6183 feature is present}
6184 Examples: >
6185 :echo libcall("libc.so", "getenv", "HOME")
6186
6187< Can also be used as a |method|, the base is passed as the
6188 third argument: >
6189 GetValue()->libcall("libc.so", "getenv")
6190<
6191 *libcallnr()*
6192libcallnr({libname}, {funcname}, {argument})
6193 Just like |libcall()|, but used for a function that returns an
6194 int instead of a string.
6195 {only in Win32 on some Unix versions, when the |+libcall|
6196 feature is present}
6197 Examples: >
6198 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6199 :call libcallnr("libc.so", "printf", "Hello World!\n")
6200 :call libcallnr("libc.so", "sleep", 10)
6201<
6202 Can also be used as a |method|, the base is passed as the
6203 third argument: >
6204 GetValue()->libcallnr("libc.so", "printf")
6205<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006206 Return type: |String|
6207
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006208
6209line({expr} [, {winid}]) *line()*
6210 The result is a Number, which is the line number of the file
6211 position given with {expr}. The {expr} argument is a string.
zeertzjq02f3eba2024-06-12 20:45:24 +02006212 See |getpos()| for accepted positions.
6213
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006214 To get the column number use |col()|. To get both use
6215 |getpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02006216
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006217 With the optional {winid} argument the values are obtained for
6218 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02006219
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006220 Returns 0 for invalid values of {expr} and {winid}.
zeertzjq02f3eba2024-06-12 20:45:24 +02006221
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006222 Examples: >
6223 line(".") line number of the cursor
6224 line(".", winid) idem, in window "winid"
6225 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006226 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006227<
6228 To jump to the last known position when opening a file see
6229 |last-position-jump|.
6230
6231 Can also be used as a |method|: >
6232 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006233<
6234 Return type: |Number|
6235
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006236
6237line2byte({lnum}) *line2byte()*
6238 Return the byte count from the start of the buffer for line
6239 {lnum}. This includes the end-of-line character, depending on
6240 the 'fileformat' option for the current buffer. The first
6241 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6242 This can also be used to get the byte count for the line just
6243 below the last line: >
6244 line2byte(line("$") + 1)
6245< This is the buffer size plus one. If 'fileencoding' is empty
6246 it is the file size plus one. {lnum} is used like with
6247 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6248 feature has been disabled at compile time, -1 is returned.
6249 Also see |byte2line()|, |go| and |:goto|.
6250
6251 Can also be used as a |method|: >
6252 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006253<
6254 Return type: |Number|
6255
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006256
6257lispindent({lnum}) *lispindent()*
6258 Get the amount of indent for line {lnum} according the lisp
6259 indenting rules, as with 'lisp'.
6260 The indent is counted in spaces, the value of 'tabstop' is
6261 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006262 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006263 error is given.
6264
6265 Can also be used as a |method|: >
6266 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006267<
6268 Return type: |Number|
6269
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006270
6271list2blob({list}) *list2blob()*
6272 Return a Blob concatenating all the number values in {list}.
6273 Examples: >
6274 list2blob([1, 2, 3, 4]) returns 0z01020304
6275 list2blob([]) returns 0z
6276< Returns an empty Blob on error. If one of the numbers is
6277 negative or more than 255 error *E1239* is given.
6278
6279 |blob2list()| does the opposite.
6280
6281 Can also be used as a |method|: >
6282 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006283<
6284 Return type: |Blob|
6285
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006286
6287list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006288 Convert each number in {list} to a character string and
6289 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006290 list2str([32]) returns " "
6291 list2str([65, 66, 67]) returns "ABC"
6292< The same can be done (slowly) with: >
6293 join(map(list, {nr, val -> nr2char(val)}), '')
6294< |str2list()| does the opposite.
6295
6296 When {utf8} is omitted or zero, the current 'encoding' is used.
6297 When {utf8} is TRUE, always return UTF-8 characters.
6298 With UTF-8 composing characters work as expected: >
6299 list2str([97, 769]) returns "á"
6300<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006301 Returns an empty string on error.
6302
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006303 Can also be used as a |method|: >
6304 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006305<
6306 Return type: |String|
6307
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006308
6309listener_add({callback} [, {buf}]) *listener_add()*
6310 Add a callback function that will be invoked when changes have
6311 been made to buffer {buf}.
6312 {buf} refers to a buffer name or number. For the accepted
6313 values, see |bufname()|. When {buf} is omitted the current
6314 buffer is used.
6315 Returns a unique ID that can be passed to |listener_remove()|.
6316
6317 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006318 bufnr the buffer that was changed
6319 start first changed line number
6320 end first line number below the change
6321 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006322 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006323 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006324
6325 Example: >
6326 func Listener(bufnr, start, end, added, changes)
6327 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6328 endfunc
6329 call listener_add('Listener', bufnr)
6330
Bram Moolenaar944697a2022-02-20 19:48:20 +00006331< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006332 dictionary with these entries:
6333 lnum the first line number of the change
6334 end the first line below the change
6335 added number of lines added; negative if lines were
6336 deleted
6337 col first column in "lnum" that was affected by
6338 the change; one if unknown or the whole line
6339 was affected; this is a byte index, first
6340 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006341 When lines are inserted (not when a line is split, e.g. by
6342 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006343 lnum line above which the new line is added
6344 end equal to "lnum"
6345 added number of lines inserted
6346 col 1
6347 When lines are deleted the values are:
6348 lnum the first deleted line
6349 end the line below the first deleted line, before
6350 the deletion was done
6351 added negative, number of lines deleted
6352 col 1
6353 When lines are changed:
6354 lnum the first changed line
6355 end the line below the last changed line
6356 added 0
6357 col first column with a change or 1
6358
6359 The entries are in the order the changes were made, thus the
6360 most recent change is at the end. The line numbers are valid
6361 when the callback is invoked, but later changes may make them
6362 invalid, thus keeping a copy for later might not work.
6363
6364 The {callback} is invoked just before the screen is updated,
6365 when |listener_flush()| is called or when a change is being
6366 made that changes the line count in a way it causes a line
6367 number in the list of changes to become invalid.
6368
6369 The {callback} is invoked with the text locked, see
6370 |textlock|. If you do need to make changes to the buffer, use
6371 a timer to do this later |timer_start()|.
6372
6373 The {callback} is not invoked when the buffer is first loaded.
6374 Use the |BufReadPost| autocmd event to handle the initial text
6375 of a buffer.
6376 The {callback} is also not invoked when the buffer is
6377 unloaded, use the |BufUnload| autocmd event for that.
6378
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006379 Returns zero if {callback} or {buf} is invalid.
6380
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006381 Can also be used as a |method|, the base is passed as the
6382 second argument: >
6383 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006384<
6385 Return type: |Number|
6386
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006387
6388listener_flush([{buf}]) *listener_flush()*
6389 Invoke listener callbacks for buffer {buf}. If there are no
6390 pending changes then no callbacks are invoked.
6391
6392 {buf} refers to a buffer name or number. For the accepted
6393 values, see |bufname()|. When {buf} is omitted the current
6394 buffer is used.
6395
6396 Can also be used as a |method|: >
6397 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006398<
6399 Return type: |Number|
6400
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006401
6402listener_remove({id}) *listener_remove()*
6403 Remove a listener previously added with listener_add().
6404 Returns FALSE when {id} could not be found, TRUE when {id} was
6405 removed.
6406
6407 Can also be used as a |method|: >
6408 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006409<
6410 Return type: |Number|
6411
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006412
6413localtime() *localtime()*
6414 Return the current time, measured as seconds since 1st Jan
6415 1970. See also |strftime()|, |strptime()| and |getftime()|.
6416
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006417 Return type: |Number|
6418
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006419
6420log({expr}) *log()*
6421 Return the natural logarithm (base e) of {expr} as a |Float|.
6422 {expr} must evaluate to a |Float| or a |Number| in the range
6423 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006424 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006425 Examples: >
6426 :echo log(10)
6427< 2.302585 >
6428 :echo log(exp(5))
6429< 5.0
6430
6431 Can also be used as a |method|: >
6432 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006433<
6434 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006435
6436
6437log10({expr}) *log10()*
6438 Return the logarithm of Float {expr} to base 10 as a |Float|.
6439 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006440 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006441 Examples: >
6442 :echo log10(1000)
6443< 3.0 >
6444 :echo log10(0.01)
6445< -2.0
6446
6447 Can also be used as a |method|: >
6448 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006449<
6450 Return type: |Float|
6451
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006452
6453luaeval({expr} [, {expr}]) *luaeval()*
6454 Evaluate Lua expression {expr} and return its result converted
6455 to Vim data structures. Second {expr} may hold additional
6456 argument accessible as _A inside first {expr}.
6457 Strings are returned as they are.
6458 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006459 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006460 Dictionaries and lists obtained by vim.eval() are returned
6461 as-is.
6462 Other objects are returned as zero without any errors.
6463 See |lua-luaeval| for more details.
6464 Note that in a `:def` function local variables are not visible
6465 to {expr}.
6466
6467 Can also be used as a |method|: >
6468 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006469<
6470 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006471
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006472 {only available when compiled with the |+lua| feature}
6473
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006474
6475map({expr1}, {expr2}) *map()*
6476 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006477 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006478 item in {expr1} with the result of evaluating {expr2}.
6479 For a |Blob| each byte is replaced.
6480 For a |String|, each character, including composing
6481 characters, is replaced.
6482 If the item type changes you may want to use |mapnew()| to
6483 create a new List or Dictionary. This is required when using
6484 Vim9 script.
6485
6486 {expr2} must be a |String| or |Funcref|.
6487
6488 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6489 of the current item. For a |Dictionary| |v:key| has the key
6490 of the current item and for a |List| |v:key| has the index of
6491 the current item. For a |Blob| |v:key| has the index of the
6492 current byte. For a |String| |v:key| has the index of the
6493 current character.
6494 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006495 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006496< This puts "> " before and " <" after each item in "mylist".
6497
6498 Note that {expr2} is the result of an expression and is then
6499 used as an expression again. Often it is good to use a
6500 |literal-string| to avoid having to double backslashes. You
6501 still have to double ' quotes
6502
6503 If {expr2} is a |Funcref| it is called with two arguments:
6504 1. The key or the index of the current item.
6505 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006506 With a legacy script lambda you don't get an error if it only
6507 accepts one argument, but with a Vim9 lambda you get "E1106:
6508 One argument too many", the number of arguments must match.
6509
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006510 The function must return the new value of the item. Example
6511 that changes each value by "key-value": >
6512 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006513 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006514 endfunc
6515 call map(myDict, function('KeyValue'))
6516< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006517 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006518< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006519 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006520< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006521 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006522<
6523 The operation is done in-place for a |List| and |Dictionary|.
6524 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006525 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006526
6527< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6528 or a new |Blob| or |String|.
6529 When an error is encountered while evaluating {expr2} no
6530 further items in {expr1} are processed.
6531 When {expr2} is a Funcref errors inside a function are ignored,
6532 unless it was defined with the "abort" flag.
6533
6534 Can also be used as a |method|: >
6535 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006536<
6537 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6538 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006539
6540
6541maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6542 When {dict} is omitted or zero: Return the rhs of mapping
6543 {name} in mode {mode}. The returned String has special
6544 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006545 listing. When {dict} is TRUE a dictionary is returned, see
6546 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006547
6548 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006549 returned if {dict} is FALSE, otherwise returns an empty Dict.
6550 When the mapping for {name} is empty, then "<Nop>" is
6551 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006552
6553 The {name} can have special key names, like in the ":map"
6554 command.
6555
6556 {mode} can be one of these strings:
6557 "n" Normal
6558 "v" Visual (including Select)
6559 "o" Operator-pending
6560 "i" Insert
6561 "c" Cmd-line
6562 "s" Select
6563 "x" Visual
6564 "l" langmap |language-mapping|
6565 "t" Terminal-Job
6566 "" Normal, Visual and Operator-pending
6567 When {mode} is omitted, the modes for "" are used.
6568
6569 When {abbr} is there and it is |TRUE| use abbreviations
6570 instead of mappings.
6571
6572 When {dict} is there and it is |TRUE| return a dictionary
6573 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006574 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006575 "lhs" The {lhs} of the mapping as it would be typed
6576 "lhsraw" The {lhs} of the mapping as raw bytes
6577 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6578 form, only present when it differs from "lhsraw"
6579 "rhs" The {rhs} of the mapping as typed.
6580 "silent" 1 for a |:map-silent| mapping, else 0.
6581 "noremap" 1 if the {rhs} of the mapping is not remappable.
6582 "script" 1 if mapping was defined with <script>.
6583 "expr" 1 for an expression mapping (|:map-<expr>|).
6584 "buffer" 1 for a buffer local mapping (|:map-local|).
6585 "mode" Modes for which the mapping is defined. In
6586 addition to the modes mentioned above, these
6587 characters will be used:
6588 " " Normal, Visual and Operator-pending
6589 "!" Insert and Commandline mode
6590 (|mapmode-ic|)
6591 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006592 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006593 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006594 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006595 "lnum" The line number in "sid", zero if unknown.
6596 "nowait" Do not wait for other, longer mappings.
6597 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006598 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006599 "mode_bits" Vim's internal binary representation of "mode".
6600 |mapset()| ignores this; only "mode" is used.
6601 See |maplist()| for usage examples. The values
6602 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006603
6604 The dictionary can be used to restore a mapping with
6605 |mapset()|.
6606
6607 The mappings local to the current buffer are checked first,
6608 then the global mappings.
6609 This function can be used to map a key even when it's already
6610 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006611 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006612
6613< Can also be used as a |method|: >
6614 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006615<
6616 Return type: |String| or dict<any> depending on {dict}
6617
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006618
6619mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6620 Check if there is a mapping that matches with {name} in mode
6621 {mode}. See |maparg()| for {mode} and special names in
6622 {name}.
6623 When {abbr} is there and it is |TRUE| use abbreviations
6624 instead of mappings.
6625 A match happens with a mapping that starts with {name} and
6626 with a mapping which is equal to the start of {name}.
6627
6628 matches mapping "a" "ab" "abc" ~
6629 mapcheck("a") yes yes yes
6630 mapcheck("abc") yes yes yes
6631 mapcheck("ax") yes no no
6632 mapcheck("b") no no no
6633
6634 The difference with maparg() is that mapcheck() finds a
6635 mapping that matches with {name}, while maparg() only finds a
6636 mapping for {name} exactly.
6637 When there is no mapping that starts with {name}, an empty
6638 String is returned. If there is one, the RHS of that mapping
6639 is returned. If there are several mappings that start with
6640 {name}, the RHS of one of them is returned. This will be
6641 "<Nop>" if the RHS is empty.
6642 The mappings local to the current buffer are checked first,
6643 then the global mappings.
6644 This function can be used to check if a mapping can be added
6645 without being ambiguous. Example: >
6646 :if mapcheck("_vv") == ""
6647 : map _vv :set guifont=7x13<CR>
6648 :endif
6649< This avoids adding the "_vv" mapping when there already is a
6650 mapping for "_v" or for "_vvv".
6651
6652 Can also be used as a |method|: >
6653 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006654<
6655 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006656
6657
Ernie Rael09661202022-04-25 14:40:44 +01006658maplist([{abbr}]) *maplist()*
6659 Returns a |List| of all mappings. Each List item is a |Dict|,
6660 the same as what is returned by |maparg()|, see
6661 |mapping-dict|. When {abbr} is there and it is |TRUE| use
6662 abbreviations instead of mappings.
6663
6664 Example to show all mappings with 'MultiMatch' in rhs: >
6665 vim9script
6666 echo maplist()->filter(
6667 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01006668< It can be tricky to find mappings for particular |:map-modes|.
6669 |mapping-dict|'s "mode_bits" can simplify this. For example,
6670 the mode_bits for Normal, Insert or Command-line modes are
6671 0x19. To find all the mappings available in those modes you
6672 can do: >
6673 vim9script
6674 var saved_maps = []
6675 for m in maplist()
6676 if and(m.mode_bits, 0x19) != 0
6677 saved_maps->add(m)
6678 endif
6679 endfor
6680 echo saved_maps->mapnew((_, m) => m.lhs)
6681< The values of the mode_bits are defined in Vim's src/vim.h
6682 file and they can be discovered at runtime using
6683 |:map-commands| and "maplist()". Example: >
6684 vim9script
6685 omap xyzzy <Nop>
6686 var op_bit = maplist()->filter(
6687 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
6688 ounmap xyzzy
6689 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006690<
6691 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01006692
6693
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006694mapnew({expr1}, {expr2}) *mapnew()*
6695 Like |map()| but instead of replacing items in {expr1} a new
6696 List or Dictionary is created and returned. {expr1} remains
6697 unchanged. Items can still be changed by {expr2}, if you
6698 don't want that use |deepcopy()| first.
6699
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006700 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6701 depending on {expr1}
6702
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006703
6704mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01006705mapset({dict})
6706 Restore a mapping from a dictionary, possibly returned by
6707 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
6708 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006709 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01006710 feature allows copying mappings from one buffer to another.
6711 The dict.mode value may restore a single mapping that covers
6712 more than one mode, like with mode values of '!', ' ', 'nox',
6713 or 'v'. *E1276*
6714
6715 In the first form, {mode} and {abbr} should be the same as
6716 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006717 {mode} is used to define the mode in which the mapping is set,
6718 not the "mode" entry in {dict}.
6719 Example for saving and restoring a mapping: >
6720 let save_map = maparg('K', 'n', 0, 1)
6721 nnoremap K somethingelse
6722 ...
6723 call mapset('n', 0, save_map)
6724< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01006725 e.g. with `:map!`, you need to save/restore the mapping for
6726 all of them, when they might differ.
6727
6728 In the second form, with {dict} as the only argument, mode
6729 and abbr are taken from the dict.
6730 Example: >
6731 vim9script
6732 var save_maps = maplist()->filter(
6733 (_, m) => m.lhs == 'K')
6734 nnoremap K somethingelse
6735 cnoremap K somethingelse2
6736 # ...
6737 unmap K
6738 for d in save_maps
6739 mapset(d)
6740 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006741<
6742 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006743
6744
6745match({expr}, {pat} [, {start} [, {count}]]) *match()*
6746 When {expr} is a |List| then this returns the index of the
6747 first item where {pat} matches. Each item is used as a
6748 String, |Lists| and |Dictionaries| are used as echoed.
6749
6750 Otherwise, {expr} is used as a String. The result is a
6751 Number, which gives the index (byte offset) in {expr} where
6752 {pat} matches.
6753
6754 A match at the first character or |List| item returns zero.
6755 If there is no match -1 is returned.
6756
6757 For getting submatches see |matchlist()|.
6758 Example: >
6759 :echo match("testing", "ing") " results in 4
6760 :echo match([1, 'x'], '\a') " results in 1
6761< See |string-match| for how {pat} is used.
6762 *strpbrk()*
6763 Vim doesn't have a strpbrk() function. But you can do: >
6764 :let sepidx = match(line, '[.,;: \t]')
6765< *strcasestr()*
6766 Vim doesn't have a strcasestr() function. But you can add
6767 "\c" to the pattern to ignore case: >
6768 :let idx = match(haystack, '\cneedle')
6769<
6770 If {start} is given, the search starts from byte index
6771 {start} in a String or item {start} in a |List|.
6772 The result, however, is still the index counted from the
6773 first character/item. Example: >
6774 :echo match("testing", "ing", 2)
6775< result is again "4". >
6776 :echo match("testing", "ing", 4)
6777< result is again "4". >
6778 :echo match("testing", "t", 2)
6779< result is "3".
6780 For a String, if {start} > 0 then it is like the string starts
6781 {start} bytes later, thus "^" will match at {start}. Except
6782 when {count} is given, then it's like matches before the
6783 {start} byte are ignored (this is a bit complicated to keep it
6784 backwards compatible).
6785 For a String, if {start} < 0, it will be set to 0. For a list
6786 the index is counted from the end.
6787 If {start} is out of range ({start} > strlen({expr}) for a
6788 String or {start} > len({expr}) for a |List|) -1 is returned.
6789
6790 When {count} is given use the {count}'th match. When a match
6791 is found in a String the search for the next one starts one
6792 character further. Thus this example results in 1: >
6793 echo match("testing", "..", 0, 2)
6794< In a |List| the search continues in the next item.
6795 Note that when {count} is added the way {start} works changes,
6796 see above.
6797
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01006798 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006799 See |pattern| for the patterns that are accepted.
6800 The 'ignorecase' option is used to set the ignore-caseness of
6801 the pattern. 'smartcase' is NOT used. The matching is always
6802 done like 'magic' is set and 'cpoptions' is empty.
6803 Note that a match at the start is preferred, thus when the
6804 pattern is using "*" (any number of matches) it tends to find
6805 zero matches at the start instead of a number of matches
6806 further down in the text.
6807
6808 Can also be used as a |method|: >
6809 GetText()->match('word')
6810 GetList()->match('word')
6811<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006812 Return type: |Number|
6813
6814
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006815 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006816matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
6817 Defines a pattern to be highlighted in the current window (a
6818 "match"). It will be highlighted with {group}. Returns an
6819 identification number (ID), which can be used to delete the
6820 match using |matchdelete()|. The ID is bound to the window.
6821 Matching is case sensitive and magic, unless case sensitivity
6822 or magicness are explicitly overridden in {pattern}. The
6823 'magic', 'smartcase' and 'ignorecase' options are not used.
6824 The "Conceal" value is special, it causes the match to be
6825 concealed.
6826
6827 The optional {priority} argument assigns a priority to the
6828 match. A match with a high priority will have its
6829 highlighting overrule that of a match with a lower priority.
6830 A priority is specified as an integer (negative numbers are no
6831 exception). If the {priority} argument is not specified, the
6832 default priority is 10. The priority of 'hlsearch' is zero,
6833 hence all matches with a priority greater than zero will
6834 overrule it. Syntax highlighting (see 'syntax') is a separate
6835 mechanism, and regardless of the chosen priority a match will
6836 always overrule syntax highlighting.
6837
6838 The optional {id} argument allows the request for a specific
6839 match ID. If a specified ID is already taken, an error
6840 message will appear and the match will not be added. An ID
6841 is specified as a positive integer (zero excluded). IDs 1, 2
6842 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01006843 respectively. 3 is reserved for use by the |matchparen|
6844 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01006845 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01006846 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006847
6848 The optional {dict} argument allows for further custom
6849 values. Currently this is used to specify a match specific
6850 conceal character that will be shown for |hl-Conceal|
6851 highlighted matches. The dict can have the following members:
6852
6853 conceal Special character to show instead of the
6854 match (only for |hl-Conceal| highlighted
6855 matches, see |:syn-cchar|)
6856 window Instead of the current window use the
6857 window with this number or window ID.
6858
6859 The number of matches is not limited, as it is the case with
6860 the |:match| commands.
6861
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006862 Returns -1 on error.
6863
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006864 Example: >
6865 :highlight MyGroup ctermbg=green guibg=green
6866 :let m = matchadd("MyGroup", "TODO")
6867< Deletion of the pattern: >
6868 :call matchdelete(m)
6869
6870< A list of matches defined by |matchadd()| and |:match| are
6871 available from |getmatches()|. All matches can be deleted in
6872 one operation by |clearmatches()|.
6873
6874 Can also be used as a |method|: >
6875 GetGroup()->matchadd('TODO')
6876<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006877 Return type: |Number|
6878
6879
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006880 *matchaddpos()*
6881matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
6882 Same as |matchadd()|, but requires a list of positions {pos}
6883 instead of a pattern. This command is faster than |matchadd()|
6884 because it does not require to handle regular expressions and
6885 sets buffer line boundaries to redraw screen. It is supposed
6886 to be used when fast match additions and deletions are
6887 required, for example to highlight matching parentheses.
6888
6889 {pos} is a list of positions. Each position can be one of
6890 these:
6891 - A number. This whole line will be highlighted. The first
6892 line has number 1.
6893 - A list with one number, e.g., [23]. The whole line with this
6894 number will be highlighted.
6895 - A list with two numbers, e.g., [23, 11]. The first number is
6896 the line number, the second one is the column number (first
6897 column is 1, the value must correspond to the byte index as
6898 |col()| would return). The character at this position will
6899 be highlighted.
6900 - A list with three numbers, e.g., [23, 11, 3]. As above, but
6901 the third number gives the length of the highlight in bytes.
6902
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006903 Returns -1 on error.
6904
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006905 Example: >
6906 :highlight MyGroup ctermbg=green guibg=green
6907 :let m = matchaddpos("MyGroup", [[23, 24], 34])
6908< Deletion of the pattern: >
6909 :call matchdelete(m)
6910
6911< Matches added by |matchaddpos()| are returned by
6912 |getmatches()|.
6913
6914 Can also be used as a |method|: >
6915 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006916<
6917 Return type: |Number|
6918
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006919
6920matcharg({nr}) *matcharg()*
6921 Selects the {nr} match item, as set with a |:match|,
6922 |:2match| or |:3match| command.
6923 Return a |List| with two elements:
6924 The name of the highlight group used
6925 The pattern used.
6926 When {nr} is not 1, 2 or 3 returns an empty |List|.
6927 When there is no match item set returns ['', ''].
6928 This is useful to save and restore a |:match|.
6929 Highlighting matches using the |:match| commands are limited
6930 to three matches. |matchadd()| does not have this limitation.
6931
6932 Can also be used as a |method|: >
6933 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006934<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006935 Return type: list<string>
6936
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006937 *matchbufline()*
6938matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
6939 Returns the |List| of matches in lines from {lnum} to {end} in
6940 buffer {buf} where {pat} matches.
6941
6942 {lnum} and {end} can either be a line number or the string "$"
6943 to refer to the last line in {buf}.
6944
6945 The {dict} argument supports following items:
6946 submatches include submatch information (|/\(|)
6947
6948 For each match, a |Dict| with the following items is returned:
6949 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08006950 lnum line number where there is a match
6951 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006952 Note that there can be multiple matches in a single line.
6953
6954 This function works only for loaded buffers. First call
6955 |bufload()| if needed.
6956
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01006957 See |match-pattern| for information about the effect of some
6958 option settings on the pattern.
6959
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006960 When {buf} is not a valid buffer, the buffer is not loaded or
6961 {lnum} or {end} is not valid then an error is given and an
6962 empty |List| is returned.
6963
6964 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08006965 " Assuming line 3 in buffer 5 contains "a"
6966 :echo matchbufline(5, '\<\k\+\>', 3, 3)
6967 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
6968 " Assuming line 4 in buffer 10 contains "tik tok"
6969 :echo matchbufline(10, '\<\k\+\>', 1, 4)
6970 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006971<
6972 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08006973 "\1", "\2", etc. are also returned. Example: >
6974 " Assuming line 2 in buffer 2 contains "acd"
6975 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006976 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08006977 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006978< The "submatches" List always contains 9 items. If a submatch
6979 is not found, then an empty string is returned for that
6980 submatch.
6981
6982 Can also be used as a |method|: >
6983 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006984<
6985 Return type: list<dict<any>> or list<any>
6986
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006987
6988matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
6989 Deletes a match with ID {id} previously defined by |matchadd()|
6990 or one of the |:match| commands. Returns 0 if successful,
6991 otherwise -1. See example for |matchadd()|. All matches can
6992 be deleted in one operation by |clearmatches()|.
6993 If {win} is specified, use the window with this number or
6994 window ID instead of the current window.
6995
6996 Can also be used as a |method|: >
6997 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006998<
6999 Return type: |Number|
7000
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007001
7002matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
7003 Same as |match()|, but return the index of first character
7004 after the match. Example: >
7005 :echo matchend("testing", "ing")
7006< results in "7".
7007 *strspn()* *strcspn()*
7008 Vim doesn't have a strspn() or strcspn() function, but you can
7009 do it with matchend(): >
7010 :let span = matchend(line, '[a-zA-Z]')
7011 :let span = matchend(line, '[^a-zA-Z]')
7012< Except that -1 is returned when there are no matches.
7013
7014 The {start}, if given, has the same meaning as for |match()|. >
7015 :echo matchend("testing", "ing", 2)
7016< results in "7". >
7017 :echo matchend("testing", "ing", 5)
7018< result is "-1".
7019 When {expr} is a |List| the result is equal to |match()|.
7020
7021 Can also be used as a |method|: >
7022 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007023<
7024 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007025
7026
7027matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7028 If {list} is a list of strings, then returns a |List| with all
7029 the strings in {list} that fuzzy match {str}. The strings in
7030 the returned list are sorted based on the matching score.
7031
7032 The optional {dict} argument always supports the following
7033 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007034 matchseq When this item is present return only matches
7035 that contain the characters in {str} in the
7036 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007037 limit Maximum number of matches in {list} to be
7038 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007039
7040 If {list} is a list of dictionaries, then the optional {dict}
7041 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007042 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007043 {str}. The value of this item should be a
7044 string.
7045 text_cb |Funcref| that will be called for every item
7046 in {list} to get the text for fuzzy matching.
7047 This should accept a dictionary item as the
7048 argument and return the text for that item to
7049 use for fuzzy matching.
7050
7051 {str} is treated as a literal string and regular expression
7052 matching is NOT supported. The maximum supported {str} length
7053 is 256.
7054
7055 When {str} has multiple words each separated by white space,
7056 then the list of strings that have all the words is returned.
7057
7058 If there are no matching strings or there is an error, then an
7059 empty list is returned. If length of {str} is greater than
7060 256, then returns an empty list.
7061
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007062 When {limit} is given, matchfuzzy() will find up to this
7063 number of matches in {list} and return them in sorted order.
7064
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007065 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007066 matching strings.
7067
7068 Example: >
7069 :echo matchfuzzy(["clay", "crow"], "cay")
7070< results in ["clay"]. >
7071 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7072< results in a list of buffer names fuzzy matching "ndl". >
7073 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7074< results in a list of buffer information dicts with buffer
7075 names fuzzy matching "ndl". >
7076 :echo getbufinfo()->matchfuzzy("spl",
7077 \ {'text_cb' : {v -> v.name}})
7078< results in a list of buffer information dicts with buffer
7079 names fuzzy matching "spl". >
7080 :echo v:oldfiles->matchfuzzy("test")
7081< results in a list of file names fuzzy matching "test". >
7082 :let l = readfile("buffer.c")->matchfuzzy("str")
7083< results in a list of lines in "buffer.c" fuzzy matching "str". >
7084 :echo ['one two', 'two one']->matchfuzzy('two one')
7085< results in ['two one', 'one two']. >
7086 :echo ['one two', 'two one']->matchfuzzy('two one',
7087 \ {'matchseq': 1})
7088< results in ['two one'].
7089
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007090 Return type: list<string> or list<any>
7091
7092
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007093matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7094 Same as |matchfuzzy()|, but returns the list of matched
7095 strings, the list of character positions where characters
7096 in {str} matches and a list of matching scores. You can
7097 use |byteidx()| to convert a character position to a byte
7098 position.
7099
7100 If {str} matches multiple times in a string, then only the
7101 positions for the best match is returned.
7102
7103 If there are no matching strings or there is an error, then a
7104 list with three empty list items is returned.
7105
7106 Example: >
7107 :echo matchfuzzypos(['testing'], 'tsg')
7108< results in [['testing'], [[0, 2, 6]], [99]] >
7109 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7110< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7111 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7112< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7113
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007114 Return type: list<list<any>>
7115
7116
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007117matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7118 Same as |match()|, but return a |List|. The first item in the
7119 list is the matched string, same as what matchstr() would
7120 return. Following items are submatches, like "\1", "\2", etc.
7121 in |:substitute|. When an optional submatch didn't match an
7122 empty string is used. Example: >
7123 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7124< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7125 When there is no match an empty list is returned.
7126
7127 You can pass in a List, but that is not very useful.
7128
7129 Can also be used as a |method|: >
7130 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007131<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007132 Return type: list<string> or list<any>
7133
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007134 *matchstrlist()*
7135matchstrlist({list}, {pat} [, {dict}])
7136 Returns the |List| of matches in {list} where {pat} matches.
7137 {list} is a |List| of strings. {pat} is matched against each
7138 string in {list}.
7139
7140 The {dict} argument supports following items:
7141 submatches include submatch information (|/\(|)
7142
7143 For each match, a |Dict| with the following items is returned:
7144 byteidx starting byte index of the match.
7145 idx index in {list} of the match.
7146 text matched string
7147 submatches a List of submatches. Present only if
7148 "submatches" is set to v:true in {dict}.
7149
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007150 See |match-pattern| for information about the effect of some
7151 option settings on the pattern.
7152
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007153 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007154 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7155 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7156 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7157 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007158<
7159 If "submatches" is present and is v:true, then submatches like
7160 "\1", "\2", etc. are also returned. Example: >
7161 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7162 \ #{submatches: v:true})
7163 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7164< The "submatches" List always contains 9 items. If a submatch
7165 is not found, then an empty string is returned for that
7166 submatch.
7167
7168 Can also be used as a |method|: >
7169 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007170<
7171 Return type: list<dict<any>> or list<any>
7172
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007173
7174matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7175 Same as |match()|, but return the matched string. Example: >
7176 :echo matchstr("testing", "ing")
7177< results in "ing".
7178 When there is no match "" is returned.
7179 The {start}, if given, has the same meaning as for |match()|. >
7180 :echo matchstr("testing", "ing", 2)
7181< results in "ing". >
7182 :echo matchstr("testing", "ing", 5)
7183< result is "".
7184 When {expr} is a |List| then the matching item is returned.
7185 The type isn't changed, it's not necessarily a String.
7186
7187 Can also be used as a |method|: >
7188 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007189<
7190 Return type: |String|
7191
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007192
7193matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7194 Same as |matchstr()|, but return the matched string, the start
7195 position and the end position of the match. Example: >
7196 :echo matchstrpos("testing", "ing")
7197< results in ["ing", 4, 7].
7198 When there is no match ["", -1, -1] is returned.
7199 The {start}, if given, has the same meaning as for |match()|. >
7200 :echo matchstrpos("testing", "ing", 2)
7201< results in ["ing", 4, 7]. >
7202 :echo matchstrpos("testing", "ing", 5)
7203< result is ["", -1, -1].
7204 When {expr} is a |List| then the matching item, the index
7205 of first item where {pat} matches, the start position and the
7206 end position of the match are returned. >
7207 :echo matchstrpos([1, '__x'], '\a')
7208< result is ["x", 1, 2, 3].
7209 The type isn't changed, it's not necessarily a String.
7210
7211 Can also be used as a |method|: >
7212 GetText()->matchstrpos('word')
7213<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007214 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007215
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007216
7217max({expr}) *max()*
7218 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007219 echo max([apples, pears, oranges])
7220
7221< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7222 it returns the maximum of all values in the Dictionary.
7223 If {expr} is neither a List nor a Dictionary, or one of the
7224 items in {expr} cannot be used as a Number this results in
7225 an error. An empty |List| or |Dictionary| results in zero.
7226
7227 Can also be used as a |method|: >
7228 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007229<
7230 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007231
7232
7233menu_info({name} [, {mode}]) *menu_info()*
7234 Return information about the specified menu {name} in
7235 mode {mode}. The menu name should be specified without the
7236 shortcut character ('&'). If {name} is "", then the top-level
7237 menu names are returned.
7238
7239 {mode} can be one of these strings:
7240 "n" Normal
7241 "v" Visual (including Select)
7242 "o" Operator-pending
7243 "i" Insert
7244 "c" Cmd-line
7245 "s" Select
7246 "x" Visual
7247 "t" Terminal-Job
7248 "" Normal, Visual and Operator-pending
7249 "!" Insert and Cmd-line
7250 When {mode} is omitted, the modes for "" are used.
7251
7252 Returns a |Dictionary| containing the following items:
7253 accel menu item accelerator text |menu-text|
7254 display display name (name without '&')
7255 enabled v:true if this menu item is enabled
7256 Refer to |:menu-enable|
7257 icon name of the icon file (for toolbar)
7258 |toolbar-icon|
7259 iconidx index of a built-in icon
7260 modes modes for which the menu is defined. In
7261 addition to the modes mentioned above, these
7262 characters will be used:
7263 " " Normal, Visual and Operator-pending
7264 name menu item name.
7265 noremenu v:true if the {rhs} of the menu item is not
7266 remappable else v:false.
7267 priority menu order priority |menu-priority|
7268 rhs right-hand-side of the menu item. The returned
7269 string has special characters translated like
7270 in the output of the ":menu" command listing.
7271 When the {rhs} of a menu item is empty, then
7272 "<Nop>" is returned.
7273 script v:true if script-local remapping of {rhs} is
7274 allowed else v:false. See |:menu-script|.
7275 shortcut shortcut key (character after '&' in
7276 the menu name) |menu-shortcut|
7277 silent v:true if the menu item is created
7278 with <silent> argument |:menu-silent|
7279 submenus |List| containing the names of
7280 all the submenus. Present only if the menu
7281 item has submenus.
7282
7283 Returns an empty dictionary if the menu item is not found.
7284
7285 Examples: >
7286 :echo menu_info('Edit.Cut')
7287 :echo menu_info('File.Save', 'n')
7288
7289 " Display the entire menu hierarchy in a buffer
7290 func ShowMenu(name, pfx)
7291 let m = menu_info(a:name)
7292 call append(line('$'), a:pfx .. m.display)
7293 for child in m->get('submenus', [])
7294 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7295 \ a:pfx .. ' ')
7296 endfor
7297 endfunc
7298 new
7299 for topmenu in menu_info('').submenus
7300 call ShowMenu(topmenu, '')
7301 endfor
7302<
7303 Can also be used as a |method|: >
7304 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007305<
7306 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007307
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007308min({expr}) *min()*
7309 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007310 echo min([apples, pears, oranges])
7311
7312< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7313 it returns the minimum of all values in the Dictionary.
7314 If {expr} is neither a List nor a Dictionary, or one of the
7315 items in {expr} cannot be used as a Number this results in
7316 an error. An empty |List| or |Dictionary| results in zero.
7317
7318 Can also be used as a |method|: >
7319 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007320<
7321 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007322
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007323
7324mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007325 Create directory {name}.
7326
Bram Moolenaar938ae282023-02-20 20:44:55 +00007327 When {flags} is present it must be a string. An empty string
7328 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007329
Bram Moolenaar938ae282023-02-20 20:44:55 +00007330 If {flags} contains "p" then intermediate directories are
7331 created as necessary.
7332
7333 If {flags} contains "D" then {name} is deleted at the end of
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007334 the current function, as with: >
7335 defer delete({name}, 'd')
7336<
Bram Moolenaar938ae282023-02-20 20:44:55 +00007337 If {flags} contains "R" then {name} is deleted recursively at
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007338 the end of the current function, as with: >
7339 defer delete({name}, 'rf')
7340< Note that when {name} has more than one part and "p" is used
7341 some directories may already exist. Only the first one that
7342 is created and what it contains is scheduled to be deleted.
7343 E.g. when using: >
7344 call mkdir('subdir/tmp/autoload', 'pR')
7345< and "subdir" already exists then "subdir/tmp" will be
7346 scheduled for deletion, like with: >
7347 defer delete('subdir/tmp', 'rf')
7348< Note that if scheduling the defer fails the directory is not
7349 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007350
7351 If {prot} is given it is used to set the protection bits of
7352 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7353 the user, readable for others). Use 0o700 to make it
7354 unreadable for others. This is only used for the last part of
7355 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
7356 created with 0o755.
7357 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007358 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007359
7360< This function is not available in the |sandbox|.
7361
7362 There is no error if the directory already exists and the "p"
7363 flag is passed (since patch 8.0.1708). However, without the
7364 "p" option the call will fail.
7365
7366 The function result is a Number, which is TRUE if the call was
7367 successful or FALSE if the directory creation failed or partly
7368 failed.
7369
7370 Not available on all systems. To check use: >
7371 :if exists("*mkdir")
7372
7373< Can also be used as a |method|: >
7374 GetName()->mkdir()
7375<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007376 Return type: |Number|
7377
7378
7379mode([{expr}]) *mode()*
7380 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007381 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007382 a non-empty String (|non-zero-arg|), then the full mode is
7383 returned, otherwise only the first letter is returned.
7384 Also see |state()|.
7385
7386 n Normal
7387 no Operator-pending
7388 nov Operator-pending (forced characterwise |o_v|)
7389 noV Operator-pending (forced linewise |o_V|)
7390 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7391 CTRL-V is one character
7392 niI Normal using |i_CTRL-O| in |Insert-mode|
7393 niR Normal using |i_CTRL-O| in |Replace-mode|
7394 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7395 nt Terminal-Normal (insert goes to Terminal-Job mode)
7396 v Visual by character
7397 vs Visual by character using |v_CTRL-O| in Select mode
7398 V Visual by line
7399 Vs Visual by line using |v_CTRL-O| in Select mode
7400 CTRL-V Visual blockwise
7401 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7402 s Select by character
7403 S Select by line
7404 CTRL-S Select blockwise
7405 i Insert
7406 ic Insert mode completion |compl-generic|
7407 ix Insert mode |i_CTRL-X| completion
7408 R Replace |R|
7409 Rc Replace mode completion |compl-generic|
7410 Rx Replace mode |i_CTRL-X| completion
7411 Rv Virtual Replace |gR|
7412 Rvc Virtual Replace mode completion |compl-generic|
7413 Rvx Virtual Replace mode |i_CTRL-X| completion
7414 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007415 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007416 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007417 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007418 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007419 ce Normal Ex mode |Q|
7420 r Hit-enter prompt
7421 rm The -- more -- prompt
7422 r? A |:confirm| query of some sort
7423 ! Shell or external command is executing
7424 t Terminal-Job mode: keys go to the job
7425
7426 This is useful in the 'statusline' option or when used
7427 with |remote_expr()| In most other places it always returns
7428 "c" or "n".
7429 Note that in the future more modes and more specific modes may
7430 be added. It's better not to compare the whole string but only
7431 the leading character(s).
7432 Also see |visualmode()|.
7433
7434 Can also be used as a |method|: >
7435 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007436<
7437 Return type: |String|
7438
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007439
7440mzeval({expr}) *mzeval()*
7441 Evaluate MzScheme expression {expr} and return its result
7442 converted to Vim data structures.
7443 Numbers and strings are returned as they are.
7444 Pairs (including lists and improper lists) and vectors are
7445 returned as Vim |Lists|.
7446 Hash tables are represented as Vim |Dictionary| type with keys
7447 converted to strings.
7448 All other types are converted to string with display function.
7449 Examples: >
7450 :mz (define l (list 1 2 3))
7451 :mz (define h (make-hash)) (hash-set! h "list" l)
7452 :echo mzeval("l")
7453 :echo mzeval("h")
7454<
7455 Note that in a `:def` function local variables are not visible
7456 to {expr}.
7457
7458 Can also be used as a |method|: >
7459 GetExpr()->mzeval()
7460<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007461 Return type: any, depending on {expr}
7462
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007463 {only available when compiled with the |+mzscheme| feature}
7464
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007465
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007466nextnonblank({lnum}) *nextnonblank()*
7467 Return the line number of the first line at or below {lnum}
7468 that is not blank. Example: >
7469 if getline(nextnonblank(1)) =~ "Java"
7470< When {lnum} is invalid or there is no non-blank line at or
7471 below it, zero is returned.
7472 {lnum} is used like with |getline()|.
7473 See also |prevnonblank()|.
7474
7475 Can also be used as a |method|: >
7476 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007477<
7478 Return type: |Number|
7479
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007480
7481nr2char({expr} [, {utf8}]) *nr2char()*
7482 Return a string with a single character, which has the number
7483 value {expr}. Examples: >
7484 nr2char(64) returns "@"
7485 nr2char(32) returns " "
7486< When {utf8} is omitted or zero, the current 'encoding' is used.
7487 Example for "utf-8": >
7488 nr2char(300) returns I with bow character
7489< When {utf8} is TRUE, always return UTF-8 characters.
7490 Note that a NUL character in the file is specified with
7491 nr2char(10), because NULs are represented with newline
7492 characters. nr2char(0) is a real NUL and terminates the
7493 string, thus results in an empty string.
7494 To turn a list of character numbers into a string: >
7495 let list = [65, 66, 67]
7496 let str = join(map(list, {_, val -> nr2char(val)}), '')
7497< Result: "ABC"
7498
7499 Can also be used as a |method|: >
7500 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007501<
7502 Return type: |String|
7503
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007504
7505or({expr}, {expr}) *or()*
7506 Bitwise OR on the two arguments. The arguments are converted
7507 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007508 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007509 Example: >
7510 :let bits = or(bits, 0x80)
7511< Can also be used as a |method|: >
7512 :let bits = bits->or(0x80)
7513
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007514< Rationale: The reason this is a function and not using the "|"
7515 character like many languages, is that Vi has always used "|"
7516 to separate commands. In many places it would not be clear if
7517 "|" is an operator or a command separator.
7518
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007519 Return type: |Number|
7520
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007521
7522pathshorten({path} [, {len}]) *pathshorten()*
7523 Shorten directory names in the path {path} and return the
7524 result. The tail, the file name, is kept as-is. The other
7525 components in the path are reduced to {len} letters in length.
7526 If {len} is omitted or smaller than 1 then 1 is used (single
7527 letters). Leading '~' and '.' characters are kept. Examples: >
7528 :echo pathshorten('~/.vim/autoload/myfile.vim')
7529< ~/.v/a/myfile.vim ~
7530>
7531 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7532< ~/.vi/au/myfile.vim ~
7533 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007534 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007535
7536 Can also be used as a |method|: >
7537 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007538<
7539 Return type: |String|
7540
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007541
7542perleval({expr}) *perleval()*
7543 Evaluate Perl expression {expr} in scalar context and return
7544 its result converted to Vim data structures. If value can't be
7545 converted, it is returned as a string Perl representation.
7546 Note: If you want an array or hash, {expr} must return a
7547 reference to it.
7548 Example: >
7549 :echo perleval('[1 .. 4]')
7550< [1, 2, 3, 4]
7551
7552 Note that in a `:def` function local variables are not visible
7553 to {expr}.
7554
7555 Can also be used as a |method|: >
7556 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007557<
7558 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007559
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007560 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007561
7562
7563popup_ functions are documented here: |popup-functions|
7564
7565
7566pow({x}, {y}) *pow()*
7567 Return the power of {x} to the exponent {y} as a |Float|.
7568 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007569 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007570 Examples: >
7571 :echo pow(3, 3)
7572< 27.0 >
7573 :echo pow(2, 16)
7574< 65536.0 >
7575 :echo pow(32, 0.20)
7576< 2.0
7577
7578 Can also be used as a |method|: >
7579 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007580<
7581 Return type: |Number|
7582
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007583
7584prevnonblank({lnum}) *prevnonblank()*
7585 Return the line number of the first line at or above {lnum}
7586 that is not blank. Example: >
7587 let ind = indent(prevnonblank(v:lnum - 1))
7588< When {lnum} is invalid or there is no non-blank line at or
7589 above it, zero is returned.
7590 {lnum} is used like with |getline()|.
7591 Also see |nextnonblank()|.
7592
7593 Can also be used as a |method|: >
7594 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007595<
7596 Return type: |Number|
7597
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007598
7599printf({fmt}, {expr1} ...) *printf()*
7600 Return a String with {fmt}, where "%" items are replaced by
7601 the formatted form of their respective arguments. Example: >
7602 printf("%4d: E%d %.30s", lnum, errno, msg)
7603< May result in:
7604 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7605
7606 When used as a |method| the base is passed as the second
7607 argument: >
7608 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007609<
7610 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007611
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007612 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007613 %s string
7614 %6S string right-aligned in 6 display cells
7615 %6s string right-aligned in 6 bytes
7616 %.9s string truncated to 9 bytes
7617 %c single byte
7618 %d decimal number
7619 %5d decimal number padded with spaces to 5 characters
7620 %x hex number
7621 %04x hex number padded with zeros to at least 4 characters
7622 %X hex number using upper case letters
7623 %o octal number
7624 %08b binary number padded with zeros to at least 8 chars
7625 %f floating point number as 12.23, inf, -inf or nan
7626 %F floating point number as 12.23, INF, -INF or NAN
7627 %e floating point number as 1.23e3, inf, -inf or nan
7628 %E floating point number as 1.23E3, INF, -INF or NAN
7629 %g floating point number, as %f or %e depending on value
7630 %G floating point number, as %F or %E depending on value
7631 %% the % character itself
7632
7633 Conversion specifications start with '%' and end with the
7634 conversion type. All other characters are copied unchanged to
7635 the result.
7636
7637 The "%" starts a conversion specification. The following
7638 arguments appear in sequence:
7639
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007640 % [pos-argument] [flags] [field-width] [.precision] type
7641
7642 pos-argument
7643 At most one positional argument specifier. These
7644 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007645
7646 flags
7647 Zero or more of the following flags:
7648
7649 # The value should be converted to an "alternate
7650 form". For c, d, and s conversions, this option
7651 has no effect. For o conversions, the precision
7652 of the number is increased to force the first
7653 character of the output string to a zero (except
7654 if a zero value is printed with an explicit
7655 precision of zero).
7656 For b and B conversions, a non-zero result has
7657 the string "0b" (or "0B" for B conversions)
7658 prepended to it.
7659 For x and X conversions, a non-zero result has
7660 the string "0x" (or "0X" for X conversions)
7661 prepended to it.
7662
7663 0 (zero) Zero padding. For all conversions the converted
7664 value is padded on the left with zeros rather
7665 than blanks. If a precision is given with a
7666 numeric conversion (d, b, B, o, x, and X), the 0
7667 flag is ignored.
7668
7669 - A negative field width flag; the converted value
7670 is to be left adjusted on the field boundary.
7671 The converted value is padded on the right with
7672 blanks, rather than on the left with blanks or
7673 zeros. A - overrides a 0 if both are given.
7674
7675 ' ' (space) A blank should be left before a positive
7676 number produced by a signed conversion (d).
7677
7678 + A sign must always be placed before a number
7679 produced by a signed conversion. A + overrides
7680 a space if both are used.
7681
7682 field-width
7683 An optional decimal digit string specifying a minimum
7684 field width. If the converted value has fewer bytes
7685 than the field width, it will be padded with spaces on
7686 the left (or right, if the left-adjustment flag has
7687 been given) to fill out the field width. For the S
7688 conversion the count is in cells.
7689
7690 .precision
7691 An optional precision, in the form of a period '.'
7692 followed by an optional digit string. If the digit
7693 string is omitted, the precision is taken as zero.
7694 This gives the minimum number of digits to appear for
7695 d, o, x, and X conversions, the maximum number of
7696 bytes to be printed from a string for s conversions,
7697 or the maximum number of cells to be printed from a
7698 string for S conversions.
7699 For floating point it is the number of digits after
7700 the decimal point.
7701
7702 type
7703 A character that specifies the type of conversion to
7704 be applied, see below.
7705
7706 A field width or precision, or both, may be indicated by an
7707 asterisk '*' instead of a digit string. In this case, a
7708 Number argument supplies the field width or precision. A
7709 negative field width is treated as a left adjustment flag
7710 followed by a positive field width; a negative precision is
7711 treated as though it were missing. Example: >
7712 :echo printf("%d: %.*s", nr, width, line)
7713< This limits the length of the text used from "line" to
7714 "width" bytes.
7715
Dominique Pellé17dca3c2023-12-14 20:36:32 +01007716 If the argument to be formatted is specified using a
7717 positional argument specifier, and a '*' is used to indicate
7718 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007719 precision, the argument(s) to be used must also be specified
7720 using a {n$} positional argument specifier. See |printf-$|.
7721
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007722 The conversion specifiers and their meanings are:
7723
7724 *printf-d* *printf-b* *printf-B* *printf-o*
7725 *printf-x* *printf-X*
7726 dbBoxX The Number argument is converted to signed decimal
7727 (d), unsigned binary (b and B), unsigned octal (o), or
7728 unsigned hexadecimal (x and X) notation. The letters
7729 "abcdef" are used for x conversions; the letters
7730 "ABCDEF" are used for X conversions.
7731 The precision, if any, gives the minimum number of
7732 digits that must appear; if the converted value
7733 requires fewer digits, it is padded on the left with
7734 zeros.
7735 In no case does a non-existent or small field width
7736 cause truncation of a numeric field; if the result of
7737 a conversion is wider than the field width, the field
7738 is expanded to contain the conversion result.
7739 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02007740 The 'l' modifier indicates the argument is a long
7741 integer. The size will be 32 bits or 64 bits
7742 depending on your platform.
7743 The "ll" modifier indicates the argument is 64 bits.
7744 The b and B conversion specifiers never take a width
7745 modifier and always assume their argument is a 64 bit
7746 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007747 Generally, these modifiers are not useful. They are
7748 ignored when type is known from the argument.
7749
7750 i alias for d
7751 D alias for ld
7752 U alias for lu
7753 O alias for lo
7754
7755 *printf-c*
7756 c The Number argument is converted to a byte, and the
7757 resulting character is written.
7758
7759 *printf-s*
7760 s The text of the String argument is used. If a
7761 precision is specified, no more bytes than the number
7762 specified are used.
7763 If the argument is not a String type, it is
7764 automatically converted to text with the same format
7765 as ":echo".
7766 *printf-S*
7767 S The text of the String argument is used. If a
7768 precision is specified, no more display cells than the
7769 number specified are used.
7770
7771 *printf-f* *E807*
7772 f F The Float argument is converted into a string of the
7773 form 123.456. The precision specifies the number of
7774 digits after the decimal point. When the precision is
7775 zero the decimal point is omitted. When the precision
7776 is not specified 6 is used. A really big number
7777 (out of range or dividing by zero) results in "inf"
7778 or "-inf" with %f (INF or -INF with %F).
7779 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
7780 Example: >
7781 echo printf("%.2f", 12.115)
7782< 12.12
7783 Note that roundoff depends on the system libraries.
7784 Use |round()| when in doubt.
7785
7786 *printf-e* *printf-E*
7787 e E The Float argument is converted into a string of the
7788 form 1.234e+03 or 1.234E+03 when using 'E'. The
7789 precision specifies the number of digits after the
7790 decimal point, like with 'f'.
7791
7792 *printf-g* *printf-G*
7793 g G The Float argument is converted like with 'f' if the
7794 value is between 0.001 (inclusive) and 10000000.0
7795 (exclusive). Otherwise 'e' is used for 'g' and 'E'
7796 for 'G'. When no precision is specified superfluous
7797 zeroes and '+' signs are removed, except for the zero
7798 immediately after the decimal point. Thus 10000000.0
7799 results in 1.0e7.
7800
7801 *printf-%*
7802 % A '%' is written. No argument is converted. The
7803 complete conversion specification is "%%".
7804
7805 When a Number argument is expected a String argument is also
7806 accepted and automatically converted.
7807 When a Float or String argument is expected a Number argument
7808 is also accepted and automatically converted.
7809 Any other argument type results in an error message.
7810
7811 *E766* *E767*
7812 The number of {exprN} arguments must exactly match the number
7813 of "%" items. If there are not sufficient or too many
7814 arguments an error is given. Up to 18 arguments can be used.
7815
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007816 *printf-$*
7817 In certain languages, error and informative messages are
7818 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02007819 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007820 having a different word order, positional arguments may be
7821 used to indicate this. For instance: >
7822
h_east596a9f22023-11-21 21:24:23 +09007823 #, c-format
7824 msgid "%s returning %s"
7825 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007826<
h_east596a9f22023-11-21 21:24:23 +09007827 In this example, the sentence has its 2 string arguments
7828 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007829
h_east596a9f22023-11-21 21:24:23 +09007830 echo printf(
7831 "In The Netherlands, vim's creator's name is: %1$s %2$s",
7832 "Bram", "Moolenaar")
7833< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007834
h_east596a9f22023-11-21 21:24:23 +09007835 echo printf(
7836 "In Belgium, vim's creator's name is: %2$s %1$s",
7837 "Bram", "Moolenaar")
7838< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007839
7840 Width (and precision) can be specified using the '*' specifier.
7841 In this case, you must specify the field width position in the
7842 argument list. >
7843
h_east596a9f22023-11-21 21:24:23 +09007844 echo printf("%1$*2$.*3$d", 1, 2, 3)
7845< 001 >
7846 echo printf("%2$*3$.*1$d", 1, 2, 3)
7847< 2 >
7848 echo printf("%3$*1$.*2$d", 1, 2, 3)
7849< 03 >
7850 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
7851< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007852
7853 You can mix specifying the width and/or precision directly
7854 and via positional arguments: >
7855
h_east596a9f22023-11-21 21:24:23 +09007856 echo printf("%1$4.*2$f", 1.4142135, 6)
7857< 1.414214 >
7858 echo printf("%1$*2$.4f", 1.4142135, 6)
7859< 1.4142 >
7860 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
7861< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007862
Christ van Willegenc35fc032024-03-14 18:30:41 +01007863 You will get an overflow error |E1510|, when the field-width
7864 or precision will result in a string longer than 6400 chars.
7865
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007866 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007867 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09007868 echo printf("%s%1$s", "One", "Two")
7869< E1500: Cannot mix positional and non-positional arguments:
7870 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007871
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007872 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007873 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09007874 echo printf("%3$s%1$s", "One", "Two", "Three")
7875< E1501: format argument 2 unused in $-style format:
7876 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007877
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007878 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007879 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09007880 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
7881< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007882
7883 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09007884 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
7885< E1502: Positional argument 2 used as field width reused as
7886 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007887
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007888 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007889 When a positional argument is used, but not the correct number
7890 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09007891 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
7892< E1503: Positional argument 3 out of bounds: %1$d at width
7893 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007894
7895 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09007896 echo printf("%01$*2$.*3$d %4$d", 1, 2)
7897< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
7898 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007899
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007900 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007901 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09007902 echo printf("%1$s %2$s %1$s", "One", "Two")
7903< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007904
7905 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09007906 echo printf("%1$s %2$s %1$d", "One", "Two")
7907< E1504: Positional argument 1 type used inconsistently:
7908 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007909
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007910 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007911 Various other errors that lead to a format string being
7912 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09007913 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
7914< E1505: Invalid format specifier: %1$d at width %2$d is:
7915 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007916
Christ van Willegenea746f92023-10-05 20:48:36 +02007917 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08007918 This internal error indicates that the logic to parse a
7919 positional format argument ran into a problem that couldn't be
7920 otherwise reported. Please file a bug against Vim if you run
7921 into this, copying the exact format string and parameters that
7922 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02007923
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007924 Return type: |String|
7925
Christ van Willegenea746f92023-10-05 20:48:36 +02007926
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007927prompt_getprompt({buf}) *prompt_getprompt()*
7928 Returns the effective prompt text for buffer {buf}. {buf} can
7929 be a buffer name or number. See |prompt-buffer|.
7930
7931 If the buffer doesn't exist or isn't a prompt buffer, an empty
7932 string is returned.
7933
7934 Can also be used as a |method|: >
7935 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007936<
7937 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007938
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007939 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007940
7941
7942prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
7943 Set prompt callback for buffer {buf} to {expr}. When {expr}
7944 is an empty string the callback is removed. This has only
7945 effect if {buf} has 'buftype' set to "prompt".
7946
7947 The callback is invoked when pressing Enter. The current
7948 buffer will always be the prompt buffer. A new line for a
7949 prompt is added before invoking the callback, thus the prompt
7950 for which the callback was invoked will be in the last but one
7951 line.
7952 If the callback wants to add text to the buffer, it must
7953 insert it above the last line, since that is where the current
7954 prompt is. This can also be done asynchronously.
7955 The callback is invoked with one argument, which is the text
7956 that was entered at the prompt. This can be an empty string
7957 if the user only typed Enter.
7958 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007959 func s:TextEntered(text)
7960 if a:text == 'exit' || a:text == 'quit'
7961 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01007962 " Reset 'modified' to allow the buffer to be closed.
7963 " We assume there is nothing useful to be saved.
7964 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007965 close
7966 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01007967 " Do something useful with "a:text". In this example
7968 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007969 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007970 endif
7971 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01007972 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007973
7974< Can also be used as a |method|: >
7975 GetBuffer()->prompt_setcallback(callback)
7976
7977< {only available when compiled with the |+channel| feature}
7978
7979prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
7980 Set a callback for buffer {buf} to {expr}. When {expr} is an
7981 empty string the callback is removed. This has only effect if
7982 {buf} has 'buftype' set to "prompt".
7983
7984 This callback will be invoked when pressing CTRL-C in Insert
7985 mode. Without setting a callback Vim will exit Insert mode,
7986 as in any buffer.
7987
7988 Can also be used as a |method|: >
7989 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007990<
7991 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007992
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007993 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007994
7995prompt_setprompt({buf}, {text}) *prompt_setprompt()*
7996 Set prompt for buffer {buf} to {text}. You most likely want
7997 {text} to end in a space.
7998 The result is only visible if {buf} has 'buftype' set to
7999 "prompt". Example: >
8000 call prompt_setprompt(bufnr(), 'command: ')
8001<
8002 Can also be used as a |method|: >
8003 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008004<
8005 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008006
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008007 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008008
8009prop_ functions are documented here: |text-prop-functions|
8010
8011pum_getpos() *pum_getpos()*
8012 If the popup menu (see |ins-completion-menu|) is not visible,
8013 returns an empty |Dictionary|, otherwise, returns a
8014 |Dictionary| with the following keys:
8015 height nr of items visible
8016 width screen cells
8017 row top screen row (0 first row)
8018 col leftmost screen column (0 first col)
8019 size total nr of items
8020 scrollbar |TRUE| if scrollbar is visible
8021
8022 The values are the same as in |v:event| during
8023 |CompleteChanged|.
8024
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008025 Return type: dict<any>
8026
8027
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008028pumvisible() *pumvisible()*
8029 Returns non-zero when the popup menu is visible, zero
8030 otherwise. See |ins-completion-menu|.
8031 This can be used to avoid some things that would remove the
8032 popup menu.
8033
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008034 Return type: |Number|
8035
8036
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008037py3eval({expr}) *py3eval()*
8038 Evaluate Python expression {expr} and return its result
8039 converted to Vim data structures.
8040 Numbers and strings are returned as they are (strings are
8041 copied though, Unicode strings are additionally converted to
8042 'encoding').
8043 Lists are represented as Vim |List| type.
8044 Dictionaries are represented as Vim |Dictionary| type with
8045 keys converted to strings.
8046 Note that in a `:def` function local variables are not visible
8047 to {expr}.
8048
8049 Can also be used as a |method|: >
8050 GetExpr()->py3eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008051<
8052 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008053
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008054 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008055
8056 *E858* *E859*
8057pyeval({expr}) *pyeval()*
8058 Evaluate Python expression {expr} and return its result
8059 converted to Vim data structures.
8060 Numbers and strings are returned as they are (strings are
8061 copied though).
8062 Lists are represented as Vim |List| type.
8063 Dictionaries are represented as Vim |Dictionary| type,
8064 non-string keys result in error.
8065 Note that in a `:def` function local variables are not visible
8066 to {expr}.
8067
8068 Can also be used as a |method|: >
8069 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008070<
8071 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008072
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008073 {only available when compiled with the |+python| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008074
8075pyxeval({expr}) *pyxeval()*
8076 Evaluate Python expression {expr} and return its result
8077 converted to Vim data structures.
8078 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8079 See also: |pyeval()|, |py3eval()|
8080
8081 Can also be used as a |method|: >
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008082 < GetExpr()->pyxeval()
8083<
8084 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008085
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008086 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008087 |+python3| feature}
8088
8089rand([{expr}]) *rand()* *random*
8090 Return a pseudo-random Number generated with an xoshiro128**
8091 algorithm using seed {expr}. The returned number is 32 bits,
8092 also on 64 bits systems, for consistency.
8093 {expr} can be initialized by |srand()| and will be updated by
8094 rand(). If {expr} is omitted, an internal seed value is used
8095 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008096 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008097
8098 Examples: >
8099 :echo rand()
8100 :let seed = srand()
8101 :echo rand(seed)
8102 :echo rand(seed) % 16 " random number 0 - 15
8103<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008104 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008105
8106 *E726* *E727*
8107range({expr} [, {max} [, {stride}]]) *range()*
8108 Returns a |List| with Numbers:
8109 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8110 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8111 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8112 {max}] (increasing {expr} with {stride} each time, not
8113 producing a value past {max}).
8114 When the maximum is one before the start the result is an
8115 empty list. When the maximum is more than one before the
8116 start this is an error.
8117 Examples: >
8118 range(4) " [0, 1, 2, 3]
8119 range(2, 4) " [2, 3, 4]
8120 range(2, 9, 3) " [2, 5, 8]
8121 range(2, -2, -1) " [2, 1, 0, -1, -2]
8122 range(0) " []
8123 range(2, 0) " error!
8124<
8125 Can also be used as a |method|: >
8126 GetExpr()->range()
8127<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008128 Return type: list<number>
8129
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008130
K.Takata11df3ae2022-10-19 14:02:40 +01008131readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008132 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008133 If {offset} is specified, read the file from the specified
8134 offset. If it is a negative value, it is used as an offset
8135 from the end of the file. E.g., to read the last 12 bytes: >
8136 readblob('file.bin', -12)
8137< If {size} is specified, only the specified size will be read.
8138 E.g. to read the first 100 bytes of a file: >
8139 readblob('file.bin', 0, 100)
8140< If {size} is -1 or omitted, the whole data starting from
8141 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008142 This can be also used to read the data from a character device
8143 on Unix when {size} is explicitly set. Only if the device
8144 supports seeking {offset} can be used. Otherwise it should be
8145 zero. E.g. to read 10 bytes from a serial console: >
8146 readblob('/dev/ttyS0', 0, 10)
8147< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008148 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008149 When the offset is beyond the end of the file the result is an
8150 empty blob.
8151 When trying to read more bytes than are available the result
8152 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008153 Also see |readfile()| and |writefile()|.
8154
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008155 Return type: |Blob|
8156
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008157
8158readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8159 Return a list with file and directory names in {directory}.
8160 You can also use |glob()| if you don't need to do complicated
8161 things, such as limiting the number of matches.
8162 The list will be sorted (case sensitive), see the {dict}
8163 argument below for changing the sort order.
8164
8165 When {expr} is omitted all entries are included.
8166 When {expr} is given, it is evaluated to check what to do:
8167 If {expr} results in -1 then no further entries will
8168 be handled.
8169 If {expr} results in 0 then this entry will not be
8170 added to the list.
8171 If {expr} results in 1 then this entry will be added
8172 to the list.
8173 The entries "." and ".." are always excluded.
8174 Each time {expr} is evaluated |v:val| is set to the entry name.
8175 When {expr} is a function the name is passed as the argument.
8176 For example, to get a list of files ending in ".txt": >
8177 readdir(dirname, {n -> n =~ '.txt$'})
8178< To skip hidden and backup files: >
8179 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008180< *E857*
8181 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008182 values. Currently this is used to specify if and how sorting
8183 should be performed. The dict can have the following members:
8184
8185 sort How to sort the result returned from the system.
8186 Valid values are:
8187 "none" do not sort (fastest method)
8188 "case" sort case sensitive (byte value of
8189 each character, technically, using
8190 strcmp()) (default)
8191 "icase" sort case insensitive (technically
8192 using strcasecmp())
8193 "collate" sort using the collation order
8194 of the "POSIX" or "C" |locale|
8195 (technically using strcoll())
8196 Other values are silently ignored.
8197
8198 For example, to get a list of all files in the current
8199 directory without sorting the individual entries: >
8200 readdir('.', '1', #{sort: 'none'})
8201< If you want to get a directory tree: >
8202 function! s:tree(dir)
8203 return {a:dir : map(readdir(a:dir),
8204 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008205 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008206 endfunction
8207 echo s:tree(".")
8208<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008209 Returns an empty List on error.
8210
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008211 Can also be used as a |method|: >
8212 GetDirName()->readdir()
8213<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008214 Return type: list<string> or list<any>
8215
8216
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008217readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8218 Extended version of |readdir()|.
8219 Return a list of Dictionaries with file and directory
8220 information in {directory}.
8221 This is useful if you want to get the attributes of file and
8222 directory at the same time as getting a list of a directory.
8223 This is much faster than calling |readdir()| then calling
8224 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8225 each file and directory especially on MS-Windows.
8226 The list will by default be sorted by name (case sensitive),
8227 the sorting can be changed by using the optional {dict}
8228 argument, see |readdir()|.
8229
8230 The Dictionary for file and directory information has the
8231 following items:
8232 group Group name of the entry. (Only on Unix)
8233 name Name of the entry.
8234 perm Permissions of the entry. See |getfperm()|.
8235 size Size of the entry. See |getfsize()|.
8236 time Timestamp of the entry. See |getftime()|.
8237 type Type of the entry.
8238 On Unix, almost same as |getftype()| except:
8239 Symlink to a dir "linkd"
8240 Other symlink "link"
8241 On MS-Windows:
8242 Normal file "file"
8243 Directory "dir"
8244 Junction "junction"
8245 Symlink to a dir "linkd"
8246 Other symlink "link"
8247 Other reparse point "reparse"
8248 user User name of the entry's owner. (Only on Unix)
8249 On Unix, if the entry is a symlink, the Dictionary includes
8250 the information of the target (except the "type" item).
8251 On MS-Windows, it includes the information of the symlink
8252 itself because of performance reasons.
8253
8254 When {expr} is omitted all entries are included.
8255 When {expr} is given, it is evaluated to check what to do:
8256 If {expr} results in -1 then no further entries will
8257 be handled.
8258 If {expr} results in 0 then this entry will not be
8259 added to the list.
8260 If {expr} results in 1 then this entry will be added
8261 to the list.
8262 The entries "." and ".." are always excluded.
8263 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8264 of the entry.
8265 When {expr} is a function the entry is passed as the argument.
8266 For example, to get a list of files ending in ".txt": >
8267 readdirex(dirname, {e -> e.name =~ '.txt$'})
8268<
8269 For example, to get a list of all files in the current
8270 directory without sorting the individual entries: >
8271 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008272<
8273 Can also be used as a |method|: >
8274 GetDirName()->readdirex()
8275<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008276 Return type: list<dict<any>> or list<any>
8277
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008278
8279 *readfile()*
8280readfile({fname} [, {type} [, {max}]])
8281 Read file {fname} and return a |List|, each line of the file
8282 as an item. Lines are broken at NL characters. Macintosh
8283 files separated with CR will result in a single long line
8284 (unless a NL appears somewhere).
8285 All NUL characters are replaced with a NL character.
8286 When {type} contains "b" binary mode is used:
8287 - When the last line ends in a NL an extra empty list item is
8288 added.
8289 - No CR characters are removed.
8290 Otherwise:
8291 - CR characters that appear before a NL are removed.
8292 - Whether the last line ends in a NL or not does not matter.
8293 - When 'encoding' is Unicode any UTF-8 byte order mark is
8294 removed from the text.
8295 When {max} is given this specifies the maximum number of lines
8296 to be read. Useful if you only want to check the first ten
8297 lines of a file: >
8298 :for line in readfile(fname, '', 10)
8299 : if line =~ 'Date' | echo line | endif
8300 :endfor
8301< When {max} is negative -{max} lines from the end of the file
8302 are returned, or as many as there are.
8303 When {max} is zero the result is an empty list.
8304 Note that without {max} the whole file is read into memory.
8305 Also note that there is no recognition of encoding. Read a
8306 file into a buffer if you need to.
8307 Deprecated (use |readblob()| instead): When {type} contains
8308 "B" a |Blob| is returned with the binary data of the file
8309 unmodified.
8310 When the file can't be opened an error message is given and
8311 the result is an empty list.
8312 Also see |writefile()|.
8313
8314 Can also be used as a |method|: >
8315 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008316<
8317 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008318
8319reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8320 {func} is called for every item in {object}, which can be a
8321 |String|, |List| or a |Blob|. {func} is called with two
8322 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008323 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008324
8325 {initial} is the initial result. When omitted, the first item
8326 in {object} is used and {func} is first called for the second
8327 item. If {initial} is not given and {object} is empty no
8328 result can be computed, an E998 error is given.
8329
8330 Examples: >
8331 echo reduce([1, 3, 5], { acc, val -> acc + val })
8332 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8333 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8334 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8335<
8336 Can also be used as a |method|: >
8337 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008338<
8339 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8340 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008341
8342
8343reg_executing() *reg_executing()*
8344 Returns the single letter name of the register being executed.
8345 Returns an empty string when no register is being executed.
8346 See |@|.
8347
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008348 Return type: |String|
8349
8350
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008351reg_recording() *reg_recording()*
8352 Returns the single letter name of the register being recorded.
8353 Returns an empty string when not recording. See |q|.
8354
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008355 Return type: |String|
8356
8357
8358reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008359reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008360reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008361 Return an item that represents a time value. The item is a
8362 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008363 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008364 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008365 string or |reltimefloat()| to convert to a Float. For
8366 example, to see the time spent in function Work(): >
8367 var startTime = reltime()
8368 Work()
8369 echo startTime->reltime()->reltimestr()
8370<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008371 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008372 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008373 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008374 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008375 specified in the argument.
8376 With two arguments it returns the time passed between {start}
8377 and {end}.
8378
8379 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008380 reltime(). If there is an error an empty List is returned in
8381 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008382
8383 Can also be used as a |method|: >
8384 GetStart()->reltime()
8385<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008386 Return type: list<number>
8387
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008388 {only available when compiled with the |+reltime| feature}
8389
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008390
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008391reltimefloat({time}) *reltimefloat()*
8392 Return a Float that represents the time value of {time}.
8393 Example: >
8394 let start = reltime()
8395 call MyFunction()
8396 let seconds = reltimefloat(reltime(start))
8397< See the note of reltimestr() about overhead.
8398 Also see |profiling|.
8399 If there is an error 0.0 is returned in legacy script, in Vim9
8400 script an error is given.
8401
8402 Can also be used as a |method|: >
8403 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008404<
8405 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008406
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008407 {only available when compiled with the |+reltime| feature}
8408
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008409
8410reltimestr({time}) *reltimestr()*
8411 Return a String that represents the time value of {time}.
8412 This is the number of seconds, a dot and the number of
8413 microseconds. Example: >
8414 let start = reltime()
8415 call MyFunction()
8416 echo reltimestr(reltime(start))
8417< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008418 The accuracy depends on the system. Use reltimefloat() for the
8419 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008420 Leading spaces are used to make the string align nicely. You
8421 can use split() to remove it. >
8422 echo split(reltimestr(reltime(start)))[0]
8423< Also see |profiling|.
8424 If there is an error an empty string is returned in legacy
8425 script, in Vim9 script an error is given.
8426
8427 Can also be used as a |method|: >
8428 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008429<
8430 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008431
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008432 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008433
8434 *remote_expr()* *E449*
8435remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008436 Send the {string} to {server}. The {server} argument is a
8437 string, also see |{server}|.
8438
8439 The string is sent as an expression and the result is returned
8440 after evaluation. The result must be a String or a |List|. A
8441 |List| is turned into a String by joining the items with a
8442 line break in between (not at the end), like with join(expr,
8443 "\n").
8444
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008445 If {idvar} is present and not empty, it is taken as the name
8446 of a variable and a {serverid} for later use with
8447 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008448
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008449 If {timeout} is given the read times out after this many
8450 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008451
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008452 See also |clientserver| |RemoteReply|.
8453 This function is not available in the |sandbox|.
8454 {only available when compiled with the |+clientserver| feature}
8455 Note: Any errors will cause a local error message to be issued
8456 and the result will be the empty string.
8457
8458 Variables will be evaluated in the global namespace,
8459 independent of a function currently being active. Except
8460 when in debug mode, then local function variables and
8461 arguments can be evaluated.
8462
8463 Examples: >
8464 :echo remote_expr("gvim", "2+2")
8465 :echo remote_expr("gvim1", "b:current_syntax")
8466<
8467 Can also be used as a |method|: >
8468 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008469<
8470 Return type: |String| or list<{type}>
8471
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008472
8473remote_foreground({server}) *remote_foreground()*
8474 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008475 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008476 This works like: >
8477 remote_expr({server}, "foreground()")
8478< Except that on Win32 systems the client does the work, to work
8479 around the problem that the OS doesn't always allow the server
8480 to bring itself to the foreground.
8481 Note: This does not restore the window if it was minimized,
8482 like foreground() does.
8483 This function is not available in the |sandbox|.
8484
8485 Can also be used as a |method|: >
8486 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008487<
8488 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008489
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008490 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008491 Win32 console version}
8492
8493
8494remote_peek({serverid} [, {retvar}]) *remote_peek()*
8495 Returns a positive number if there are available strings
8496 from {serverid}. Copies any reply string into the variable
8497 {retvar} if specified. {retvar} must be a string with the
8498 name of a variable.
8499 Returns zero if none are available.
8500 Returns -1 if something is wrong.
8501 See also |clientserver|.
8502 This function is not available in the |sandbox|.
8503 {only available when compiled with the |+clientserver| feature}
8504 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008505 :let repl = ""
8506 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008507
8508< Can also be used as a |method|: >
8509 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008510<
8511 Return type: |Number|
8512
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008513
8514remote_read({serverid}, [{timeout}]) *remote_read()*
8515 Return the oldest available reply from {serverid} and consume
8516 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008517 reply is available. Returns an empty string, if a reply is
8518 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008519 See also |clientserver|.
8520 This function is not available in the |sandbox|.
8521 {only available when compiled with the |+clientserver| feature}
8522 Example: >
8523 :echo remote_read(id)
8524
8525< Can also be used as a |method|: >
8526 ServerId()->remote_read()
8527<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008528 Return type: |String|
8529
8530
8531remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008532 Send the {string} to {server}. The {server} argument is a
8533 string, also see |{server}|.
8534
8535 The string is sent as input keys and the function returns
8536 immediately. At the Vim server the keys are not mapped
8537 |:map|.
8538
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008539 If {idvar} is present, it is taken as the name of a variable
8540 and a {serverid} for later use with remote_read() is stored
8541 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008542
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008543 See also |clientserver| |RemoteReply|.
8544 This function is not available in the |sandbox|.
8545 {only available when compiled with the |+clientserver| feature}
8546
8547 Note: Any errors will be reported in the server and may mess
8548 up the display.
8549 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008550 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008551 \ remote_read(serverid)
8552
8553 :autocmd NONE RemoteReply *
8554 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008555 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008556 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8557<
8558 Can also be used as a |method|: >
8559 ServerName()->remote_send(keys)
8560<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008561 Return type: |String|
8562
8563
8564remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008565 Become the server {name}. {name} must be a non-empty string.
8566 This fails if already running as a server, when |v:servername|
8567 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008568
8569 Can also be used as a |method|: >
8570 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008571<
8572 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008573
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008574 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008575
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008576
8577remove({list}, {idx}) *remove()*
8578remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008579 Without {end}: Remove the item at {idx} from |List| {list} and
8580 return the item.
8581 With {end}: Remove items from {idx} to {end} (inclusive) and
8582 return a |List| with these items. When {idx} points to the same
8583 item as {end} a list with one item is returned. When {end}
8584 points to an item before {idx} this is an error.
8585 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008586 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008587 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008588 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008589 :call remove(mylist, 0, 9)
8590<
8591 Use |delete()| to remove a file.
8592
8593 Can also be used as a |method|: >
8594 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008595<
8596 Return type: any, depending on {list}
8597
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008598
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008599remove({blob}, {idx})
8600remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008601 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8602 return the byte.
8603 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8604 return a |Blob| with these bytes. When {idx} points to the same
8605 byte as {end} a |Blob| with one byte is returned. When {end}
8606 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008607 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008608 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008609 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008610 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008611<
8612 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008613
8614remove({dict}, {key})
8615 Remove the entry from {dict} with key {key} and return it.
8616 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008617 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008618< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008619 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008620
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008621 Return type: any, depending on {dict}
8622
8623
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008624rename({from}, {to}) *rename()*
8625 Rename the file by the name {from} to the name {to}. This
8626 should also work to move files across file systems. The
8627 result is a Number, which is 0 if the file was renamed
8628 successfully, and non-zero when the renaming failed.
8629 NOTE: If {to} exists it is overwritten without warning.
8630 This function is not available in the |sandbox|.
8631
8632 Can also be used as a |method|: >
8633 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008634<
8635 Return type: |Number|
8636
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008637
8638repeat({expr}, {count}) *repeat()*
8639 Repeat {expr} {count} times and return the concatenated
8640 result. Example: >
8641 :let separator = repeat('-', 80)
8642< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01008643 When {expr} is a |List| or a |Blob| the result is {expr}
8644 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008645 :let longlist = repeat(['a', 'b'], 3)
8646< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
8647
8648 Can also be used as a |method|: >
8649 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008650<
8651 Return type: |String|, |Blob| or list<{type}> depending on
8652 {expr}
8653
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008654
8655resolve({filename}) *resolve()* *E655*
8656 On MS-Windows, when {filename} is a shortcut (a .lnk file),
8657 returns the path the shortcut points to in a simplified form.
8658 When {filename} is a symbolic link or junction point, return
8659 the full path to the target. If the target of junction is
8660 removed, return {filename}.
8661 On Unix, repeat resolving symbolic links in all path
8662 components of {filename} and return the simplified result.
8663 To cope with link cycles, resolving of symbolic links is
8664 stopped after 100 iterations.
8665 On other systems, return the simplified {filename}.
8666 The simplification step is done as by |simplify()|.
8667 resolve() keeps a leading path component specifying the
8668 current directory (provided the result is still a relative
8669 path name) and also keeps a trailing path separator.
8670
8671 Can also be used as a |method|: >
8672 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008673<
8674 Return type: |String|
8675
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008676
8677reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01008678 Reverse the order of items in {object}. {object} can be a
8679 |List|, a |Blob| or a |String|. For a List and a Blob the
8680 items are reversed in-place and {object} is returned.
8681 For a String a new String is returned.
8682 Returns zero if {object} is not a List, Blob or a String.
8683 If you want a List or Blob to remain unmodified make a copy
8684 first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008685 :let revlist = reverse(copy(mylist))
8686< Can also be used as a |method|: >
8687 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008688<
8689 Return type: |String|, |Blob| or list<{type}> depending on
8690 {object}
8691
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008692
8693round({expr}) *round()*
8694 Round off {expr} to the nearest integral value and return it
8695 as a |Float|. If {expr} lies halfway between two integral
8696 values, then use the larger one (away from zero).
8697 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008698 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008699 Examples: >
8700 echo round(0.456)
8701< 0.0 >
8702 echo round(4.5)
8703< 5.0 >
8704 echo round(-4.5)
8705< -5.0
8706
8707 Can also be used as a |method|: >
8708 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008709<
8710 Return type: |Float|
8711
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008712
8713rubyeval({expr}) *rubyeval()*
8714 Evaluate Ruby expression {expr} and return its result
8715 converted to Vim data structures.
8716 Numbers, floats and strings are returned as they are (strings
8717 are copied though).
8718 Arrays are represented as Vim |List| type.
8719 Hashes are represented as Vim |Dictionary| type.
8720 Other objects are represented as strings resulted from their
8721 "Object#to_s" method.
8722 Note that in a `:def` function local variables are not visible
8723 to {expr}.
8724
8725 Can also be used as a |method|: >
8726 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008727<
8728 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008729
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008730 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008731
8732screenattr({row}, {col}) *screenattr()*
8733 Like |screenchar()|, but return the attribute. This is a rather
8734 arbitrary number that can only be used to compare to the
8735 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008736 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008737
8738 Can also be used as a |method|: >
8739 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008740<
8741 Return type: |Number|
8742
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008743
8744screenchar({row}, {col}) *screenchar()*
8745 The result is a Number, which is the character at position
8746 [row, col] on the screen. This works for every possible
8747 screen position, also status lines, window separators and the
8748 command line. The top left position is row one, column one
8749 The character excludes composing characters. For double-byte
8750 encodings it may only be the first byte.
8751 This is mainly to be used for testing.
8752 Returns -1 when row or col is out of range.
8753
8754 Can also be used as a |method|: >
8755 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008756<
8757 Return type: |Number|
8758
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008759
8760screenchars({row}, {col}) *screenchars()*
8761 The result is a |List| of Numbers. The first number is the same
8762 as what |screenchar()| returns. Further numbers are
8763 composing characters on top of the base character.
8764 This is mainly to be used for testing.
8765 Returns an empty List when row or col is out of range.
8766
8767 Can also be used as a |method|: >
8768 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008769<
8770 Return type: list<number> or list<any>
8771
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008772
8773screencol() *screencol()*
8774 The result is a Number, which is the current screen column of
8775 the cursor. The leftmost column has number 1.
8776 This function is mainly used for testing.
8777
8778 Note: Always returns the current screen column, thus if used
8779 in a command (e.g. ":echo screencol()") it will return the
8780 column inside the command line, which is 1 when the command is
8781 executed. To get the cursor position in the file use one of
8782 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008783 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008784 nnoremap <silent> GG :echom screencol()<CR>
8785 nnoremap GG <Cmd>echom screencol()<CR>
8786<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008787 Return type: |Number|
8788
8789
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008790screenpos({winid}, {lnum}, {col}) *screenpos()*
8791 The result is a Dict with the screen position of the text
8792 character in window {winid} at buffer line {lnum} and column
8793 {col}. {col} is a one-based byte index.
8794 The Dict has these members:
8795 row screen row
8796 col first screen column
8797 endcol last screen column
8798 curscol cursor screen column
8799 If the specified position is not visible, all values are zero.
8800 The "endcol" value differs from "col" when the character
8801 occupies more than one screen cell. E.g. for a Tab "col" can
8802 be 1 and "endcol" can be 8.
8803 The "curscol" value is where the cursor would be placed. For
8804 a Tab it would be the same as "endcol", while for a double
8805 width character it would be the same as "col".
8806 The |conceal| feature is ignored here, the column numbers are
8807 as if 'conceallevel' is zero. You can set the cursor to the
8808 right position and use |screencol()| to get the value with
8809 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008810 If the position is in a closed fold the screen position of the
8811 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008812 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008813
8814 Can also be used as a |method|: >
8815 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008816<
8817 Return type: dict<number> or dict<any>
8818
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008819
8820screenrow() *screenrow()*
8821 The result is a Number, which is the current screen row of the
8822 cursor. The top line has number one.
8823 This function is mainly used for testing.
8824 Alternatively you can use |winline()|.
8825
8826 Note: Same restrictions as with |screencol()|.
8827
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008828 Return type: |Number|
8829
8830
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008831screenstring({row}, {col}) *screenstring()*
8832 The result is a String that contains the base character and
8833 any composing characters at position [row, col] on the screen.
8834 This is like |screenchars()| but returning a String with the
8835 characters.
8836 This is mainly to be used for testing.
8837 Returns an empty String when row or col is out of range.
8838
8839 Can also be used as a |method|: >
8840 GetRow()->screenstring(col)
8841<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008842 Return type: |String|
8843
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008844 *search()*
8845search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
8846 Search for regexp pattern {pattern}. The search starts at the
8847 cursor position (you can use |cursor()| to set it).
8848
8849 When a match has been found its line number is returned.
8850 If there is no match a 0 is returned and the cursor doesn't
8851 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01008852 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008853
8854 {flags} is a String, which can contain these character flags:
8855 'b' search Backward instead of forward
8856 'c' accept a match at the Cursor position
8857 'e' move to the End of the match
8858 'n' do Not move the cursor
8859 'p' return number of matching sub-Pattern (see below)
8860 's' Set the ' mark at the previous location of the cursor
8861 'w' Wrap around the end of the file
8862 'W' don't Wrap around the end of the file
8863 'z' start searching at the cursor column instead of zero
8864 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
8865
8866 If the 's' flag is supplied, the ' mark is set, only if the
8867 cursor is moved. The 's' flag cannot be combined with the 'n'
8868 flag.
8869
8870 'ignorecase', 'smartcase' and 'magic' are used.
8871
8872 When the 'z' flag is not given, forward searching always
8873 starts in column zero and then matches before the cursor are
8874 skipped. When the 'c' flag is present in 'cpo' the next
8875 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01008876 search starts one column after the start of the match. This
8877 matters for overlapping matches. See |cpo-c|. You can also
8878 insert "\ze" to change where the match ends, see |/\ze|.
8879
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008880 When searching backwards and the 'z' flag is given then the
8881 search starts in column zero, thus no match in the current
8882 line will be found (unless wrapping around the end of the
8883 file).
8884
8885 When the {stopline} argument is given then the search stops
8886 after searching this line. This is useful to restrict the
8887 search to a range of lines. Examples: >
8888 let match = search('(', 'b', line("w0"))
8889 let end = search('END', '', line("w$"))
8890< When {stopline} is used and it is not zero this also implies
8891 that the search does not wrap around the end of the file.
8892 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01008893 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008894 When the {timeout} argument is given the search stops when
8895 more than this many milliseconds have passed. Thus when
8896 {timeout} is 500 the search stops after half a second.
8897 The value must not be negative. A zero value is like not
8898 giving the argument.
8899 {only available when compiled with the |+reltime| feature}
8900
8901 If the {skip} expression is given it is evaluated with the
8902 cursor positioned on the start of a match. If it evaluates to
8903 non-zero this match is skipped. This can be used, for
8904 example, to skip a match in a comment or a string.
8905 {skip} can be a string, which is evaluated as an expression, a
8906 function reference or a lambda.
8907 When {skip} is omitted or empty, every match is accepted.
8908 When evaluating {skip} causes an error the search is aborted
8909 and -1 returned.
8910 *search()-sub-match*
8911 With the 'p' flag the returned value is one more than the
8912 first sub-match in \(\). One if none of them matched but the
8913 whole pattern did match.
8914 To get the column number too use |searchpos()|.
8915
8916 The cursor will be positioned at the match, unless the 'n'
8917 flag is used.
8918
8919 Example (goes over all files in the argument list): >
8920 :let n = 1
8921 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008922 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008923 : " start at the last char in the file and wrap for the
8924 : " first search to find match at start of file
8925 : normal G$
8926 : let flags = "w"
8927 : while search("foo", flags) > 0
8928 : s/foo/bar/g
8929 : let flags = "W"
8930 : endwhile
8931 : update " write the file if modified
8932 : let n = n + 1
8933 :endwhile
8934<
8935 Example for using some flags: >
8936 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
8937< This will search for the keywords "if", "else", and "endif"
8938 under or after the cursor. Because of the 'p' flag, it
8939 returns 1, 2, or 3 depending on which keyword is found, or 0
8940 if the search fails. With the cursor on the first word of the
8941 line:
8942 if (foo == 0) | let foo = foo + 1 | endif ~
8943 the function returns 1. Without the 'c' flag, the function
8944 finds the "endif" and returns 3. The same thing happens
8945 without the 'e' flag if the cursor is on the "f" of "if".
8946 The 'n' flag tells the function not to move the cursor.
8947
8948 Can also be used as a |method|: >
8949 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008950<
8951 Return type: |Number|
8952
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008953
8954searchcount([{options}]) *searchcount()*
8955 Get or update the last search count, like what is displayed
8956 without the "S" flag in 'shortmess'. This works even if
8957 'shortmess' does contain the "S" flag.
8958
8959 This returns a |Dictionary|. The dictionary is empty if the
8960 previous pattern was not set and "pattern" was not specified.
8961
8962 key type meaning ~
8963 current |Number| current position of match;
8964 0 if the cursor position is
8965 before the first match
8966 exact_match |Boolean| 1 if "current" is matched on
8967 "pos", otherwise 0
8968 total |Number| total count of matches found
8969 incomplete |Number| 0: search was fully completed
8970 1: recomputing was timed out
8971 2: max count exceeded
8972
8973 For {options} see further down.
8974
8975 To get the last search count when |n| or |N| was pressed, call
8976 this function with `recompute: 0` . This sometimes returns
8977 wrong information because |n| and |N|'s maximum count is 99.
8978 If it exceeded 99 the result must be max count + 1 (100). If
8979 you want to get correct information, specify `recompute: 1`: >
8980
8981 " result == maxcount + 1 (100) when many matches
8982 let result = searchcount(#{recompute: 0})
8983
8984 " Below returns correct result (recompute defaults
8985 " to 1)
8986 let result = searchcount()
8987<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01008988 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008989 function! LastSearchCount() abort
8990 let result = searchcount(#{recompute: 0})
8991 if empty(result)
8992 return ''
8993 endif
8994 if result.incomplete ==# 1 " timed out
8995 return printf(' /%s [?/??]', @/)
8996 elseif result.incomplete ==# 2 " max count exceeded
8997 if result.total > result.maxcount &&
8998 \ result.current > result.maxcount
8999 return printf(' /%s [>%d/>%d]', @/,
9000 \ result.current, result.total)
9001 elseif result.total > result.maxcount
9002 return printf(' /%s [%d/>%d]', @/,
9003 \ result.current, result.total)
9004 endif
9005 endif
9006 return printf(' /%s [%d/%d]', @/,
9007 \ result.current, result.total)
9008 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009009 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009010
9011 " Or if you want to show the count only when
9012 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009013 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009014 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9015<
9016 You can also update the search count, which can be useful in a
9017 |CursorMoved| or |CursorMovedI| autocommand: >
9018
9019 autocmd CursorMoved,CursorMovedI *
9020 \ let s:searchcount_timer = timer_start(
9021 \ 200, function('s:update_searchcount'))
9022 function! s:update_searchcount(timer) abort
9023 if a:timer ==# s:searchcount_timer
9024 call searchcount(#{
9025 \ recompute: 1, maxcount: 0, timeout: 100})
9026 redrawstatus
9027 endif
9028 endfunction
9029<
9030 This can also be used to count matched texts with specified
9031 pattern in the current buffer using "pattern": >
9032
9033 " Count '\<foo\>' in this buffer
9034 " (Note that it also updates search count)
9035 let result = searchcount(#{pattern: '\<foo\>'})
9036
9037 " To restore old search count by old pattern,
9038 " search again
9039 call searchcount()
9040<
9041 {options} must be a |Dictionary|. It can contain:
9042 key type meaning ~
9043 recompute |Boolean| if |TRUE|, recompute the count
9044 like |n| or |N| was executed.
9045 otherwise returns the last
9046 computed result (when |n| or
9047 |N| was used when "S" is not
9048 in 'shortmess', or this
9049 function was called).
9050 (default: |TRUE|)
9051 pattern |String| recompute if this was given
9052 and different with |@/|.
9053 this works as same as the
9054 below command is executed
9055 before calling this function >
9056 let @/ = pattern
9057< (default: |@/|)
9058 timeout |Number| 0 or negative number is no
9059 timeout. timeout milliseconds
9060 for recomputing the result
9061 (default: 0)
9062 maxcount |Number| 0 or negative number is no
9063 limit. max count of matched
9064 text while recomputing the
9065 result. if search exceeded
9066 total count, "total" value
9067 becomes `maxcount + 1`
9068 (default: 99)
9069 pos |List| `[lnum, col, off]` value
9070 when recomputing the result.
9071 this changes "current" result
9072 value. see |cursor()|,
9073 |getpos()|
9074 (default: cursor's position)
9075
9076 Can also be used as a |method|: >
9077 GetSearchOpts()->searchcount()
9078<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009079 Return type: dict<number>
9080
9081
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009082searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9083 Search for the declaration of {name}.
9084
9085 With a non-zero {global} argument it works like |gD|, find
9086 first match in the file. Otherwise it works like |gd|, find
9087 first match in the function.
9088
9089 With a non-zero {thisblock} argument matches in a {} block
9090 that ends before the cursor position are ignored. Avoids
9091 finding variable declarations only valid in another scope.
9092
9093 Moves the cursor to the found match.
9094 Returns zero for success, non-zero for failure.
9095 Example: >
9096 if searchdecl('myvar') == 0
9097 echo getline('.')
9098 endif
9099<
9100 Can also be used as a |method|: >
9101 GetName()->searchdecl()
9102<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009103 Return type: |Number|
9104
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009105 *searchpair()*
9106searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9107 [, {stopline} [, {timeout}]]]])
9108 Search for the match of a nested start-end pair. This can be
9109 used to find the "endif" that matches an "if", while other
9110 if/endif pairs in between are ignored.
9111 The search starts at the cursor. The default is to search
9112 forward, include 'b' in {flags} to search backward.
9113 If a match is found, the cursor is positioned at it and the
9114 line number is returned. If no match is found 0 or -1 is
9115 returned and the cursor doesn't move. No error message is
9116 given.
9117
9118 {start}, {middle} and {end} are patterns, see |pattern|. They
9119 must not contain \( \) pairs. Use of \%( \) is allowed. When
9120 {middle} is not empty, it is found when searching from either
9121 direction, but only when not in a nested start-end pair. A
9122 typical use is: >
9123 searchpair('\<if\>', '\<else\>', '\<endif\>')
9124< By leaving {middle} empty the "else" is skipped.
9125
9126 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9127 |search()|. Additionally:
9128 'r' Repeat until no more matches found; will find the
9129 outer pair. Implies the 'W' flag.
9130 'm' Return number of matches instead of line number with
9131 the match; will be > 1 when 'r' is used.
9132 Note: it's nearly always a good idea to use the 'W' flag, to
9133 avoid wrapping around the end of the file.
9134
9135 When a match for {start}, {middle} or {end} is found, the
9136 {skip} expression is evaluated with the cursor positioned on
9137 the start of the match. It should return non-zero if this
9138 match is to be skipped. E.g., because it is inside a comment
9139 or a string.
9140 When {skip} is omitted or empty, every match is accepted.
9141 When evaluating {skip} causes an error the search is aborted
9142 and -1 returned.
9143 {skip} can be a string, a lambda, a funcref or a partial.
9144 Anything else makes the function fail.
9145 In a `:def` function when the {skip} argument is a string
9146 constant it is compiled into instructions.
9147
9148 For {stopline} and {timeout} see |search()|.
9149
9150 The value of 'ignorecase' is used. 'magic' is ignored, the
9151 patterns are used like it's on.
9152
9153 The search starts exactly at the cursor. A match with
9154 {start}, {middle} or {end} at the next character, in the
9155 direction of searching, is the first one found. Example: >
9156 if 1
9157 if 2
9158 endif 2
9159 endif 1
9160< When starting at the "if 2", with the cursor on the "i", and
9161 searching forwards, the "endif 2" is found. When starting on
9162 the character just before the "if 2", the "endif 1" will be
9163 found. That's because the "if 2" will be found first, and
9164 then this is considered to be a nested if/endif from "if 2" to
9165 "endif 2".
9166 When searching backwards and {end} is more than one character,
9167 it may be useful to put "\zs" at the end of the pattern, so
9168 that when the cursor is inside a match with the end it finds
9169 the matching start.
9170
9171 Example, to find the "endif" command in a Vim script: >
9172
9173 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9174 \ 'getline(".") =~ "^\\s*\""')
9175
9176< The cursor must be at or after the "if" for which a match is
9177 to be found. Note that single-quote strings are used to avoid
9178 having to double the backslashes. The skip expression only
9179 catches comments at the start of a line, not after a command.
9180 Also, a word "en" or "if" halfway a line is considered a
9181 match.
9182 Another example, to search for the matching "{" of a "}": >
9183
9184 :echo searchpair('{', '', '}', 'bW')
9185
9186< This works when the cursor is at or before the "}" for which a
9187 match is to be found. To reject matches that syntax
9188 highlighting recognized as strings: >
9189
9190 :echo searchpair('{', '', '}', 'bW',
9191 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9192<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009193 Return type: |Number|
9194
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009195 *searchpairpos()*
9196searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9197 [, {stopline} [, {timeout}]]]])
9198 Same as |searchpair()|, but returns a |List| with the line and
9199 column position of the match. The first element of the |List|
9200 is the line number and the second element is the byte index of
9201 the column position of the match. If no match is found,
9202 returns [0, 0]. >
9203
9204 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9205<
9206 See |match-parens| for a bigger and more useful example.
9207
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009208 Return type: list<number>
9209
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009210 *searchpos()*
9211searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9212 Same as |search()|, but returns a |List| with the line and
9213 column position of the match. The first element of the |List|
9214 is the line number and the second element is the byte index of
9215 the column position of the match. If no match is found,
9216 returns [0, 0].
9217 Example: >
9218 :let [lnum, col] = searchpos('mypattern', 'n')
9219
9220< When the 'p' flag is given then there is an extra item with
9221 the sub-pattern match number |search()-sub-match|. Example: >
9222 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9223< In this example "submatch" is 2 when a lowercase letter is
9224 found |/\l|, 3 when an uppercase letter is found |/\u|.
9225
9226 Can also be used as a |method|: >
9227 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009228<
9229 Return type: list<number>
9230
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009231
9232server2client({clientid}, {string}) *server2client()*
9233 Send a reply string to {clientid}. The most recent {clientid}
9234 that sent a string can be retrieved with expand("<client>").
9235 {only available when compiled with the |+clientserver| feature}
9236 Returns zero for success, -1 for failure.
9237 Note:
9238 This id has to be stored before the next command can be
9239 received. I.e. before returning from the received command and
9240 before calling any commands that waits for input.
9241 See also |clientserver|.
9242 Example: >
9243 :echo server2client(expand("<client>"), "HELLO")
9244
9245< Can also be used as a |method|: >
9246 GetClientId()->server2client(string)
9247<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009248 Return type: |Number|
9249
9250
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009251serverlist() *serverlist()*
9252 Return a list of available server names, one per line.
9253 When there are no servers or the information is not available
9254 an empty string is returned. See also |clientserver|.
9255 {only available when compiled with the |+clientserver| feature}
9256 Example: >
9257 :echo serverlist()
9258<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009259 Return type: |String|
9260
9261
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009262setbufline({buf}, {lnum}, {text}) *setbufline()*
9263 Set line {lnum} to {text} in buffer {buf}. This works like
9264 |setline()| for the specified buffer.
9265
9266 This function works only for loaded buffers. First call
9267 |bufload()| if needed.
9268
9269 To insert lines use |appendbufline()|.
9270 Any text properties in {lnum} are cleared.
9271
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009272 {text} can be a string to set one line, or a List of strings
9273 to set multiple lines. If the List extends below the last
9274 line then those lines are added. If the List is empty then
9275 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009276
9277 For the use of {buf}, see |bufname()| above.
9278
9279 {lnum} is used like with |setline()|.
9280 Use "$" to refer to the last line in buffer {buf}.
9281 When {lnum} is just below the last line the {text} will be
9282 added below the last line.
9283
9284 When {buf} is not a valid buffer, the buffer is not loaded or
9285 {lnum} is not valid then 1 is returned. In |Vim9| script an
9286 error is given.
9287 On success 0 is returned.
9288
9289 Can also be used as a |method|, the base is passed as the
9290 third argument: >
9291 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009292<
9293 Return type: |Number|
9294
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009295
9296setbufvar({buf}, {varname}, {val}) *setbufvar()*
9297 Set option or local variable {varname} in buffer {buf} to
9298 {val}.
9299 This also works for a global or local window option, but it
9300 doesn't work for a global or local window variable.
9301 For a local window option the global value is unchanged.
9302 For the use of {buf}, see |bufname()| above.
9303 The {varname} argument is a string.
9304 Note that the variable name without "b:" must be used.
9305 Examples: >
9306 :call setbufvar(1, "&mod", 1)
9307 :call setbufvar("todo", "myvar", "foobar")
9308< This function is not available in the |sandbox|.
9309
9310 Can also be used as a |method|, the base is passed as the
9311 third argument: >
9312 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009313<
9314 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009315
9316
9317setcellwidths({list}) *setcellwidths()*
9318 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009319 tells Vim how wide characters are when displayed in the
9320 terminal, counted in screen cells. The values override
9321 'ambiwidth'. Example: >
9322 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009323 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009324 \ [0x2194, 0x2199, 2],
9325 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009326
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009327< The {list} argument is a List of Lists with each three
9328 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9329 {low} and {high} can be the same, in which case this refers to
9330 one character. Otherwise it is the range of characters from
9331 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009332 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009333
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009334 {width} must be either 1 or 2, indicating the character width
9335 in screen cells. *E1112*
9336 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009337 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009338
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009339 If the new value causes 'fillchars' or 'listchars' to become
9340 invalid it is rejected and an error is given.
9341
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009342 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009343 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009344
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009345< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009346 the effect for known emoji characters. Move the cursor
9347 through the text to check if the cell widths of your terminal
9348 match with what Vim knows about each emoji. If it doesn't
9349 look right you need to adjust the {list} argument.
9350
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009351 Return type: |Number|
9352
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009353
9354setcharpos({expr}, {list}) *setcharpos()*
9355 Same as |setpos()| but uses the specified column number as the
9356 character index instead of the byte index in the line.
9357
9358 Example:
9359 With the text "여보세요" in line 8: >
9360 call setcharpos('.', [0, 8, 4, 0])
9361< positions the cursor on the fourth character '요'. >
9362 call setpos('.', [0, 8, 4, 0])
9363< positions the cursor on the second character '보'.
9364
9365 Can also be used as a |method|: >
9366 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009367<
9368 Return type: |Number|
9369
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009370
9371setcharsearch({dict}) *setcharsearch()*
9372 Set the current character search information to {dict},
9373 which contains one or more of the following entries:
9374
9375 char character which will be used for a subsequent
9376 |,| or |;| command; an empty string clears the
9377 character search
9378 forward direction of character search; 1 for forward,
9379 0 for backward
9380 until type of character search; 1 for a |t| or |T|
9381 character search, 0 for an |f| or |F|
9382 character search
9383
9384 This can be useful to save/restore a user's character search
9385 from a script: >
9386 :let prevsearch = getcharsearch()
9387 :" Perform a command which clobbers user's search
9388 :call setcharsearch(prevsearch)
9389< Also see |getcharsearch()|.
9390
9391 Can also be used as a |method|: >
9392 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009393<
9394 Return type: dict<any>
9395
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009396
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009397setcmdline({str} [, {pos}]) *setcmdline()*
9398 Set the command line to {str} and set the cursor position to
9399 {pos}.
9400 If {pos} is omitted, the cursor is positioned after the text.
9401 Returns 0 when successful, 1 when not editing the command
9402 line.
9403
9404 Can also be used as a |method|: >
9405 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009406<
9407 Return type: |Number|
9408
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009409
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009410setcmdpos({pos}) *setcmdpos()*
9411 Set the cursor position in the command line to byte position
9412 {pos}. The first position is 1.
9413 Use |getcmdpos()| to obtain the current position.
9414 Only works while editing the command line, thus you must use
9415 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9416 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9417 set after the command line is set to the expression. For
9418 |c_CTRL-R_=| it is set after evaluating the expression but
9419 before inserting the resulting text.
9420 When the number is too big the cursor is put at the end of the
9421 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009422 Returns 0 when successful, 1 when not editing the command
9423 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009424
9425 Can also be used as a |method|: >
9426 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009427<
9428 Return type: |Number|
9429
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009430
9431setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9432setcursorcharpos({list})
9433 Same as |cursor()| but uses the specified column number as the
9434 character index instead of the byte index in the line.
9435
9436 Example:
9437 With the text "여보세요" in line 4: >
9438 call setcursorcharpos(4, 3)
9439< positions the cursor on the third character '세'. >
9440 call cursor(4, 3)
9441< positions the cursor on the first character '여'.
9442
9443 Can also be used as a |method|: >
9444 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009445<
9446 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009447
9448
9449setenv({name}, {val}) *setenv()*
9450 Set environment variable {name} to {val}. Example: >
9451 call setenv('HOME', '/home/myhome')
9452
9453< When {val} is |v:null| the environment variable is deleted.
9454 See also |expr-env|.
9455
9456 Can also be used as a |method|, the base is passed as the
9457 second argument: >
9458 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009459<
9460 Return type: |Number|
9461
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009462
9463setfperm({fname}, {mode}) *setfperm()* *chmod*
9464 Set the file permissions for {fname} to {mode}.
9465 {mode} must be a string with 9 characters. It is of the form
9466 "rwxrwxrwx", where each group of "rwx" flags represent, in
9467 turn, the permissions of the owner of the file, the group the
9468 file belongs to, and other users. A '-' character means the
9469 permission is off, any other character means on. Multi-byte
9470 characters are not supported.
9471
9472 For example "rw-r-----" means read-write for the user,
9473 readable by the group, not accessible by others. "xx-x-----"
9474 would do the same thing.
9475
9476 Returns non-zero for success, zero for failure.
9477
9478 Can also be used as a |method|: >
9479 GetFilename()->setfperm(mode)
9480<
9481 To read permissions see |getfperm()|.
9482
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009483 Return type: |Number|
9484
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009485
9486setline({lnum}, {text}) *setline()*
9487 Set line {lnum} of the current buffer to {text}. To insert
9488 lines use |append()|. To set lines in another buffer use
9489 |setbufline()|. Any text properties in {lnum} are cleared.
9490
9491 {lnum} is used like with |getline()|.
9492 When {lnum} is just below the last line the {text} will be
9493 added below the last line.
9494 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009495 converted to a String. When {text} is an empty List then
9496 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009497
9498 If this succeeds, FALSE is returned. If this fails (most likely
9499 because {lnum} is invalid) TRUE is returned.
9500 In |Vim9| script an error is given if {lnum} is invalid.
9501
9502 Example: >
9503 :call setline(5, strftime("%c"))
9504
9505< When {text} is a |List| then line {lnum} and following lines
9506 will be set to the items in the list. Example: >
9507 :call setline(5, ['aaa', 'bbb', 'ccc'])
9508< This is equivalent to: >
9509 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9510 : call setline(n, l)
9511 :endfor
9512
9513< Note: The '[ and '] marks are not set.
9514
9515 Can also be used as a |method|, the base is passed as the
9516 second argument: >
9517 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009518<
9519 Return type: |Number|
9520
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009521
9522setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9523 Create or replace or add to the location list for window {nr}.
9524 {nr} can be the window number or the |window-ID|.
9525 When {nr} is zero the current window is used.
9526
9527 For a location list window, the displayed location list is
9528 modified. For an invalid window number {nr}, -1 is returned.
9529 Otherwise, same as |setqflist()|.
9530 Also see |location-list|.
9531
9532 For {action} see |setqflist-action|.
9533
9534 If the optional {what} dictionary argument is supplied, then
9535 only the items listed in {what} are set. Refer to |setqflist()|
9536 for the list of supported keys in {what}.
9537
9538 Can also be used as a |method|, the base is passed as the
9539 second argument: >
9540 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009541<
9542 Return type: |Number|
9543
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009544
9545setmatches({list} [, {win}]) *setmatches()*
9546 Restores a list of matches saved by |getmatches()| for the
9547 current window. Returns 0 if successful, otherwise -1. All
9548 current matches are cleared before the list is restored. See
9549 example for |getmatches()|.
9550 If {win} is specified, use the window with this number or
9551 window ID instead of the current window.
9552
9553 Can also be used as a |method|: >
9554 GetMatches()->setmatches()
9555<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009556 Return type: |Number|
9557
9558
9559setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009560 Set the position for String {expr}. Possible values:
9561 . the cursor
9562 'x mark x
9563
9564 {list} must be a |List| with four or five numbers:
9565 [bufnum, lnum, col, off]
9566 [bufnum, lnum, col, off, curswant]
9567
9568 "bufnum" is the buffer number. Zero can be used for the
9569 current buffer. When setting an uppercase mark "bufnum" is
9570 used for the mark position. For other marks it specifies the
9571 buffer to set the mark in. You can use the |bufnr()| function
9572 to turn a file name into a buffer number.
9573 For setting the cursor and the ' mark "bufnum" is ignored,
9574 since these are associated with a window, not a buffer.
9575 Does not change the jumplist.
9576
9577 "lnum" and "col" are the position in the buffer. The first
9578 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9579 smaller than 1 then 1 is used. To use the character count
9580 instead of the byte count, use |setcharpos()|.
9581
9582 The "off" number is only used when 'virtualedit' is set. Then
9583 it is the offset in screen columns from the start of the
9584 character. E.g., a position within a <Tab> or after the last
9585 character.
9586
9587 The "curswant" number is only used when setting the cursor
9588 position. It sets the preferred column for when moving the
9589 cursor vertically. When the "curswant" number is missing the
9590 preferred column is not set. When it is present and setting a
9591 mark position it is not used.
9592
9593 Note that for '< and '> changing the line number may result in
9594 the marks to be effectively be swapped, so that '< is always
9595 before '>.
9596
9597 Returns 0 when the position could be set, -1 otherwise.
9598 An error message is given if {expr} is invalid.
9599
9600 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9601
9602 This does not restore the preferred column for moving
9603 vertically; if you set the cursor position with this, |j| and
9604 |k| motions will jump to previous columns! Use |cursor()| to
9605 also set the preferred column. Also see the "curswant" key in
9606 |winrestview()|.
9607
9608 Can also be used as a |method|: >
9609 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009610<
9611 Return type: |Number|
9612
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009613
9614setqflist({list} [, {action} [, {what}]]) *setqflist()*
9615 Create or replace or add to the quickfix list.
9616
9617 If the optional {what} dictionary argument is supplied, then
9618 only the items listed in {what} are set. The first {list}
9619 argument is ignored. See below for the supported items in
9620 {what}.
9621 *setqflist-what*
9622 When {what} is not present, the items in {list} are used. Each
9623 item must be a dictionary. Non-dictionary items in {list} are
9624 ignored. Each dictionary item can contain the following
9625 entries:
9626
9627 bufnr buffer number; must be the number of a valid
9628 buffer
9629 filename name of a file; only used when "bufnr" is not
9630 present or it is invalid.
9631 module name of a module; if given it will be used in
9632 quickfix error window instead of the filename.
9633 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00009634 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009635 pattern search pattern used to locate the error
9636 col column number
9637 vcol when non-zero: "col" is visual column
9638 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00009639 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009640 nr error number
9641 text description of the error
9642 type single-character error type, 'E', 'W', etc.
9643 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +02009644 user_data custom data associated with the item, can be
9645 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009646
9647 The "col", "vcol", "nr", "type" and "text" entries are
9648 optional. Either "lnum" or "pattern" entry can be used to
9649 locate a matching error line.
9650 If the "filename" and "bufnr" entries are not present or
9651 neither the "lnum" or "pattern" entries are present, then the
9652 item will not be handled as an error line.
9653 If both "pattern" and "lnum" are present then "pattern" will
9654 be used.
9655 If the "valid" entry is not supplied, then the valid flag is
9656 set when "bufnr" is a valid buffer or "filename" exists.
9657 If you supply an empty {list}, the quickfix list will be
9658 cleared.
9659 Note that the list is not exactly the same as what
9660 |getqflist()| returns.
9661
9662 {action} values: *setqflist-action* *E927*
9663 'a' The items from {list} are added to the existing
9664 quickfix list. If there is no existing list, then a
9665 new list is created.
9666
9667 'r' The items from the current quickfix list are replaced
9668 with the items from {list}. This can also be used to
9669 clear the list: >
9670 :call setqflist([], 'r')
9671<
9672 'f' All the quickfix lists in the quickfix stack are
9673 freed.
9674
9675 If {action} is not present or is set to ' ', then a new list
9676 is created. The new quickfix list is added after the current
9677 quickfix list in the stack and all the following lists are
9678 freed. To add a new quickfix list at the end of the stack,
9679 set "nr" in {what} to "$".
9680
9681 The following items can be specified in dictionary {what}:
9682 context quickfix list context. See |quickfix-context|
9683 efm errorformat to use when parsing text from
9684 "lines". If this is not present, then the
9685 'errorformat' option value is used.
9686 See |quickfix-parse|
9687 id quickfix list identifier |quickfix-ID|
9688 idx index of the current entry in the quickfix
9689 list specified by 'id' or 'nr'. If set to '$',
9690 then the last entry in the list is set as the
9691 current entry. See |quickfix-index|
9692 items list of quickfix entries. Same as the {list}
9693 argument.
9694 lines use 'errorformat' to parse a list of lines and
9695 add the resulting entries to the quickfix list
9696 {nr} or {id}. Only a |List| value is supported.
9697 See |quickfix-parse|
9698 nr list number in the quickfix stack; zero
9699 means the current quickfix list and "$" means
9700 the last quickfix list.
9701 quickfixtextfunc
9702 function to get the text to display in the
9703 quickfix window. The value can be the name of
9704 a function or a funcref or a lambda. Refer to
9705 |quickfix-window-function| for an explanation
9706 of how to write the function and an example.
9707 title quickfix list title text. See |quickfix-title|
9708 Unsupported keys in {what} are ignored.
9709 If the "nr" item is not present, then the current quickfix list
9710 is modified. When creating a new quickfix list, "nr" can be
9711 set to a value one greater than the quickfix stack size.
9712 When modifying a quickfix list, to guarantee that the correct
9713 list is modified, "id" should be used instead of "nr" to
9714 specify the list.
9715
9716 Examples (See also |setqflist-examples|): >
9717 :call setqflist([], 'r', {'title': 'My search'})
9718 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
9719 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
9720<
9721 Returns zero for success, -1 for failure.
9722
9723 This function can be used to create a quickfix list
9724 independent of the 'errorformat' setting. Use a command like
9725 `:cc 1` to jump to the first position.
9726
9727 Can also be used as a |method|, the base is passed as the
9728 second argument: >
9729 GetErrorlist()->setqflist()
9730<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009731 Return type: |Number|
9732
9733
9734setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009735 Set the register {regname} to {value}.
9736 If {regname} is "" or "@", the unnamed register '"' is used.
9737 The {regname} argument is a string. In |Vim9-script|
9738 {regname} must be one character.
9739
9740 {value} may be any value returned by |getreg()| or
9741 |getreginfo()|, including a |List| or |Dict|.
9742 If {options} contains "a" or {regname} is upper case,
9743 then the value is appended.
9744
9745 {options} can also contain a register type specification:
9746 "c" or "v" |characterwise| mode
9747 "l" or "V" |linewise| mode
9748 "b" or "<CTRL-V>" |blockwise-visual| mode
9749 If a number immediately follows "b" or "<CTRL-V>" then this is
9750 used as the width of the selection - if it is not specified
9751 then the width of the block is set to the number of characters
9752 in the longest line (counting a <Tab> as 1 character).
9753
9754 If {options} contains no register settings, then the default
9755 is to use character mode unless {value} ends in a <NL> for
9756 string {value} and linewise mode for list {value}. Blockwise
9757 mode is never selected automatically.
9758 Returns zero for success, non-zero for failure.
9759
9760 *E883*
9761 Note: you may not use |List| containing more than one item to
9762 set search and expression registers. Lists containing no
9763 items act like empty strings.
9764
9765 Examples: >
9766 :call setreg(v:register, @*)
9767 :call setreg('*', @%, 'ac')
9768 :call setreg('a', "1\n2\n3", 'b5')
9769 :call setreg('"', { 'points_to': 'a'})
9770
9771< This example shows using the functions to save and restore a
9772 register: >
9773 :let var_a = getreginfo()
9774 :call setreg('a', var_a)
9775< or: >
9776 :let var_a = getreg('a', 1, 1)
9777 :let var_amode = getregtype('a')
9778 ....
9779 :call setreg('a', var_a, var_amode)
9780< Note: you may not reliably restore register value
9781 without using the third argument to |getreg()| as without it
9782 newlines are represented as newlines AND Nul bytes are
9783 represented as newlines as well, see |NL-used-for-Nul|.
9784
9785 You can also change the type of a register by appending
9786 nothing: >
9787 :call setreg('a', '', 'al')
9788
9789< Can also be used as a |method|, the base is passed as the
9790 second argument: >
9791 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009792<
9793 Return type: |Number|
9794
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009795
9796settabvar({tabnr}, {varname}, {val}) *settabvar()*
9797 Set tab-local variable {varname} to {val} in tab page {tabnr}.
9798 |t:var|
9799 The {varname} argument is a string.
9800 Note that autocommands are blocked, side effects may not be
9801 triggered, e.g. when setting 'filetype'.
9802 Note that the variable name without "t:" must be used.
9803 Tabs are numbered starting with one.
9804 This function is not available in the |sandbox|.
9805
9806 Can also be used as a |method|, the base is passed as the
9807 third argument: >
9808 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009809<
9810 Return type: |Number|
9811
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009812
9813settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
9814 Set option or local variable {varname} in window {winnr} to
9815 {val}.
9816 Tabs are numbered starting with one. For the current tabpage
9817 use |setwinvar()|.
9818 {winnr} can be the window number or the |window-ID|.
9819 When {winnr} is zero the current window is used.
9820 Note that autocommands are blocked, side effects may not be
9821 triggered, e.g. when setting 'filetype' or 'syntax'.
9822 This also works for a global or local buffer option, but it
9823 doesn't work for a global or local buffer variable.
9824 For a local buffer option the global value is unchanged.
9825 Note that the variable name without "w:" must be used.
9826 Examples: >
9827 :call settabwinvar(1, 1, "&list", 0)
9828 :call settabwinvar(3, 2, "myvar", "foobar")
9829< This function is not available in the |sandbox|.
9830
9831 Can also be used as a |method|, the base is passed as the
9832 fourth argument: >
9833 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009834<
9835 Return type: |Number|
9836
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009837
9838settagstack({nr}, {dict} [, {action}]) *settagstack()*
9839 Modify the tag stack of the window {nr} using {dict}.
9840 {nr} can be the window number or the |window-ID|.
9841
9842 For a list of supported items in {dict}, refer to
9843 |gettagstack()|. "curidx" takes effect before changing the tag
9844 stack.
9845 *E962*
9846 How the tag stack is modified depends on the {action}
9847 argument:
9848 - If {action} is not present or is set to 'r', then the tag
9849 stack is replaced.
9850 - If {action} is set to 'a', then new entries from {dict} are
9851 pushed (added) onto the tag stack.
9852 - If {action} is set to 't', then all the entries from the
9853 current entry in the tag stack or "curidx" in {dict} are
9854 removed and then new entries are pushed to the stack.
9855
9856 The current index is set to one after the length of the tag
9857 stack after the modification.
9858
9859 Returns zero for success, -1 for failure.
9860
9861 Examples (for more examples see |tagstack-examples|):
9862 Empty the tag stack of window 3: >
9863 call settagstack(3, {'items' : []})
9864
9865< Save and restore the tag stack: >
9866 let stack = gettagstack(1003)
9867 " do something else
9868 call settagstack(1003, stack)
9869 unlet stack
9870<
9871 Can also be used as a |method|, the base is passed as the
9872 second argument: >
9873 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009874<
9875 Return type: |Number|
9876
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009877
9878setwinvar({winnr}, {varname}, {val}) *setwinvar()*
9879 Like |settabwinvar()| for the current tab page.
9880 Examples: >
9881 :call setwinvar(1, "&list", 0)
9882 :call setwinvar(2, "myvar", "foobar")
9883
9884< Can also be used as a |method|, the base is passed as the
9885 third argument: >
9886 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009887<
9888 Return type: |Number|
9889
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009890
9891sha256({string}) *sha256()*
9892 Returns a String with 64 hex characters, which is the SHA256
9893 checksum of {string}.
9894
9895 Can also be used as a |method|: >
9896 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009897<
9898 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009899
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009900 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009901
9902shellescape({string} [, {special}]) *shellescape()*
9903 Escape {string} for use as a shell command argument.
9904 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +00009905 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009906 in single quotes and will double up all internal single
9907 quotes.
9908 On MS-Windows, when 'shellslash' is not set, it will enclose
9909 {string} in double quotes and double all double quotes within
9910 {string}.
9911 Otherwise it will enclose {string} in single quotes and
9912 replace all "'" with "'\''".
9913
Enno5faeb602024-05-15 21:54:19 +02009914 The {special} argument adds additional escaping of keywords
9915 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +09009916 number or a non-empty String (|non-zero-arg|), then special
9917 items such as "!", "%", "#" and "<cword>" (as listed in
9918 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +02009919 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009920
9921 The "!" character will be escaped (again with a |non-zero-arg|
9922 {special}) when 'shell' contains "csh" in the tail. That is
9923 because for csh and tcsh "!" is used for history replacement
9924 even when inside single quotes.
9925
9926 With a |non-zero-arg| {special} the <NL> character is also
9927 escaped. When 'shell' containing "csh" in the tail it's
9928 escaped a second time.
9929
9930 The "\" character will be escaped when 'shell' contains "fish"
9931 in the tail. That is because for fish "\" is used as an escape
9932 character inside single quotes.
9933
9934 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009935 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009936< This results in a directory listing for the file under the
9937 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009938 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009939< See also |::S|.
9940
9941 Can also be used as a |method|: >
9942 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009943<
9944 Return type: |String|
9945
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009946
9947shiftwidth([{col}]) *shiftwidth()*
9948 Returns the effective value of 'shiftwidth'. This is the
9949 'shiftwidth' value unless it is zero, in which case it is the
9950 'tabstop' value. This function was introduced with patch
9951 7.3.694 in 2012, everybody should have it by now (however it
9952 did not allow for the optional {col} argument until 8.1.542).
9953
9954 When there is one argument {col} this is used as column number
9955 for which to return the 'shiftwidth' value. This matters for the
9956 'vartabstop' feature. If the 'vartabstop' setting is enabled and
9957 no {col} argument is given, column 1 will be assumed.
9958
9959 Can also be used as a |method|: >
9960 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009961<
9962 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009963
9964sign_ functions are documented here: |sign-functions-details|
9965
9966
9967simplify({filename}) *simplify()*
9968 Simplify the file name as much as possible without changing
9969 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
9970 Unix) are not resolved. If the first path component in
9971 {filename} designates the current directory, this will be
9972 valid for the result as well. A trailing path separator is
9973 not removed either. On Unix "//path" is unchanged, but
9974 "///path" is simplified to "/path" (this follows the Posix
9975 standard).
9976 Example: >
9977 simplify("./dir/.././/file/") == "./file/"
9978< Note: The combination "dir/.." is only removed if "dir" is
9979 a searchable directory or does not exist. On Unix, it is also
9980 removed when "dir" is a symbolic link within the same
9981 directory. In order to resolve all the involved symbolic
9982 links before simplifying the path name, use |resolve()|.
9983
9984 Can also be used as a |method|: >
9985 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009986<
9987 Return type: |String|
9988
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009989
9990sin({expr}) *sin()*
9991 Return the sine of {expr}, measured in radians, as a |Float|.
9992 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009993 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009994 Examples: >
9995 :echo sin(100)
9996< -0.506366 >
9997 :echo sin(-4.01)
9998< 0.763301
9999
10000 Can also be used as a |method|: >
10001 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010002<
10003 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010004
10005
10006sinh({expr}) *sinh()*
10007 Return the hyperbolic sine of {expr} as a |Float| in the range
10008 [-inf, inf].
10009 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010010 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010011 Examples: >
10012 :echo sinh(0.5)
10013< 0.521095 >
10014 :echo sinh(-0.9)
10015< -1.026517
10016
10017 Can also be used as a |method|: >
10018 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010019<
10020 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010021
10022
10023slice({expr}, {start} [, {end}]) *slice()*
10024 Similar to using a |slice| "expr[start : end]", but "end" is
10025 used exclusive. And for a string the indexes are used as
10026 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010027 |vim9script|. Also, composing characters are treated as a
10028 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010029 When {end} is omitted the slice continues to the last item.
10030 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010031 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010032
10033 Can also be used as a |method|: >
10034 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010035<
10036 Return type: list<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010037
10038
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010039sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010040 Sort the items in {list} in-place. Returns {list}.
10041
10042 If you want a list to remain unmodified make a copy first: >
10043 :let sortedlist = sort(copy(mylist))
10044
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010045< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010046 string representation of each item to sort on. Numbers sort
10047 after Strings, |Lists| after Numbers. For sorting text in the
10048 current buffer use |:sort|.
10049
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010050 When {how} is given and it is 'i' then case is ignored.
10051 In legacy script, for backwards compatibility, the value one
10052 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010053
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010054 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010055 locale is used for ordering. Implementation details: strcoll()
10056 is used to compare strings. See |:language| check or set the
10057 collation locale. |v:collate| can also be used to check the
10058 current locale. Sorting using the locale typically ignores
10059 case. Example: >
10060 " ö is sorted similarly to o with English locale.
10061 :language collate en_US.UTF8
10062 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10063< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10064>
10065 " ö is sorted after z with Swedish locale.
10066 :language collate sv_SE.UTF8
10067 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10068< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10069 This does not work properly on Mac.
10070
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010071 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010072 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010073 strtod() function to parse numbers. Strings, Lists, Dicts and
10074 Funcrefs will be considered as being 0). Note that this won't
10075 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010076
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010077 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010078 sorted numerical. This is like 'n' but a string containing
10079 digits will be used as the number they represent.
10080
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010081 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010082 sorted numerical. All values must be a Number or a Float.
10083
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010084 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010085 is called to compare items. The function is invoked with two
10086 items as argument and must return zero if they are equal, 1 or
10087 bigger if the first one sorts after the second one, -1 or
10088 smaller if the first one sorts before the second one.
10089
10090 {dict} is for functions with the "dict" attribute. It will be
10091 used to set the local variable "self". |Dictionary-function|
10092
10093 The sort is stable, items which compare equal (as number or as
10094 string) will keep their relative position. E.g., when sorting
10095 on numbers, text strings will sort next to each other, in the
10096 same order as they were originally.
10097
10098 Can also be used as a |method|: >
10099 mylist->sort()
10100
10101< Also see |uniq()|.
10102
10103 Example: >
10104 func MyCompare(i1, i2)
10105 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10106 endfunc
10107 eval mylist->sort("MyCompare")
10108< A shorter compare version for this specific simple case, which
10109 ignores overflow: >
10110 func MyCompare(i1, i2)
10111 return a:i1 - a:i2
10112 endfunc
10113< For a simple expression you can use a lambda: >
10114 eval mylist->sort({i1, i2 -> i1 - i2})
10115<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010116 Return type: list<{type}>
10117
10118
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010119sound_clear() *sound_clear()*
10120 Stop playing all sounds.
10121
10122 On some Linux systems you may need the libcanberra-pulse
10123 package, otherwise sound may not stop.
10124
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010125 Return type: |Number|
10126
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010127 {only available when compiled with the |+sound| feature}
10128
10129 *sound_playevent()*
10130sound_playevent({name} [, {callback}])
10131 Play a sound identified by {name}. Which event names are
10132 supported depends on the system. Often the XDG sound names
10133 are used. On Ubuntu they may be found in
10134 /usr/share/sounds/freedesktop/stereo. Example: >
10135 call sound_playevent('bell')
10136< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10137 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10138 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010139 On macOS, {name} refers to files located in
10140 /System/Library/Sounds (e.g. "Tink"). It will also work for
10141 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010142
10143 When {callback} is specified it is invoked when the sound is
10144 finished. The first argument is the sound ID, the second
10145 argument is the status:
10146 0 sound was played to the end
10147 1 sound was interrupted
10148 2 error occurred after sound started
10149 Example: >
10150 func Callback(id, status)
10151 echomsg "sound " .. a:id .. " finished with " .. a:status
10152 endfunc
10153 call sound_playevent('bell', 'Callback')
10154
10155< MS-Windows: {callback} doesn't work for this function.
10156
10157 Returns the sound ID, which can be passed to `sound_stop()`.
10158 Returns zero if the sound could not be played.
10159
10160 Can also be used as a |method|: >
10161 GetSoundName()->sound_playevent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010162<
10163 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010164
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010165 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010166
10167 *sound_playfile()*
10168sound_playfile({path} [, {callback}])
10169 Like `sound_playevent()` but play sound file {path}. {path}
10170 must be a full path. On Ubuntu you may find files to play
10171 with this command: >
10172 :!find /usr/share/sounds -type f | grep -v index.theme
10173
10174< Can also be used as a |method|: >
10175 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010176<
10177 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010178
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010179 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010180
10181
10182sound_stop({id}) *sound_stop()*
10183 Stop playing sound {id}. {id} must be previously returned by
10184 `sound_playevent()` or `sound_playfile()`.
10185
10186 On some Linux systems you may need the libcanberra-pulse
10187 package, otherwise sound may not stop.
10188
10189 On MS-Windows, this does not work for event sound started by
10190 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10191
10192 Can also be used as a |method|: >
10193 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010194<
10195 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010196
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010197 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010198
10199 *soundfold()*
10200soundfold({word})
10201 Return the sound-folded equivalent of {word}. Uses the first
10202 language in 'spelllang' for the current window that supports
10203 soundfolding. 'spell' must be set. When no sound folding is
10204 possible the {word} is returned unmodified.
10205 This can be used for making spelling suggestions. Note that
10206 the method can be quite slow.
10207
10208 Can also be used as a |method|: >
10209 GetWord()->soundfold()
10210<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010211 Return type: |String|
10212
10213
10214spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010215 Without argument: The result is the badly spelled word under
10216 or after the cursor. The cursor is moved to the start of the
10217 bad word. When no bad word is found in the cursor line the
10218 result is an empty string and the cursor doesn't move.
10219
10220 With argument: The result is the first word in {sentence} that
10221 is badly spelled. If there are no spelling mistakes the
10222 result is an empty string.
10223
10224 The return value is a list with two items:
10225 - The badly spelled word or an empty string.
10226 - The type of the spelling error:
10227 "bad" spelling mistake
10228 "rare" rare word
10229 "local" word only valid in another region
10230 "caps" word should start with Capital
10231 Example: >
10232 echo spellbadword("the quik brown fox")
10233< ['quik', 'bad'] ~
10234
10235 The spelling information for the current window and the value
10236 of 'spelllang' are used.
10237
10238 Can also be used as a |method|: >
10239 GetText()->spellbadword()
10240<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010241 Return type: list<string>
10242
10243
10244spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010245 Return a |List| with spelling suggestions to replace {word}.
10246 When {max} is given up to this number of suggestions are
10247 returned. Otherwise up to 25 suggestions are returned.
10248
10249 When the {capital} argument is given and it's non-zero only
10250 suggestions with a leading capital will be given. Use this
10251 after a match with 'spellcapcheck'.
10252
10253 {word} can be a badly spelled word followed by other text.
10254 This allows for joining two words that were split. The
10255 suggestions also include the following text, thus you can
10256 replace a line.
10257
10258 {word} may also be a good word. Similar words will then be
10259 returned. {word} itself is not included in the suggestions,
10260 although it may appear capitalized.
10261
10262 The spelling information for the current window is used. The
10263 values of 'spelllang' and 'spellsuggest' are used.
10264
10265 Can also be used as a |method|: >
10266 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010267<
10268 Return type: list<string> or list<any>
10269
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010270
10271split({string} [, {pattern} [, {keepempty}]]) *split()*
10272 Make a |List| out of {string}. When {pattern} is omitted or
10273 empty each white-separated sequence of characters becomes an
10274 item.
10275 Otherwise the string is split where {pattern} matches,
10276 removing the matched characters. 'ignorecase' is not used
10277 here, add \c to ignore case. |/\c|
10278 When the first or last item is empty it is omitted, unless the
10279 {keepempty} argument is given and it's non-zero.
10280 Other empty items are kept when {pattern} matches at least one
10281 character or when {keepempty} is non-zero.
10282 Example: >
10283 :let words = split(getline('.'), '\W\+')
10284< To split a string in individual characters: >
10285 :for c in split(mystring, '\zs')
10286< If you want to keep the separator you can also use '\zs' at
10287 the end of the pattern: >
10288 :echo split('abc:def:ghi', ':\zs')
10289< ['abc:', 'def:', 'ghi'] ~
10290 Splitting a table where the first element can be empty: >
10291 :let items = split(line, ':', 1)
10292< The opposite function is |join()|.
10293
10294 Can also be used as a |method|: >
10295 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010296<
10297 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010298
10299sqrt({expr}) *sqrt()*
10300 Return the non-negative square root of Float {expr} as a
10301 |Float|.
10302 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010303 is negative the result is NaN (Not a Number). Returns 0.0 if
10304 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010305 Examples: >
10306 :echo sqrt(100)
10307< 10.0 >
10308 :echo sqrt(-4.01)
10309< nan
10310 "nan" may be different, it depends on system libraries.
10311
10312 Can also be used as a |method|: >
10313 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010314<
10315 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010316
10317
10318srand([{expr}]) *srand()*
10319 Initialize seed used by |rand()|:
10320 - If {expr} is not given, seed values are initialized by
10321 reading from /dev/urandom, if possible, or using time(NULL)
10322 a.k.a. epoch time otherwise; this only has second accuracy.
10323 - If {expr} is given it must be a Number. It is used to
10324 initialize the seed values. This is useful for testing or
10325 when a predictable sequence is intended.
10326
10327 Examples: >
10328 :let seed = srand()
10329 :let seed = srand(userinput)
10330 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010331<
10332 Return type: list<number>
10333
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010334
10335state([{what}]) *state()*
10336 Return a string which contains characters indicating the
10337 current state. Mostly useful in callbacks that want to do
10338 work that may not always be safe. Roughly this works like:
10339 - callback uses state() to check if work is safe to do.
10340 Yes: then do it right away.
10341 No: add to work queue and add a |SafeState| and/or
10342 |SafeStateAgain| autocommand (|SafeState| triggers at
10343 toplevel, |SafeStateAgain| triggers after handling
10344 messages and callbacks).
10345 - When SafeState or SafeStateAgain is triggered and executes
10346 your autocommand, check with `state()` if the work can be
10347 done now, and if yes remove it from the queue and execute.
10348 Remove the autocommand if the queue is now empty.
10349 Also see |mode()|.
10350
10351 When {what} is given only characters in this string will be
10352 added. E.g, this checks if the screen has scrolled: >
10353 if state('s') == ''
10354 " screen has not scrolled
10355<
10356 These characters indicate the state, generally indicating that
10357 something is busy:
10358 m halfway a mapping, :normal command, feedkeys() or
10359 stuffed command
10360 o operator pending, e.g. after |d|
10361 a Insert mode autocomplete active
10362 x executing an autocommand
10363 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10364 ch_readraw() when reading json
10365 S not triggering SafeState or SafeStateAgain, e.g. after
10366 |f| or a count
10367 c callback invoked, including timer (repeats for
10368 recursiveness up to "ccc")
10369 s screen has scrolled for messages
10370
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010371 Return type: |String|
10372
10373
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010374str2float({string} [, {quoted}]) *str2float()*
10375 Convert String {string} to a Float. This mostly works the
10376 same as when using a floating point number in an expression,
10377 see |floating-point-format|. But it's a bit more permissive.
10378 E.g., "1e40" is accepted, while in an expression you need to
10379 write "1.0e40". The hexadecimal form "0x123" is also
10380 accepted, but not others, like binary or octal.
10381 When {quoted} is present and non-zero then embedded single
10382 quotes before the dot are ignored, thus "1'000.0" is a
10383 thousand.
10384 Text after the number is silently ignored.
10385 The decimal point is always '.', no matter what the locale is
10386 set to. A comma ends the number: "12,345.67" is converted to
10387 12.0. You can strip out thousands separators with
10388 |substitute()|: >
10389 let f = str2float(substitute(text, ',', '', 'g'))
10390<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010391 Returns 0.0 if the conversion fails.
10392
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010393 Can also be used as a |method|: >
10394 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010395<
10396 Return type: |Float|
10397
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010398
10399str2list({string} [, {utf8}]) *str2list()*
10400 Return a list containing the number values which represent
10401 each character in String {string}. Examples: >
10402 str2list(" ") returns [32]
10403 str2list("ABC") returns [65, 66, 67]
10404< |list2str()| does the opposite.
10405
10406 When {utf8} is omitted or zero, the current 'encoding' is used.
10407 When {utf8} is TRUE, always treat the String as UTF-8
10408 characters. With UTF-8 composing characters are handled
10409 properly: >
10410 str2list("á") returns [97, 769]
10411
10412< Can also be used as a |method|: >
10413 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010414<
10415 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010416
10417
10418str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10419 Convert string {string} to a number.
10420 {base} is the conversion base, it can be 2, 8, 10 or 16.
10421 When {quoted} is present and non-zero then embedded single
10422 quotes are ignored, thus "1'000'000" is a million.
10423
10424 When {base} is omitted base 10 is used. This also means that
10425 a leading zero doesn't cause octal conversion to be used, as
10426 with the default String to Number conversion. Example: >
10427 let nr = str2nr('0123')
10428<
10429 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10430 different base the result will be zero. Similarly, when
10431 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10432 {base} is 2 a leading "0b" or "0B" is ignored.
10433 Text after the number is silently ignored.
10434
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010435 Returns 0 if {string} is empty or on error.
10436
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010437 Can also be used as a |method|: >
10438 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010439<
10440 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010441
10442
10443strcharlen({string}) *strcharlen()*
10444 The result is a Number, which is the number of characters
10445 in String {string}. Composing characters are ignored.
10446 |strchars()| can count the number of characters, counting
10447 composing characters separately.
10448
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010449 Returns 0 if {string} is empty or on error.
10450
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010451 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10452
10453 Can also be used as a |method|: >
10454 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010455<
10456 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010457
10458
10459strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10460 Like |strpart()| but using character index and length instead
10461 of byte index and length.
10462 When {skipcc} is omitted or zero, composing characters are
10463 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010464 When {skipcc} set to 1, composing characters are treated as a
10465 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010466 When a character index is used where a character does not
10467 exist it is omitted and counted as one character. For
10468 example: >
10469 strcharpart('abc', -1, 2)
10470< results in 'a'.
10471
Bram Moolenaard592deb2022-06-17 15:42:40 +010010472 Returns an empty string on error.
10473
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010474 Can also be used as a |method|: >
10475 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010476<
10477 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010478
10479
10480strchars({string} [, {skipcc}]) *strchars()*
10481 The result is a Number, which is the number of characters
10482 in String {string}.
10483 When {skipcc} is omitted or zero, composing characters are
10484 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010485 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010486 |strcharlen()| always does this.
10487
Bram Moolenaard592deb2022-06-17 15:42:40 +010010488 Returns zero on error.
10489
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010490 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10491
10492 {skipcc} is only available after 7.4.755. For backward
10493 compatibility, you can define a wrapper function: >
10494 if has("patch-7.4.755")
10495 function s:strchars(str, skipcc)
10496 return strchars(a:str, a:skipcc)
10497 endfunction
10498 else
10499 function s:strchars(str, skipcc)
10500 if a:skipcc
10501 return strlen(substitute(a:str, ".", "x", "g"))
10502 else
10503 return strchars(a:str)
10504 endif
10505 endfunction
10506 endif
10507<
10508 Can also be used as a |method|: >
10509 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010510<
10511 Return type: |Number|
10512
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010513
10514strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10515 The result is a Number, which is the number of display cells
10516 String {string} occupies on the screen when it starts at {col}
10517 (first column is zero). When {col} is omitted zero is used.
10518 Otherwise it is the screen column where to start. This
10519 matters for Tab characters.
10520 The option settings of the current window are used. This
10521 matters for anything that's displayed differently, such as
10522 'tabstop' and 'display'.
10523 When {string} contains characters with East Asian Width Class
10524 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010525 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010526 Also see |strlen()|, |strwidth()| and |strchars()|.
10527
10528 Can also be used as a |method|: >
10529 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010530<
10531 Return type: |Number|
10532
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010533
10534strftime({format} [, {time}]) *strftime()*
10535 The result is a String, which is a formatted date and time, as
10536 specified by the {format} string. The given {time} is used,
10537 or the current time if no time is given. The accepted
10538 {format} depends on your system, thus this is not portable!
10539 See the manual page of the C function strftime() for the
10540 format. The maximum length of the result is 80 characters.
10541 See also |localtime()|, |getftime()| and |strptime()|.
10542 The language can be changed with the |:language| command.
10543 Examples: >
10544 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10545 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10546 :echo strftime("%y%m%d %T") 970427 11:53:55
10547 :echo strftime("%H:%M") 11:55
10548 :echo strftime("%c", getftime("file.c"))
10549 Show mod time of file.c.
10550< Not available on all systems. To check use: >
10551 :if exists("*strftime")
10552
10553< Can also be used as a |method|: >
10554 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010555<
10556 Return type: |String|
10557
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010558
10559strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010560 Get a Number corresponding to the character at {index} in
10561 {str}. This uses a zero-based character index, not a byte
10562 index. Composing characters are considered separate
10563 characters here. Use |nr2char()| to convert the Number to a
10564 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010565 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010566 Also see |strcharpart()| and |strchars()|.
10567
10568 Can also be used as a |method|: >
10569 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010570<
10571 Return type: |Number|
10572
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010573
10574stridx({haystack}, {needle} [, {start}]) *stridx()*
10575 The result is a Number, which gives the byte index in
10576 {haystack} of the first occurrence of the String {needle}.
10577 If {start} is specified, the search starts at index {start}.
10578 This can be used to find a second match: >
10579 :let colon1 = stridx(line, ":")
10580 :let colon2 = stridx(line, ":", colon1 + 1)
10581< The search is done case-sensitive.
10582 For pattern searches use |match()|.
10583 -1 is returned if the {needle} does not occur in {haystack}.
10584 See also |strridx()|.
10585 Examples: >
10586 :echo stridx("An Example", "Example") 3
10587 :echo stridx("Starting point", "Start") 0
10588 :echo stridx("Starting point", "start") -1
10589< *strstr()* *strchr()*
10590 stridx() works similar to the C function strstr(). When used
10591 with a single character it works similar to strchr().
10592
10593 Can also be used as a |method|: >
10594 GetHaystack()->stridx(needle)
10595<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010596 Return type: |Number|
10597
10598
10599string({expr}) *string()*
10600 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010601 Float, String, Blob or a composition of them, then the result
10602 can be parsed back with |eval()|.
10603 {expr} type result ~
10604 String 'string' (single quotes are doubled)
10605 Number 123
10606 Float 123.123456 or 1.123456e8
10607 Funcref function('name')
10608 Blob 0z00112233.44556677.8899
10609 List [item, item]
10610 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000010611 Class class SomeName
10612 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010010613 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020010614 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010615
10616 When a |List| or |Dictionary| has a recursive reference it is
10617 replaced by "[...]" or "{...}". Using eval() on the result
10618 will then fail.
10619
mityu7f0bba22024-03-29 10:14:41 +010010620 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010621 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010010622 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010623
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010624 Can also be used as a |method|: >
10625 mylist->string()
10626
10627< Also see |strtrans()|.
10628
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010629 Return type: |String|
10630
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010631
10632strlen({string}) *strlen()*
10633 The result is a Number, which is the length of the String
10634 {string} in bytes.
10635 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010636 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010637 If you want to count the number of multibyte characters use
10638 |strchars()|.
10639 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
10640
10641 Can also be used as a |method|: >
10642 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010643<
10644 Return type: |Number|
10645
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010646
10647strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
10648 The result is a String, which is part of {src}, starting from
10649 byte {start}, with the byte length {len}.
10650 When {chars} is present and TRUE then {len} is the number of
10651 characters positions (composing characters are not counted
10652 separately, thus "1" means one base character and any
10653 following composing characters).
10654 To count {start} as characters instead of bytes use
10655 |strcharpart()|.
10656
10657 When bytes are selected which do not exist, this doesn't
10658 result in an error, the bytes are simply omitted.
10659 If {len} is missing, the copy continues from {start} till the
10660 end of the {src}. >
10661 strpart("abcdefg", 3, 2) == "de"
10662 strpart("abcdefg", -2, 4) == "ab"
10663 strpart("abcdefg", 5, 4) == "fg"
10664 strpart("abcdefg", 3) == "defg"
10665
10666< Note: To get the first character, {start} must be 0. For
10667 example, to get the character under the cursor: >
10668 strpart(getline("."), col(".") - 1, 1, v:true)
10669<
Bram Moolenaard592deb2022-06-17 15:42:40 +010010670 Returns an empty string on error.
10671
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010672 Can also be used as a |method|: >
10673 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010674<
10675 Return type: |String|
10676
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010677
10678strptime({format}, {timestring}) *strptime()*
10679 The result is a Number, which is a unix timestamp representing
10680 the date and time in {timestring}, which is expected to match
10681 the format specified in {format}.
10682
10683 The accepted {format} depends on your system, thus this is not
10684 portable! See the manual page of the C function strptime()
10685 for the format. Especially avoid "%c". The value of $TZ also
10686 matters.
10687
10688 If the {timestring} cannot be parsed with {format} zero is
10689 returned. If you do not know the format of {timestring} you
10690 can try different {format} values until you get a non-zero
10691 result.
10692
10693 See also |strftime()|.
10694 Examples: >
10695 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
10696< 862156163 >
10697 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
10698< Sun Apr 27 11:53:55 1997 >
10699 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
10700< Sun Apr 27 12:53:55 1997
10701
10702 Can also be used as a |method|: >
10703 GetFormat()->strptime(timestring)
10704<
10705 Not available on all systems. To check use: >
10706 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010707<
10708 Return type: |Number|
10709
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010710
10711strridx({haystack}, {needle} [, {start}]) *strridx()*
10712 The result is a Number, which gives the byte index in
10713 {haystack} of the last occurrence of the String {needle}.
10714 When {start} is specified, matches beyond this index are
10715 ignored. This can be used to find a match before a previous
10716 match: >
10717 :let lastcomma = strridx(line, ",")
10718 :let comma2 = strridx(line, ",", lastcomma - 1)
10719< The search is done case-sensitive.
10720 For pattern searches use |match()|.
10721 -1 is returned if the {needle} does not occur in {haystack}.
10722 If the {needle} is empty the length of {haystack} is returned.
10723 See also |stridx()|. Examples: >
10724 :echo strridx("an angry armadillo", "an") 3
10725< *strrchr()*
10726 When used with a single character it works similar to the C
10727 function strrchr().
10728
10729 Can also be used as a |method|: >
10730 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010731<
10732 Return type: |Number|
10733
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010734
10735strtrans({string}) *strtrans()*
10736 The result is a String, which is {string} with all unprintable
10737 characters translated into printable characters |'isprint'|.
10738 Like they are shown in a window. Example: >
10739 echo strtrans(@a)
10740< This displays a newline in register a as "^@" instead of
10741 starting a new line.
10742
Bram Moolenaard592deb2022-06-17 15:42:40 +010010743 Returns an empty string on error.
10744
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010745 Can also be used as a |method|: >
10746 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010747<
10748 Return type: |String|
10749
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010750
Christian Brabandt67672ef2023-04-24 21:09:54 +010010751strutf16len({string} [, {countcc}]) *strutf16len()*
10752 The result is a Number, which is the number of UTF-16 code
10753 units in String {string} (after converting it to UTF-16).
10754
10755 When {countcc} is TRUE, composing characters are counted
10756 separately.
10757 When {countcc} is omitted or FALSE, composing characters are
10758 ignored.
10759
10760 Returns zero on error.
10761
10762 Also see |strlen()| and |strcharlen()|.
10763 Examples: >
10764 echo strutf16len('a') returns 1
10765 echo strutf16len('©') returns 1
10766 echo strutf16len('😊') returns 2
10767 echo strutf16len('ą́') returns 1
10768 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090010769<
Christian Brabandt67672ef2023-04-24 21:09:54 +010010770 Can also be used as a |method|: >
10771 GetText()->strutf16len()
10772<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010773 Return type: |Number|
10774
10775
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010776strwidth({string}) *strwidth()*
10777 The result is a Number, which is the number of display cells
10778 String {string} occupies. A Tab character is counted as one
10779 cell, alternatively use |strdisplaywidth()|.
10780 When {string} contains characters with East Asian Width Class
10781 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010782 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010783 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
10784
10785 Can also be used as a |method|: >
10786 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010787<
10788 Return type: |Number|
10789
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010790
10791submatch({nr} [, {list}]) *submatch()* *E935*
10792 Only for an expression in a |:substitute| command or
10793 substitute() function.
10794 Returns the {nr}'th submatch of the matched text. When {nr}
10795 is 0 the whole matched text is returned.
10796 Note that a NL in the string can stand for a line break of a
10797 multi-line match or a NUL character in the text.
10798 Also see |sub-replace-expression|.
10799
10800 If {list} is present and non-zero then submatch() returns
10801 a list of strings, similar to |getline()| with two arguments.
10802 NL characters in the text represent NUL characters in the
10803 text.
10804 Only returns more than one item for |:substitute|, inside
10805 |substitute()| this list will always contain one or zero
10806 items, since there are no real line breaks.
10807
10808 When substitute() is used recursively only the submatches in
10809 the current (deepest) call can be obtained.
10810
Bram Moolenaard592deb2022-06-17 15:42:40 +010010811 Returns an empty string or list on error.
10812
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010813 Examples: >
10814 :s/\d\+/\=submatch(0) + 1/
10815 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
10816< This finds the first number in the line and adds one to it.
10817 A line break is included as a newline character.
10818
10819 Can also be used as a |method|: >
10820 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010821<
10822 Return type: |String| or list<string> depending on {list}
10823
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010824
10825substitute({string}, {pat}, {sub}, {flags}) *substitute()*
10826 The result is a String, which is a copy of {string}, in which
10827 the first match of {pat} is replaced with {sub}.
10828 When {flags} is "g", all matches of {pat} in {string} are
10829 replaced. Otherwise {flags} should be "".
10830
10831 This works like the ":substitute" command (without any flags).
10832 But the matching with {pat} is always done like the 'magic'
10833 option is set and 'cpoptions' is empty (to make scripts
10834 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
10835 if you want to ignore or match case and ignore 'ignorecase'.
10836 'smartcase' is not used. See |string-match| for how {pat} is
10837 used.
10838
10839 A "~" in {sub} is not replaced with the previous {sub}.
10840 Note that some codes in {sub} have a special meaning
10841 |sub-replace-special|. For example, to replace something with
10842 "\n" (two characters), use "\\\\n" or '\\n'.
10843
10844 When {pat} does not match in {string}, {string} is returned
10845 unmodified.
10846
10847 Example: >
10848 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
10849< This removes the last component of the 'path' option. >
10850 :echo substitute("testing", ".*", "\\U\\0", "")
10851< results in "TESTING".
10852
10853 When {sub} starts with "\=", the remainder is interpreted as
10854 an expression. See |sub-replace-expression|. Example: >
10855 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010856 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010857
10858< When {sub} is a Funcref that function is called, with one
10859 optional argument. Example: >
10860 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
10861< The optional argument is a list which contains the whole
10862 matched string and up to nine submatches, like what
10863 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010864 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010865
Bram Moolenaard592deb2022-06-17 15:42:40 +010010866< Returns an empty string on error.
10867
10868 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010869 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010870<
10871 Return type: |String|
10872
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010873
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000010874swapfilelist() *swapfilelist()*
10875 Returns a list of swap file names, like what "vim -r" shows.
10876 See the |-r| command argument. The 'directory' option is used
10877 for the directories to inspect. If you only want to get a
10878 list of swap files in the current directory then temporarily
10879 set 'directory' to a dot: >
10880 let save_dir = &directory
10881 let &directory = '.'
10882 let swapfiles = swapfilelist()
10883 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010884<
10885 Return type: list<string>
10886
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000010887
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010888swapinfo({fname}) *swapinfo()*
10889 The result is a dictionary, which holds information about the
10890 swapfile {fname}. The available fields are:
10891 version Vim version
10892 user user name
10893 host host name
10894 fname original file name
10895 pid PID of the Vim process that created the swap
10896 file
10897 mtime last modification time in seconds
10898 inode Optional: INODE number of the file
10899 dirty 1 if file was modified, 0 if not
10900 Note that "user" and "host" are truncated to at most 39 bytes.
10901 In case of failure an "error" item is added with the reason:
10902 Cannot open file: file not found or in accessible
10903 Cannot read file: cannot read first block
10904 Not a swap file: does not contain correct block ID
10905 Magic number mismatch: Info in first block is invalid
10906
10907 Can also be used as a |method|: >
10908 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010909<
10910 Return type: dict<any> or dict<string>
10911
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010912
10913swapname({buf}) *swapname()*
10914 The result is the swap file path of the buffer {expr}.
10915 For the use of {buf}, see |bufname()| above.
10916 If buffer {buf} is the current buffer, the result is equal to
10917 |:swapname| (unless there is no swap file).
10918 If buffer {buf} has no swap file, returns an empty string.
10919
10920 Can also be used as a |method|: >
10921 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010922<
10923 Return type: |String|
10924
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010925
10926synID({lnum}, {col}, {trans}) *synID()*
10927 The result is a Number, which is the syntax ID at the position
10928 {lnum} and {col} in the current window.
10929 The syntax ID can be used with |synIDattr()| and
10930 |synIDtrans()| to obtain syntax information about text.
10931
10932 {col} is 1 for the leftmost column, {lnum} is 1 for the first
10933 line. 'synmaxcol' applies, in a longer line zero is returned.
10934 Note that when the position is after the last character,
10935 that's where the cursor can be in Insert mode, synID() returns
10936 zero. {lnum} is used like with |getline()|.
10937
10938 When {trans} is |TRUE|, transparent items are reduced to the
10939 item that they reveal. This is useful when wanting to know
10940 the effective color. When {trans} is |FALSE|, the transparent
10941 item is returned. This is useful when wanting to know which
10942 syntax item is effective (e.g. inside parens).
10943 Warning: This function can be very slow. Best speed is
10944 obtained by going through the file in forward direction.
10945
Bram Moolenaard592deb2022-06-17 15:42:40 +010010946 Returns zero on error.
10947
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010948 Example (echoes the name of the syntax item under the cursor): >
10949 :echo synIDattr(synID(line("."), col("."), 1), "name")
10950<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010951 Return type: |Number|
10952
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010953
10954synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
10955 The result is a String, which is the {what} attribute of
10956 syntax ID {synID}. This can be used to obtain information
10957 about a syntax item.
10958 {mode} can be "gui", "cterm" or "term", to get the attributes
10959 for that mode. When {mode} is omitted, or an invalid value is
10960 used, the attributes for the currently active highlighting are
10961 used (GUI, cterm or term).
10962 Use synIDtrans() to follow linked highlight groups.
10963 {what} result
10964 "name" the name of the syntax item
10965 "fg" foreground color (GUI: color name used to set
10966 the color, cterm: color number as a string,
10967 term: empty string)
10968 "bg" background color (as with "fg")
10969 "font" font name (only available in the GUI)
10970 |highlight-font|
10971 "sp" special color for the GUI (as with "fg")
10972 |highlight-guisp|
10973 "ul" underline color for cterm: number as a string
10974 "fg#" like "fg", but for the GUI and the GUI is
10975 running the name in "#RRGGBB" form
10976 "bg#" like "fg#" for "bg"
10977 "sp#" like "fg#" for "sp"
10978 "bold" "1" if bold
10979 "italic" "1" if italic
10980 "reverse" "1" if reverse
10981 "inverse" "1" if inverse (= reverse)
10982 "standout" "1" if standout
10983 "underline" "1" if underlined
10984 "undercurl" "1" if undercurled
10985 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010010986 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010987
Bram Moolenaard592deb2022-06-17 15:42:40 +010010988 Returns an empty string on error.
10989
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010990 Example (echoes the color of the syntax item under the
10991 cursor): >
10992 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
10993<
10994 Can also be used as a |method|: >
10995 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010996<
10997 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010998
10999
11000synIDtrans({synID}) *synIDtrans()*
11001 The result is a Number, which is the translated syntax ID of
11002 {synID}. This is the syntax group ID of what is being used to
11003 highlight the character. Highlight links given with
11004 ":highlight link" are followed.
11005
Bram Moolenaard592deb2022-06-17 15:42:40 +010011006 Returns zero on error.
11007
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011008 Can also be used as a |method|: >
11009 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011010<
11011 Return type: |Number|
11012
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011013
11014synconcealed({lnum}, {col}) *synconcealed()*
11015 The result is a |List| with currently three items:
11016 1. The first item in the list is 0 if the character at the
11017 position {lnum} and {col} is not part of a concealable
11018 region, 1 if it is. {lnum} is used like with |getline()|.
11019 2. The second item in the list is a string. If the first item
11020 is 1, the second item contains the text which will be
11021 displayed in place of the concealed text, depending on the
11022 current setting of 'conceallevel' and 'listchars'.
11023 3. The third and final item in the list is a number
11024 representing the specific syntax region matched in the
11025 line. When the character is not concealed the value is
11026 zero. This allows detection of the beginning of a new
11027 concealable region if there are two consecutive regions
11028 with the same replacement character. For an example, if
11029 the text is "123456" and both "23" and "45" are concealed
11030 and replaced by the character "X", then:
11031 call returns ~
11032 synconcealed(lnum, 1) [0, '', 0]
11033 synconcealed(lnum, 2) [1, 'X', 1]
11034 synconcealed(lnum, 3) [1, 'X', 1]
11035 synconcealed(lnum, 4) [1, 'X', 2]
11036 synconcealed(lnum, 5) [1, 'X', 2]
11037 synconcealed(lnum, 6) [0, '', 0]
11038
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011039 Note: Doesn't consider |matchadd()| highlighting items,
11040 since syntax and matching highlighting are two different
11041 mechanisms |syntax-vs-match|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011042<
11043 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011044
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011045
11046synstack({lnum}, {col}) *synstack()*
11047 Return a |List|, which is the stack of syntax items at the
11048 position {lnum} and {col} in the current window. {lnum} is
11049 used like with |getline()|. Each item in the List is an ID
11050 like what |synID()| returns.
11051 The first item in the List is the outer region, following are
11052 items contained in that one. The last one is what |synID()|
11053 returns, unless not the whole item is highlighted or it is a
11054 transparent item.
11055 This function is useful for debugging a syntax file.
11056 Example that shows the syntax stack under the cursor: >
11057 for id in synstack(line("."), col("."))
11058 echo synIDattr(id, "name")
11059 endfor
11060< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011061 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011062 character in a line and the first column in an empty line are
11063 valid positions.
11064
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011065 Return type: list<number> or list<any>
11066
11067
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011068system({expr} [, {input}]) *system()* *E677*
11069 Get the output of the shell command {expr} as a |String|. See
11070 |systemlist()| to get the output as a |List|.
11071
11072 When {input} is given and is a |String| this string is written
11073 to a file and passed as stdin to the command. The string is
11074 written as-is, you need to take care of using the correct line
11075 separators yourself.
11076 If {input} is given and is a |List| it is written to the file
11077 in a way |writefile()| does with {binary} set to "b" (i.e.
11078 with a newline between each list item with newlines inside
11079 list items converted to NULs).
11080 When {input} is given and is a number that is a valid id for
11081 an existing buffer then the content of the buffer is written
11082 to the file line by line, each line terminated by a NL and
11083 NULs characters where the text has a NL.
11084
11085 Pipes are not used, the 'shelltemp' option is not used.
11086
11087 When prepended by |:silent| the terminal will not be set to
11088 cooked mode. This is meant to be used for commands that do
11089 not need the user to type. It avoids stray characters showing
11090 up on the screen which require |CTRL-L| to remove. >
11091 :silent let f = system('ls *.vim')
11092<
11093 Note: Use |shellescape()| or |::S| with |expand()| or
11094 |fnamemodify()| to escape special characters in a command
11095 argument. Newlines in {expr} may cause the command to fail.
11096 The characters in 'shellquote' and 'shellxquote' may also
11097 cause trouble.
11098 This is not to be used for interactive commands.
11099
11100 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011101 :let files = system('ls ' .. shellescape(expand('%:h')))
11102 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011103
11104< To make the result more system-independent, the shell output
11105 is filtered to replace <CR> with <NL> for Macintosh, and
11106 <CR><NL> with <NL> for DOS-like systems.
11107 To avoid the string being truncated at a NUL, all NUL
11108 characters are replaced with SOH (0x01).
11109
11110 The command executed is constructed using several options:
11111 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11112 ({tmp} is an automatically generated file name).
11113 For Unix, braces are put around {expr} to allow for
11114 concatenated commands.
11115
11116 The command will be executed in "cooked" mode, so that a
11117 CTRL-C will interrupt the command (on Unix at least).
11118
11119 The resulting error code can be found in |v:shell_error|.
11120 This function will fail in |restricted-mode|.
11121
11122 Note that any wrong value in the options mentioned above may
11123 make the function fail. It has also been reported to fail
11124 when using a security agent application.
11125 Unlike ":!cmd" there is no automatic check for changed files.
11126 Use |:checktime| to force a check.
11127
11128 Can also be used as a |method|: >
11129 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011130<
11131 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011132
11133
11134systemlist({expr} [, {input}]) *systemlist()*
11135 Same as |system()|, but returns a |List| with lines (parts of
11136 output separated by NL) with NULs transformed into NLs. Output
11137 is the same as |readfile()| will output with {binary} argument
11138 set to "b", except that there is no extra empty item when the
11139 result ends in a NL.
11140 Note that on MS-Windows you may get trailing CR characters.
11141
11142 To see the difference between "echo hello" and "echo -n hello"
11143 use |system()| and |split()|: >
11144 echo system('echo hello')->split('\n', 1)
11145<
11146 Returns an empty string on error.
11147
11148 Can also be used as a |method|: >
11149 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011150<
11151 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011152
11153
11154tabpagebuflist([{arg}]) *tabpagebuflist()*
11155 The result is a |List|, where each item is the number of the
11156 buffer associated with each window in the current tab page.
11157 {arg} specifies the number of the tab page to be used. When
11158 omitted the current tab page is used.
11159 When {arg} is invalid the number zero is returned.
11160 To get a list of all buffers in all tabs use this: >
11161 let buflist = []
11162 for i in range(tabpagenr('$'))
11163 call extend(buflist, tabpagebuflist(i + 1))
11164 endfor
11165< Note that a buffer may appear in more than one window.
11166
11167 Can also be used as a |method|: >
11168 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011169<
11170 Return type: list<number>
11171
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011172
11173tabpagenr([{arg}]) *tabpagenr()*
11174 The result is a Number, which is the number of the current
11175 tab page. The first tab page has number 1.
11176
11177 The optional argument {arg} supports the following values:
11178 $ the number of the last tab page (the tab page
11179 count).
11180 # the number of the last accessed tab page
11181 (where |g<Tab>| goes to). if there is no
11182 previous tab page 0 is returned.
11183 The number can be used with the |:tab| command.
11184
Bram Moolenaard592deb2022-06-17 15:42:40 +010011185 Returns zero on error.
11186
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011187 Return type: |Number|
11188
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011189
11190tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11191 Like |winnr()| but for tab page {tabarg}.
11192 {tabarg} specifies the number of tab page to be used.
11193 {arg} is used like with |winnr()|:
11194 - When omitted the current window number is returned. This is
11195 the window which will be used when going to this tab page.
11196 - When "$" the number of windows is returned.
11197 - When "#" the previous window nr is returned.
11198 Useful examples: >
11199 tabpagewinnr(1) " current window of tab page 1
11200 tabpagewinnr(4, '$') " number of windows in tab page 4
11201< When {tabarg} is invalid zero is returned.
11202
11203 Can also be used as a |method|: >
11204 GetTabpage()->tabpagewinnr()
11205<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011206 Return type: |Number|
11207
11208
11209tagfiles() *tagfiles()*
11210 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011211 for the current buffer. This is the 'tags' option expanded.
11212
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011213 Return type: list<string> or list<any>
11214
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011215
11216taglist({expr} [, {filename}]) *taglist()*
11217 Returns a |List| of tags matching the regular expression {expr}.
11218
11219 If {filename} is passed it is used to prioritize the results
11220 in the same way that |:tselect| does. See |tag-priority|.
11221 {filename} should be the full path of the file.
11222
11223 Each list item is a dictionary with at least the following
11224 entries:
11225 name Name of the tag.
11226 filename Name of the file where the tag is
11227 defined. It is either relative to the
11228 current directory or a full path.
11229 cmd Ex command used to locate the tag in
11230 the file.
11231 kind Type of the tag. The value for this
11232 entry depends on the language specific
11233 kind values. Only available when
11234 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011235 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011236 static A file specific tag. Refer to
11237 |static-tag| for more information.
11238 More entries may be present, depending on the content of the
11239 tags file: access, implementation, inherits and signature.
11240 Refer to the ctags documentation for information about these
11241 fields. For C code the fields "struct", "class" and "enum"
11242 may appear, they give the name of the entity the tag is
11243 contained in.
11244
11245 The ex-command "cmd" can be either an ex search pattern, a
11246 line number or a line number followed by a byte number.
11247
11248 If there are no matching tags, then an empty list is returned.
11249
11250 To get an exact tag match, the anchors '^' and '$' should be
11251 used in {expr}. This also make the function work faster.
11252 Refer to |tag-regexp| for more information about the tag
11253 search regular expression pattern.
11254
11255 Refer to |'tags'| for information about how the tags file is
11256 located by Vim. Refer to |tags-file-format| for the format of
11257 the tags file generated by the different ctags tools.
11258
11259 Can also be used as a |method|: >
11260 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011261<
11262 Return type: list<dict<any>> or list<any>
11263
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011264
11265tan({expr}) *tan()*
11266 Return the tangent of {expr}, measured in radians, as a |Float|
11267 in the range [-inf, inf].
11268 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011269 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011270 Examples: >
11271 :echo tan(10)
11272< 0.648361 >
11273 :echo tan(-4.01)
11274< -1.181502
11275
11276 Can also be used as a |method|: >
11277 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011278<
11279 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011280
11281
11282tanh({expr}) *tanh()*
11283 Return the hyperbolic tangent of {expr} as a |Float| in the
11284 range [-1, 1].
11285 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011286 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011287 Examples: >
11288 :echo tanh(0.5)
11289< 0.462117 >
11290 :echo tanh(-1)
11291< -0.761594
11292
11293 Can also be used as a |method|: >
11294 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011295<
11296 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011297
11298
11299tempname() *tempname()* *temp-file-name*
11300 The result is a String, which is the name of a file that
11301 doesn't exist. It can be used for a temporary file. The name
11302 is different for at least 26 consecutive calls. Example: >
11303 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011304 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011305< For Unix, the file will be in a private directory |tempfile|
11306 that is recursively deleted when Vim exits, on other systems
11307 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011308 For MS-Windows forward slashes are used when the 'shellslash'
11309 option is set, or when 'shellcmdflag' starts with '-' and
11310 'shell' does not contain powershell or pwsh.
11311
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011312 Return type: |String|
11313
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011314
11315term_ functions are documented here: |terminal-function-details|
11316
11317
11318terminalprops() *terminalprops()*
11319 Returns a |Dictionary| with properties of the terminal that Vim
11320 detected from the response to |t_RV| request. See
11321 |v:termresponse| for the response itself. If |v:termresponse|
11322 is empty most values here will be 'u' for unknown.
11323 cursor_style whether sending |t_RS| works **
11324 cursor_blink_mode whether sending |t_RC| works **
11325 underline_rgb whether |t_8u| works **
11326 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011327 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011328
11329 ** value 'u' for unknown, 'y' for yes, 'n' for no
11330
11331 If the |+termresponse| feature is missing then the result is
11332 an empty dictionary.
11333
11334 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11335 current cursor style.
11336 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11337 request the cursor blink status.
11338 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11339 is not empty, Vim will detect the working of sending |t_RS|
11340 and |t_RC| on startup.
11341
11342 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11343 This avoids sending it to xterm, which would clear the colors.
11344
11345 For "mouse" the value 'u' is unknown
11346
11347 Also see:
11348 - 'ambiwidth' - detected by using |t_u7|.
11349 - |v:termstyleresp| and |v:termblinkresp| for the response to
11350 |t_RS| and |t_RC|.
11351
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011352 Return type: dict<string>
11353
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011354
11355test_ functions are documented here: |test-functions-details|
11356
11357
11358 *timer_info()*
11359timer_info([{id}])
11360 Return a list with information about timers.
11361 When {id} is given only information about this timer is
11362 returned. When timer {id} does not exist an empty list is
11363 returned.
11364 When {id} is omitted information about all timers is returned.
11365
11366 For each timer the information is stored in a |Dictionary| with
11367 these items:
11368 "id" the timer ID
11369 "time" time the timer was started with
11370 "remaining" time until the timer fires
11371 "repeat" number of times the timer will still fire;
11372 -1 means forever
11373 "callback" the callback
11374 "paused" 1 if the timer is paused, 0 otherwise
11375
11376 Can also be used as a |method|: >
11377 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011378<
11379 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011380
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011381 {only available when compiled with the |+timers| feature}
11382
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011383
11384timer_pause({timer}, {paused}) *timer_pause()*
11385 Pause or unpause a timer. A paused timer does not invoke its
11386 callback when its time expires. Unpausing a timer may cause
11387 the callback to be invoked almost immediately if enough time
11388 has passed.
11389
11390 Pausing a timer is useful to avoid the callback to be called
11391 for a short time.
11392
11393 If {paused} evaluates to a non-zero Number or a non-empty
11394 String, then the timer is paused, otherwise it is unpaused.
11395 See |non-zero-arg|.
11396
11397 Can also be used as a |method|: >
11398 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011399<
11400 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011401
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011402 {only available when compiled with the |+timers| feature}
11403
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011404
11405 *timer_start()* *timer* *timers*
11406timer_start({time}, {callback} [, {options}])
11407 Create a timer and return the timer ID.
11408
11409 {time} is the waiting time in milliseconds. This is the
11410 minimum time before invoking the callback. When the system is
11411 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011412 Zero can be used to execute the callback when Vim is back in
11413 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011414
11415 {callback} is the function to call. It can be the name of a
11416 function or a |Funcref|. It is called with one argument, which
11417 is the timer ID. The callback is only invoked when Vim is
11418 waiting for input.
11419 If you want to show a message look at |popup_notification()|
11420 to avoid interfering with what the user is doing.
11421
11422 {options} is a dictionary. Supported entries:
11423 "repeat" Number of times to repeat calling the
11424 callback. -1 means forever. When not present
11425 the callback will be called once.
11426 If the timer causes an error three times in a
11427 row the repeat is cancelled. This avoids that
11428 Vim becomes unusable because of all the error
11429 messages.
11430
Bram Moolenaard592deb2022-06-17 15:42:40 +010011431 Returns -1 on error.
11432
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011433 Example: >
11434 func MyHandler(timer)
11435 echo 'Handler called'
11436 endfunc
11437 let timer = timer_start(500, 'MyHandler',
11438 \ {'repeat': 3})
11439< This will invoke MyHandler() three times at 500 msec
11440 intervals.
11441
11442 Can also be used as a |method|: >
11443 GetMsec()->timer_start(callback)
11444
11445< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011446
11447 Return type: |Number|
11448
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011449 {only available when compiled with the |+timers| feature}
11450
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011451
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011452timer_stop({timer}) *timer_stop()*
11453 Stop a timer. The timer callback will no longer be invoked.
11454 {timer} is an ID returned by timer_start(), thus it must be a
11455 Number. If {timer} does not exist there is no error.
11456
11457 Can also be used as a |method|: >
11458 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011459<
11460 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011461
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011462 {only available when compiled with the |+timers| feature}
11463
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011464
11465timer_stopall() *timer_stopall()*
11466 Stop all timers. The timer callbacks will no longer be
11467 invoked. Useful if a timer is misbehaving. If there are no
11468 timers there is no error.
11469
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011470 Return type: |Number|
11471
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011472 {only available when compiled with the |+timers| feature}
11473
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011474
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011475tolower({expr}) *tolower()*
11476 The result is a copy of the String given, with all uppercase
11477 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011478 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011479
11480 Can also be used as a |method|: >
11481 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011482<
11483 Return type: |String|
11484
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011485
11486toupper({expr}) *toupper()*
11487 The result is a copy of the String given, with all lowercase
11488 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011489 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011490
11491 Can also be used as a |method|: >
11492 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011493<
11494 Return type: |String|
11495
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011496
11497tr({src}, {fromstr}, {tostr}) *tr()*
11498 The result is a copy of the {src} string with all characters
11499 which appear in {fromstr} replaced by the character in that
11500 position in the {tostr} string. Thus the first character in
11501 {fromstr} is translated into the first character in {tostr}
11502 and so on. Exactly like the unix "tr" command.
11503 This code also deals with multibyte characters properly.
11504
Bram Moolenaard592deb2022-06-17 15:42:40 +010011505 Returns an empty string on error.
11506
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011507 Examples: >
11508 echo tr("hello there", "ht", "HT")
11509< returns "Hello THere" >
11510 echo tr("<blob>", "<>", "{}")
11511< returns "{blob}"
11512
11513 Can also be used as a |method|: >
11514 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011515<
11516 Return type: |String|
11517
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011518
11519trim({text} [, {mask} [, {dir}]]) *trim()*
11520 Return {text} as a String where any character in {mask} is
11521 removed from the beginning and/or end of {text}.
11522
Illia Bobyr80799172023-10-17 18:00:50 +020011523 If {mask} is not given, or is an empty string, {mask} is all
11524 characters up to 0x20, which includes Tab, space, NL and CR,
11525 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011526
11527 The optional {dir} argument specifies where to remove the
11528 characters:
11529 0 remove from the beginning and end of {text}
11530 1 remove only at the beginning of {text}
11531 2 remove only at the end of {text}
11532 When omitted both ends are trimmed.
11533
11534 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011535 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011536
11537 Examples: >
11538 echo trim(" some text ")
11539< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011540 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011541< returns "RESERVE_TAIL" >
11542 echo trim("rm<Xrm<>X>rrm", "rm<>")
11543< returns "Xrm<>X" (characters in the middle are not removed) >
11544 echo trim(" vim ", " ", 2)
11545< returns " vim"
11546
11547 Can also be used as a |method|: >
11548 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011549<
11550 Return type: |String|
11551
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011552
11553trunc({expr}) *trunc()*
11554 Return the largest integral value with magnitude less than or
11555 equal to {expr} as a |Float| (truncate towards zero).
11556 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011557 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011558 Examples: >
11559 echo trunc(1.456)
11560< 1.0 >
11561 echo trunc(-5.456)
11562< -5.0 >
11563 echo trunc(4.0)
11564< 4.0
11565
11566 Can also be used as a |method|: >
11567 Compute()->trunc()
11568<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011569 Return type: |Float|
11570
11571
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011572 *type()*
11573type({expr}) The result is a Number representing the type of {expr}.
11574 Instead of using the number directly, it is better to use the
11575 v:t_ variable that has the value:
11576 Number: 0 |v:t_number|
11577 String: 1 |v:t_string|
11578 Funcref: 2 |v:t_func|
11579 List: 3 |v:t_list|
11580 Dictionary: 4 |v:t_dict|
11581 Float: 5 |v:t_float|
11582 Boolean: 6 |v:t_bool| (v:false and v:true)
11583 None: 7 |v:t_none| (v:null and v:none)
11584 Job: 8 |v:t_job|
11585 Channel: 9 |v:t_channel|
11586 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090011587 Class: 12 |v:t_class|
11588 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010011589 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011590 Enum: 15 |v:t_enum|
11591 EnumValue: 16 |v:t_enumvalue|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011592 For backward compatibility, this method can be used: >
11593 :if type(myvar) == type(0)
11594 :if type(myvar) == type("")
11595 :if type(myvar) == type(function("tr"))
11596 :if type(myvar) == type([])
11597 :if type(myvar) == type({})
11598 :if type(myvar) == type(0.0)
11599 :if type(myvar) == type(v:false)
11600 :if type(myvar) == type(v:none)
11601< To check if the v:t_ variables exist use this: >
11602 :if exists('v:t_number')
11603
11604< Can also be used as a |method|: >
11605 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011606<
11607 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011608
11609
11610typename({expr}) *typename()*
11611 Return a string representation of the type of {expr}.
11612 Example: >
11613 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000011614< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011615
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011616 Return type: |String|
11617
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011618
11619undofile({name}) *undofile()*
11620 Return the name of the undo file that would be used for a file
11621 with name {name} when writing. This uses the 'undodir'
11622 option, finding directories that exist. It does not check if
11623 the undo file exists.
11624 {name} is always expanded to the full path, since that is what
11625 is used internally.
11626 If {name} is empty undofile() returns an empty string, since a
11627 buffer without a file name will not write an undo file.
11628 Useful in combination with |:wundo| and |:rundo|.
11629 When compiled without the |+persistent_undo| option this always
11630 returns an empty string.
11631
11632 Can also be used as a |method|: >
11633 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011634<
11635 Return type: |String|
11636
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011637
Devin J. Pohly5fee1112023-04-23 20:26:59 -050011638undotree([{buf}]) *undotree()*
11639 Return the current state of the undo tree for the current
11640 buffer, or for a specific buffer if {buf} is given. The
11641 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011642 "seq_last" The highest undo sequence number used.
11643 "seq_cur" The sequence number of the current position in
11644 the undo tree. This differs from "seq_last"
11645 when some changes were undone.
11646 "time_cur" Time last used for |:earlier| and related
11647 commands. Use |strftime()| to convert to
11648 something readable.
11649 "save_last" Number of the last file write. Zero when no
11650 write yet.
11651 "save_cur" Number of the current position in the undo
11652 tree.
11653 "synced" Non-zero when the last undo block was synced.
11654 This happens when waiting from input from the
11655 user. See |undo-blocks|.
11656 "entries" A list of dictionaries with information about
11657 undo blocks.
11658
11659 The first item in the "entries" list is the oldest undo item.
11660 Each List item is a |Dictionary| with these items:
11661 "seq" Undo sequence number. Same as what appears in
11662 |:undolist|.
11663 "time" Timestamp when the change happened. Use
11664 |strftime()| to convert to something readable.
11665 "newhead" Only appears in the item that is the last one
11666 that was added. This marks the last change
11667 and where further changes will be added.
11668 "curhead" Only appears in the item that is the last one
11669 that was undone. This marks the current
11670 position in the undo tree, the block that will
11671 be used by a redo command. When nothing was
11672 undone after the last change this item will
11673 not appear anywhere.
11674 "save" Only appears on the last block before a file
11675 write. The number is the write count. The
11676 first write has number 1, the last one the
11677 "save_last" mentioned above.
11678 "alt" Alternate entry. This is again a List of undo
11679 blocks. Each item may again have an "alt"
11680 item.
11681
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011682 Return type: dict<any>
11683
11684
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011685uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
11686 Remove second and succeeding copies of repeated adjacent
11687 {list} items in-place. Returns {list}. If you want a list
11688 to remain unmodified make a copy first: >
11689 :let newlist = uniq(copy(mylist))
11690< The default compare function uses the string representation of
11691 each item. For the use of {func} and {dict} see |sort()|.
11692
Bram Moolenaard592deb2022-06-17 15:42:40 +010011693 Returns zero if {list} is not a |List|.
11694
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011695 Can also be used as a |method|: >
11696 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010011697<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011698 Return type: list<{type}>
11699
11700
Christian Brabandt67672ef2023-04-24 21:09:54 +010011701 *utf16idx()*
11702utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011703 Same as |charidx()| but returns the UTF-16 code unit index of
11704 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010011705
11706 When {charidx} is present and TRUE, {idx} is used as the
11707 character index in the String {string} instead of as the byte
11708 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010011709 An {idx} in the middle of a UTF-8 sequence is rounded
11710 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010011711
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011712 Returns -1 if the arguments are invalid or if there are less
11713 than {idx} bytes in {string}. If there are exactly {idx} bytes
11714 the length of the string in UTF-16 code units is returned.
11715
Christian Brabandt67672ef2023-04-24 21:09:54 +010011716 See |byteidx()| and |byteidxcomp()| for getting the byte index
11717 from the UTF-16 index and |charidx()| for getting the
11718 character index from the UTF-16 index.
11719 Refer to |string-offset-encoding| for more information.
11720 Examples: >
11721 echo utf16idx('a😊😊', 3) returns 2
11722 echo utf16idx('a😊😊', 7) returns 4
11723 echo utf16idx('a😊😊', 1, 0, 1) returns 2
11724 echo utf16idx('a😊😊', 2, 0, 1) returns 4
11725 echo utf16idx('aą́c', 6) returns 2
11726 echo utf16idx('aą́c', 6, 1) returns 4
11727 echo utf16idx('a😊😊', 9) returns -1
11728<
11729 Can also be used as a |method|: >
11730 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011731<
11732 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010011733
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011734
11735values({dict}) *values()*
11736 Return a |List| with all the values of {dict}. The |List| is
11737 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011738 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011739
11740 Can also be used as a |method|: >
11741 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011742<
11743 Return type: list<any>
11744
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011745
zeertzjq825cf812023-08-17 22:55:25 +020011746virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011747 The result is a Number, which is the screen column of the file
11748 position given with {expr}. That is, the last screen position
11749 occupied by the character at that position, when the screen
11750 would be of unlimited width. When there is a <Tab> at the
11751 position, the returned Number will be the column at the end of
11752 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
11753 set to 8, it returns 8. |conceal| is ignored.
11754 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011755
zeertzjq02f3eba2024-06-12 20:45:24 +020011756 For the use of {expr} see |getpos()| and |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011757
11758 When 'virtualedit' is used {expr} can be [lnum, col, off],
11759 where "off" is the offset in screen columns from the start of
11760 the character. E.g., a position within a <Tab> or after the
11761 last character. When "off" is omitted zero is used. When
11762 Virtual editing is active in the current mode, a position
11763 beyond the end of the line can be returned. Also see
11764 |'virtualedit'|
11765
zeertzjq825cf812023-08-17 22:55:25 +020011766 If {list} is present and non-zero then virtcol() returns a
11767 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010011768 character.
11769
zeertzjq825cf812023-08-17 22:55:25 +020011770 With the optional {winid} argument the values are obtained for
11771 that window instead of the current window.
11772
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011773 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +020011774
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011775 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010011776 " With text "foo^Lbar" and cursor on the "^L":
11777
11778 virtcol(".") " returns 5
11779 virtcol(".", 1) " returns [4, 5]
11780 virtcol("$") " returns 9
11781
11782 " With text " there", with 't at 'h':
11783
11784 virtcol("'t") " returns 6
zeertzjq02f3eba2024-06-12 20:45:24 +020011785<
11786 The first column is 1. 0 or [0, 0] is returned for an error.
11787
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011788 A more advanced example that echoes the maximum length of
11789 all lines: >
11790 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
11791
11792< Can also be used as a |method|: >
11793 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011794<
11795 Return type: |Number|
11796
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011797
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011798virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
11799 The result is a Number, which is the byte index of the
11800 character in window {winid} at buffer line {lnum} and virtual
11801 column {col}.
11802
zeertzjqb583eda2023-10-14 11:32:28 +020011803 If buffer line {lnum} is an empty line, 0 is returned.
11804
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011805 If {col} is greater than the last virtual column in line
11806 {lnum}, then the byte index of the character at the last
11807 virtual column is returned.
11808
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020011809 For a multi-byte character, the column number of the first
11810 byte in the character is returned.
11811
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011812 The {winid} argument can be the window number or the
11813 |window-ID|. If this is zero, then the current window is used.
11814
11815 Returns -1 if the window {winid} doesn't exist or the buffer
11816 line {lnum} or virtual column {col} is invalid.
11817
11818 See also |screenpos()|, |virtcol()| and |col()|.
11819
11820 Can also be used as a |method|: >
11821 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011822<
11823 Return type: |Number|
11824
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011825
11826visualmode([{expr}]) *visualmode()*
11827 The result is a String, which describes the last Visual mode
11828 used in the current buffer. Initially it returns an empty
11829 string, but once Visual mode has been used, it returns "v",
11830 "V", or "<CTRL-V>" (a single CTRL-V character) for
11831 character-wise, line-wise, or block-wise Visual mode
11832 respectively.
11833 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011834 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011835< This enters the same Visual mode as before. It is also useful
11836 in scripts if you wish to act differently depending on the
11837 Visual mode that was used.
11838 If Visual mode is active, use |mode()| to get the Visual mode
11839 (e.g., in a |:vmap|).
11840 If {expr} is supplied and it evaluates to a non-zero Number or
11841 a non-empty String, then the Visual mode will be cleared and
11842 the old value is returned. See |non-zero-arg|.
11843
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011844 Return type: |String|
11845
11846
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011847wildmenumode() *wildmenumode()*
11848 Returns |TRUE| when the wildmenu is active and |FALSE|
11849 otherwise. See 'wildmenu' and 'wildmode'.
11850 This can be used in mappings to handle the 'wildcharm' option
11851 gracefully. (Makes only sense with |mapmode-c| mappings).
11852
11853 For example to make <c-j> work like <down> in wildmode, use: >
11854 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
11855<
11856 (Note, this needs the 'wildcharm' option set appropriately).
11857
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011858 Return type: |Number|
11859
11860
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011861win_execute({id}, {command} [, {silent}]) *win_execute()*
11862 Like `execute()` but in the context of window {id}.
11863 The window will temporarily be made the current window,
11864 without triggering autocommands or changing directory. When
11865 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010011866 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011867 Example: >
11868 call win_execute(winid, 'set syntax=python')
11869< Doing the same with `setwinvar()` would not trigger
11870 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011871 *E994*
11872 Not all commands are allowed in popup windows.
11873 When window {id} does not exist then no error is given and
11874 an empty string is returned.
11875
11876 Can also be used as a |method|, the base is passed as the
11877 second argument: >
11878 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011879<
11880 Return type: |String|
11881
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011882
11883win_findbuf({bufnr}) *win_findbuf()*
11884 Returns a |List| with |window-ID|s for windows that contain
11885 buffer {bufnr}. When there is none the list is empty.
11886
11887 Can also be used as a |method|: >
11888 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011889<
11890 Return type: list<number> or list<any>
11891
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011892
11893win_getid([{win} [, {tab}]]) *win_getid()*
11894 Get the |window-ID| for the specified window.
11895 When {win} is missing use the current window.
11896 With {win} this is the window number. The top window has
11897 number 1.
11898 Without {tab} use the current tab, otherwise the tab with
11899 number {tab}. The first tab has number one.
11900 Return zero if the window cannot be found.
11901
11902 Can also be used as a |method|: >
11903 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011904<
11905 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011906
11907
11908win_gettype([{nr}]) *win_gettype()*
11909 Return the type of the window:
11910 "autocmd" autocommand window. Temporary window
11911 used to execute autocommands.
11912 "command" command-line window |cmdwin|
11913 (empty) normal window
11914 "loclist" |location-list-window|
11915 "popup" popup window |popup|
11916 "preview" preview window |preview-window|
11917 "quickfix" |quickfix-window|
11918 "unknown" window {nr} not found
11919
11920 When {nr} is omitted return the type of the current window.
11921 When {nr} is given return the type of this window by number or
11922 |window-ID|.
11923
11924 Also see the 'buftype' option. When running a terminal in a
11925 popup window then 'buftype' is "terminal" and win_gettype()
11926 returns "popup".
11927
11928 Can also be used as a |method|: >
11929 GetWinid()->win_gettype()
11930<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011931 Return type: |String|
11932
11933
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011934win_gotoid({expr}) *win_gotoid()*
11935 Go to window with ID {expr}. This may also change the current
11936 tabpage.
11937 Return TRUE if successful, FALSE if the window cannot be found.
11938
11939 Can also be used as a |method|: >
11940 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011941<
11942 Return type: |Number|
11943
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011944
11945win_id2tabwin({expr}) *win_id2tabwin()*
11946 Return a list with the tab number and window number of window
11947 with ID {expr}: [tabnr, winnr].
11948 Return [0, 0] if the window cannot be found.
11949
11950 Can also be used as a |method|: >
11951 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011952<
11953 Return type: list<number>
11954
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011955
11956win_id2win({expr}) *win_id2win()*
11957 Return the window number of window with ID {expr}.
11958 Return 0 if the window cannot be found in the current tabpage.
11959
11960 Can also be used as a |method|: >
11961 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011962<
11963 Return type: |Number|
11964
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011965
Daniel Steinbergee630312022-01-10 13:36:34 +000011966win_move_separator({nr}, {offset}) *win_move_separator()*
11967 Move window {nr}'s vertical separator (i.e., the right border)
11968 by {offset} columns, as if being dragged by the mouse. {nr}
11969 can be a window number or |window-ID|. A positive {offset}
11970 moves right and a negative {offset} moves left. Moving a
11971 window's vertical separator will change the width of the
11972 window and the width of other windows adjacent to the vertical
11973 separator. The magnitude of movement may be smaller than
11974 specified (e.g., as a consequence of maintaining
11975 'winminwidth'). Returns TRUE if the window can be found and
11976 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011977 This will fail for the rightmost window and a full-width
11978 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000011979 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000011980
11981 Can also be used as a |method|: >
11982 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011983<
11984 Return type: |Number|
11985
Daniel Steinbergee630312022-01-10 13:36:34 +000011986
11987win_move_statusline({nr}, {offset}) *win_move_statusline()*
11988 Move window {nr}'s status line (i.e., the bottom border) by
11989 {offset} rows, as if being dragged by the mouse. {nr} can be a
11990 window number or |window-ID|. A positive {offset} moves down
11991 and a negative {offset} moves up. Moving a window's status
11992 line will change the height of the window and the height of
11993 other windows adjacent to the status line. The magnitude of
11994 movement may be smaller than specified (e.g., as a consequence
11995 of maintaining 'winminheight'). Returns TRUE if the window can
11996 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000011997 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000011998
11999 Can also be used as a |method|: >
12000 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012001<
12002 Return type: |Number|
12003
Daniel Steinbergee630312022-01-10 13:36:34 +000012004
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012005win_screenpos({nr}) *win_screenpos()*
12006 Return the screen position of window {nr} as a list with two
12007 numbers: [row, col]. The first window always has position
12008 [1, 1], unless there is a tabline, then it is [2, 1].
12009 {nr} can be the window number or the |window-ID|. Use zero
12010 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012011 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012012
12013 Can also be used as a |method|: >
12014 GetWinid()->win_screenpos()
12015<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012016 Return type: list<number>
12017
12018
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012019win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012020 Temporarily switch to window {target}, then move window {nr}
12021 to a new split adjacent to {target}.
12022 Unlike commands such as |:split|, no new windows are created
12023 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012024
12025 Both {nr} and {target} can be window numbers or |window-ID|s.
12026 Both must be in the current tab page.
12027
12028 Returns zero for success, non-zero for failure.
12029
12030 {options} is a |Dictionary| with the following optional entries:
12031 "vertical" When TRUE, the split is created vertically,
12032 like with |:vsplit|.
12033 "rightbelow" When TRUE, the split is made below or to the
12034 right (if vertical). When FALSE, it is done
12035 above or to the left (if vertical). When not
12036 present, the values of 'splitbelow' and
12037 'splitright' are used.
12038
12039 Can also be used as a |method|: >
12040 GetWinid()->win_splitmove(target)
12041<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012042 Return type: |Number|
12043
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012044
12045 *winbufnr()*
12046winbufnr({nr}) The result is a Number, which is the number of the buffer
12047 associated with window {nr}. {nr} can be the window number or
12048 the |window-ID|.
12049 When {nr} is zero, the number of the buffer in the current
12050 window is returned.
12051 When window {nr} doesn't exist, -1 is returned.
12052 Example: >
12053 :echo "The file in the current window is " . bufname(winbufnr(0))
12054<
12055 Can also be used as a |method|: >
12056 FindWindow()->winbufnr()->bufname()
12057<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012058 Return type: |Number|
12059
12060
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012061 *wincol()*
12062wincol() The result is a Number, which is the virtual column of the
12063 cursor in the window. This is counting screen cells from the
12064 left side of the window. The leftmost column is one.
12065
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012066 Return type: |Number|
12067
12068
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012069 *windowsversion()*
12070windowsversion()
12071 The result is a String. For MS-Windows it indicates the OS
12072 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12073 Windows XP is "5.1". For non-MS-Windows systems the result is
12074 an empty string.
12075
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012076 Return type: |String|
12077
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012078winheight({nr}) *winheight()*
12079 The result is a Number, which is the height of window {nr}.
12080 {nr} can be the window number or the |window-ID|.
12081 When {nr} is zero, the height of the current window is
12082 returned. When window {nr} doesn't exist, -1 is returned.
12083 An existing window always has a height of zero or more.
12084 This excludes any window toolbar line.
12085 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012086 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012087
12088< Can also be used as a |method|: >
12089 GetWinid()->winheight()
12090<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012091 Return type: |Number|
12092
12093
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012094winlayout([{tabnr}]) *winlayout()*
12095 The result is a nested List containing the layout of windows
12096 in a tabpage.
12097
12098 Without {tabnr} use the current tabpage, otherwise the tabpage
12099 with number {tabnr}. If the tabpage {tabnr} is not found,
12100 returns an empty list.
12101
12102 For a leaf window, it returns:
12103 ['leaf', {winid}]
12104 For horizontally split windows, which form a column, it
12105 returns:
12106 ['col', [{nested list of windows}]]
12107 For vertically split windows, which form a row, it returns:
12108 ['row', [{nested list of windows}]]
12109
12110 Example: >
12111 " Only one window in the tab page
12112 :echo winlayout()
12113 ['leaf', 1000]
12114 " Two horizontally split windows
12115 :echo winlayout()
12116 ['col', [['leaf', 1000], ['leaf', 1001]]]
12117 " The second tab page, with three horizontally split
12118 " windows, with two vertically split windows in the
12119 " middle window
12120 :echo winlayout(2)
12121 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12122 ['leaf', 1001]]], ['leaf', 1000]]]
12123<
12124 Can also be used as a |method|: >
12125 GetTabnr()->winlayout()
12126<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012127 Return type: list<any>
12128
12129
12130winline() *winline()*
12131 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012132 in the window. This is counting screen lines from the top of
12133 the window. The first line is one.
12134 If the cursor was moved the view on the file will be updated
12135 first, this may cause a scroll.
12136
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012137 Return type: |Number|
12138
12139
12140winnr([{arg}]) *winnr()*
12141 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012142 window. The top window has number 1.
12143 Returns zero for a popup window.
12144
12145 The optional argument {arg} supports the following values:
12146 $ the number of the last window (the window
12147 count).
12148 # the number of the last accessed window (where
12149 |CTRL-W_p| goes to). If there is no previous
12150 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012151 returned. May refer to the current window in
12152 some cases (e.g. when evaluating 'statusline'
12153 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012154 {N}j the number of the Nth window below the
12155 current window (where |CTRL-W_j| goes to).
12156 {N}k the number of the Nth window above the current
12157 window (where |CTRL-W_k| goes to).
12158 {N}h the number of the Nth window left of the
12159 current window (where |CTRL-W_h| goes to).
12160 {N}l the number of the Nth window right of the
12161 current window (where |CTRL-W_l| goes to).
12162 The number can be used with |CTRL-W_w| and ":wincmd w"
12163 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012164 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012165 Also see |tabpagewinnr()| and |win_getid()|.
12166 Examples: >
12167 let window_count = winnr('$')
12168 let prev_window = winnr('#')
12169 let wnum = winnr('3k')
12170
12171< Can also be used as a |method|: >
12172 GetWinval()->winnr()
12173<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012174 Return type: |Number|
12175
12176
12177winrestcmd() *winrestcmd()*
12178 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012179 the current window sizes. Only works properly when no windows
12180 are opened or closed and the current window and tab page is
12181 unchanged.
12182 Example: >
12183 :let cmd = winrestcmd()
12184 :call MessWithWindowSizes()
12185 :exe cmd
12186<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012187 Return type: |String|
12188
12189
12190winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012191 Uses the |Dictionary| returned by |winsaveview()| to restore
12192 the view of the current window.
12193 Note: The {dict} does not have to contain all values, that are
12194 returned by |winsaveview()|. If values are missing, those
12195 settings won't be restored. So you can use: >
12196 :call winrestview({'curswant': 4})
12197<
12198 This will only set the curswant value (the column the cursor
12199 wants to move on vertical movements) of the cursor to column 5
12200 (yes, that is 5), while all other settings will remain the
12201 same. This is useful, if you set the cursor position manually.
12202
12203 If you have changed the values the result is unpredictable.
12204 If the window size changed the result won't be the same.
12205
12206 Can also be used as a |method|: >
12207 GetView()->winrestview()
12208<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012209 Return type: |Number|
12210
12211
12212winsaveview() *winsaveview()*
12213 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012214 the view of the current window. Use |winrestview()| to
12215 restore the view.
12216 This is useful if you have a mapping that jumps around in the
12217 buffer and you want to go back to the original view.
12218 This does not save fold information. Use the 'foldenable'
12219 option to temporarily switch off folding, so that folds are
12220 not opened when moving around. This may have side effects.
12221 The return value includes:
12222 lnum cursor line number
12223 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012224 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012225 returns)
12226 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012227 curswant column for vertical movement (Note:
12228 the first column is zero, as opposed
12229 to what |getcurpos()| returns). After
12230 |$| command it will be a very large
12231 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012232 topline first line in the window
12233 topfill filler lines, only in diff mode
12234 leftcol first column displayed; only used when
12235 'wrap' is off
12236 skipcol columns skipped
12237 Note that no option values are saved.
12238
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012239 Return type: dict<number>
12240
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012241
12242winwidth({nr}) *winwidth()*
12243 The result is a Number, which is the width of window {nr}.
12244 {nr} can be the window number or the |window-ID|.
12245 When {nr} is zero, the width of the current window is
12246 returned. When window {nr} doesn't exist, -1 is returned.
12247 An existing window always has a width of zero or more.
12248 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012249 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012250 :if winwidth(0) <= 50
12251 : 50 wincmd |
12252 :endif
12253< For getting the terminal or screen size, see the 'columns'
12254 option.
12255
12256 Can also be used as a |method|: >
12257 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012258<
12259 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012260
12261
12262wordcount() *wordcount()*
12263 The result is a dictionary of byte/chars/word statistics for
12264 the current buffer. This is the same info as provided by
12265 |g_CTRL-G|
12266 The return value includes:
12267 bytes Number of bytes in the buffer
12268 chars Number of chars in the buffer
12269 words Number of words in the buffer
12270 cursor_bytes Number of bytes before cursor position
12271 (not in Visual mode)
12272 cursor_chars Number of chars before cursor position
12273 (not in Visual mode)
12274 cursor_words Number of words before cursor position
12275 (not in Visual mode)
12276 visual_bytes Number of bytes visually selected
12277 (only in Visual mode)
12278 visual_chars Number of chars visually selected
12279 (only in Visual mode)
12280 visual_words Number of words visually selected
12281 (only in Visual mode)
12282
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012283 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012284
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012285
12286writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012287 When {object} is a |List| write it to file {fname}. Each list
12288 item is separated with a NL. Each list item must be a String
12289 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012290 All NL characters are replaced with a NUL character.
12291 Inserting CR characters needs to be done before passing {list}
12292 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012293
12294 When {object} is a |Blob| write the bytes to file {fname}
12295 unmodified, also when binary mode is not specified.
12296
12297 {flags} must be a String. These characters are recognized:
12298
12299 'b' Binary mode is used: There will not be a NL after the
12300 last list item. An empty item at the end does cause the
12301 last line in the file to end in a NL.
12302
12303 'a' Append mode is used, lines are appended to the file: >
12304 :call writefile(["foo"], "event.log", "a")
12305 :call writefile(["bar"], "event.log", "a")
12306<
12307 'D' Delete the file when the current function ends. This
12308 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012309 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012310< Fails when not in a function. Also see |:defer|.
12311
12312 's' fsync() is called after writing the file. This flushes
12313 the file to disk, if possible. This takes more time but
12314 avoids losing the file if the system crashes.
12315
12316 'S' fsync() is not called, even when 'fsync' is set.
12317
12318 When {flags} does not contain "S" or "s" then fsync() is
12319 called if the 'fsync' option is set.
12320
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012321 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012322
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012323 When the write fails -1 is returned, otherwise 0. There is an
12324 error message if the file can't be created or when writing
12325 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012326
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012327 Also see |readfile()|.
12328 To copy a file byte for byte: >
12329 :let fl = readfile("foo", "b")
12330 :call writefile(fl, "foocopy", "b")
12331
12332< Can also be used as a |method|: >
12333 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012334<
12335 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012336
12337
12338xor({expr}, {expr}) *xor()*
12339 Bitwise XOR on the two arguments. The arguments are converted
12340 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012341 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012342 Example: >
12343 :let bits = xor(bits, 0x80)
12344<
12345 Can also be used as a |method|: >
12346 :let bits = bits->xor(0x80)
12347<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012348 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012349
12350==============================================================================
123513. Feature list *feature-list*
12352
12353There are three types of features:
123541. Features that are only supported when they have been enabled when Vim
12355 was compiled |+feature-list|. Example: >
12356 :if has("cindent")
12357< *gui_running*
123582. Features that are only supported when certain conditions have been met.
12359 Example: >
12360 :if has("gui_running")
12361< *has-patch*
123623. Beyond a certain version or at a certain version and including a specific
12363 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12364 later, or it is version 7.4 and patch 248 was included. Example: >
12365 :if has("patch-7.4.248")
12366< Note that it's possible for patch 248 to be omitted even though 249 is
12367 included. Only happens when cherry-picking patches.
12368 Note that this form only works for patch 7.4.237 and later, before that
12369 you need to check for the patch and the v:version. Example (checking
12370 version 6.2.148 or later): >
12371 :if v:version > 602 || (v:version == 602 && has("patch148"))
12372
12373Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12374use: `if exists('+shellslash')`
12375
12376
12377acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012378all_builtin_terms Compiled with all builtin terminals enabled. (always
12379 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012380amiga Amiga version of Vim.
12381arabic Compiled with Arabic support |Arabic|.
12382arp Compiled with ARP support (Amiga).
12383autocmd Compiled with autocommand support. (always true)
12384autochdir Compiled with support for 'autochdir'
12385autoservername Automatically enable |clientserver|
12386balloon_eval Compiled with |balloon-eval| support.
12387balloon_multiline GUI supports multiline balloons.
12388beos BeOS version of Vim.
12389browse Compiled with |:browse| support, and browse() will
12390 work.
12391browsefilter Compiled with support for |browsefilter|.
12392bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012393builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012394byte_offset Compiled with support for 'o' in 'statusline'
12395channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012396cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012397clientserver Compiled with remote invocation support |clientserver|.
12398clipboard Compiled with 'clipboard' support.
12399clipboard_working Compiled with 'clipboard' support and it can be used.
12400cmdline_compl Compiled with |cmdline-completion| support.
12401cmdline_hist Compiled with |cmdline-history| support.
12402cmdline_info Compiled with 'showcmd' and 'ruler' support.
12403comments Compiled with |'comments'| support.
12404compatible Compiled to be very Vi compatible.
12405conpty Platform where |ConPTY| can be used.
12406cryptv Compiled with encryption support |encryption|.
12407cscope Compiled with |cscope| support.
12408cursorbind Compiled with |'cursorbind'| (always true)
12409debug Compiled with "DEBUG" defined.
12410dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012411dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012412dialog_gui Compiled with GUI dialog support.
12413diff Compiled with |vimdiff| and 'diff' support.
12414digraphs Compiled with support for digraphs.
12415directx Compiled with support for DirectX and 'renderoptions'.
12416dnd Compiled with support for the "~ register |quote_~|.
12417drop_file Compiled with |drop_file| support.
12418ebcdic Compiled on a machine with ebcdic character set.
12419emacs_tags Compiled with support for Emacs tags.
12420eval Compiled with expression evaluation support. Always
12421 true, of course!
12422ex_extra |+ex_extra| (always true)
12423extra_search Compiled with support for |'incsearch'| and
12424 |'hlsearch'|
12425farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012426file_in_path Compiled with support for |gf| and |<cfile>| (always
12427 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012428filterpipe When 'shelltemp' is off pipes are used for shell
12429 read/write/filter commands
12430find_in_path Compiled with support for include file searches
12431 |+find_in_path|.
12432float Compiled with support for |Float|.
12433fname_case Case in file names matters (for Amiga and MS-Windows
12434 this is not present).
12435folding Compiled with |folding| support.
12436footer Compiled with GUI footer support. |gui-footer|
12437fork Compiled to use fork()/exec() instead of system().
12438gettext Compiled with message translation |multi-lang|
12439gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012440gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012441gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12442gui_gtk Compiled with GTK+ GUI (any version).
12443gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12444gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12445gui_haiku Compiled with Haiku GUI.
12446gui_mac Compiled with Macintosh GUI.
12447gui_motif Compiled with Motif GUI.
12448gui_photon Compiled with Photon GUI.
12449gui_running Vim is running in the GUI, or it will start soon.
12450gui_win32 Compiled with MS-Windows Win32 GUI.
12451gui_win32s idem, and Win32s system being used (Windows 3.1)
12452haiku Haiku version of Vim.
12453hangul_input Compiled with Hangul input support. |hangul|
12454hpux HP-UX version of Vim.
12455iconv Can use iconv() for conversion.
12456insert_expand Compiled with support for CTRL-X expansion commands in
12457 Insert mode. (always true)
12458job Compiled with support for |channel| and |job|
12459ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012460jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012461keymap Compiled with 'keymap' support.
12462lambda Compiled with |lambda| support.
12463langmap Compiled with 'langmap' support.
12464libcall Compiled with |libcall()| support.
12465linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12466 'breakindent' support.
12467linux Linux version of Vim.
12468lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012469 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012470listcmds Compiled with commands for the buffer list |:files|
12471 and the argument list |arglist|.
12472localmap Compiled with local mappings and abbr. |:map-local|
12473lua Compiled with Lua interface |Lua|.
12474mac Any Macintosh version of Vim cf. osx
12475macunix Synonym for osxdarwin
12476menu Compiled with support for |:menu|.
12477mksession Compiled with support for |:mksession|.
12478modify_fname Compiled with file name modifiers. |filename-modifiers|
12479 (always true)
12480mouse Compiled with support for mouse.
12481mouse_dec Compiled with support for Dec terminal mouse.
12482mouse_gpm Compiled with support for gpm (Linux console mouse)
12483mouse_gpm_enabled GPM mouse is working
12484mouse_netterm Compiled with support for netterm mouse.
12485mouse_pterm Compiled with support for qnx pterm mouse.
12486mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12487mouse_sgr Compiled with support for sgr mouse.
12488mouse_urxvt Compiled with support for urxvt mouse.
12489mouse_xterm Compiled with support for xterm mouse.
12490mouseshape Compiled with support for 'mouseshape'.
12491multi_byte Compiled with support for 'encoding' (always true)
12492multi_byte_encoding 'encoding' is set to a multibyte encoding.
12493multi_byte_ime Compiled with support for IME input method.
12494multi_lang Compiled with support for multiple languages.
12495mzscheme Compiled with MzScheme interface |mzscheme|.
12496nanotime Compiled with sub-second time stamp checks.
12497netbeans_enabled Compiled with support for |netbeans| and connected.
12498netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012499num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012500ole Compiled with OLE automation support for Win32.
12501osx Compiled for macOS cf. mac
12502osxdarwin Compiled for macOS, with |mac-darwin-feature|
12503packages Compiled with |packages| support.
12504path_extra Compiled with up/downwards search in 'path' and 'tags'
12505perl Compiled with Perl interface.
12506persistent_undo Compiled with support for persistent undo history.
12507postscript Compiled with PostScript file printing.
12508printer Compiled with |:hardcopy| support.
12509profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012510prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012511python Python 2.x interface available. |has-python|
12512python_compiled Compiled with Python 2.x interface. |has-python|
12513python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12514python3 Python 3.x interface available. |has-python|
12515python3_compiled Compiled with Python 3.x interface. |has-python|
12516python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012517python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012518pythonx Python 2.x and/or 3.x interface available. |python_x|
12519qnx QNX version of Vim.
12520quickfix Compiled with |quickfix| support.
12521reltime Compiled with |reltime()| support.
12522rightleft Compiled with 'rightleft' support.
12523ruby Compiled with Ruby interface |ruby|.
12524scrollbind Compiled with 'scrollbind' support. (always true)
12525showcmd Compiled with 'showcmd' support.
12526signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012527smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012528sodium Compiled with libsodium for better crypt support
12529sound Compiled with sound support, e.g. `sound_playevent()`
12530spell Compiled with spell checking support |spell|.
12531startuptime Compiled with |--startuptime| support.
12532statusline Compiled with support for 'statusline', 'rulerformat'
12533 and special formats of 'titlestring' and 'iconstring'.
12534sun SunOS version of Vim.
12535sun_workshop Support for Sun |workshop| has been removed.
12536syntax Compiled with syntax highlighting support |syntax|.
12537syntax_items There are active syntax highlighting items for the
12538 current buffer.
12539system Compiled to use system() instead of fork()/exec().
12540tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012541 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012542tag_old_static Support for old static tags was removed, see
12543 |tag-old-static|.
12544tcl Compiled with Tcl interface.
12545termguicolors Compiled with true color in terminal support.
12546terminal Compiled with |terminal| support.
12547terminfo Compiled with terminfo instead of termcap.
12548termresponse Compiled with support for |t_RV| and |v:termresponse|.
12549textobjects Compiled with support for |text-objects|.
12550textprop Compiled with support for |text-properties|.
12551tgetent Compiled with tgetent support, able to use a termcap
12552 or terminfo file.
12553timers Compiled with |timer_start()| support.
12554title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012555 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012556toolbar Compiled with support for |gui-toolbar|.
12557ttyin input is a terminal (tty)
12558ttyout output is a terminal (tty)
12559unix Unix version of Vim. *+unix*
12560unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
12561user_commands User-defined commands. (always true)
12562vartabs Compiled with variable tabstop support |'vartabstop'|.
12563vcon Win32: Virtual console support is working, can use
12564 'termguicolors'. Also see |+vtp|.
12565vertsplit Compiled with vertically split windows |:vsplit|.
12566 (always true)
12567vim_starting True while initial source'ing takes place. |startup|
12568 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000012569vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012570viminfo Compiled with viminfo support.
12571vimscript-1 Compiled Vim script version 1 support
12572vimscript-2 Compiled Vim script version 2 support
12573vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010012574vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012575virtualedit Compiled with 'virtualedit' option. (always true)
12576visual Compiled with Visual mode. (always true)
12577visualextra Compiled with extra Visual mode commands. (always
12578 true) |blockwise-operators|.
12579vms VMS version of Vim.
12580vreplace Compiled with |gR| and |gr| commands. (always true)
12581vtp Compiled for vcon support |+vtp| (check vcon to find
12582 out if it works in the current console).
12583wildignore Compiled with 'wildignore' option.
12584wildmenu Compiled with 'wildmenu' option.
12585win16 old version for MS-Windows 3.1 (always false)
12586win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
12587 64 bits)
12588win32unix Win32 version of Vim, using Unix files (Cygwin)
12589win64 Win64 version of Vim (MS-Windows 64 bit).
12590win95 Win32 version for MS-Windows 95/98/ME (always false)
12591winaltkeys Compiled with 'winaltkeys' option.
12592windows Compiled with support for more than one window.
12593 (always true)
12594writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020012595xattr Compiled with extended attributes support |xattr|
12596 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012597xfontset Compiled with X fontset support |xfontset|.
12598xim Compiled with X input method support |xim|.
12599xpm Compiled with pixmap support.
12600xpm_w32 Compiled with pixmap support for Win32. (Only for
12601 backward compatibility. Use "xpm" instead.)
12602xsmp Compiled with X session management support.
12603xsmp_interact Compiled with interactive X session management support.
12604xterm_clipboard Compiled with support for xterm clipboard.
12605xterm_save Compiled with support for saving and restoring the
12606 xterm screen.
12607x11 Compiled with X11 support.
12608
12609
12610==============================================================================
126114. Matching a pattern in a String *string-match*
12612
12613This is common between several functions. A regexp pattern as explained at
12614|pattern| is normally used to find a match in the buffer lines. When a
12615pattern is used to find a match in a String, almost everything works in the
12616same way. The difference is that a String is handled like it is one line.
12617When it contains a "\n" character, this is not seen as a line break for the
12618pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
12619>
12620 :let a = "aaaa\nxxxx"
12621 :echo matchstr(a, "..\n..")
12622 aa
12623 xx
12624 :echo matchstr(a, "a.x")
12625 a
12626 x
12627
12628Don't forget that "^" will only match at the first character of the String and
12629"$" at the last character of the string. They don't match after or before a
12630"\n".
12631
12632 vim:tw=78:ts=8:noet:ft=help:norl: