blob: 34c0b0a673abeb8b05b21e20ae7f161af4acaf9d [file] [log] [blame]
Christ van Willegence0ef912024-06-20 23:41:59 +02001*builtin.txt* For Vim version 9.1. Last change: 2024 Jun 20
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
Christ van Willegence0ef912024-06-20 23:41:59 +020070bindtextdomain({package}, {path})
71 none bind text domain to specied path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000072blob2list({blob}) List convert {blob} into a list of numbers
73browse({save}, {title}, {initdir}, {default})
74 String put up a file requester
75browsedir({title}, {initdir}) String put up a directory requester
76bufadd({name}) Number add a buffer to the buffer list
77bufexists({buf}) Number |TRUE| if buffer {buf} exists
78buflisted({buf}) Number |TRUE| if buffer {buf} is listed
79bufload({buf}) Number load buffer {buf} if not loaded yet
80bufloaded({buf}) Number |TRUE| if buffer {buf} is loaded
81bufname([{buf}]) String Name of the buffer {buf}
82bufnr([{buf} [, {create}]]) Number Number of the buffer {buf}
83bufwinid({buf}) Number window ID of buffer {buf}
84bufwinnr({buf}) Number window number of buffer {buf}
85byte2line({byte}) Number line number at byte count {byte}
Christian Brabandt67672ef2023-04-24 21:09:54 +010086byteidx({expr}, {nr} [, {utf16}])
87 Number byte index of {nr}'th char in {expr}
88byteidxcomp({expr}, {nr} [, {utf16}])
89 Number byte index of {nr}'th char in {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000090call({func}, {arglist} [, {dict}])
91 any call {func} with arguments {arglist}
92ceil({expr}) Float round {expr} up
93ch_canread({handle}) Number check if there is something to read
94ch_close({handle}) none close {handle}
95ch_close_in({handle}) none close in part of {handle}
96ch_evalexpr({handle}, {expr} [, {options}])
97 any evaluate {expr} on JSON {handle}
98ch_evalraw({handle}, {string} [, {options}])
99 any evaluate {string} on raw {handle}
100ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
101ch_getjob({channel}) Job get the Job of {channel}
102ch_info({handle}) String info about channel {handle}
103ch_log({msg} [, {handle}]) none write {msg} in the channel log file
104ch_logfile({fname} [, {mode}]) none start logging channel activity
105ch_open({address} [, {options}])
106 Channel open a channel to {address}
107ch_read({handle} [, {options}]) String read from {handle}
108ch_readblob({handle} [, {options}])
109 Blob read Blob from {handle}
110ch_readraw({handle} [, {options}])
111 String read raw from {handle}
112ch_sendexpr({handle}, {expr} [, {options}])
113 any send {expr} over JSON {handle}
114ch_sendraw({handle}, {expr} [, {options}])
115 any send {expr} over raw {handle}
116ch_setoptions({handle}, {options})
117 none set options for {handle}
118ch_status({handle} [, {options}])
119 String status of channel {handle}
120changenr() Number current change number
121char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr}
122charclass({string}) Number character class of {string}
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000123charcol({expr} [, {winid}]) Number column number of cursor or mark
Christian Brabandt67672ef2023-04-24 21:09:54 +0100124charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000125 Number char index of byte {idx} in {string}
126chdir({dir}) String change current working directory
127cindent({lnum}) Number C indent for line {lnum}
128clearmatches([{win}]) none clear all matches
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000129col({expr} [, {winid}]) Number column byte index of cursor or mark
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000130complete({startcol}, {matches}) none set Insert mode completion
131complete_add({expr}) Number add completion match
132complete_check() Number check for key typed during completion
133complete_info([{what}]) Dict get current completion information
134confirm({msg} [, {choices} [, {default} [, {type}]]])
135 Number number of choice picked by user
136copy({expr}) any make a shallow copy of {expr}
137cos({expr}) Float cosine of {expr}
138cosh({expr}) Float hyperbolic cosine of {expr}
139count({comp}, {expr} [, {ic} [, {start}]])
140 Number count how many {expr} are in {comp}
141cscope_connection([{num}, {dbpath} [, {prepend}]])
142 Number checks existence of cscope connection
143cursor({lnum}, {col} [, {off}])
144 Number move cursor to {lnum}, {col}, {off}
145cursor({list}) Number move cursor to position in {list}
146debugbreak({pid}) Number interrupt process being debugged
147deepcopy({expr} [, {noref}]) any make a full copy of {expr}
148delete({fname} [, {flags}]) Number delete the file or directory {fname}
149deletebufline({buf}, {first} [, {last}])
150 Number delete lines from buffer {buf}
151did_filetype() Number |TRUE| if FileType autocmd event used
Yegappan Lakshmananfa378352024-02-01 22:05:27 +0100152diff({fromlist}, {tolist} [, {options}])
153 List diff two Lists of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000154diff_filler({lnum}) Number diff filler lines about {lnum}
155diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
156digraph_get({chars}) String get the |digraph| of {chars}
157digraph_getlist([{listall}]) List get all |digraph|s
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200158digraph_set({chars}, {digraph}) Bool register |digraph|
159digraph_setlist({digraphlist}) Bool register multiple |digraph|s
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000160echoraw({expr}) none output {expr} as-is
161empty({expr}) Number |TRUE| if {expr} is empty
162environ() Dict return environment variables
Sean Dewarb0efa492023-07-08 10:35:19 +0100163err_teapot([{expr}]) none give E418, or E503 if {expr} is |TRUE|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000164escape({string}, {chars}) String escape {chars} in {string} with '\'
165eval({string}) any evaluate {string} into its value
166eventhandler() Number |TRUE| if inside an event handler
167executable({expr}) Number 1 if executable {expr} exists
168execute({command}) String execute {command} and get the output
169exepath({expr}) String full path of the command {expr}
170exists({expr}) Number |TRUE| if {expr} exists
171exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
172exp({expr}) Float exponential of {expr}
173expand({expr} [, {nosuf} [, {list}]])
174 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100175expandcmd({string} [, {options}])
176 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000177extend({expr1}, {expr2} [, {expr3}])
178 List/Dict insert items of {expr2} into {expr1}
179extendnew({expr1}, {expr2} [, {expr3}])
180 List/Dict like |extend()| but creates a new
181 List or Dictionary
182feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
Shougo Matsushita60c87432024-06-03 22:59:27 +0200183filecopy({from}, {to}) Number |TRUE| if copying file {from} to {to}
184 worked
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000185filereadable({file}) Number |TRUE| if {file} is a readable file
186filewritable({file}) Number |TRUE| if {file} is a writable file
187filter({expr1}, {expr2}) List/Dict/Blob/String
188 remove items from {expr1} where
189 {expr2} is 0
190finddir({name} [, {path} [, {count}]])
191 String find directory {name} in {path}
192findfile({name} [, {path} [, {count}]])
193 String find file {name} in {path}
194flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
195flattennew({list} [, {maxdepth}])
196 List flatten a copy of {list}
197float2nr({expr}) Number convert Float {expr} to a Number
198floor({expr}) Float round {expr} down
199fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
200fnameescape({fname}) String escape special characters in {fname}
201fnamemodify({fname}, {mods}) String modify file name
202foldclosed({lnum}) Number first line of fold at {lnum} if closed
203foldclosedend({lnum}) Number last line of fold at {lnum} if closed
204foldlevel({lnum}) Number fold level at {lnum}
205foldtext() String line displayed for closed fold
206foldtextresult({lnum}) String text for closed fold at {lnum}
Ernie Raele79e2072024-01-13 11:47:33 +0100207foreach({expr1}, {expr2}) List/Dict/Blob/String
208 for each item in {expr1} call {expr2}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000209foreground() Number bring the Vim window to the foreground
Bram Moolenaaraa534142022-09-15 21:46:02 +0100210fullcommand({name} [, {vim9}]) String get full command from {name}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000211funcref({name} [, {arglist}] [, {dict}])
212 Funcref reference to function {name}
213function({name} [, {arglist}] [, {dict}])
214 Funcref named reference to function {name}
215garbagecollect([{atexit}]) none free memory, breaking cyclic references
216get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
217get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
218get({func}, {what}) any get property of funcref/partial {func}
219getbufinfo([{buf}]) List information about buffers
220getbufline({buf}, {lnum} [, {end}])
221 List lines {lnum} to {end} of buffer {buf}
Bram Moolenaarce30ccc2022-11-21 19:57:04 +0000222getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000223getbufvar({buf}, {varname} [, {def}])
224 any variable {varname} in buffer {buf}
Kota Kato66bb9ae2023-01-17 18:31:56 +0000225getcellwidths() List get character cell width overrides
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000226getchangelist([{buf}]) List list of change list items
Doug Kearns9cd9e752024-04-07 17:42:17 +0200227getchar([{expr}]) Number or String
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000228 get one character from the user
229getcharmod() Number modifiers for the last typed character
230getcharpos({expr}) List position of cursor, mark, etc.
231getcharsearch() Dict last character search
Doug Kearns9cd9e752024-04-07 17:42:17 +0200232getcharstr([{expr}]) String get one character from the user
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100233getcmdcompltype() String return the type of the current
234 command-line completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000235getcmdline() String return the current command-line
236getcmdpos() Number return cursor position in command-line
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100237getcmdscreenpos() Number return cursor screen position in
238 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000239getcmdtype() String return current command-line type
240getcmdwintype() String return current command-line window type
241getcompletion({pat}, {type} [, {filtered}])
242 List list of cmdline completion matches
243getcurpos([{winnr}]) List position of the cursor
244getcursorcharpos([{winnr}]) List character position of the cursor
245getcwd([{winnr} [, {tabnr}]]) String get the current working directory
246getenv({name}) String return environment variable
247getfontname([{name}]) String name of font being used
248getfperm({fname}) String file permissions of file {fname}
249getfsize({fname}) Number size in bytes of file {fname}
250getftime({fname}) Number last modification time of file
251getftype({fname}) String description of type of file {fname}
252getimstatus() Number |TRUE| if the IME status is active
253getjumplist([{winnr} [, {tabnr}]])
254 List list of jump list items
255getline({lnum}) String line {lnum} of current buffer
256getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
257getloclist({nr}) List list of location list items
258getloclist({nr}, {what}) Dict get specific location list properties
259getmarklist([{buf}]) List list of global/local marks
260getmatches([{win}]) List list of current matches
261getmousepos() Dict last known mouse position
Bram Moolenaar24dc19c2022-11-14 19:49:15 +0000262getmouseshape() String current mouse shape name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000263getpid() Number process ID of Vim
264getpos({expr}) List position of cursor, mark, etc.
265getqflist() List list of quickfix items
266getqflist({what}) Dict get specific quickfix list properties
267getreg([{regname} [, 1 [, {list}]]])
268 String or List contents of a register
269getreginfo([{regname}]) Dict information about a register
Shougo Matsushita19b71882024-02-28 22:48:12 +0100270getregion({pos1}, {pos2} [, {opts}])
Shougo Matsushita3f905ab2024-02-21 00:02:45 +0100271 List get the text from {pos1} to {pos2}
Shougo Matsushitab4757e62024-05-07 20:49:24 +0200272getregionpos({pos1}, {pos2} [, {opts}])
273 List get a list of positions for a region
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000274getregtype([{regname}]) String type of a register
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +0100275getscriptinfo([{opts}]) List list of sourced scripts
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000276gettabinfo([{expr}]) List list of tab pages
277gettabvar({nr}, {varname} [, {def}])
278 any variable {varname} in tab {nr} or {def}
279gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
280 any {name} in {winnr} in tab page {tabnr}
281gettagstack([{nr}]) Dict get the tag stack of window {nr}
Christ van Willegence0ef912024-06-20 23:41:59 +0200282gettext({text} [, {package}])
283 String lookup translation of {text}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000284getwininfo([{winid}]) List list of info about each window
Bram Moolenaar938ae282023-02-20 20:44:55 +0000285getwinpos([{timeout}]) List X and Y coord in pixels of Vim window
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000286getwinposx() Number X coord in pixels of the Vim window
287getwinposy() Number Y coord in pixels of the Vim window
288getwinvar({nr}, {varname} [, {def}])
289 any variable {varname} in window {nr}
290glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
291 any expand file wildcards in {expr}
292glob2regpat({expr}) String convert a glob pat into a search pat
293globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
294 String do glob({expr}) for all dirs in {path}
295has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
296has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
297haslocaldir([{winnr} [, {tabnr}]])
298 Number |TRUE| if the window executed |:lcd|
299 or |:tcd|
300hasmapto({what} [, {mode} [, {abbr}]])
301 Number |TRUE| if mapping to {what} exists
302histadd({history}, {item}) Number add an item to a history
303histdel({history} [, {item}]) Number remove an item from a history
304histget({history} [, {index}]) String get the item {index} from a history
305histnr({history}) Number highest index of a history
306hlID({name}) Number syntax ID of highlight group {name}
307hlexists({name}) Number |TRUE| if highlight group {name} exists
308hlget([{name} [, {resolve}]]) List get highlight group attributes
309hlset({list}) Number set highlight group attributes
310hostname() String name of the machine Vim is running on
311iconv({expr}, {from}, {to}) String convert encoding of {expr}
312indent({lnum}) Number indent of line {lnum}
313index({object}, {expr} [, {start} [, {ic}]])
314 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100315indexof({object}, {expr} [, {opts}]])
316 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000317input({prompt} [, {text} [, {completion}]])
318 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100319inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000320 String like input() but in a GUI dialog
321inputlist({textlist}) Number let the user pick from a choice list
322inputrestore() Number restore typeahead
323inputsave() Number save and clear typeahead
324inputsecret({prompt} [, {text}]) String like input() but hiding the text
325insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
LemonBoyafe04662023-08-23 21:08:11 +0200326instanceof({object}, {class}) Number |TRUE| if {object} is an instance of {class}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000327interrupt() none interrupt script execution
328invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100329isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000330isdirectory({directory}) Number |TRUE| if {directory} is a directory
331isinf({expr}) Number determine if {expr} is infinity value
332 (positive or negative)
333islocked({expr}) Number |TRUE| if {expr} is locked
334isnan({expr}) Number |TRUE| if {expr} is NaN
335items({dict}) List key-value pairs in {dict}
336job_getchannel({job}) Channel get the channel handle for {job}
337job_info([{job}]) Dict get information about {job}
338job_setoptions({job}, {options}) none set options for {job}
339job_start({command} [, {options}])
340 Job start a job
341job_status({job}) String get the status of {job}
342job_stop({job} [, {how}]) Number stop {job}
343join({list} [, {sep}]) String join {list} items into one String
344js_decode({string}) any decode JS style JSON
345js_encode({expr}) String encode JS style JSON
346json_decode({string}) any decode JSON
347json_encode({expr}) String encode JSON
348keys({dict}) List keys in {dict}
zeertzjqcdc83932022-09-12 13:38:41 +0100349keytrans({string}) String translate internal keycodes to a form
350 that can be used by |:map|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000351len({expr}) Number the length of {expr}
352libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
353libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
354line({expr} [, {winid}]) Number line nr of cursor, last line or mark
355line2byte({lnum}) Number byte count of line {lnum}
356lispindent({lnum}) Number Lisp indent for line {lnum}
357list2blob({list}) Blob turn {list} of numbers into a Blob
358list2str({list} [, {utf8}]) String turn {list} of numbers into a String
359listener_add({callback} [, {buf}])
360 Number add a callback to listen to changes
361listener_flush([{buf}]) none invoke listener callbacks
362listener_remove({id}) none remove a listener callback
363localtime() Number current time
364log({expr}) Float natural logarithm (base e) of {expr}
365log10({expr}) Float logarithm of Float {expr} to base 10
366luaeval({expr} [, {expr}]) any evaluate |Lua| expression
367map({expr1}, {expr2}) List/Dict/Blob/String
368 change each item in {expr1} to {expr2}
369maparg({name} [, {mode} [, {abbr} [, {dict}]]])
370 String or Dict
371 rhs of mapping {name} in mode {mode}
372mapcheck({name} [, {mode} [, {abbr}]])
373 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100374maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000375mapnew({expr1}, {expr2}) List/Dict/Blob/String
376 like |map()| but creates a new List or
377 Dictionary
378mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
379match({expr}, {pat} [, {start} [, {count}]])
380 Number position where {pat} matches in {expr}
381matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
382 Number highlight {pattern} with {group}
383matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
384 Number highlight positions with {group}
385matcharg({nr}) List arguments of |:match|
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100386matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict})
387 List all the {pat} matches in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000388matchdelete({id} [, {win}]) Number delete match identified by {id}
389matchend({expr}, {pat} [, {start} [, {count}]])
390 Number position where {pat} ends in {expr}
391matchfuzzy({list}, {str} [, {dict}])
392 List fuzzy match {str} in {list}
393matchfuzzypos({list}, {str} [, {dict}])
394 List fuzzy match {str} in {list}
395matchlist({expr}, {pat} [, {start} [, {count}]])
396 List match and submatches of {pat} in {expr}
397matchstr({expr}, {pat} [, {start} [, {count}]])
398 String {count}'th match of {pat} in {expr}
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100399matchstrlist({list}, {pat} [, {dict})
400 List all the {pat} matches in {list}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000401matchstrpos({expr}, {pat} [, {start} [, {count}]])
402 List {count}'th match of {pat} in {expr}
403max({expr}) Number maximum value of items in {expr}
404menu_info({name} [, {mode}]) Dict get menu item information
405min({expr}) Number minimum value of items in {expr}
Bram Moolenaar938ae282023-02-20 20:44:55 +0000406mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000407 Number create directory {name}
Doug Kearns9cd9e752024-04-07 17:42:17 +0200408mode([{expr}]) String current editing mode
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000409mzeval({expr}) any evaluate |MzScheme| expression
410nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
411nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
412or({expr}, {expr}) Number bitwise OR
413pathshorten({expr} [, {len}]) String shorten directory names in a path
414perleval({expr}) any evaluate |Perl| expression
415popup_atcursor({what}, {options}) Number create popup window near the cursor
416popup_beval({what}, {options}) Number create popup window for 'ballooneval'
417popup_clear() none close all popup windows
418popup_close({id} [, {result}]) none close popup window {id}
419popup_create({what}, {options}) Number create a popup window
420popup_dialog({what}, {options}) Number create a popup window used as a dialog
421popup_filter_menu({id}, {key}) Number filter for a menu popup window
422popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100423popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000424popup_findinfo() Number get window ID of info popup window
425popup_findpreview() Number get window ID of preview popup window
426popup_getoptions({id}) Dict get options of popup window {id}
427popup_getpos({id}) Dict get position of popup window {id}
428popup_hide({id}) none hide popup menu {id}
429popup_list() List get a list of window IDs of all popups
430popup_locate({row}, {col}) Number get window ID of popup at position
431popup_menu({what}, {options}) Number create a popup window used as a menu
432popup_move({id}, {options}) none set position of popup window {id}
433popup_notification({what}, {options})
434 Number create a notification popup window
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200435popup_setbuf({id}, {buf}) Bool set the buffer for the popup window {id}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000436popup_setoptions({id}, {options})
437 none set options for popup window {id}
438popup_settext({id}, {text}) none set the text of popup window {id}
439popup_show({id}) none unhide popup window {id}
440pow({x}, {y}) Float {x} to the power of {y}
441prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
442printf({fmt}, {expr1}...) String format text
443prompt_getprompt({buf}) String get prompt text
444prompt_setcallback({buf}, {expr}) none set prompt callback function
445prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
446prompt_setprompt({buf}, {text}) none set prompt text
447prop_add({lnum}, {col}, {props}) none add one text property
448prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
449 none add multiple text properties
450prop_clear({lnum} [, {lnum-end} [, {props}]])
451 none remove all text properties
452prop_find({props} [, {direction}])
453 Dict search for a text property
454prop_list({lnum} [, {props}]) List text properties in {lnum}
455prop_remove({props} [, {lnum} [, {lnum-end}]])
456 Number remove a text property
457prop_type_add({name}, {props}) none define a new property type
458prop_type_change({name}, {props})
459 none change an existing property type
460prop_type_delete({name} [, {props}])
461 none delete a property type
462prop_type_get({name} [, {props}])
463 Dict get property type values
464prop_type_list([{props}]) List get list of property types
465pum_getpos() Dict position and size of pum if visible
466pumvisible() Number whether popup menu is visible
467py3eval({expr}) any evaluate |python3| expression
468pyeval({expr}) any evaluate |Python| expression
469pyxeval({expr}) any evaluate |python_x| expression
470rand([{expr}]) Number get pseudo-random number
471range({expr} [, {max} [, {stride}]])
472 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100473readblob({fname} [, {offset} [, {size}]])
474 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000475readdir({dir} [, {expr} [, {dict}]])
476 List file names in {dir} selected by {expr}
477readdirex({dir} [, {expr} [, {dict}]])
478 List file info in {dir} selected by {expr}
479readfile({fname} [, {type} [, {max}]])
480 List get list of lines from file {fname}
481reduce({object}, {func} [, {initial}])
482 any reduce {object} using {func}
483reg_executing() String get the executing register name
484reg_recording() String get the recording register name
485reltime([{start} [, {end}]]) List get time value
486reltimefloat({time}) Float turn the time value into a Float
487reltimestr({time}) String turn time value into a String
488remote_expr({server}, {string} [, {idvar} [, {timeout}]])
489 String send expression
490remote_foreground({server}) Number bring Vim server to the foreground
491remote_peek({serverid} [, {retvar}])
492 Number check for reply string
493remote_read({serverid} [, {timeout}])
494 String read reply string
495remote_send({server}, {string} [, {idvar}])
496 String send key sequence
497remote_startserver({name}) none become server {name}
498remove({list}, {idx} [, {end}]) any/List
499 remove items {idx}-{end} from {list}
500remove({blob}, {idx} [, {end}]) Number/Blob
501 remove bytes {idx}-{end} from {blob}
502remove({dict}, {key}) any remove entry {key} from {dict}
503rename({from}, {to}) Number rename (move) file from {from} to {to}
Bakudankun375141e2022-09-09 18:46:47 +0100504repeat({expr}, {count}) List/Blob/String
505 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000506resolve({filename}) String get filename a shortcut points to
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +0100507reverse({obj}) List/Blob/String
508 reverse {obj}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000509round({expr}) Float round off {expr}
510rubyeval({expr}) any evaluate |Ruby| expression
511screenattr({row}, {col}) Number attribute at screen position
512screenchar({row}, {col}) Number character at screen position
513screenchars({row}, {col}) List List of characters at screen position
514screencol() Number current cursor column
515screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
516screenrow() Number current cursor row
517screenstring({row}, {col}) String characters at screen position
518search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
519 Number search for {pattern}
520searchcount([{options}]) Dict get or update search stats
521searchdecl({name} [, {global} [, {thisblock}]])
522 Number search for variable declaration
523searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
524 Number search for other end of start/end pair
525searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
526 List search for other end of start/end pair
527searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
528 List search for {pattern}
529server2client({clientid}, {string})
530 Number send reply string
531serverlist() String get a list of available servers
532setbufline({expr}, {lnum}, {text})
533 Number set line {lnum} to {text} in buffer
534 {expr}
535setbufvar({buf}, {varname}, {val})
536 none set {varname} in buffer {buf} to {val}
537setcellwidths({list}) none set character cell width overrides
538setcharpos({expr}, {list}) Number set the {expr} position to {list}
539setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100540setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000541setcmdpos({pos}) Number set cursor position in command-line
542setcursorcharpos({list}) Number move cursor to position in {list}
543setenv({name}, {val}) none set environment variable
544setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
545setline({lnum}, {line}) Number set line {lnum} to {line}
546setloclist({nr}, {list} [, {action}])
547 Number modify location list using {list}
548setloclist({nr}, {list}, {action}, {what})
549 Number modify specific location list props
550setmatches({list} [, {win}]) Number restore a list of matches
551setpos({expr}, {list}) Number set the {expr} position to {list}
552setqflist({list} [, {action}]) Number modify quickfix list using {list}
553setqflist({list}, {action}, {what})
554 Number modify specific quickfix list props
555setreg({n}, {v} [, {opt}]) Number set register to value and type
556settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
557settabwinvar({tabnr}, {winnr}, {varname}, {val})
558 none set {varname} in window {winnr} in tab
559 page {tabnr} to {val}
560settagstack({nr}, {dict} [, {action}])
561 Number modify tag stack using {dict}
562setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
563sha256({string}) String SHA256 checksum of {string}
564shellescape({string} [, {special}])
565 String escape {string} for use as shell
566 command argument
567shiftwidth([{col}]) Number effective value of 'shiftwidth'
568sign_define({name} [, {dict}]) Number define or update a sign
569sign_define({list}) List define or update a list of signs
570sign_getdefined([{name}]) List get a list of defined signs
571sign_getplaced([{buf} [, {dict}]])
572 List get a list of placed signs
573sign_jump({id}, {group}, {buf})
574 Number jump to a sign
575sign_place({id}, {group}, {name}, {buf} [, {dict}])
576 Number place a sign
577sign_placelist({list}) List place a list of signs
578sign_undefine([{name}]) Number undefine a sign
579sign_undefine({list}) List undefine a list of signs
580sign_unplace({group} [, {dict}])
581 Number unplace a sign
582sign_unplacelist({list}) List unplace a list of signs
583simplify({filename}) String simplify filename as much as possible
584sin({expr}) Float sine of {expr}
585sinh({expr}) Float hyperbolic sine of {expr}
586slice({expr}, {start} [, {end}]) String, List or Blob
587 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000588sort({list} [, {how} [, {dict}]])
589 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000590sound_clear() none stop playing all sounds
591sound_playevent({name} [, {callback}])
592 Number play an event sound
593sound_playfile({path} [, {callback}])
594 Number play sound file {path}
595sound_stop({id}) none stop playing sound {id}
596soundfold({word}) String sound-fold {word}
597spellbadword() String badly spelled word at cursor
598spellsuggest({word} [, {max} [, {capital}]])
599 List spelling suggestions
600split({expr} [, {pat} [, {keepempty}]])
601 List make |List| from {pat} separated {expr}
602sqrt({expr}) Float square root of {expr}
603srand([{expr}]) List get seed for |rand()|
604state([{what}]) String current state of Vim
605str2float({expr} [, {quoted}]) Float convert String to Float
606str2list({expr} [, {utf8}]) List convert each character of {expr} to
607 ASCII/UTF-8 value
608str2nr({expr} [, {base} [, {quoted}]])
609 Number convert String to Number
610strcharlen({expr}) Number character length of the String {expr}
611strcharpart({str}, {start} [, {len} [, {skipcc}]])
612 String {len} characters of {str} at
613 character {start}
614strchars({expr} [, {skipcc}]) Number character count of the String {expr}
615strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
616strftime({format} [, {time}]) String format time with a specified format
617strgetchar({str}, {index}) Number get char {index} from {str}
618stridx({haystack}, {needle} [, {start}])
619 Number index of {needle} in {haystack}
620string({expr}) String String representation of {expr} value
621strlen({expr}) Number length of the String {expr}
622strpart({str}, {start} [, {len} [, {chars}]])
623 String {len} bytes/chars of {str} at
624 byte {start}
625strptime({format}, {timestring})
626 Number Convert {timestring} to unix timestamp
627strridx({haystack}, {needle} [, {start}])
628 Number last index of {needle} in {haystack}
629strtrans({expr}) String translate string to make it printable
Christian Brabandt67672ef2023-04-24 21:09:54 +0100630strutf16len({string} [, {countcc}])
631 Number number of UTF-16 code units in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000632strwidth({expr}) Number display cell length of the String {expr}
633submatch({nr} [, {list}]) String or List
634 specific match in ":s" or substitute()
635substitute({expr}, {pat}, {sub}, {flags})
636 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000637swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000638swapinfo({fname}) Dict information about swap file {fname}
639swapname({buf}) String swap file of buffer {buf}
640synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
641synIDattr({synID}, {what} [, {mode}])
642 String attribute {what} of syntax ID {synID}
643synIDtrans({synID}) Number translated syntax ID of {synID}
644synconcealed({lnum}, {col}) List info about concealing
645synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
646system({expr} [, {input}]) String output of shell command/filter {expr}
647systemlist({expr} [, {input}]) List output of shell command/filter {expr}
648tabpagebuflist([{arg}]) List list of buffer numbers in tab page
649tabpagenr([{arg}]) Number number of current or last tab page
650tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
651tagfiles() List tags files used
652taglist({expr} [, {filename}]) List list of tags matching {expr}
653tan({expr}) Float tangent of {expr}
654tanh({expr}) Float hyperbolic tangent of {expr}
655tempname() String name for a temporary file
656term_dumpdiff({filename}, {filename} [, {options}])
657 Number display difference between two dumps
658term_dumpload({filename} [, {options}])
659 Number displaying a screen dump
660term_dumpwrite({buf}, {filename} [, {options}])
661 none dump terminal window contents
662term_getaltscreen({buf}) Number get the alternate screen flag
663term_getansicolors({buf}) List get ANSI palette in GUI color mode
664term_getattr({attr}, {what}) Number get the value of attribute {what}
665term_getcursor({buf}) List get the cursor position of a terminal
666term_getjob({buf}) Job get the job associated with a terminal
667term_getline({buf}, {row}) String get a line of text from a terminal
668term_getscrolled({buf}) Number get the scroll count of a terminal
669term_getsize({buf}) List get the size of a terminal
670term_getstatus({buf}) String get the status of a terminal
671term_gettitle({buf}) String get the title of a terminal
672term_gettty({buf}, [{input}]) String get the tty name of a terminal
673term_list() List get the list of terminal buffers
674term_scrape({buf}, {row}) List get row of a terminal screen
675term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
676term_setansicolors({buf}, {colors})
677 none set ANSI palette in GUI color mode
678term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
679term_setkill({buf}, {how}) none set signal to stop job in terminal
680term_setrestore({buf}, {command}) none set command to restore terminal
681term_setsize({buf}, {rows}, {cols})
682 none set the size of a terminal
683term_start({cmd} [, {options}]) Number open a terminal window and run a job
684term_wait({buf} [, {time}]) Number wait for screen to be updated
685terminalprops() Dict properties of the terminal
686test_alloc_fail({id}, {countdown}, {repeat})
687 none make memory allocation fail
688test_autochdir() none enable 'autochdir' during startup
689test_feedinput({string}) none add key sequence to input buffer
690test_garbagecollect_now() none free memory right now for testing
691test_garbagecollect_soon() none free memory soon for testing
692test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000693test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000694test_ignore_error({expr}) none ignore a specific error
Christopher Plewright20b795e2022-12-20 20:01:58 +0000695test_mswin_event({event}, {args})
696 bool generate MS-Windows event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000697test_null_blob() Blob null value for testing
698test_null_channel() Channel null value for testing
699test_null_dict() Dict null value for testing
700test_null_function() Funcref null value for testing
701test_null_job() Job null value for testing
702test_null_list() List null value for testing
703test_null_partial() Funcref null value for testing
704test_null_string() String null value for testing
705test_option_not_set({name}) none reset flag indicating option was set
706test_override({expr}, {val}) none test with Vim internal overrides
707test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000708test_setmouse({row}, {col}) none set the mouse position for testing
709test_settime({expr}) none set current time for testing
Doug Kearns9cd9e752024-04-07 17:42:17 +0200710test_srand_seed([{seed}]) none set seed for testing srand()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000711test_unknown() any unknown value for testing
712test_void() any void value for testing
713timer_info([{id}]) List information about timers
714timer_pause({id}, {pause}) none pause or unpause a timer
715timer_start({time}, {callback} [, {options}])
716 Number create a timer
717timer_stop({timer}) none stop a timer
718timer_stopall() none stop all timers
719tolower({expr}) String the String {expr} switched to lowercase
720toupper({expr}) String the String {expr} switched to uppercase
721tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
722 to chars in {tostr}
723trim({text} [, {mask} [, {dir}]])
724 String trim characters in {mask} from {text}
725trunc({expr}) Float truncate Float {expr}
726type({expr}) Number type of value {expr}
727typename({expr}) String representation of the type of {expr}
728undofile({name}) String undo file name for {name}
Devin J. Pohly5fee1112023-04-23 20:26:59 -0500729undotree([{buf}]) List undo file tree for buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000730uniq({list} [, {func} [, {dict}]])
731 List remove adjacent duplicates from a list
Christian Brabandt67672ef2023-04-24 21:09:54 +0100732utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
733 Number UTF-16 index of byte {idx} in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000734values({dict}) List values in {dict}
zeertzjq825cf812023-08-17 22:55:25 +0200735virtcol({expr} [, {list} [, {winid}])
736 Number or List
LemonBoy0f7a3e12022-05-26 12:10:37 +0100737 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100738virtcol2col({winid}, {lnum}, {col})
739 Number byte index of a character on screen
Doug Kearns9cd9e752024-04-07 17:42:17 +0200740visualmode([{expr}]) String last visual mode used
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000741wildmenumode() Number whether 'wildmenu' mode is active
742win_execute({id}, {command} [, {silent}])
743 String execute {command} in window {id}
744win_findbuf({bufnr}) List find windows containing {bufnr}
745win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
746win_gettype([{nr}]) String type of window {nr}
747win_gotoid({expr}) Number go to window with ID {expr}
748win_id2tabwin({expr}) List get tab and window nr from window ID
749win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000750win_move_separator({nr}) Number move window vertical separator
751win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000752win_screenpos({nr}) List get screen position of window {nr}
753win_splitmove({nr}, {target} [, {options}])
754 Number move window {nr} to split of {target}
755winbufnr({nr}) Number buffer number of window {nr}
756wincol() Number window column of the cursor
757windowsversion() String MS-Windows OS version
758winheight({nr}) Number height of window {nr}
759winlayout([{tabnr}]) List layout of windows in tab {tabnr}
760winline() Number window line of the cursor
761winnr([{expr}]) Number number of current window
762winrestcmd() String returns command to restore window sizes
763winrestview({dict}) none restore view of current window
764winsaveview() Dict save view of current window
765winwidth({nr}) Number width of window {nr}
766wordcount() Dict get byte/char/word statistics
767writefile({object}, {fname} [, {flags}])
768 Number write |Blob| or |List| of lines to file
769xor({expr}, {expr}) Number bitwise XOR
770
771==============================================================================
7722. Details *builtin-function-details*
773
774Not all functions are here, some have been moved to a help file covering the
775specific functionality.
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200776Return type specifies the type for |Vim9-script|, see |vim9-types|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000777
778abs({expr}) *abs()*
779 Return the absolute value of {expr}. When {expr} evaluates to
780 a |Float| abs() returns a |Float|. When {expr} can be
781 converted to a |Number| abs() returns a |Number|. Otherwise
782 abs() gives an error message and returns -1.
783 Examples: >
784 echo abs(1.456)
785< 1.456 >
786 echo abs(-5.456)
787< 5.456 >
788 echo abs(-4)
789< 4
790
791 Can also be used as a |method|: >
792 Compute()->abs()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200793<
794 Return type: |Number| or |Float| depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000795
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000796
797acos({expr}) *acos()*
798 Return the arc cosine of {expr} measured in radians, as a
799 |Float| in the range of [0, pi].
800 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100801 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000802 Examples: >
803 :echo acos(0)
804< 1.570796 >
805 :echo acos(-0.5)
806< 2.094395
807
808 Can also be used as a |method|: >
809 Compute()->acos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200810<
811 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000812
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000813
814add({object}, {expr}) *add()*
815 Append the item {expr} to |List| or |Blob| {object}. Returns
816 the resulting |List| or |Blob|. Examples: >
817 :let alist = add([1, 2, 3], item)
818 :call add(mylist, "woodstock")
819< Note that when {expr} is a |List| it is appended as a single
820 item. Use |extend()| to concatenate |Lists|.
821 When {object} is a |Blob| then {expr} must be a number.
822 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100823 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000824
825 Can also be used as a |method|: >
826 mylist->add(val1)->add(val2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200827<
828 Return type: list<{type}> (depending on the given |List|) or
829 |Blob|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000830
831
832and({expr}, {expr}) *and()*
833 Bitwise AND on the two arguments. The arguments are converted
834 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100835 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000836 Example: >
837 :let flag = and(bits, 0x80)
838< Can also be used as a |method|: >
839 :let flag = bits->and(0x80)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200840<
841 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000842
843
844append({lnum}, {text}) *append()*
845 When {text} is a |List|: Append each item of the |List| as a
846 text line below line {lnum} in the current buffer.
847 Otherwise append {text} as one text line below line {lnum} in
848 the current buffer.
849 Any type of item is accepted and converted to a String.
850 {lnum} can be zero to insert a line before the first one.
851 {lnum} is used like with |getline()|.
852 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000853 0 for success. When {text} is an empty list zero is returned,
854 no matter the value of {lnum}.
855 In |Vim9| script an invalid argument or negative number
856 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000857 :let failed = append(line('$'), "# THE END")
858 :let failed = append(0, ["Chapter 1", "the beginning"])
859
860< Can also be used as a |method| after a List, the base is
861 passed as the second argument: >
862 mylist->append(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200863<
864 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000865
866
867appendbufline({buf}, {lnum}, {text}) *appendbufline()*
868 Like |append()| but append the text in buffer {buf}.
869
870 This function works only for loaded buffers. First call
871 |bufload()| if needed.
872
873 For the use of {buf}, see |bufname()|.
874
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000875 {lnum} is the line number to append below. Note that using
876 |line()| would use the current buffer, not the one appending
877 to. Use "$" to append at the end of the buffer. Other string
878 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000879
880 On success 0 is returned, on failure 1 is returned.
881 In |Vim9| script an error is given for an invalid {lnum}.
882
883 If {buf} is not a valid buffer or {lnum} is not valid, an
884 error message is given. Example: >
885 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000886< However, when {text} is an empty list then no error is given
887 for an invalid {lnum}, since {lnum} isn't actually used.
888
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000889 Can also be used as a |method| after a List, the base is
890 passed as the second argument: >
891 mylist->appendbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200892<
893 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000894
895
896argc([{winid}]) *argc()*
897 The result is the number of files in the argument list. See
898 |arglist|.
899 If {winid} is not supplied, the argument list of the current
900 window is used.
901 If {winid} is -1, the global argument list is used.
902 Otherwise {winid} specifies the window of which the argument
903 list is used: either the window number or the window ID.
904 Returns -1 if the {winid} argument is invalid.
905
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200906 Return type: |Number|
907
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000908 *argidx()*
909argidx() The result is the current index in the argument list. 0 is
910 the first file. argc() - 1 is the last one. See |arglist|.
911
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200912 Return type: |Number|
913
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000914 *arglistid()*
915arglistid([{winnr} [, {tabnr}]])
916 Return the argument list ID. This is a number which
917 identifies the argument list being used. Zero is used for the
918 global argument list. See |arglist|.
919 Returns -1 if the arguments are invalid.
920
921 Without arguments use the current window.
922 With {winnr} only use this window in the current tab page.
923 With {winnr} and {tabnr} use the window in the specified tab
924 page.
925 {winnr} can be the window number or the |window-ID|.
926
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200927 Return type: |Number|
928
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000929 *argv()*
930argv([{nr} [, {winid}]])
931 The result is the {nr}th file in the argument list. See
932 |arglist|. "argv(0)" is the first one. Example: >
933 :let i = 0
934 :while i < argc()
935 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000936 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000937 : let i = i + 1
938 :endwhile
939< Without the {nr} argument, or when {nr} is -1, a |List| with
940 the whole |arglist| is returned.
941
942 The {winid} argument specifies the window ID, see |argc()|.
943 For the Vim command line arguments see |v:argv|.
944
Bram Moolenaar016188f2022-06-06 20:52:59 +0100945 Returns an empty string if {nr}th argument is not present in
946 the argument list. Returns an empty List if the {winid}
947 argument is invalid.
948
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200949 Return type: |String|
950
951
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000952asin({expr}) *asin()*
953 Return the arc sine of {expr} measured in radians, as a |Float|
954 in the range of [-pi/2, pi/2].
955 {expr} must evaluate to a |Float| or a |Number| in the range
956 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100957 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
958 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000959 Examples: >
960 :echo asin(0.8)
961< 0.927295 >
962 :echo asin(-0.5)
963< -0.523599
964
965 Can also be used as a |method|: >
966 Compute()->asin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200967<
968 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000969
970assert_ functions are documented here: |assert-functions-details|
971
972
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000973atan({expr}) *atan()*
974 Return the principal value of the arc tangent of {expr}, in
975 the range [-pi/2, +pi/2] radians, as a |Float|.
976 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100977 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000978 Examples: >
979 :echo atan(100)
980< 1.560797 >
981 :echo atan(-4.01)
982< -1.326405
983
984 Can also be used as a |method|: >
985 Compute()->atan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200986<
987 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000988
989
990atan2({expr1}, {expr2}) *atan2()*
991 Return the arc tangent of {expr1} / {expr2}, measured in
992 radians, as a |Float| in the range [-pi, pi].
993 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100994 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
995 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000996 Examples: >
997 :echo atan2(-1, 1)
998< -0.785398 >
999 :echo atan2(1, -1)
1000< 2.356194
1001
1002 Can also be used as a |method|: >
1003 Compute()->atan2(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001004<
1005 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001006
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001007
1008autocmd_add({acmds}) *autocmd_add()*
1009 Adds a List of autocmds and autocmd groups.
1010
1011 The {acmds} argument is a List where each item is a Dict with
1012 the following optional items:
1013 bufnr buffer number to add a buffer-local autocmd.
1014 If this item is specified, then the "pattern"
1015 item is ignored.
1016 cmd Ex command to execute for this autocmd event
1017 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001018 This can be either a String with a single
1019 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001020 group autocmd group name. Refer to |autocmd-groups|.
1021 If this group doesn't exist then it is
1022 created. If not specified or empty, then the
1023 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001024 nested boolean flag, set to v:true to add a nested
1025 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +01001026 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001027 which executes only once. Refer to
1028 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001029 pattern autocmd pattern string. Refer to
1030 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001031 present, then this item is ignored. This can
1032 be a String with a single pattern or a List of
1033 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001034 replace boolean flag, set to v:true to remove all the
1035 commands associated with the specified autocmd
1036 event and group and add the {cmd}. This is
1037 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +01001038 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001039
1040 Returns v:true on success and v:false on failure.
1041 Examples: >
1042 " Create a buffer-local autocmd for buffer 5
1043 let acmd = {}
1044 let acmd.group = 'MyGroup'
1045 let acmd.event = 'BufEnter'
1046 let acmd.bufnr = 5
1047 let acmd.cmd = 'call BufEnterFunc()'
1048 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00001049<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001050 Can also be used as a |method|: >
1051 GetAutocmdList()->autocmd_add()
1052<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001053 Return type: |vim9-boolean|
1054
1055
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001056autocmd_delete({acmds}) *autocmd_delete()*
1057 Deletes a List of autocmds and autocmd groups.
1058
1059 The {acmds} argument is a List where each item is a Dict with
1060 the following optional items:
1061 bufnr buffer number to delete a buffer-local autocmd.
1062 If this item is specified, then the "pattern"
1063 item is ignored.
1064 cmd Ex command for this autocmd event
1065 event autocmd event name. Refer to |autocmd-events|.
1066 If '*' then all the autocmd events in this
1067 group are deleted.
1068 group autocmd group name. Refer to |autocmd-groups|.
1069 If not specified or empty, then the default
1070 group is used.
1071 nested set to v:true for a nested autocmd.
1072 Refer to |autocmd-nested|.
1073 once set to v:true for an autocmd which executes
1074 only once. Refer to |autocmd-once|.
1075 pattern autocmd pattern string. Refer to
1076 |autocmd-patterns|. If "bufnr" item is
1077 present, then this item is ignored.
1078
1079 If only {group} is specified in a {acmds} entry and {event},
1080 {pattern} and {cmd} are not specified, then that autocmd group
1081 is deleted.
1082
Bram Moolenaar016188f2022-06-06 20:52:59 +01001083 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001084 Examples: >
1085 " :autocmd! BufLeave *.vim
1086 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1087 call autocmd_delete([acmd]})
1088 " :autocmd! MyGroup1 BufLeave
1089 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1090 call autocmd_delete([acmd])
1091 " :autocmd! MyGroup2 BufEnter *.c
1092 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1093 \ pattern: '*.c'}
1094 " :autocmd! MyGroup2 * *.c
1095 let acmd = #{group: 'MyGroup2', event: '*',
1096 \ pattern: '*.c'}
1097 call autocmd_delete([acmd])
1098 " :autocmd! MyGroup3
1099 let acmd = #{group: 'MyGroup3'}
1100 call autocmd_delete([acmd])
1101<
1102 Can also be used as a |method|: >
1103 GetAutocmdList()->autocmd_delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001104<
1105 Return type: |vim9-boolean|
1106
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001107
1108autocmd_get([{opts}]) *autocmd_get()*
1109 Returns a |List| of autocmds. If {opts} is not supplied, then
1110 returns the autocmds for all the events in all the groups.
1111
1112 The optional {opts} Dict argument supports the following
1113 items:
1114 group Autocmd group name. If specified, returns only
1115 the autocmds defined in this group. If the
1116 specified group doesn't exist, results in an
1117 error message. If set to an empty string,
1118 then the default autocmd group is used.
1119 event Autocmd event name. If specified, returns only
1120 the autocmds defined for this event. If set
1121 to "*", then returns autocmds for all the
1122 events. If the specified event doesn't exist,
1123 results in an error message.
1124 pattern Autocmd pattern. If specified, returns only
1125 the autocmds defined for this pattern.
1126 A combination of the above three times can be supplied in
1127 {opts}.
1128
1129 Each Dict in the returned List contains the following items:
1130 bufnr For buffer-local autocmds, buffer number where
1131 the autocmd is defined.
1132 cmd Command executed for this autocmd.
1133 event Autocmd event name.
1134 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001135 nested Boolean flag, set to v:true for a nested
1136 autocmd. See |autocmd-nested|.
1137 once Boolean flag, set to v:true, if the autocmd
1138 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001139 pattern Autocmd pattern. For a buffer-local
1140 autocmd, this will be of the form "<buffer=n>".
1141 If there are multiple commands for an autocmd event in a
1142 group, then separate items are returned for each command.
1143
Bram Moolenaar016188f2022-06-06 20:52:59 +01001144 Returns an empty List if an autocmd with the specified group
1145 or event or pattern is not found.
1146
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001147 Examples: >
1148 " :autocmd MyGroup
1149 echo autocmd_get(#{group: 'Mygroup'})
1150 " :autocmd G BufUnload
1151 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1152 " :autocmd G * *.ts
1153 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1154 echo autocmd_get(acmd)
1155 " :autocmd Syntax
1156 echo autocmd_get(#{event: 'Syntax'})
1157 " :autocmd G BufEnter *.ts
1158 let acmd = #{group: 'G', event: 'BufEnter',
1159 \ pattern: '*.ts'}
1160 echo autocmd_get(acmd)
1161<
1162 Can also be used as a |method|: >
1163 Getopts()->autocmd_get()
1164<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001165 Return type: list<dict<any>>
1166
1167
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001168balloon_gettext() *balloon_gettext()*
1169 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001170 not used for the List. Returns an empty string if balloon
1171 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001172
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001173 Return type: |String|
1174
1175
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001176balloon_show({expr}) *balloon_show()*
1177 Show {expr} inside the balloon. For the GUI {expr} is used as
1178 a string. For a terminal {expr} can be a list, which contains
1179 the lines of the balloon. If {expr} is not a list it will be
1180 split with |balloon_split()|.
1181 If {expr} is an empty string any existing balloon is removed.
1182
1183 Example: >
1184 func GetBalloonContent()
1185 " ... initiate getting the content
1186 return ''
1187 endfunc
1188 set balloonexpr=GetBalloonContent()
1189
1190 func BalloonCallback(result)
1191 call balloon_show(a:result)
1192 endfunc
1193< Can also be used as a |method|: >
1194 GetText()->balloon_show()
1195<
1196 The intended use is that fetching the content of the balloon
1197 is initiated from 'balloonexpr'. It will invoke an
1198 asynchronous method, in which a callback invokes
1199 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001200 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001201
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001202 When showing a balloon is not possible then nothing happens,
1203 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001204 {only available when compiled with the |+balloon_eval| or
1205 |+balloon_eval_term| feature}
1206
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001207 Return type: |Number|
1208
1209
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001210balloon_split({msg}) *balloon_split()*
1211 Split String {msg} into lines to be displayed in a balloon.
1212 The splits are made for the current window size and optimize
1213 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001214 Returns a |List| with the split lines. Returns an empty List
1215 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001216 Can also be used as a |method|: >
1217 GetText()->balloon_split()->balloon_show()
1218
1219< {only available when compiled with the |+balloon_eval_term|
1220 feature}
1221
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001222 Return type: list<any> or list<string>
1223
Christ van Willegence0ef912024-06-20 23:41:59 +02001224bindtextdomain({package}, {path}) *bindtextdomain()*
1225 Bind a specific {package} to a {path} so that the
1226 |gettext()| function can be used to get language-specific
1227 translations for a package. {path} is the directory name
1228 for the translations. See |package-create|.
1229
1230 Return type: none
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001231
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001232blob2list({blob}) *blob2list()*
1233 Return a List containing the number value of each byte in Blob
1234 {blob}. Examples: >
1235 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1236 blob2list(0z) returns []
1237< Returns an empty List on error. |list2blob()| does the
1238 opposite.
1239
1240 Can also be used as a |method|: >
1241 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001242<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001243 Return type: list<any> or list<number>
1244
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001245 *browse()*
1246browse({save}, {title}, {initdir}, {default})
1247 Put up a file requester. This only works when "has("browse")"
1248 returns |TRUE| (only in some GUI versions).
1249 The input fields are:
1250 {save} when |TRUE|, select file to write
1251 {title} title for the requester
1252 {initdir} directory to start browsing in
1253 {default} default file name
1254 An empty string is returned when the "Cancel" button is hit,
1255 something went wrong, or browsing is not possible.
1256
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001257 Return type: |String|
1258
1259
1260browsedir({title}, {initdir}) *browsedir()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001261 Put up a directory requester. This only works when
1262 "has("browse")" returns |TRUE| (only in some GUI versions).
1263 On systems where a directory browser is not supported a file
1264 browser is used. In that case: select a file in the directory
1265 to be used.
1266 The input fields are:
1267 {title} title for the requester
1268 {initdir} directory to start browsing in
1269 When the "Cancel" button is hit, something went wrong, or
1270 browsing is not possible, an empty string is returned.
1271
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001272 Return type: |String|
1273
1274
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001275bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001276 Add a buffer to the buffer list with name {name} (must be a
1277 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001278 If a buffer for file {name} already exists, return that buffer
1279 number. Otherwise return the buffer number of the newly
1280 created buffer. When {name} is an empty string then a new
1281 buffer is always created.
1282 The buffer will not have 'buflisted' set and not be loaded
1283 yet. To add some text to the buffer use this: >
1284 let bufnr = bufadd('someName')
1285 call bufload(bufnr)
1286 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001287< Returns 0 on error.
1288 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001289 let bufnr = 'somename'->bufadd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001290<
1291 Return type: |Number|
1292
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001293
1294bufexists({buf}) *bufexists()*
1295 The result is a Number, which is |TRUE| if a buffer called
1296 {buf} exists.
1297 If the {buf} argument is a number, buffer numbers are used.
1298 Number zero is the alternate buffer for the current window.
1299
1300 If the {buf} argument is a string it must match a buffer name
1301 exactly. The name can be:
1302 - Relative to the current directory.
1303 - A full path.
1304 - The name of a buffer with 'buftype' set to "nofile".
1305 - A URL name.
1306 Unlisted buffers will be found.
1307 Note that help files are listed by their short name in the
1308 output of |:buffers|, but bufexists() requires using their
1309 long name to be able to find them.
1310 bufexists() may report a buffer exists, but to use the name
1311 with a |:buffer| command you may need to use |expand()|. Esp
1312 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1313 Use "bufexists(0)" to test for the existence of an alternate
1314 file name.
1315
1316 Can also be used as a |method|: >
1317 let exists = 'somename'->bufexists()
1318<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001319 Return type: |Number|
1320
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001321 Obsolete name: buffer_exists(). *buffer_exists()*
1322
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001323
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001324buflisted({buf}) *buflisted()*
1325 The result is a Number, which is |TRUE| if a buffer called
1326 {buf} exists and is listed (has the 'buflisted' option set).
1327 The {buf} argument is used like with |bufexists()|.
1328
1329 Can also be used as a |method|: >
1330 let listed = 'somename'->buflisted()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001331<
1332 Return type: |Number|
1333
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001334
1335bufload({buf}) *bufload()*
1336 Ensure the buffer {buf} is loaded. When the buffer name
1337 refers to an existing file then the file is read. Otherwise
1338 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001339 then there is no change. If the buffer is not related to a
Daniel Steinbergc2bd2052023-08-09 12:10:59 -04001340 file then no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001341 If there is an existing swap file for the file of the buffer,
1342 there will be no dialog, the buffer will be loaded anyway.
1343 The {buf} argument is used like with |bufexists()|.
1344
1345 Can also be used as a |method|: >
1346 eval 'somename'->bufload()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001347<
1348 Return type: |Number|
1349
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001350
1351bufloaded({buf}) *bufloaded()*
1352 The result is a Number, which is |TRUE| if a buffer called
1353 {buf} exists and is loaded (shown in a window or hidden).
1354 The {buf} argument is used like with |bufexists()|.
1355
1356 Can also be used as a |method|: >
1357 let loaded = 'somename'->bufloaded()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001358<
1359 Return type: |Number|
1360
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001361
1362bufname([{buf}]) *bufname()*
1363 The result is the name of a buffer. Mostly as it is displayed
1364 by the `:ls` command, but not using special names such as
1365 "[No Name]".
1366 If {buf} is omitted the current buffer is used.
1367 If {buf} is a Number, that buffer number's name is given.
1368 Number zero is the alternate buffer for the current window.
1369 If {buf} is a String, it is used as a |file-pattern| to match
1370 with the buffer names. This is always done like 'magic' is
1371 set and 'cpoptions' is empty. When there is more than one
1372 match an empty string is returned.
1373 "" or "%" can be used for the current buffer, "#" for the
1374 alternate buffer.
1375 A full match is preferred, otherwise a match at the start, end
1376 or middle of the buffer name is accepted. If you only want a
1377 full match then put "^" at the start and "$" at the end of the
1378 pattern.
1379 Listed buffers are found first. If there is a single match
1380 with a listed buffer, that one is returned. Next unlisted
1381 buffers are searched for.
1382 If the {buf} is a String, but you want to use it as a buffer
1383 number, force it to be a Number by adding zero to it: >
1384 :echo bufname("3" + 0)
1385< Can also be used as a |method|: >
1386 echo bufnr->bufname()
1387
1388< If the buffer doesn't exist, or doesn't have a name, an empty
1389 string is returned. >
1390 bufname("#") alternate buffer name
1391 bufname(3) name of buffer 3
1392 bufname("%") name of current buffer
1393 bufname("file2") name of buffer where "file2" matches.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001394<
1395 Return type: |String|
1396 *buffer_name()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001397 Obsolete name: buffer_name().
1398
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001399
1400bufnr([{buf} [, {create}]]) *bufnr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001401 The result is the number of a buffer, as it is displayed by
1402 the `:ls` command. For the use of {buf}, see |bufname()|
1403 above.
1404
1405 If the buffer doesn't exist, -1 is returned. Or, if the
1406 {create} argument is present and TRUE, a new, unlisted,
1407 buffer is created and its number is returned. Example: >
1408 let newbuf = bufnr('Scratch001', 1)
1409< Using an empty name uses the current buffer. To create a new
1410 buffer with an empty name use |bufadd()|.
1411
1412 bufnr("$") is the last buffer: >
1413 :let last_buffer = bufnr("$")
1414< The result is a Number, which is the highest buffer number
1415 of existing buffers. Note that not all buffers with a smaller
1416 number necessarily exist, because ":bwipeout" may have removed
1417 them. Use bufexists() to test for the existence of a buffer.
1418
1419 Can also be used as a |method|: >
1420 echo bufref->bufnr()
1421<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001422 Return type: |Number|
1423
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001424 Obsolete name: buffer_number(). *buffer_number()*
1425 *last_buffer_nr()*
1426 Obsolete name for bufnr("$"): last_buffer_nr().
1427
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001428
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001429bufwinid({buf}) *bufwinid()*
1430 The result is a Number, which is the |window-ID| of the first
1431 window associated with buffer {buf}. For the use of {buf},
1432 see |bufname()| above. If buffer {buf} doesn't exist or
1433 there is no such window, -1 is returned. Example: >
1434
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001435 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001436<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001437 Only deals with the current tab page. See |win_findbuf()| for
1438 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001439
1440 Can also be used as a |method|: >
1441 FindBuffer()->bufwinid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001442<
1443 Return type: |Number|
1444
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001445
1446bufwinnr({buf}) *bufwinnr()*
1447 Like |bufwinid()| but return the window number instead of the
1448 |window-ID|.
1449 If buffer {buf} doesn't exist or there is no such window, -1
1450 is returned. Example: >
1451
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001452 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001453
1454< The number can be used with |CTRL-W_w| and ":wincmd w"
1455 |:wincmd|.
1456
1457 Can also be used as a |method|: >
1458 FindBuffer()->bufwinnr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001459<
1460 Return type: |Number|
1461
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001462
1463byte2line({byte}) *byte2line()*
1464 Return the line number that contains the character at byte
1465 count {byte} in the current buffer. This includes the
1466 end-of-line character, depending on the 'fileformat' option
1467 for the current buffer. The first character has byte count
1468 one.
1469 Also see |line2byte()|, |go| and |:goto|.
1470
Bram Moolenaar016188f2022-06-06 20:52:59 +01001471 Returns -1 if the {byte} value is invalid.
1472
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001473 Can also be used as a |method|: >
1474 GetOffset()->byte2line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001475<
1476 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001477
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001478 {not available when compiled without the |+byte_offset|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001479 feature}
1480
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001481
Christian Brabandt67672ef2023-04-24 21:09:54 +01001482byteidx({expr}, {nr} [, {utf16}]) *byteidx()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001483 Return byte index of the {nr}'th character in the String
1484 {expr}. Use zero for the first character, it then returns
1485 zero.
1486 If there are no multibyte characters the returned value is
1487 equal to {nr}.
1488 Composing characters are not counted separately, their byte
1489 length is added to the preceding base character. See
1490 |byteidxcomp()| below for counting composing characters
1491 separately.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001492 When {utf16} is present and TRUE, {nr} is used as the UTF-16
1493 index in the String {expr} instead of as the character index.
1494 The UTF-16 index is the index in the string when it is encoded
1495 with 16-bit words. If the specified UTF-16 index is in the
1496 middle of a character (e.g. in a 4-byte character), then the
1497 byte index of the first byte in the character is returned.
1498 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001499 Example : >
1500 echo matchstr(str, ".", byteidx(str, 3))
1501< will display the fourth character. Another way to do the
1502 same: >
1503 let s = strpart(str, byteidx(str, 3))
1504 echo strpart(s, 0, byteidx(s, 1))
1505< Also see |strgetchar()| and |strcharpart()|.
1506
1507 If there are less than {nr} characters -1 is returned.
1508 If there are exactly {nr} characters the length of the string
1509 in bytes is returned.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001510 See |charidx()| and |utf16idx()| for getting the character and
1511 UTF-16 index respectively from the byte index.
1512 Examples: >
1513 echo byteidx('a😊😊', 2) returns 5
1514 echo byteidx('a😊😊', 2, 1) returns 1
1515 echo byteidx('a😊😊', 3, 1) returns 5
1516<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001517 Can also be used as a |method|: >
1518 GetName()->byteidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001519<
1520 Return type: |Number|
1521
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001522
Christian Brabandt67672ef2023-04-24 21:09:54 +01001523byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001524 Like byteidx(), except that a composing character is counted
1525 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001526 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001527 echo byteidx(s, 1)
1528 echo byteidxcomp(s, 1)
1529 echo byteidxcomp(s, 2)
1530< The first and third echo result in 3 ('e' plus composing
1531 character is 3 bytes), the second echo results in 1 ('e' is
1532 one byte).
1533 Only works differently from byteidx() when 'encoding' is set
1534 to a Unicode encoding.
1535
1536 Can also be used as a |method|: >
1537 GetName()->byteidxcomp(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001538<
1539 Return type: |Number|
1540
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001541
1542call({func}, {arglist} [, {dict}]) *call()* *E699*
1543 Call function {func} with the items in |List| {arglist} as
1544 arguments.
1545 {func} can either be a |Funcref| or the name of a function.
1546 a:firstline and a:lastline are set to the cursor line.
1547 Returns the return value of the called function.
1548 {dict} is for functions with the "dict" attribute. It will be
1549 used to set the local variable "self". |Dictionary-function|
1550
1551 Can also be used as a |method|: >
1552 GetFunc()->call([arg, arg], dict)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001553<
1554 Return type: any, depending on {func}
1555
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001556
1557ceil({expr}) *ceil()*
1558 Return the smallest integral value greater than or equal to
1559 {expr} as a |Float| (round up).
1560 {expr} must evaluate to a |Float| or a |Number|.
1561 Examples: >
1562 echo ceil(1.456)
1563< 2.0 >
1564 echo ceil(-5.456)
1565< -5.0 >
1566 echo ceil(4.0)
1567< 4.0
1568
Bram Moolenaar016188f2022-06-06 20:52:59 +01001569 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1570
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001571 Can also be used as a |method|: >
1572 Compute()->ceil()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001573<
1574 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001575
1576
1577ch_ functions are documented here: |channel-functions-details|
1578
1579
1580changenr() *changenr()*
1581 Return the number of the most recent change. This is the same
1582 number as what is displayed with |:undolist| and can be used
1583 with the |:undo| command.
1584 When a change was made it is the number of that change. After
1585 redo it is the number of the redone change. After undo it is
1586 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001587 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001588
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001589 Return type: |Number|
1590
1591
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001592char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001593 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001594 Examples: >
1595 char2nr(" ") returns 32
1596 char2nr("ABC") returns 65
1597< When {utf8} is omitted or zero, the current 'encoding' is used.
1598 Example for "utf-8": >
1599 char2nr("á") returns 225
1600 char2nr("á"[0]) returns 195
1601< When {utf8} is TRUE, always treat as UTF-8 characters.
1602 A combining character is a separate character.
1603 |nr2char()| does the opposite.
1604 To turn a string into a list of character numbers: >
1605 let str = "ABC"
1606 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1607< Result: [65, 66, 67]
1608
Bram Moolenaar016188f2022-06-06 20:52:59 +01001609 Returns 0 if {string} is not a |String|.
1610
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001611 Can also be used as a |method|: >
1612 GetChar()->char2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001613<
1614 Return type: |Number|
1615
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001616
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001617charclass({string}) *charclass()*
1618 Return the character class of the first character in {string}.
1619 The character class is one of:
1620 0 blank
1621 1 punctuation
1622 2 word character
1623 3 emoji
1624 other specific Unicode class
1625 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001626 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001627
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001628 Return type: |Number|
1629
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001630
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001631charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001632 Same as |col()| but returns the character index of the column
1633 position given with {expr} instead of the byte position.
1634
1635 Example:
1636 With the cursor on '세' in line 5 with text "여보세요": >
1637 charcol('.') returns 3
1638 col('.') returns 7
1639
1640< Can also be used as a |method|: >
1641 GetPos()->col()
1642<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001643 Return type: |Number|
1644
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001645 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001646charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001647 Return the character index of the byte at {idx} in {string}.
1648 The index of the first character is zero.
1649 If there are no multibyte characters the returned value is
1650 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001651
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001652 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001653 are not counted separately, their byte length is added to the
1654 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001655 When {countcc} is |TRUE|, then composing characters are
1656 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001657
1658 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1659 index in the String {expr} instead of as the byte index.
1660
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001661 Returns -1 if the arguments are invalid or if there are less
1662 than {idx} bytes. If there are exactly {idx} bytes the length
1663 of the string in characters is returned.
1664
1665 An error is given and -1 is returned if the first argument is
1666 not a string, the second argument is not a number or when the
1667 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001668
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001669 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001670 from the character index and |utf16idx()| for getting the
1671 UTF-16 index from the character index.
1672 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001673 Examples: >
1674 echo charidx('áb́ć', 3) returns 1
1675 echo charidx('áb́ć', 6, 1) returns 4
1676 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001677 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001678<
1679 Can also be used as a |method|: >
1680 GetName()->charidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001681<
1682 Return type: |Number|
1683
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001684
1685chdir({dir}) *chdir()*
1686 Change the current working directory to {dir}. The scope of
1687 the directory change depends on the directory of the current
1688 window:
1689 - If the current window has a window-local directory
1690 (|:lcd|), then changes the window local directory.
1691 - Otherwise, if the current tabpage has a local
1692 directory (|:tcd|) then changes the tabpage local
1693 directory.
1694 - Otherwise, changes the global directory.
1695 {dir} must be a String.
1696 If successful, returns the previous working directory. Pass
1697 this to another chdir() to restore the directory.
1698 On failure, returns an empty string.
1699
1700 Example: >
1701 let save_dir = chdir(newdir)
1702 if save_dir != ""
1703 " ... do some work
1704 call chdir(save_dir)
1705 endif
1706
1707< Can also be used as a |method|: >
1708 GetDir()->chdir()
1709<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001710 Return type: |String|
1711
1712
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001713cindent({lnum}) *cindent()*
1714 Get the amount of indent for line {lnum} according the C
1715 indenting rules, as with 'cindent'.
1716 The indent is counted in spaces, the value of 'tabstop' is
1717 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001718 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001719 See |C-indenting|.
1720
1721 Can also be used as a |method|: >
1722 GetLnum()->cindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001723<
1724 Return type: |Number|
1725
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001726
1727clearmatches([{win}]) *clearmatches()*
1728 Clears all matches previously defined for the current window
1729 by |matchadd()| and the |:match| commands.
1730 If {win} is specified, use the window with this number or
1731 window ID instead of the current window.
1732
1733 Can also be used as a |method|: >
1734 GetWin()->clearmatches()
1735<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001736 Return type: |Number|
1737
1738
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001739col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001740 The result is a Number, which is the byte index of the column
zeertzjq02f3eba2024-06-12 20:45:24 +02001741 position given with {expr}.
1742 For accepted positions see |getpos()|.
zeertzjqd353d272024-06-13 23:00:25 +08001743 When {expr} is "$", it means the end of the cursor line, so
1744 the result is the number of bytes in the cursor line plus one.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001745 Additionally {expr} can be [lnum, col]: a |List| with the line
1746 and column number. Most useful when the column is "$", to get
1747 the last column of a specific line. When "lnum" or "col" is
1748 out of range then col() returns zero.
zeertzjq02f3eba2024-06-12 20:45:24 +02001749
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001750 With the optional {winid} argument the values are obtained for
1751 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02001752
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001753 To get the line number use |line()|. To get both use
1754 |getpos()|.
1755 For the screen column position use |virtcol()|. For the
1756 character position use |charcol()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02001757
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001758 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +02001759
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001760 Examples: >
1761 col(".") column of cursor
1762 col("$") length of cursor line plus one
1763 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001764 col("'" .. markname) column of mark markname
zeertzjq02f3eba2024-06-12 20:45:24 +02001765<
1766 The first column is 1. Returns 0 if {expr} is invalid or when
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001767 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001768 For an uppercase mark the column may actually be in another
1769 buffer.
1770 For the cursor position, when 'virtualedit' is active, the
1771 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001772 line. Also, when using a <Cmd> mapping the cursor isn't
1773 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001774 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001775
1776< Can also be used as a |method|: >
1777 GetPos()->col()
1778<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001779 Return type: |Number|
1780
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001781
1782complete({startcol}, {matches}) *complete()* *E785*
1783 Set the matches for Insert mode completion.
1784 Can only be used in Insert mode. You need to use a mapping
1785 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1786 or with an expression mapping.
1787 {startcol} is the byte offset in the line where the completed
1788 text start. The text up to the cursor is the original text
1789 that will be replaced by the matches. Use col('.') for an
1790 empty string. "col('.') - 1" will replace one character by a
1791 match.
1792 {matches} must be a |List|. Each |List| item is one match.
1793 See |complete-items| for the kind of items that are possible.
1794 "longest" in 'completeopt' is ignored.
1795 Note that the after calling this function you need to avoid
1796 inserting anything that would cause completion to stop.
1797 The match can be selected with CTRL-N and CTRL-P as usual with
1798 Insert mode completion. The popup menu will appear if
1799 specified, see |ins-completion-menu|.
1800 Example: >
1801 inoremap <F5> <C-R>=ListMonths()<CR>
1802
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001803 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001804 call complete(col('.'), ['January', 'February', 'March',
1805 \ 'April', 'May', 'June', 'July', 'August', 'September',
1806 \ 'October', 'November', 'December'])
1807 return ''
1808 endfunc
1809< This isn't very useful, but it shows how it works. Note that
1810 an empty string is returned to avoid a zero being inserted.
1811
1812 Can also be used as a |method|, the base is passed as the
1813 second argument: >
1814 GetMatches()->complete(col('.'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001815<
1816 Return type: |Number|
1817
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001818
1819complete_add({expr}) *complete_add()*
1820 Add {expr} to the list of matches. Only to be used by the
1821 function specified with the 'completefunc' option.
1822 Returns 0 for failure (empty string or out of memory),
1823 1 when the match was added, 2 when the match was already in
1824 the list.
1825 See |complete-functions| for an explanation of {expr}. It is
1826 the same as one item in the list that 'omnifunc' would return.
1827
1828 Can also be used as a |method|: >
1829 GetMoreMatches()->complete_add()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001830<
1831 Return type: |Number|
1832
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001833
1834complete_check() *complete_check()*
1835 Check for a key typed while looking for completion matches.
1836 This is to be used when looking for matches takes some time.
1837 Returns |TRUE| when searching for matches is to be aborted,
1838 zero otherwise.
1839 Only to be used by the function specified with the
1840 'completefunc' option.
1841
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001842 Return type: |Number|
1843
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001844
1845complete_info([{what}]) *complete_info()*
1846 Returns a |Dictionary| with information about Insert mode
1847 completion. See |ins-completion|.
1848 The items are:
1849 mode Current completion mode name string.
1850 See |complete_info_mode| for the values.
1851 pum_visible |TRUE| if popup menu is visible.
1852 See |pumvisible()|.
1853 items List of completion matches. Each item is a
1854 dictionary containing the entries "word",
1855 "abbr", "menu", "kind", "info" and "user_data".
1856 See |complete-items|.
1857 selected Selected item index. First index is zero.
1858 Index is -1 if no item is selected (showing
1859 typed text only, or the last completion after
1860 no item is selected when using the <Up> or
1861 <Down> keys)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01001862 inserted Inserted string. [NOT IMPLEMENTED YET]
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001863
1864 *complete_info_mode*
1865 mode values are:
1866 "" Not in completion mode
1867 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1868 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1869 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1870 |i_CTRL-X_CTRL-Y|
1871 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1872 "files" File names |i_CTRL-X_CTRL-F|
1873 "tags" Tags |i_CTRL-X_CTRL-]|
1874 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1875 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1876 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1877 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1878 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1879 "function" User defined completion |i_CTRL-X_CTRL-U|
1880 "omni" Omni completion |i_CTRL-X_CTRL-O|
1881 "spell" Spelling suggestions |i_CTRL-X_s|
1882 "eval" |complete()| completion
1883 "unknown" Other internal modes
1884
1885 If the optional {what} list argument is supplied, then only
1886 the items listed in {what} are returned. Unsupported items in
1887 {what} are silently ignored.
1888
1889 To get the position and size of the popup menu, see
1890 |pum_getpos()|. It's also available in |v:event| during the
1891 |CompleteChanged| event.
1892
Bram Moolenaar016188f2022-06-06 20:52:59 +01001893 Returns an empty |Dictionary| on error.
1894
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001895 Examples: >
1896 " Get all items
1897 call complete_info()
1898 " Get only 'mode'
1899 call complete_info(['mode'])
1900 " Get only 'mode' and 'pum_visible'
1901 call complete_info(['mode', 'pum_visible'])
1902
1903< Can also be used as a |method|: >
1904 GetItems()->complete_info()
1905<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001906 Return type: dict<any>
1907
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001908 *confirm()*
1909confirm({msg} [, {choices} [, {default} [, {type}]]])
1910 confirm() offers the user a dialog, from which a choice can be
1911 made. It returns the number of the choice. For the first
1912 choice this is 1.
1913 Note: confirm() is only supported when compiled with dialog
glepnirdf461152024-04-04 22:23:29 +02001914 support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001915
1916 {msg} is displayed in a |dialog| with {choices} as the
1917 alternatives. When {choices} is missing or empty, "&OK" is
1918 used (and translated).
1919 {msg} is a String, use '\n' to include a newline. Only on
1920 some systems the string is wrapped when it doesn't fit.
1921
1922 {choices} is a String, with the individual choices separated
1923 by '\n', e.g. >
1924 confirm("Save changes?", "&Yes\n&No\n&Cancel")
1925< The letter after the '&' is the shortcut key for that choice.
1926 Thus you can type 'c' to select "Cancel". The shortcut does
1927 not need to be the first letter: >
1928 confirm("file has been modified", "&Save\nSave &All")
1929< For the console, the first letter of each choice is used as
1930 the default shortcut key. Case is ignored.
1931
1932 The optional {default} argument is the number of the choice
1933 that is made if the user hits <CR>. Use 1 to make the first
1934 choice the default one. Use 0 to not set a default. If
1935 {default} is omitted, 1 is used.
1936
1937 The optional {type} String argument gives the type of dialog.
1938 This is only used for the icon of the GTK, Mac, Motif and
1939 Win32 GUI. It can be one of these values: "Error",
1940 "Question", "Info", "Warning" or "Generic". Only the first
1941 character is relevant. When {type} is omitted, "Generic" is
1942 used.
1943
1944 If the user aborts the dialog by pressing <Esc>, CTRL-C,
1945 or another valid interrupt key, confirm() returns 0.
1946
1947 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01001948 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001949 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01001950 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001951 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001952 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001953 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001954 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001955 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01001956 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001957< In a GUI dialog, buttons are used. The layout of the buttons
1958 depends on the 'v' flag in 'guioptions'. If it is included,
1959 the buttons are always put vertically. Otherwise, confirm()
1960 tries to put the buttons in one horizontal line. If they
1961 don't fit, a vertical layout is used anyway. For some systems
1962 the horizontal layout is always used.
1963
1964 Can also be used as a |method|in: >
1965 BuildMessage()->confirm("&Yes\n&No")
1966<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001967 Return type: |Number|
1968
1969
1970copy({expr}) *copy()*
1971 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001972 different from using {expr} directly.
1973 When {expr} is a |List| a shallow copy is created. This means
1974 that the original |List| can be changed without changing the
1975 copy, and vice versa. But the items are identical, thus
1976 changing an item changes the contents of both |Lists|.
1977 A |Dictionary| is copied in a similar way as a |List|.
1978 Also see |deepcopy()|.
1979 Can also be used as a |method|: >
1980 mylist->copy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001981<
1982 Return type: any, depending on {expr}
1983
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001984
1985cos({expr}) *cos()*
1986 Return the cosine of {expr}, measured in radians, as a |Float|.
1987 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001988 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001989 Examples: >
1990 :echo cos(100)
1991< 0.862319 >
1992 :echo cos(-4.01)
1993< -0.646043
1994
1995 Can also be used as a |method|: >
1996 Compute()->cos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001997<
1998 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001999
2000
2001cosh({expr}) *cosh()*
2002 Return the hyperbolic cosine of {expr} as a |Float| in the range
2003 [1, inf].
2004 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002005 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002006 Examples: >
2007 :echo cosh(0.5)
2008< 1.127626 >
2009 :echo cosh(-0.5)
2010< -1.127626
2011
2012 Can also be used as a |method|: >
2013 Compute()->cosh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002014<
2015 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002016
2017
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07002018count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002019 Return the number of times an item with value {expr} appears
2020 in |String|, |List| or |Dictionary| {comp}.
2021
2022 If {start} is given then start with the item with this index.
2023 {start} can only be used with a |List|.
2024
2025 When {ic} is given and it's |TRUE| then case is ignored.
2026
2027 When {comp} is a string then the number of not overlapping
2028 occurrences of {expr} is returned. Zero is returned when
2029 {expr} is an empty string.
2030
2031 Can also be used as a |method|: >
2032 mylist->count(val)
2033<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002034 Return type: |Number|
2035
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002036 *cscope_connection()*
2037cscope_connection([{num} , {dbpath} [, {prepend}]])
2038 Checks for the existence of a |cscope| connection. If no
2039 parameters are specified, then the function returns:
2040 0, if cscope was not available (not compiled in), or
2041 if there are no cscope connections;
2042 1, if there is at least one cscope connection.
2043
2044 If parameters are specified, then the value of {num}
2045 determines how existence of a cscope connection is checked:
2046
2047 {num} Description of existence check
2048 ----- ------------------------------
2049 0 Same as no parameters (e.g., "cscope_connection()").
2050 1 Ignore {prepend}, and use partial string matches for
2051 {dbpath}.
2052 2 Ignore {prepend}, and use exact string matches for
2053 {dbpath}.
2054 3 Use {prepend}, use partial string matches for both
2055 {dbpath} and {prepend}.
2056 4 Use {prepend}, use exact string matches for both
2057 {dbpath} and {prepend}.
2058
2059 Note: All string comparisons are case sensitive!
2060
2061 Examples. Suppose we had the following (from ":cs show"): >
2062
2063 # pid database name prepend path
2064 0 27664 cscope.out /usr/local
2065<
2066 Invocation Return Val ~
2067 ---------- ---------- >
2068 cscope_connection() 1
2069 cscope_connection(1, "out") 1
2070 cscope_connection(2, "out") 0
2071 cscope_connection(3, "out") 0
2072 cscope_connection(3, "out", "local") 1
2073 cscope_connection(4, "out") 0
2074 cscope_connection(4, "out", "local") 0
2075 cscope_connection(4, "cscope.out", "/usr/local") 1
2076<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002077 Return type: |Number|
2078
2079
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002080cursor({lnum}, {col} [, {off}]) *cursor()*
2081cursor({list})
2082 Positions the cursor at the column (byte count) {col} in the
2083 line {lnum}. The first column is one.
2084
2085 When there is one argument {list} this is used as a |List|
2086 with two, three or four item:
2087 [{lnum}, {col}]
2088 [{lnum}, {col}, {off}]
2089 [{lnum}, {col}, {off}, {curswant}]
2090 This is like the return value of |getpos()| or |getcurpos()|,
2091 but without the first item.
2092
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01002093 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002094 |setcursorcharpos()|.
2095
2096 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01002097 {lnum} is used like with |getline()|, except that if {lnum} is
2098 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002099 If {lnum} is greater than the number of lines in the buffer,
2100 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002101 If {col} is greater than the number of bytes in the line,
2102 the cursor will be positioned at the last character in the
2103 line.
2104 If {col} is zero, the cursor will stay in the current column.
2105 If {curswant} is given it is used to set the preferred column
2106 for vertical movement. Otherwise {col} is used.
2107
2108 When 'virtualedit' is used {off} specifies the offset in
2109 screen columns from the start of the character. E.g., a
2110 position within a <Tab> or after the last character.
2111 Returns 0 when the position could be set, -1 otherwise.
2112
2113 Can also be used as a |method|: >
2114 GetCursorPos()->cursor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002115<
2116 Return type: |Number|
2117
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002118
2119debugbreak({pid}) *debugbreak()*
2120 Specifically used to interrupt a program being debugged. It
2121 will cause process {pid} to get a SIGTRAP. Behavior for other
2122 processes is undefined. See |terminal-debugger|.
2123 {only available on MS-Windows}
2124
Bram Moolenaar016188f2022-06-06 20:52:59 +01002125 Returns |TRUE| if successfully interrupted the program.
2126 Otherwise returns |FALSE|.
2127
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002128 Can also be used as a |method|: >
2129 GetPid()->debugbreak()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002130<
2131 Return type: |Number|
2132
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002133
2134deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
2135 Make a copy of {expr}. For Numbers and Strings this isn't
2136 different from using {expr} directly.
2137 When {expr} is a |List| a full copy is created. This means
2138 that the original |List| can be changed without changing the
2139 copy, and vice versa. When an item is a |List| or
2140 |Dictionary|, a copy for it is made, recursively. Thus
2141 changing an item in the copy does not change the contents of
2142 the original |List|.
2143 A |Dictionary| is copied in a similar way as a |List|.
2144
2145 When {noref} is omitted or zero a contained |List| or
2146 |Dictionary| is only copied once. All references point to
2147 this single copy. With {noref} set to 1 every occurrence of a
2148 |List| or |Dictionary| results in a new copy. This also means
2149 that a cyclic reference causes deepcopy() to fail.
2150 *E724*
2151 Nesting is possible up to 100 levels. When there is an item
2152 that refers back to a higher level making a deep copy with
2153 {noref} set to 1 will fail.
2154 Also see |copy()|.
2155
2156 Can also be used as a |method|: >
2157 GetObject()->deepcopy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002158<
2159 Return type: any, depending on {expr}
2160
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002161
2162delete({fname} [, {flags}]) *delete()*
2163 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002164 name {fname}.
2165
2166 This also works when {fname} is a symbolic link. The symbolic
2167 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002168
2169 When {flags} is "d": Deletes the directory by the name
2170 {fname}. This fails when directory {fname} is not empty.
2171
2172 When {flags} is "rf": Deletes the directory by the name
2173 {fname} and everything in it, recursively. BE CAREFUL!
2174 Note: on MS-Windows it is not possible to delete a directory
2175 that is being used.
2176
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002177 The result is a Number, which is 0/false if the delete
2178 operation was successful and -1/true when the deletion failed
2179 or partly failed.
2180
2181 Use |remove()| to delete an item from a |List|.
2182 To delete a line from the buffer use |:delete| or
2183 |deletebufline()|.
2184
2185 Can also be used as a |method|: >
2186 GetName()->delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002187<
2188 Return type: |Number|
2189
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002190
2191deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2192 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2193 If {last} is omitted then delete line {first} only.
2194 On success 0 is returned, on failure 1 is returned.
2195
2196 This function works only for loaded buffers. First call
2197 |bufload()| if needed.
2198
2199 For the use of {buf}, see |bufname()| above.
2200
2201 {first} and {last} are used like with |getline()|. Note that
2202 when using |line()| this refers to the current buffer. Use "$"
2203 to refer to the last line in buffer {buf}.
2204
2205 Can also be used as a |method|: >
2206 GetBuffer()->deletebufline(1)
2207<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002208 Return type: |Number|
2209
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002210 *did_filetype()*
2211did_filetype() Returns |TRUE| when autocommands are being executed and the
2212 FileType event has been triggered at least once. Can be used
2213 to avoid triggering the FileType event again in the scripts
2214 that detect the file type. |FileType|
2215 Returns |FALSE| when `:setf FALLBACK` was used.
2216 When editing another file, the counter is reset, thus this
2217 really checks if the FileType event has been triggered for the
2218 current buffer. This allows an autocommand that starts
2219 editing another buffer to set 'filetype' and load a syntax
2220 file.
2221
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002222 Return type: |Number|
2223
2224
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002225diff({fromlist}, {tolist} [, {options}]) *diff()*
2226 Returns a String or a List containing the diff between the
2227 strings in {fromlist} and {tolist}. Uses the Vim internal
2228 diff library to compute the diff.
2229
2230 *E106*
2231 The optional "output" item in {options} specifies the returned
2232 diff format. The following values are supported:
2233 indices Return a List of the starting and ending
2234 indices and a count of the strings in each
2235 diff hunk.
2236 unified Return the unified diff output as a String.
2237 This is the default.
2238
2239 If the "output" item in {options} is "indices", then a List is
2240 returned. Each List item contains a Dict with the following
2241 items for each diff hunk:
2242 from_idx start index in {fromlist} for this diff hunk.
2243 from_count number of strings in {fromlist} that are
2244 added/removed/modified in this diff hunk.
2245 to_idx start index in {tolist} for this diff hunk.
2246 to_count number of strings in {tolist} that are
2247 added/removed/modified in this diff hunk.
2248
2249 The {options} Dict argument also specifies diff options
2250 (similar to 'diffopt') and supports the following items:
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002251 algorithm Dict specifying the diff algorithm to
2252 use. Supported boolean items are
2253 "myers", "minimal", "patience" and
2254 "histogram".
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002255 context diff context length. Default is 0.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002256 iblank ignore changes where lines are all
2257 blank.
2258 icase ignore changes in case of text.
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002259 indent-heuristic use the indent heuristic for the
2260 internal diff library.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002261 iwhite ignore changes in amount of white
2262 space.
2263 iwhiteall ignore all white space changes.
2264 iwhiteeol ignore white space changes at end of
2265 line.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002266 For more information about these options, refer to 'diffopt'.
2267
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002268 To compute the unified diff, all the items in {fromlist} are
2269 concatenated into a string using a newline separator and the
2270 same for {tolist}. The unified diff output uses line numbers.
2271
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002272 Returns an empty List or String if {fromlist} and {tolist} are
2273 identical.
2274
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002275 Examples: >
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002276 :echo diff(['abc'], ['xxx'])
2277 @@ -1 +1 @@
2278 -abc
2279 +xxx
2280
2281 :echo diff(['abc'], ['xxx'], {'output': 'indices'})
2282 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}]
2283 :echo diff(readfile('oldfile'), readfile('newfile'))
2284 :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$'))
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002285<
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002286 For more examples, refer to |diff-func-examples|
2287
2288 Can also be used as a |method|: >
2289 GetFromList->diff(to_list)
2290<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002291 Return type: |String| or list<dict<number>> or list<any>
2292 depending on {options}
2293
2294
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002295diff_filler({lnum}) *diff_filler()*
2296 Returns the number of filler lines above line {lnum}.
2297 These are the lines that were inserted at this point in
2298 another diff'ed window. These filler lines are shown in the
2299 display but don't exist in the buffer.
2300 {lnum} is used like with |getline()|. Thus "." is the current
2301 line, "'m" mark m, etc.
2302 Returns 0 if the current window is not in diff mode.
2303
2304 Can also be used as a |method|: >
2305 GetLnum()->diff_filler()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002306<
2307 Return type: |Number|
2308
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002309
2310diff_hlID({lnum}, {col}) *diff_hlID()*
2311 Returns the highlight ID for diff mode at line {lnum} column
2312 {col} (byte index). When the current line does not have a
2313 diff change zero is returned.
2314 {lnum} is used like with |getline()|. Thus "." is the current
2315 line, "'m" mark m, etc.
2316 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2317 line.
2318 The highlight ID can be used with |synIDattr()| to obtain
2319 syntax information about the highlighting.
2320
2321 Can also be used as a |method|: >
2322 GetLnum()->diff_hlID(col)
2323<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002324 Return type: |Number|
2325
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002326
2327digraph_get({chars}) *digraph_get()* *E1214*
2328 Return the digraph of {chars}. This should be a string with
2329 exactly two characters. If {chars} are not just two
2330 characters, or the digraph of {chars} does not exist, an error
2331 is given and an empty string is returned.
2332
2333 The character will be converted from Unicode to 'encoding'
2334 when needed. This does require the conversion to be
2335 available, it might fail.
2336
2337 Also see |digraph_getlist()|.
2338
2339 Examples: >
2340 " Get a built-in digraph
2341 :echo digraph_get('00') " Returns '∞'
2342
2343 " Get a user-defined digraph
2344 :call digraph_set('aa', 'あ')
2345 :echo digraph_get('aa') " Returns 'あ'
2346<
2347 Can also be used as a |method|: >
2348 GetChars()->digraph_get()
2349<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002350 Return type: |String|
2351
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002352 This function works only when compiled with the |+digraphs|
2353 feature. If this feature is disabled, this function will
2354 display an error message.
2355
2356
2357digraph_getlist([{listall}]) *digraph_getlist()*
2358 Return a list of digraphs. If the {listall} argument is given
2359 and it is TRUE, return all digraphs, including the default
2360 digraphs. Otherwise, return only user-defined digraphs.
2361
2362 The characters will be converted from Unicode to 'encoding'
2363 when needed. This does require the conservation to be
2364 available, it might fail.
2365
2366 Also see |digraph_get()|.
2367
2368 Examples: >
2369 " Get user-defined digraphs
2370 :echo digraph_getlist()
2371
2372 " Get all the digraphs, including default digraphs
2373 :echo digraph_getlist(1)
2374<
2375 Can also be used as a |method|: >
2376 GetNumber()->digraph_getlist()
2377<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002378 Return type: list<list<string>>
2379
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002380 This function works only when compiled with the |+digraphs|
2381 feature. If this feature is disabled, this function will
2382 display an error message.
2383
2384
Bram Moolenaara2baa732022-02-04 16:09:54 +00002385digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002386 Add digraph {chars} to the list. {chars} must be a string
2387 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002388 encoded character. *E1215*
2389 Be careful, composing characters are NOT ignored. This
2390 function is similar to |:digraphs| command, but useful to add
2391 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002392
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002393 The function returns v:true if |digraph| is registered. If
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002394 this fails an error message is given and v:false is returned.
2395
2396 If you want to define multiple digraphs at once, you can use
2397 |digraph_setlist()|.
2398
2399 Example: >
2400 call digraph_set(' ', 'あ')
2401<
2402 Can be used as a |method|: >
2403 GetString()->digraph_set('あ')
2404<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002405 Return type: |vim9-boolean|
2406
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002407 This function works only when compiled with the |+digraphs|
2408 feature. If this feature is disabled, this function will
2409 display an error message.
2410
2411
2412digraph_setlist({digraphlist}) *digraph_setlist()*
2413 Similar to |digraph_set()| but this function can add multiple
2414 digraphs at once. {digraphlist} is a list composed of lists,
2415 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002416 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002417 Example: >
2418 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2419<
2420 It is similar to the following: >
2421 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2422 call digraph_set(chars, digraph)
2423 endfor
2424< Except that the function returns after the first error,
2425 following digraphs will not be added.
2426
2427 Can be used as a |method|: >
2428 GetList()->digraph_setlist()
2429<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002430 Return type: |vim9-boolean|
2431
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002432 This function works only when compiled with the |+digraphs|
2433 feature. If this feature is disabled, this function will
2434 display an error message.
2435
2436
2437echoraw({string}) *echoraw()*
2438 Output {string} as-is, including unprintable characters.
2439 This can be used to output a terminal code. For example, to
2440 disable modifyOtherKeys: >
2441 call echoraw(&t_TE)
2442< and to enable it again: >
2443 call echoraw(&t_TI)
2444< Use with care, you can mess up the terminal this way.
2445
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002446 Return type: |Number|
2447
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002448
2449empty({expr}) *empty()*
2450 Return the Number 1 if {expr} is empty, zero otherwise.
2451 - A |List| or |Dictionary| is empty when it does not have any
2452 items.
2453 - A |String| is empty when its length is zero.
2454 - A |Number| and |Float| are empty when their value is zero.
2455 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2456 - A |Job| is empty when it failed to start.
2457 - A |Channel| is empty when it is closed.
2458 - A |Blob| is empty when its length is zero.
mityu7f0bba22024-03-29 10:14:41 +01002459 - An |Object| is empty, when the empty() method in the object
2460 (if present) returns true. |object-empty()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002461
2462 For a long |List| this is much faster than comparing the
2463 length with zero.
2464
2465 Can also be used as a |method|: >
2466 mylist->empty()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002467<
2468 Return type: |Number|
2469
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002470
2471environ() *environ()*
2472 Return all of environment variables as dictionary. You can
2473 check if an environment variable exists like this: >
2474 :echo has_key(environ(), 'HOME')
2475< Note that the variable name may be CamelCase; to ignore case
2476 use this: >
2477 :echo index(keys(environ()), 'HOME', 0, 1) != -1
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002478<
2479 Return type: dict<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002480
Bram Moolenaar416bd912023-07-07 23:19:18 +01002481
2482err_teapot([{expr}]) *err_teapot()*
2483 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002484 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002485 If {expr} is present and it is TRUE error 503 is given,
2486 indicating that coffee is temporarily not available.
2487 If {expr} is present it must be a String.
2488
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002489 Return type: |Number|
2490
Bram Moolenaar416bd912023-07-07 23:19:18 +01002491
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002492escape({string}, {chars}) *escape()*
2493 Escape the characters in {chars} that occur in {string} with a
2494 backslash. Example: >
2495 :echo escape('c:\program files\vim', ' \')
2496< results in: >
2497 c:\\program\ files\\vim
2498< Also see |shellescape()| and |fnameescape()|.
2499
2500 Can also be used as a |method|: >
2501 GetText()->escape(' \')
2502<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002503 Return type: |String|
2504
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002505 *eval()*
2506eval({string}) Evaluate {string} and return the result. Especially useful to
2507 turn the result of |string()| back into the original value.
2508 This works for Numbers, Floats, Strings, Blobs and composites
2509 of them. Also works for |Funcref|s that refer to existing
Aliaksei Budavei95740222024-04-04 23:05:33 +03002510 functions. In |Vim9| script, it can be used to obtain |enum|
2511 values from their fully qualified names.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002512
2513 Can also be used as a |method|: >
2514 argv->join()->eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002515<
2516 Return type: any, depending on {string}
2517
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002518
2519eventhandler() *eventhandler()*
2520 Returns 1 when inside an event handler. That is that Vim got
2521 interrupted while waiting for the user to type a character,
2522 e.g., when dropping a file on Vim. This means interactive
2523 commands cannot be used. Otherwise zero is returned.
2524
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002525 Return type: |Number|
2526
2527
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002528executable({expr}) *executable()*
2529 This function checks if an executable with the name {expr}
2530 exists. {expr} must be the name of the program without any
2531 arguments.
2532 executable() uses the value of $PATH and/or the normal
2533 searchpath for programs. *PATHEXT*
2534 On MS-Windows the ".exe", ".bat", etc. can optionally be
2535 included. Then the extensions in $PATHEXT are tried. Thus if
2536 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2537 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2538 by itself can be used in $PATHEXT to try using the name
2539 without an extension. When 'shell' looks like a Unix shell,
2540 then the name is also tried without adding an extension.
2541 On MS-Windows it only checks if the file exists and is not a
2542 directory, not if it's really executable.
2543 On MS-Windows an executable in the same directory as Vim is
Yasuhiro Matsumoto05cf63e2022-05-03 11:02:28 +01002544 normally found. Since this directory is added to $PATH it
2545 should also work to execute it |win32-PATH|. This can be
2546 disabled by setting the $NoDefaultCurrentDirectoryInExePath
2547 environment variable. *NoDefaultCurrentDirectoryInExePath*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002548 The result is a Number:
2549 1 exists
2550 0 does not exist
2551 -1 not implemented on this system
2552 |exepath()| can be used to get the full path of an executable.
2553
2554 Can also be used as a |method|: >
2555 GetCommand()->executable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002556<
2557 Return type: |Number|
2558
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002559
2560execute({command} [, {silent}]) *execute()*
2561 Execute an Ex command or commands and return the output as a
2562 string.
2563 {command} can be a string or a List. In case of a List the
2564 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002565 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002566 redir => var
2567 {command}
2568 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002569< Except that line continuation in {command} is not recognized.
2570
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002571 The optional {silent} argument can have these values:
2572 "" no `:silent` used
2573 "silent" `:silent` used
2574 "silent!" `:silent!` used
2575 The default is "silent". Note that with "silent!", unlike
2576 `:redir`, error messages are dropped. When using an external
2577 command the screen may be messed up, use `system()` instead.
2578 *E930*
2579 It is not possible to use `:redir` anywhere in {command}.
2580
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002581 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002582 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002583
2584< To execute a command in another window than the current one
2585 use `win_execute()`.
2586
2587 When used recursively the output of the recursive call is not
2588 included in the output of the higher level call.
2589
2590 Can also be used as a |method|: >
2591 GetCommand()->execute()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002592<
Marius Gedminasc98bfb92024-06-19 19:59:23 +02002593 Return type: |String|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002594
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002595
2596exepath({expr}) *exepath()*
2597 If {expr} is an executable and is either an absolute path, a
2598 relative path or found in $PATH, return the full path.
2599 Note that the current directory is used when {expr} starts
2600 with "./", which may be a problem for Vim: >
2601 echo exepath(v:progpath)
2602< If {expr} cannot be found in $PATH or is not executable then
2603 an empty string is returned.
2604
2605 Can also be used as a |method|: >
2606 GetCommand()->exepath()
2607<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002608 Return type: |String|
2609
2610
2611exists({expr}) *exists()*
2612 The result is a Number, which is |TRUE| if {expr} is defined,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002613 zero otherwise.
2614
2615 Note: In a compiled |:def| function the evaluation is done at
2616 runtime. Use `exists_compiled()` to evaluate the expression
2617 at compile time.
2618
2619 For checking for a supported feature use |has()|.
2620 For checking if a file exists use |filereadable()|.
2621
2622 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002623 varname internal variable (see
2624 dict.key |internal-variables|). Also works
2625 list[i] for |curly-braces-names|, |Dictionary|
Yegappan Lakshmanana2ebb6e2024-02-25 08:40:10 +01002626 import.Func entries, |List| items, class and
2627 class.Func object methods, imported items, etc.
2628 object.Func Does not work for local variables in a
2629 class.varname compiled `:def` function.
2630 object.varname Also works for a function in |Vim9|
Bram Moolenaar944697a2022-02-20 19:48:20 +00002631 script, since it can be used as a
2632 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002633 Beware that evaluating an index may
2634 cause an error message for an invalid
2635 expression. E.g.: >
2636 :let l = [1, 2, 3]
2637 :echo exists("l[5]")
2638< 0 >
2639 :echo exists("l[xx]")
2640< E121: Undefined variable: xx
2641 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002642 &option-name Vim option (only checks if it exists,
2643 not if it really works)
2644 +option-name Vim option that works.
2645 $ENVNAME environment variable (could also be
2646 done by comparing with an empty
2647 string)
2648 *funcname built-in function (see |functions|)
2649 or user defined function (see
2650 |user-functions|) that is implemented.
2651 Also works for a variable that is a
2652 Funcref.
2653 ?funcname built-in function that could be
2654 implemented; to be used to check if
2655 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002656 :cmdname Ex command: built-in command, user
2657 command or command modifier |:command|.
2658 Returns:
2659 1 for match with start of a command
2660 2 full match with a command
2661 3 matches several user commands
2662 To check for a supported command
2663 always check the return value to be 2.
2664 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002665 :3match The |:3match| command (but you
2666 probably should not use it, it is
2667 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002668 #event autocommand defined for this event
2669 #event#pattern autocommand defined for this event and
2670 pattern (the pattern is taken
2671 literally and compared to the
2672 autocommand patterns character by
2673 character)
2674 #group autocommand group exists
2675 #group#event autocommand defined for this group and
2676 event.
2677 #group#event#pattern
2678 autocommand defined for this group,
2679 event and pattern.
2680 ##event autocommand for this event is
2681 supported.
2682
2683 Examples: >
2684 exists("&shortname")
2685 exists("$HOSTNAME")
2686 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002687 exists("*s:MyFunc") " only for legacy script
2688 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002689 exists("bufcount")
2690 exists(":Make")
2691 exists("#CursorHold")
2692 exists("#BufReadPre#*.gz")
2693 exists("#filetypeindent")
2694 exists("#filetypeindent#FileType")
2695 exists("#filetypeindent#FileType#*")
2696 exists("##ColorScheme")
2697< There must be no space between the symbol (&/$/*/#) and the
2698 name.
2699 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002700 a few cases this is ignored. That may become stricter in the
2701 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002702 Working example: >
2703 exists(":make")
2704< NOT working example: >
2705 exists(":make install")
2706
2707< Note that the argument must be a string, not the name of the
2708 variable itself. For example: >
2709 exists(bufcount)
2710< This doesn't check for existence of the "bufcount" variable,
2711 but gets the value of "bufcount", and checks if that exists.
2712
2713 Can also be used as a |method|: >
2714 Varname()->exists()
2715<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002716 Return type: |String|
2717
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002718
2719exists_compiled({expr}) *exists_compiled()*
2720 Like `exists()` but evaluated at compile time. This is useful
2721 to skip a block where a function is used that would otherwise
2722 give an error: >
2723 if exists_compiled('*ThatFunction')
2724 ThatFunction('works')
2725 endif
2726< If `exists()` were used then a compilation error would be
2727 given if ThatFunction() is not defined.
2728
2729 {expr} must be a literal string. *E1232*
2730 Can only be used in a |:def| function. *E1233*
2731 This does not work to check for arguments or local variables.
2732
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002733 Return type: |String|
2734
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002735
2736exp({expr}) *exp()*
2737 Return the exponential of {expr} as a |Float| in the range
2738 [0, inf].
2739 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002740 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002741 Examples: >
2742 :echo exp(2)
2743< 7.389056 >
2744 :echo exp(-1)
2745< 0.367879
2746
2747 Can also be used as a |method|: >
2748 Compute()->exp()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002749<
2750 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002751
2752
2753expand({string} [, {nosuf} [, {list}]]) *expand()*
2754 Expand wildcards and the following special keywords in
2755 {string}. 'wildignorecase' applies.
2756
2757 If {list} is given and it is |TRUE|, a List will be returned.
2758 Otherwise the result is a String and when there are several
2759 matches, they are separated by <NL> characters. [Note: in
2760 version 5.0 a space was used, which caused problems when a
2761 file name contains a space]
2762
2763 If the expansion fails, the result is an empty string. A name
2764 for a non-existing file is not included, unless {string} does
2765 not start with '%', '#' or '<', see below.
2766
Christian Brabandtec9c3262024-02-21 20:40:05 +01002767 For a |:terminal| window '%' expands to a '!' followed by
h-east53753f62024-05-05 18:42:31 +02002768 the command or shell that is run. |terminal-bufname|
Christian Brabandtec9c3262024-02-21 20:40:05 +01002769
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002770 When {string} starts with '%', '#' or '<', the expansion is
2771 done like for the |cmdline-special| variables with their
2772 associated modifiers. Here is a short overview:
2773
2774 % current file name
2775 # alternate file name
2776 #n alternate file name n
2777 <cfile> file name under the cursor
2778 <afile> autocmd file name
2779 <abuf> autocmd buffer number (as a String!)
2780 <amatch> autocmd matched name
2781 <cexpr> C expression under the cursor
2782 <sfile> sourced script file or function name
2783 <slnum> sourced script line number or function
2784 line number
2785 <sflnum> script file line number, also when in
2786 a function
2787 <SID> "<SNR>123_" where "123" is the
2788 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002789 <script> sourced script file, or script file
2790 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002791 <stack> call stack
2792 <cword> word under the cursor
2793 <cWORD> WORD under the cursor
2794 <client> the {clientid} of the last received
2795 message |server2client()|
2796 Modifiers:
2797 :p expand to full path
2798 :h head (last path component removed)
2799 :t tail (last path component only)
2800 :r root (one extension removed)
2801 :e extension only
2802
2803 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002804 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002805< Note that when expanding a string that starts with '%', '#' or
2806 '<', any following text is ignored. This does NOT work: >
2807 :let doesntwork = expand("%:h.bak")
2808< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002809 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002810< Also note that expanding "<cfile>" and others only returns the
2811 referenced file name without further expansion. If "<cfile>"
2812 is "~/.cshrc", you need to do another expand() to have the
2813 "~/" expanded into the path of the home directory: >
2814 :echo expand(expand("<cfile>"))
2815<
2816 There cannot be white space between the variables and the
2817 following modifier. The |fnamemodify()| function can be used
2818 to modify normal file names.
2819
2820 When using '%' or '#', and the current or alternate file name
2821 is not defined, an empty string is used. Using "%:p" in a
2822 buffer with no name, results in the current directory, with a
2823 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002824 When 'verbose' is set then expanding '%', '#' and <> items
2825 will result in an error message if the argument cannot be
2826 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002827
2828 When {string} does not start with '%', '#' or '<', it is
2829 expanded like a file name is expanded on the command line.
2830 'suffixes' and 'wildignore' are used, unless the optional
2831 {nosuf} argument is given and it is |TRUE|.
2832 Names for non-existing files are included. The "**" item can
2833 be used to search in a directory tree. For example, to find
2834 all "README" files in the current directory and below: >
2835 :echo expand("**/README")
2836<
2837 expand() can also be used to expand variables and environment
2838 variables that are only known in a shell. But this can be
2839 slow, because a shell may be used to do the expansion. See
2840 |expr-env-expand|.
2841 The expanded variable is still handled like a list of file
2842 names. When an environment variable cannot be expanded, it is
2843 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2844 "$FOOBAR".
2845
2846 See |glob()| for finding existing files. See |system()| for
2847 getting the raw output of an external command.
2848
2849 Can also be used as a |method|: >
2850 Getpattern()->expand()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002851<
2852 Return type: |String| or list<string> depending on {list}
2853
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002854
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002855expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002856 Expand special items in String {string} like what is done for
2857 an Ex command such as `:edit`. This expands special keywords,
2858 like with |expand()|, and environment variables, anywhere in
2859 {string}. "~user" and "~/path" are only expanded at the
2860 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002861
2862 The following items are supported in the {options} Dict
2863 argument:
2864 errmsg If set to TRUE, error messages are displayed
2865 if an error is encountered during expansion.
2866 By default, error messages are not displayed.
2867
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002868 Returns the expanded string. If an error is encountered
2869 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002870
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002871 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002872 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002873 make /path/runtime/doc/builtin.o
2874 :echo expandcmd('make %<.o', {'errmsg': v:true})
2875<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002876 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002877 GetCommand()->expandcmd()
2878<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002879 Return type: |String| or list<string> depending on {list}
2880
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002881extend({expr1}, {expr2} [, {expr3}]) *extend()*
2882 {expr1} and {expr2} must be both |Lists| or both
2883 |Dictionaries|.
2884
2885 If they are |Lists|: Append {expr2} to {expr1}.
2886 If {expr3} is given insert the items of {expr2} before the
2887 item with index {expr3} in {expr1}. When {expr3} is zero
2888 insert before the first item. When {expr3} is equal to
2889 len({expr1}) then {expr2} is appended.
2890 Examples: >
2891 :echo sort(extend(mylist, [7, 5]))
2892 :call extend(mylist, [2, 3], 1)
2893< When {expr1} is the same List as {expr2} then the number of
2894 items copied is equal to the original length of the List.
2895 E.g., when {expr3} is 1 you get N new copies of the first item
2896 (where N is the original length of the List).
2897 Use |add()| to concatenate one item to a list. To concatenate
2898 two lists into a new list use the + operator: >
2899 :let newlist = [1, 2, 3] + [4, 5]
2900<
2901 If they are |Dictionaries|:
2902 Add all entries from {expr2} to {expr1}.
2903 If a key exists in both {expr1} and {expr2} then {expr3} is
2904 used to decide what to do:
2905 {expr3} = "keep": keep the value of {expr1}
2906 {expr3} = "force": use the value of {expr2}
2907 {expr3} = "error": give an error message *E737*
2908 When {expr3} is omitted then "force" is assumed.
2909
2910 {expr1} is changed when {expr2} is not empty. If necessary
2911 make a copy of {expr1} first.
2912 {expr2} remains unchanged.
2913 When {expr1} is locked and {expr2} is not empty the operation
2914 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002915 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002916
2917 Can also be used as a |method|: >
2918 mylist->extend(otherlist)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002919<
2920 Return type: list<{type}> or dict<{type}> depending on {expr1}
2921 and {expr2}, in case of error: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002922
2923
2924extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
2925 Like |extend()| but instead of adding items to {expr1} a new
2926 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00002927 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002928
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002929 Return type: list<{type}> or dict<{type}> depending on {expr1}
2930 and {expr2}, in case of error: |Number|
2931
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002932
2933feedkeys({string} [, {mode}]) *feedkeys()*
2934 Characters in {string} are queued for processing as if they
2935 come from a mapping or were typed by the user.
2936
2937 By default the string is added to the end of the typeahead
2938 buffer, thus if a mapping is still being executed the
2939 characters come after them. Use the 'i' flag to insert before
2940 other characters, they will be executed next, before any
2941 characters from a mapping.
2942
2943 The function does not wait for processing of keys contained in
2944 {string}.
2945
2946 To include special keys into {string}, use double-quotes
2947 and "\..." notation |expr-quote|. For example,
2948 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
2949 feedkeys('\<CR>') pushes 5 characters.
2950 A special code that might be useful is <Ignore>, it exits the
2951 wait for a character without doing anything. *<Ignore>*
2952
2953 {mode} is a String, which can contain these character flags:
2954 'm' Remap keys. This is default. If {mode} is absent,
2955 keys are remapped.
2956 'n' Do not remap keys.
2957 't' Handle keys as if typed; otherwise they are handled as
2958 if coming from a mapping. This matters for undo,
2959 opening folds, etc.
2960 'L' Lowlevel input. Only works for Unix or when using the
2961 GUI. Keys are used as if they were coming from the
2962 terminal. Other flags are not used. *E980*
2963 When a CTRL-C interrupts and 't' is included it sets
2964 the internal "got_int" flag.
2965 'i' Insert the string instead of appending (see above).
2966 'x' Execute commands until typeahead is empty. This is
2967 similar to using ":normal!". You can call feedkeys()
2968 several times without 'x' and then one time with 'x'
2969 (possibly with an empty {string}) to execute all the
2970 typeahead. Note that when Vim ends in Insert mode it
2971 will behave as if <Esc> is typed, to avoid getting
2972 stuck, waiting for a character to be typed before the
2973 script continues.
2974 Note that if you manage to call feedkeys() while
2975 executing commands, thus calling it recursively, then
2976 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00002977 'c' Remove any script context when executing, so that
2978 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01002979 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01002980 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002981 '!' When used with 'x' will not end Insert mode. Can be
2982 used in a test when a timer is set to exit Insert mode
2983 a little later. Useful for testing CursorHoldI.
2984
2985 Return value is always 0.
2986
2987 Can also be used as a |method|: >
2988 GetInput()->feedkeys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002989<
2990 Return type: |String| or list<string> depending on {list}
2991
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002992
Shougo Matsushita60c87432024-06-03 22:59:27 +02002993filecopy({from}, {to}) *filecopy()*
2994 Copy the file pointed to by the name {from} to {to}. The
2995 result is a Number, which is |TRUE| if the file was copied
2996 successfully, and |FALSE| when it failed.
2997 If a file with name {to} already exists, it will fail.
2998 Note that it does not handle directories (yet).
2999
3000 This function is not available in the |sandbox|.
3001
3002 Can also be used as a |method|: >
3003 GetOldName()->filecopy(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003004<
3005 Return type: |Number|
3006
Shougo Matsushita60c87432024-06-03 22:59:27 +02003007
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003008filereadable({file}) *filereadable()*
3009 The result is a Number, which is |TRUE| when a file with the
3010 name {file} exists, and can be read. If {file} doesn't exist,
3011 or is a directory, the result is |FALSE|. {file} is any
3012 expression, which is used as a String.
3013 If you don't care about the file being readable you can use
3014 |glob()|.
3015 {file} is used as-is, you may want to expand wildcards first: >
3016 echo filereadable('~/.vimrc')
3017 0
3018 echo filereadable(expand('~/.vimrc'))
3019 1
3020
3021< Can also be used as a |method|: >
3022 GetName()->filereadable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003023<
3024 Return type: |Number|
3025
3026 *file_readable()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003027 Obsolete name: file_readable().
3028
3029
3030filewritable({file}) *filewritable()*
3031 The result is a Number, which is 1 when a file with the
3032 name {file} exists, and can be written. If {file} doesn't
3033 exist, or is not writable, the result is 0. If {file} is a
3034 directory, and we can write to it, the result is 2.
3035
3036 Can also be used as a |method|: >
3037 GetName()->filewritable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003038<
3039 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003040
3041
3042filter({expr1}, {expr2}) *filter()*
3043 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3044 For each item in {expr1} evaluate {expr2} and when the result
3045 is zero or false remove the item from the |List| or
3046 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003047 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003048
3049 {expr2} must be a |string| or |Funcref|.
3050
3051 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3052 of the current item. For a |Dictionary| |v:key| has the key
3053 of the current item and for a |List| |v:key| has the index of
3054 the current item. For a |Blob| |v:key| has the index of the
3055 current byte. For a |String| |v:key| has the index of the
3056 current character.
3057 Examples: >
3058 call filter(mylist, 'v:val !~ "OLD"')
3059< Removes the items where "OLD" appears. >
3060 call filter(mydict, 'v:key >= 8')
3061< Removes the items with a key below 8. >
3062 call filter(var, 0)
3063< Removes all the items, thus clears the |List| or |Dictionary|.
3064
3065 Note that {expr2} is the result of expression and is then
3066 used as an expression again. Often it is good to use a
3067 |literal-string| to avoid having to double backslashes.
3068
3069 If {expr2} is a |Funcref| it must take two arguments:
3070 1. the key or the index of the current item.
3071 2. the value of the current item.
3072 The function must return |TRUE| if the item should be kept.
3073 Example that keeps the odd items of a list: >
3074 func Odd(idx, val)
3075 return a:idx % 2 == 1
3076 endfunc
3077 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003078< It is shorter when using a |lambda|. In |Vim9| syntax: >
3079 call filter(myList, (idx, val) => idx * val <= 42)
3080< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003081 call filter(myList, {idx, val -> idx * val <= 42})
3082< If you do not use "val" you can leave it out: >
3083 call filter(myList, {idx -> idx % 2 == 1})
3084<
3085 In |Vim9| script the result must be true, false, zero or one.
3086 Other values will result in a type error.
3087
3088 For a |List| and a |Dictionary| the operation is done
3089 in-place. If you want it to remain unmodified make a copy
3090 first: >
3091 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
3092
3093< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00003094 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003095 When an error is encountered while evaluating {expr2} no
3096 further items in {expr1} are processed.
3097 When {expr2} is a Funcref errors inside a function are ignored,
3098 unless it was defined with the "abort" flag.
3099
3100 Can also be used as a |method|: >
3101 mylist->filter(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003102<
3103 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
3104 depending on {expr1}
3105
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003106
3107finddir({name} [, {path} [, {count}]]) *finddir()*
3108 Find directory {name} in {path}. Supports both downwards and
3109 upwards recursive directory searches. See |file-searching|
3110 for the syntax of {path}.
3111
3112 Returns the path of the first found match. When the found
3113 directory is below the current directory a relative path is
3114 returned. Otherwise a full path is returned.
3115 If {path} is omitted or empty then 'path' is used.
3116
3117 If the optional {count} is given, find {count}'s occurrence of
3118 {name} in {path} instead of the first one.
3119 When {count} is negative return all the matches in a |List|.
3120
Bram Moolenaar016188f2022-06-06 20:52:59 +01003121 Returns an empty string if the directory is not found.
3122
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003123 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003124
3125 Can also be used as a |method|: >
3126 GetName()->finddir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003127<
3128 Return type: |String|
3129
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003130
3131findfile({name} [, {path} [, {count}]]) *findfile()*
3132 Just like |finddir()|, but find a file instead of a directory.
3133 Uses 'suffixesadd'.
3134 Example: >
3135 :echo findfile("tags.vim", ".;")
3136< Searches from the directory of the current file upwards until
3137 it finds the file "tags.vim".
3138
3139 Can also be used as a |method|: >
3140 GetName()->findfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003141<
3142 Return type: |String|
3143
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003144
3145flatten({list} [, {maxdepth}]) *flatten()*
3146 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
3147 the result is a |List| without nesting, as if {maxdepth} is
3148 a very large number.
3149 The {list} is changed in place, use |flattennew()| if you do
3150 not want that.
3151 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00003152 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003153 *E900*
3154 {maxdepth} means how deep in nested lists changes are made.
3155 {list} is not modified when {maxdepth} is 0.
3156 {maxdepth} must be positive number.
3157
3158 If there is an error the number zero is returned.
3159
3160 Example: >
3161 :echo flatten([1, [2, [3, 4]], 5])
3162< [1, 2, 3, 4, 5] >
3163 :echo flatten([1, [2, [3, 4]], 5], 1)
3164< [1, 2, [3, 4], 5]
3165
3166 Can also be used as a |method|: >
3167 mylist->flatten()
3168<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003169 Return type: list<{type}>
3170
3171
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003172flattennew({list} [, {maxdepth}]) *flattennew()*
3173 Like |flatten()| but first make a copy of {list}.
3174
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003175 Return type: list<{type}>
3176
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003177
3178float2nr({expr}) *float2nr()*
3179 Convert {expr} to a Number by omitting the part after the
3180 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00003181 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003182 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003183 When the value of {expr} is out of range for a |Number| the
3184 result is truncated to 0x7fffffff or -0x7fffffff (or when
3185 64-bit Number support is enabled, 0x7fffffffffffffff or
3186 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
3187 64-bit Number support is enabled, -0x8000000000000000).
3188 Examples: >
3189 echo float2nr(3.95)
3190< 3 >
3191 echo float2nr(-23.45)
3192< -23 >
3193 echo float2nr(1.0e100)
3194< 2147483647 (or 9223372036854775807) >
3195 echo float2nr(-1.0e150)
3196< -2147483647 (or -9223372036854775807) >
3197 echo float2nr(1.0e-100)
3198< 0
3199
3200 Can also be used as a |method|: >
3201 Compute()->float2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003202<
3203 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003204
3205
3206floor({expr}) *floor()*
3207 Return the largest integral value less than or equal to
3208 {expr} as a |Float| (round down).
3209 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003210 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003211 Examples: >
3212 echo floor(1.856)
3213< 1.0 >
3214 echo floor(-5.456)
3215< -6.0 >
3216 echo floor(4.0)
3217< 4.0
3218
3219 Can also be used as a |method|: >
3220 Compute()->floor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003221<
3222 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003223
3224
3225fmod({expr1}, {expr2}) *fmod()*
3226 Return the remainder of {expr1} / {expr2}, even if the
3227 division is not representable. Returns {expr1} - i * {expr2}
3228 for some integer i such that if {expr2} is non-zero, the
3229 result has the same sign as {expr1} and magnitude less than
3230 the magnitude of {expr2}. If {expr2} is zero, the value
3231 returned is zero. The value returned is a |Float|.
3232 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003233 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
3234 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003235 Examples: >
3236 :echo fmod(12.33, 1.22)
3237< 0.13 >
3238 :echo fmod(-12.33, 1.22)
3239< -0.13
3240
3241 Can also be used as a |method|: >
3242 Compute()->fmod(1.22)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003243<
3244 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003245
3246
3247fnameescape({string}) *fnameescape()*
3248 Escape {string} for use as file name command argument. All
3249 characters that have a special meaning, such as '%' and '|'
3250 are escaped with a backslash.
3251 For most systems the characters escaped are
3252 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3253 appears in a filename, it depends on the value of 'isfname'.
3254 A leading '+' and '>' is also escaped (special after |:edit|
3255 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01003256 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003257 Example: >
3258 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003259 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003260< results in executing: >
3261 edit \+some\ str\%nge\|name
3262<
3263 Can also be used as a |method|: >
3264 GetName()->fnameescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003265<
3266 Return type: |String|
3267
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003268
3269fnamemodify({fname}, {mods}) *fnamemodify()*
3270 Modify file name {fname} according to {mods}. {mods} is a
3271 string of characters like it is used for file names on the
3272 command line. See |filename-modifiers|.
3273 Example: >
3274 :echo fnamemodify("main.c", ":p:h")
3275< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01003276 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01003277< If {mods} is empty or an unsupported modifier is used then
3278 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01003279 When {fname} is empty then with {mods} ":h" returns ".", so
3280 that `:cd` can be used with it. This is different from
3281 expand('%:h') without a buffer name, which returns an empty
3282 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003283 Note: Environment variables don't work in {fname}, use
3284 |expand()| first then.
3285
3286 Can also be used as a |method|: >
3287 GetName()->fnamemodify(':p:h')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003288<
3289 Return type: |String|
3290
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003291
3292foldclosed({lnum}) *foldclosed()*
3293 The result is a Number. If the line {lnum} is in a closed
3294 fold, the result is the number of the first 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()->foldclosed()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003301<
3302 Return type: |Number|
3303
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003304
3305foldclosedend({lnum}) *foldclosedend()*
3306 The result is a Number. If the line {lnum} is in a closed
3307 fold, the result is the number of the last line in that fold.
3308 If the line {lnum} is not in a closed fold, -1 is returned.
3309 {lnum} is used like with |getline()|. Thus "." is the current
3310 line, "'m" mark m, etc.
3311
3312 Can also be used as a |method|: >
3313 GetLnum()->foldclosedend()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003314<
3315 Return type: |Number|
3316
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003317
3318foldlevel({lnum}) *foldlevel()*
3319 The result is a Number, which is the foldlevel of line {lnum}
3320 in the current buffer. For nested folds the deepest level is
3321 returned. If there is no fold at line {lnum}, zero is
3322 returned. It doesn't matter if the folds are open or closed.
3323 When used while updating folds (from 'foldexpr') -1 is
3324 returned for lines where folds are still to be updated and the
3325 foldlevel is unknown. As a special case the level of the
3326 previous line is usually available.
3327 {lnum} is used like with |getline()|. Thus "." is the current
3328 line, "'m" mark m, etc.
3329
3330 Can also be used as a |method|: >
3331 GetLnum()->foldlevel()
3332<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003333 Return type: |Number|
3334
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003335 *foldtext()*
3336foldtext() Returns a String, to be displayed for a closed fold. This is
3337 the default function used for the 'foldtext' option and should
3338 only be called from evaluating 'foldtext'. It uses the
3339 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3340 The returned string looks like this: >
3341 +-- 45 lines: abcdef
3342< The number of leading dashes depends on the foldlevel. The
3343 "45" is the number of lines in the fold. "abcdef" is the text
3344 in the first non-blank line of the fold. Leading white space,
3345 "//" or "/*" and the text from the 'foldmarker' and
3346 'commentstring' options is removed.
3347 When used to draw the actual foldtext, the rest of the line
3348 will be filled with the fold char from the 'fillchars'
3349 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003350 Returns an empty string when there is no fold.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003351
3352 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003353 {not available when compiled without the |+folding| feature}
3354
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003355
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003356foldtextresult({lnum}) *foldtextresult()*
3357 Returns the text that is displayed for the closed fold at line
3358 {lnum}. Evaluates 'foldtext' in the appropriate context.
3359 When there is no closed fold at {lnum} an empty string is
3360 returned.
3361 {lnum} is used like with |getline()|. Thus "." is the current
3362 line, "'m" mark m, etc.
3363 Useful when exporting folded text, e.g., to HTML.
3364 {not available when compiled without the |+folding| feature}
3365
3366
3367 Can also be used as a |method|: >
3368 GetLnum()->foldtextresult()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003369<
3370 Return type: |String|
3371
Ernie Raele79e2072024-01-13 11:47:33 +01003372
3373foreach({expr1}, {expr2}) *foreach()*
3374 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3375 For each item in {expr1} execute {expr2}. {expr1} is not
erraelc92b8be2024-01-14 10:11:07 -08003376 modified; its values may be, as with |:lockvar| 1. |E741|
Ernie Raele79e2072024-01-13 11:47:33 +01003377 See |map()| and |filter()| to modify {expr1}.
3378
3379 {expr2} must be a |string| or |Funcref|.
3380
3381 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3382 of the current item. For a |Dictionary| |v:key| has the key
3383 of the current item and for a |List| |v:key| has the index of
3384 the current item. For a |Blob| |v:key| has the index of the
3385 current byte. For a |String| |v:key| has the index of the
3386 current character.
3387 Examples: >
3388 call foreach(mylist, 'used[v:val] = true')
3389< This records the items that are in the {expr1} list.
3390
3391 Note that {expr2} is the result of expression and is then used
3392 as a command. Often it is good to use a |literal-string| to
3393 avoid having to double backslashes.
3394
3395 If {expr2} is a |Funcref| it must take two arguments:
3396 1. the key or the index of the current item.
3397 2. the value of the current item.
3398 With a legacy script lambda you don't get an error if it only
3399 accepts one argument, but with a Vim9 lambda you get "E1106:
3400 One argument too many", the number of arguments must match.
3401 If the function returns a value, it is ignored.
3402
3403 Returns {expr1} in all cases.
3404 When an error is encountered while executing {expr2} no
3405 further items in {expr1} are processed.
3406 When {expr2} is a Funcref errors inside a function are ignored,
3407 unless it was defined with the "abort" flag.
3408
3409 Can also be used as a |method|: >
3410 mylist->foreach(expr2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003411<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003412 Return type: |String|, |Blob| list<{type}> or dict<{type}>
3413 depending on {expr1}
3414
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003415 *foreground()*
3416foreground() Move the Vim window to the foreground. Useful when sent from
3417 a client to a Vim server. |remote_send()|
3418 On Win32 systems this might not work, the OS does not always
3419 allow a window to bring itself to the foreground. Use
3420 |remote_foreground()| instead.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003421
3422 Return type: |Number|
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003423 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003424 Win32 console version}
3425
Bram Moolenaaraa534142022-09-15 21:46:02 +01003426fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003427 Get the full command name from a short abbreviated command
3428 name; see |20.2| for details on command abbreviations.
3429
3430 The string argument {name} may start with a `:` and can
3431 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003432 Returns an empty string if a command doesn't exist, if it's
3433 ambiguous (for user-defined commands) or cannot be shortened
3434 this way. |vim9-no-shorten|
3435
3436 Without the {vim9} argument uses the current script version.
3437 If {vim9} is present and FALSE then legacy script rules are
3438 used. When {vim9} is present and TRUE then Vim9 rules are
3439 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003440
3441 For example `fullcommand('s')`, `fullcommand('sub')`,
3442 `fullcommand(':%substitute')` all return "substitute".
3443
3444 Can also be used as a |method|: >
3445 GetName()->fullcommand()
3446<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003447 Return type: |String|
3448
3449
3450funcref({name} [, {arglist}] [, {dict}]) *funcref()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003451 Just like |function()|, but the returned Funcref will lookup
3452 the function by reference, not by name. This matters when the
3453 function {name} is redefined later.
3454
3455 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003456 It only works for an autoloaded function if it has already
3457 been loaded (to avoid mistakenly loading the autoload script
3458 when only intending to use the function name, use |function()|
3459 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003460 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003461
3462 Can also be used as a |method|: >
3463 GetFuncname()->funcref([arg])
3464<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003465 Return type: func(...): any or |Number| on error
3466
Dominique Pellee764d1b2023-03-12 21:20:59 +00003467 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003468function({name} [, {arglist}] [, {dict}])
3469 Return a |Funcref| variable that refers to function {name}.
3470 {name} can be the name of a user defined function or an
3471 internal function.
3472
3473 {name} can also be a Funcref or a partial. When it is a
3474 partial the dict stored in it will be used and the {dict}
3475 argument is not allowed. E.g.: >
3476 let FuncWithArg = function(dict.Func, [arg])
3477 let Broken = function(dict.Func, [arg], dict)
3478<
3479 When using the Funcref the function will be found by {name},
3480 also when it was redefined later. Use |funcref()| to keep the
3481 same function.
3482
3483 When {arglist} or {dict} is present this creates a partial.
3484 That means the argument list and/or the dictionary is stored in
3485 the Funcref and will be used when the Funcref is called.
3486
3487 The arguments are passed to the function in front of other
3488 arguments, but after any argument from |method|. Example: >
3489 func Callback(arg1, arg2, name)
3490 ...
3491 let Partial = function('Callback', ['one', 'two'])
3492 ...
3493 call Partial('name')
3494< Invokes the function as with: >
3495 call Callback('one', 'two', 'name')
3496
3497< With a |method|: >
3498 func Callback(one, two, three)
3499 ...
3500 let Partial = function('Callback', ['two'])
3501 ...
3502 eval 'one'->Partial('three')
3503< Invokes the function as with: >
3504 call Callback('one', 'two', 'three')
3505
3506< The function() call can be nested to add more arguments to the
3507 Funcref. The extra arguments are appended to the list of
3508 arguments. Example: >
3509 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003510 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003511 let Func = function('Callback', ['one'])
3512 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003513 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003514 call Func2('name')
3515< Invokes the function as with: >
3516 call Callback('one', 'two', 'name')
3517
3518< The Dictionary is only useful when calling a "dict" function.
3519 In that case the {dict} is passed in as "self". Example: >
3520 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003521 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003522 endfunction
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', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003526 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003527 call Func() " will echo: called for example
3528< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003529 arguments, these two are equivalent, if Callback() is defined
3530 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003531 let Func = function('Callback', context)
3532 let Func = context.Callback
3533
3534< The argument list and the Dictionary can be combined: >
3535 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003536 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003537 let context = {"name": "example"}
3538 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003539 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003540 call Func(500)
3541< Invokes the function as with: >
3542 call context.Callback('one', 500)
3543<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003544 Returns 0 on error.
3545
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003546 Can also be used as a |method|: >
3547 GetFuncname()->function([arg])
3548
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003549<
3550 Return type: func(...): any or |Number| on error
3551
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003552
3553garbagecollect([{atexit}]) *garbagecollect()*
3554 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3555 that have circular references.
3556
3557 There is hardly ever a need to invoke this function, as it is
3558 automatically done when Vim runs out of memory or is waiting
3559 for the user to press a key after 'updatetime'. Items without
3560 circular references are always freed when they become unused.
3561 This is useful if you have deleted a very big |List| and/or
3562 |Dictionary| with circular references in a script that runs
3563 for a long time.
3564
3565 When the optional {atexit} argument is one, garbage
3566 collection will also be done when exiting Vim, if it wasn't
3567 done before. This is useful when checking for memory leaks.
3568
3569 The garbage collection is not done immediately but only when
3570 it's safe to perform. This is when waiting for the user to
3571 type a character. To force garbage collection immediately use
3572 |test_garbagecollect_now()|.
3573
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003574 Return type: |String|
3575
3576
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003577get({list}, {idx} [, {default}]) *get()*
3578 Get item {idx} from |List| {list}. When this item is not
3579 available return {default}. Return zero when {default} is
3580 omitted.
3581 Preferably used as a |method|: >
3582 mylist->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003583<
3584 Return type: any, depending on {list}
3585
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003586get({blob}, {idx} [, {default}])
3587 Get byte {idx} from |Blob| {blob}. When this byte is not
3588 available return {default}. Return -1 when {default} is
3589 omitted.
3590 Preferably used as a |method|: >
3591 myblob->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003592<
3593 Return type: |Number|
3594
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003595get({dict}, {key} [, {default}])
3596 Get item with key {key} from |Dictionary| {dict}. When this
3597 item is not available return {default}. Return zero when
3598 {default} is omitted. Useful example: >
3599 let val = get(g:, 'var_name', 'default')
3600< This gets the value of g:var_name if it exists, and uses
3601 'default' when it does not exist.
3602 Preferably used as a |method|: >
3603 mydict->get(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003604<
h-east84ac2122024-06-17 18:12:30 +02003605 Return type: any, depending on {dict}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003606
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003607get({func}, {what})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00003608 Get item {what} from Funcref {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003609 {what} are:
3610 "name" The function name
3611 "func" The function
3612 "dict" The dictionary
3613 "args" The list with arguments
Bram Moolenaar016188f2022-06-06 20:52:59 +01003614 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003615 Preferably used as a |method|: >
3616 myfunc->get(what)
3617<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003618 Return type: any, depending on {func}
3619
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003620 *getbufinfo()*
3621getbufinfo([{buf}])
3622getbufinfo([{dict}])
3623 Get information about buffers as a List of Dictionaries.
3624
3625 Without an argument information about all the buffers is
3626 returned.
3627
3628 When the argument is a |Dictionary| only the buffers matching
3629 the specified criteria are returned. The following keys can
3630 be specified in {dict}:
3631 buflisted include only listed buffers.
3632 bufloaded include only loaded buffers.
3633 bufmodified include only modified buffers.
3634
3635 Otherwise, {buf} specifies a particular buffer to return
3636 information for. For the use of {buf}, see |bufname()|
3637 above. If the buffer is found the returned List has one item.
3638 Otherwise the result is an empty list.
3639
3640 Each returned List item is a dictionary with the following
3641 entries:
3642 bufnr Buffer number.
3643 changed TRUE if the buffer is modified.
3644 changedtick Number of changes made to the buffer.
Sean Dewar1fb41032023-08-16 17:15:05 +01003645 command TRUE if the buffer belongs to the
3646 command-line window |cmdwin|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003647 hidden TRUE if the buffer is hidden.
3648 lastused Timestamp in seconds, like
3649 |localtime()|, when the buffer was
3650 last used.
3651 {only with the |+viminfo| feature}
3652 listed TRUE if the buffer is listed.
3653 lnum Line number used for the buffer when
3654 opened in the current window.
3655 Only valid if the buffer has been
3656 displayed in the window in the past.
3657 If you want the line number of the
3658 last known cursor position in a given
3659 window, use |line()|: >
3660 :echo line('.', {winid})
3661<
3662 linecount Number of lines in the buffer (only
3663 valid when loaded)
3664 loaded TRUE if the buffer is loaded.
3665 name Full path to the file in the buffer.
3666 signs List of signs placed in the buffer.
3667 Each list item is a dictionary with
3668 the following fields:
3669 id sign identifier
3670 lnum line number
3671 name sign name
3672 variables A reference to the dictionary with
3673 buffer-local variables.
3674 windows List of |window-ID|s that display this
3675 buffer
3676 popups List of popup |window-ID|s that
3677 display this buffer
3678
3679 Examples: >
3680 for buf in getbufinfo()
3681 echo buf.name
3682 endfor
3683 for buf in getbufinfo({'buflisted':1})
3684 if buf.changed
3685 ....
3686 endif
3687 endfor
3688<
3689 To get buffer-local options use: >
3690 getbufvar({bufnr}, '&option_name')
3691<
3692 Can also be used as a |method|: >
3693 GetBufnr()->getbufinfo()
3694<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003695 Return type: list<dict<any>>
3696
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003697
3698 *getbufline()*
3699getbufline({buf}, {lnum} [, {end}])
3700 Return a |List| with the lines starting from {lnum} to {end}
3701 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003702 |List| with only the line {lnum} is returned. See
3703 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003704
3705 For the use of {buf}, see |bufname()| above.
3706
3707 For {lnum} and {end} "$" can be used for the last line of the
3708 buffer. Otherwise a number must be used.
3709
3710 When {lnum} is smaller than 1 or bigger than the number of
3711 lines in the buffer, an empty |List| is returned.
3712
3713 When {end} is greater than the number of lines in the buffer,
3714 it is treated as {end} is set to the number of lines in the
3715 buffer. When {end} is before {lnum} an empty |List| is
3716 returned.
3717
3718 This function works only for loaded buffers. For unloaded and
3719 non-existing buffers, an empty |List| is returned.
3720
3721 Example: >
3722 :let lines = getbufline(bufnr("myfile"), 1, "$")
3723
3724< Can also be used as a |method|: >
3725 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003726<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003727 Return type: list<string>
3728
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003729 *getbufoneline()*
3730getbufoneline({buf}, {lnum})
3731 Just like `getbufline()` but only get one line and return it
3732 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003733
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003734 Return type: |String|
3735
3736
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003737getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3738 The result is the value of option or local buffer variable
3739 {varname} in buffer {buf}. Note that the name without "b:"
3740 must be used.
3741 The {varname} argument is a string.
3742 When {varname} is empty returns a |Dictionary| with all the
3743 buffer-local variables.
3744 When {varname} is equal to "&" returns a |Dictionary| with all
3745 the buffer-local options.
3746 Otherwise, when {varname} starts with "&" returns the value of
3747 a buffer-local option.
3748 This also works for a global or buffer-local option, but it
3749 doesn't work for a global variable, window-local variable or
3750 window-local option.
3751 For the use of {buf}, see |bufname()| above.
3752 When the buffer or variable doesn't exist {def} or an empty
3753 string is returned, there is no error message.
3754 Examples: >
3755 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003756 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003757
3758< Can also be used as a |method|: >
3759 GetBufnr()->getbufvar(varname)
3760<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003761 Return type: any, depending on {varname}
3762
3763
Kota Kato66bb9ae2023-01-17 18:31:56 +00003764getcellwidths() *getcellwidths()*
3765 Returns a |List| of cell widths of character ranges overridden
3766 by |setcellwidths()|. The format is equal to the argument of
3767 |setcellwidths()|. If no character ranges have their cell
3768 widths overridden, an empty List is returned.
h-east84ac2122024-06-17 18:12:30 +02003769
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003770 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003771
3772
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003773getchangelist([{buf}]) *getchangelist()*
3774 Returns the |changelist| for the buffer {buf}. For the use
3775 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3776 exist, an empty list is returned.
3777
3778 The returned list contains two entries: a list with the change
3779 locations and the current position in the list. Each
3780 entry in the change list is a dictionary with the following
3781 entries:
3782 col column number
3783 coladd column offset for 'virtualedit'
3784 lnum line number
3785 If buffer {buf} is the current buffer, then the current
3786 position refers to the position in the list. For other
3787 buffers, it is set to the length of the list.
3788
3789 Can also be used as a |method|: >
3790 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003791<
3792 Return type: list<any>
3793
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003794
Doug Kearns9cd9e752024-04-07 17:42:17 +02003795getchar([{expr}]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003796 Get a single character from the user or input stream.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003797 If {expr} is omitted, wait until a character is available.
3798 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003799 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003800 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003801 not consumed. Return zero if no character available.
3802 If you prefer always getting a string use |getcharstr()|.
3803
Doug Kearns9cd9e752024-04-07 17:42:17 +02003804 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003805 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003806 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003807 Otherwise a String is returned with the encoded character.
3808 For a special key it's a String with a sequence of bytes
3809 starting with 0x80 (decimal: 128). This is the same value as
3810 the String "\<Key>", e.g., "\<Left>". The returned value is
3811 also a String when a modifier (shift, control, alt) was used
3812 that is not included in the character.
3813
Doug Kearns9cd9e752024-04-07 17:42:17 +02003814 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003815 while Vim waits to see if this is the start of an escape
3816 sequence.
3817
Doug Kearns9cd9e752024-04-07 17:42:17 +02003818 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003819 one-byte character it is the character itself as a number.
3820 Use nr2char() to convert it to a String.
3821
3822 Use getcharmod() to obtain any additional modifiers.
3823
3824 When the user clicks a mouse button, the mouse event will be
3825 returned. The position can then be found in |v:mouse_col|,
3826 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3827 |getmousepos()| can also be used. Mouse move events will be
3828 ignored.
3829 This example positions the mouse as it would normally happen: >
3830 let c = getchar()
3831 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003832 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003833 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003834 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003835 endif
3836<
3837 When using bracketed paste only the first character is
3838 returned, the rest of the pasted text is dropped.
3839 |xterm-bracketed-paste|.
3840
3841 There is no prompt, you will somehow have to make clear to the
3842 user that a character has to be typed. The screen is not
3843 redrawn, e.g. when resizing the window. When using a popup
3844 window it should work better with a |popup-filter|.
3845
3846 There is no mapping for the character.
3847 Key codes are replaced, thus when the user presses the <Del>
3848 key you get the code for the <Del> key, not the raw character
3849 sequence. Examples: >
3850 getchar() == "\<Del>"
3851 getchar() == "\<S-Left>"
3852< This example redefines "f" to ignore case: >
3853 :nmap f :call FindChar()<CR>
3854 :function FindChar()
3855 : let c = nr2char(getchar())
3856 : while col('.') < col('$') - 1
3857 : normal l
3858 : if getline('.')[col('.') - 1] ==? c
3859 : break
3860 : endif
3861 : endwhile
3862 :endfunction
3863<
3864 You may also receive synthetic characters, such as
3865 |<CursorHold>|. Often you will want to ignore this and get
3866 another character: >
3867 :function GetKey()
3868 : let c = getchar()
3869 : while c == "\<CursorHold>"
3870 : let c = getchar()
3871 : endwhile
3872 : return c
3873 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003874<
3875 Return type: |Number| or |String|
3876
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003877
3878getcharmod() *getcharmod()*
3879 The result is a Number which is the state of the modifiers for
3880 the last obtained character with getchar() or in another way.
3881 These values are added together:
3882 2 shift
3883 4 control
3884 8 alt (meta)
3885 16 meta (when it's different from ALT)
3886 32 mouse double click
3887 64 mouse triple click
3888 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01003889 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003890 Only the modifiers that have not been included in the
3891 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01003892 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003893
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003894 Return type: |Number|
3895
3896
3897getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003898 Get the position for String {expr}. Same as |getpos()| but the
3899 column number in the returned List is a character index
3900 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00003901 If |getpos()| returns a very large column number, equal to
3902 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003903 of the last character.
3904
3905 Example:
3906 With the cursor on '세' in line 5 with text "여보세요": >
3907 getcharpos('.') returns [0, 5, 3, 0]
3908 getpos('.') returns [0, 5, 7, 0]
3909<
3910 Can also be used as a |method|: >
3911 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003912<
3913 Return type: list<number>
3914
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003915
3916getcharsearch() *getcharsearch()*
3917 Return the current character search information as a {dict}
3918 with the following entries:
3919
3920 char character previously used for a character
3921 search (|t|, |f|, |T|, or |F|); empty string
3922 if no character search has been performed
3923 forward direction of character search; 1 for forward,
3924 0 for backward
3925 until type of character search; 1 for a |t| or |T|
3926 character search, 0 for an |f| or |F|
3927 character search
3928
3929 This can be useful to always have |;| and |,| search
3930 forward/backward regardless of the direction of the previous
3931 character search: >
3932 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
3933 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
3934< Also see |setcharsearch()|.
3935
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003936 Return type: dict<any>
3937
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003938
Doug Kearns9cd9e752024-04-07 17:42:17 +02003939getcharstr([{expr}]) *getcharstr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003940 Get a single character from the user or input stream as a
3941 string.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003942 If {expr} is omitted, wait until a character is available.
3943 If {expr} is 0 or false, only get a character when one is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003944 available. Return an empty string otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003945 If {expr} is 1 or true, only check if a character is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003946 available, it is not consumed. Return an empty string
3947 if no character is available.
3948 Otherwise this works like |getchar()|, except that a number
3949 result is converted to a string.
3950
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003951 Return type: |String|
3952
3953
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003954getcmdcompltype() *getcmdcompltype()*
3955 Return the type of the current command-line completion.
3956 Only works when the command line is being edited, thus
3957 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01003958 See |:command-completion| for the return string.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003959 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
3960 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003961 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003962
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003963 Return type: |String|
3964
3965
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003966getcmdline() *getcmdline()*
3967 Return the current command-line. Only works when the command
3968 line is being edited, thus requires use of |c_CTRL-\_e| or
3969 |c_CTRL-R_=|.
3970 Example: >
3971 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003972< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()| and
3973 |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003974 Returns an empty string when entering a password or using
3975 |inputsecret()|.
3976
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003977 Return type: |String|
3978
3979
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003980getcmdpos() *getcmdpos()*
3981 Return the position of the cursor in the command line as a
3982 byte count. The first column is 1.
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 |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
3987 |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003988
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003989 Return type: |Number|
3990
3991
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003992getcmdscreenpos() *getcmdscreenpos()*
3993 Return the screen position of the cursor in the command line
3994 as a byte count. The first column is 1.
3995 Instead of |getcmdpos()|, it adds the prompt position.
3996 Only works when editing the command line, thus requires use of
3997 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3998 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003999 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
4000 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004001
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004002 Return type: |Number|
4003
4004
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004005getcmdtype() *getcmdtype()*
4006 Return the current command-line type. Possible return values
4007 are:
4008 : normal Ex command
4009 > debug mode command |debug-mode|
4010 / forward search command
4011 ? backward search command
4012 @ |input()| command
4013 - |:insert| or |:append| command
4014 = |i_CTRL-R_=|
4015 Only works when editing the command line, thus requires use of
4016 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4017 Returns an empty string otherwise.
4018 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4019
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004020 Return type: |String|
4021
4022
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004023getcmdwintype() *getcmdwintype()*
4024 Return the current |command-line-window| type. Possible return
4025 values are the same as |getcmdtype()|. Returns an empty string
4026 when not in the command-line window.
4027
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004028 Return type: |String|
4029
4030
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004031getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4032 Return a list of command-line completion matches. The String
4033 {type} argument specifies what for. The following completion
4034 types are supported:
4035
4036 arglist file names in argument list
4037 augroup autocmd groups
4038 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004039 behave |:behave| suboptions
4040 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004041 color color schemes
4042 command Ex command
4043 cmdline |cmdline-completion| result
4044 compiler compilers
4045 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004046 custom,{func} custom completion, defined via {func}
4047 customlist,{func} custom completion, defined via {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004048 diff_buffer |:diffget| and |:diffput| completion
4049 dir directory names
4050 environment environment variable names
4051 event autocommand events
4052 expression Vim expression
4053 file file and directory names
4054 file_in_path file and directory names in |'path'|
4055 filetype filetype names |'filetype'|
4056 function function name
4057 help help subjects
4058 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004059 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004060 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004061 locale locale names (as output of locale -a)
4062 mapclear buffer argument
4063 mapping mapping name
4064 menu menus
4065 messages |:messages| suboptions
4066 option options
4067 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004068 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004069 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004070 shellcmd Shell command
4071 sign |:sign| suboptions
4072 syntax syntax file names |'syntax'|
4073 syntime |:syntime| suboptions
4074 tag tags
4075 tag_listfiles tags, file names
4076 user user names
4077 var user variables
4078
4079 If {pat} is an empty string, then all the matches are
4080 returned. Otherwise only items matching {pat} are returned.
4081 See |wildcards| for the use of special characters in {pat}.
4082
4083 If the optional {filtered} flag is set to 1, then 'wildignore'
4084 is applied to filter the results. Otherwise all the matches
4085 are returned. The 'wildignorecase' option always applies.
4086
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004087 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4088 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004089 regular expression matching is used. Thus this function
4090 follows the user preference, what happens on the command line.
4091 If you do not want this you can make 'wildoptions' empty
4092 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004093
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004094 If {type} is "cmdline", then the |cmdline-completion| result is
4095 returned. For example, to complete the possible values after
4096 a ":call" command: >
4097 echo getcompletion('call ', 'cmdline')
4098<
4099 If there are no matches, an empty list is returned. An
4100 invalid value for {type} produces an error.
4101
4102 Can also be used as a |method|: >
4103 GetPattern()->getcompletion('color')
4104<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004105 Return type: list<string>
4106
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004107 *getcurpos()*
4108getcurpos([{winid}])
4109 Get the position of the cursor. This is like getpos('.'), but
4110 includes an extra "curswant" item in the list:
4111 [0, lnum, col, off, curswant] ~
4112 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004113 cursor vertically. After |$| command it will be a very large
4114 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004115 |getpos()|.
4116 The first "bufnum" item is always zero. The byte position of
4117 the cursor is returned in 'col'. To get the character
4118 position, use |getcursorcharpos()|.
4119
4120 The optional {winid} argument can specify the window. It can
4121 be the window number or the |window-ID|. The last known
4122 cursor position is returned, this may be invalid for the
4123 current value of the buffer if it is not the current window.
4124 If {winid} is invalid a list with zeroes is returned.
4125
4126 This can be used to save and restore the cursor position: >
4127 let save_cursor = getcurpos()
4128 MoveTheCursorAround
4129 call setpos('.', save_cursor)
4130< Note that this only works within the window. See
4131 |winrestview()| for restoring more state.
4132
4133 Can also be used as a |method|: >
4134 GetWinid()->getcurpos()
4135<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004136 Return type: list<number>
4137
4138
4139getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004140 Same as |getcurpos()| but the column number in the returned
4141 List is a character index instead of a byte index.
4142
4143 Example:
4144 With the cursor on '보' in line 3 with text "여보세요": >
4145 getcursorcharpos() returns [0, 3, 2, 0, 3]
4146 getcurpos() returns [0, 3, 4, 0, 3]
4147<
4148 Can also be used as a |method|: >
4149 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004150<
4151 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004152
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004153
4154getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004155 The result is a String, which is the name of the current
4156 working directory. 'autochdir' is ignored.
4157
4158 With {winnr} return the local current directory of this window
4159 in the current tab page. {winnr} can be the window number or
4160 the |window-ID|.
4161 If {winnr} is -1 return the name of the global working
4162 directory. See also |haslocaldir()|.
4163
4164 With {winnr} and {tabnr} return the local current directory of
4165 the window in the specified tab page. If {winnr} is -1 return
4166 the working directory of the tabpage.
4167 If {winnr} is zero use the current window, if {tabnr} is zero
4168 use the current tabpage.
4169 Without any arguments, return the actual working directory of
4170 the current window.
4171 Return an empty string if the arguments are invalid.
4172
4173 Examples: >
4174 " Get the working directory of the current window
4175 :echo getcwd()
4176 :echo getcwd(0)
4177 :echo getcwd(0, 0)
4178 " Get the working directory of window 3 in tabpage 2
4179 :echo getcwd(3, 2)
4180 " Get the global working directory
4181 :echo getcwd(-1)
4182 " Get the working directory of tabpage 3
4183 :echo getcwd(-1, 3)
4184 " Get the working directory of current tabpage
4185 :echo getcwd(-1, 0)
4186
4187< Can also be used as a |method|: >
4188 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004189<
4190 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004191
4192getenv({name}) *getenv()*
4193 Return the value of environment variable {name}. The {name}
4194 argument is a string, without a leading '$'. Example: >
4195 myHome = getenv('HOME')
4196
4197< When the variable does not exist |v:null| is returned. That
4198 is different from a variable set to an empty string, although
4199 some systems interpret the empty value as the variable being
4200 deleted. See also |expr-env|.
4201
4202 Can also be used as a |method|: >
4203 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004204<
4205 Return type: |String| or |Number|
4206
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004207
4208getfontname([{name}]) *getfontname()*
4209 Without an argument returns the name of the normal font being
4210 used. Like what is used for the Normal highlight group
4211 |hl-Normal|.
4212 With an argument a check is done whether String {name} is a
4213 valid font name. If not then an empty string is returned.
4214 Otherwise the actual font name is returned, or {name} if the
4215 GUI does not support obtaining the real name.
4216 Only works when the GUI is running, thus not in your vimrc or
4217 gvimrc file. Use the |GUIEnter| autocommand to use this
4218 function just after the GUI has started.
4219 Note that the GTK GUI accepts any font name, thus checking for
4220 a valid name does not work.
4221
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004222 Return type: |String|
4223
4224
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004225getfperm({fname}) *getfperm()*
4226 The result is a String, which is the read, write, and execute
4227 permissions of the given file {fname}.
4228 If {fname} does not exist or its directory cannot be read, an
4229 empty string is returned.
4230 The result is of the form "rwxrwxrwx", where each group of
4231 "rwx" flags represent, in turn, the permissions of the owner
4232 of the file, the group the file belongs to, and other users.
4233 If a user does not have a given permission the flag for this
4234 is replaced with the string "-". Examples: >
4235 :echo getfperm("/etc/passwd")
4236 :echo getfperm(expand("~/.vimrc"))
4237< This will hopefully (from a security point of view) display
4238 the string "rw-r--r--" or even "rw-------".
4239
4240 Can also be used as a |method|: >
4241 GetFilename()->getfperm()
4242<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004243 Return type: |String|
4244
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004245 For setting permissions use |setfperm()|.
4246
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004247
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004248getfsize({fname}) *getfsize()*
4249 The result is a Number, which is the size in bytes of the
4250 given file {fname}.
4251 If {fname} is a directory, 0 is returned.
4252 If the file {fname} can't be found, -1 is returned.
4253 If the size of {fname} is too big to fit in a Number then -2
4254 is returned.
4255
4256 Can also be used as a |method|: >
4257 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004258<
4259 Return type: |Number|
4260
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004261
4262getftime({fname}) *getftime()*
4263 The result is a Number, which is the last modification time of
4264 the given file {fname}. The value is measured as seconds
4265 since 1st Jan 1970, and may be passed to strftime(). See also
4266 |localtime()| and |strftime()|.
4267 If the file {fname} can't be found -1 is returned.
4268
4269 Can also be used as a |method|: >
4270 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004271<
4272 Return type: |Number|
4273
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004274
4275getftype({fname}) *getftype()*
4276 The result is a String, which is a description of the kind of
4277 file of the given file {fname}.
4278 If {fname} does not exist an empty string is returned.
4279 Here is a table over different kinds of files and their
4280 results:
4281 Normal file "file"
4282 Directory "dir"
4283 Symbolic link "link"
4284 Block device "bdev"
4285 Character device "cdev"
4286 Socket "socket"
4287 FIFO "fifo"
4288 All other "other"
4289 Example: >
4290 getftype("/home")
4291< Note that a type such as "link" will only be returned on
4292 systems that support it. On some systems only "dir" and
4293 "file" are returned. On MS-Windows a symbolic link to a
4294 directory returns "dir" instead of "link".
4295
4296 Can also be used as a |method|: >
4297 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004298<
4299 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004300
4301getimstatus() *getimstatus()*
4302 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004303 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004304 See 'imstatusfunc'.
4305
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004306 Return type: |Number|
4307
4308
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004309getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4310 Returns the |jumplist| for the specified window.
4311
4312 Without arguments use the current window.
4313 With {winnr} only use this window in the current tab page.
4314 {winnr} can also be a |window-ID|.
4315 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004316 page. If {winnr} or {tabnr} is invalid, an empty list is
4317 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004318
4319 The returned list contains two entries: a list with the jump
4320 locations and the last used jump position number in the list.
4321 Each entry in the jump location list is a dictionary with
4322 the following entries:
4323 bufnr buffer number
4324 col column number
4325 coladd column offset for 'virtualedit'
4326 filename filename if available
4327 lnum line number
4328
4329 Can also be used as a |method|: >
4330 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004331<
4332 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004333
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004334 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004335getline({lnum} [, {end}])
4336 Without {end} the result is a String, which is line {lnum}
4337 from the current buffer. Example: >
4338 getline(1)
4339< When {lnum} is a String that doesn't start with a
4340 digit, |line()| is called to translate the String into a Number.
4341 To get the line under the cursor: >
4342 getline(".")
4343< When {lnum} is a number smaller than 1 or bigger than the
4344 number of lines in the buffer, an empty string is returned.
4345
4346 When {end} is given the result is a |List| where each item is
4347 a line from the current buffer in the range {lnum} to {end},
4348 including line {end}.
4349 {end} is used in the same way as {lnum}.
4350 Non-existing lines are silently omitted.
4351 When {end} is before {lnum} an empty |List| is returned.
4352 Example: >
4353 :let start = line('.')
4354 :let end = search("^$") - 1
4355 :let lines = getline(start, end)
4356
4357< Can also be used as a |method|: >
4358 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004359<
4360 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004361
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004362 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004363 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004364
4365getloclist({nr} [, {what}]) *getloclist()*
4366 Returns a |List| with all the entries in the location list for
4367 window {nr}. {nr} can be the window number or the |window-ID|.
4368 When {nr} is zero the current window is used.
4369
4370 For a location list window, the displayed location list is
4371 returned. For an invalid window number {nr}, an empty list is
4372 returned. Otherwise, same as |getqflist()|.
4373
4374 If the optional {what} dictionary argument is supplied, then
4375 returns the items listed in {what} as a dictionary. Refer to
4376 |getqflist()| for the supported items in {what}.
4377
4378 In addition to the items supported by |getqflist()| in {what},
4379 the following item is supported by |getloclist()|:
4380
4381 filewinid id of the window used to display files
4382 from the location list. This field is
4383 applicable only when called from a
4384 location list window. See
4385 |location-list-file-window| for more
4386 details.
4387
4388 Returns a |Dictionary| with default values if there is no
4389 location list for the window {nr}.
4390 Returns an empty Dictionary if window {nr} does not exist.
4391
4392 Examples (See also |getqflist-examples|): >
4393 :echo getloclist(3, {'all': 0})
4394 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004395<
4396 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004397
4398
4399getmarklist([{buf}]) *getmarklist()*
4400 Without the {buf} argument returns a |List| with information
4401 about all the global marks. |mark|
4402
4403 If the optional {buf} argument is specified, returns the
4404 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004405 see |bufname()|. If {buf} is invalid, an empty list is
4406 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004407
4408 Each item in the returned List is a |Dict| with the following:
4409 mark name of the mark prefixed by "'"
4410 pos a |List| with the position of the mark:
4411 [bufnum, lnum, col, off]
4412 Refer to |getpos()| for more information.
4413 file file name
4414
4415 Refer to |getpos()| for getting information about a specific
4416 mark.
4417
4418 Can also be used as a |method|: >
4419 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004420<
4421 Return type: list<dict<any>> or list<any>
4422
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004423
4424getmatches([{win}]) *getmatches()*
4425 Returns a |List| with all matches previously defined for the
4426 current window by |matchadd()| and the |:match| commands.
4427 |getmatches()| is useful in combination with |setmatches()|,
4428 as |setmatches()| can restore a list of matches saved by
4429 |getmatches()|.
4430 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004431 window ID instead of the current window. If {win} is invalid,
4432 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004433 Example: >
4434 :echo getmatches()
4435< [{'group': 'MyGroup1', 'pattern': 'TODO',
4436 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4437 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4438 :let m = getmatches()
4439 :call clearmatches()
4440 :echo getmatches()
4441< [] >
4442 :call setmatches(m)
4443 :echo getmatches()
4444< [{'group': 'MyGroup1', 'pattern': 'TODO',
4445 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4446 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4447 :unlet m
4448<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004449 Return type: list<dict<any>> or list<any>
4450
4451
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004452getmousepos() *getmousepos()*
4453 Returns a |Dictionary| with the last known position of the
4454 mouse. This can be used in a mapping for a mouse click or in
4455 a filter of a popup window. The items are:
4456 screenrow screen row
4457 screencol screen column
4458 winid Window ID of the click
4459 winrow row inside "winid"
4460 wincol column inside "winid"
4461 line text line inside "winid"
4462 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004463 coladd offset (in screen columns) from the
4464 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004465 All numbers are 1-based.
4466
4467 If not over a window, e.g. when in the command line, then only
4468 "screenrow" and "screencol" are valid, the others are zero.
4469
4470 When on the status line below a window or the vertical
4471 separator right of a window, the "line" and "column" values
4472 are zero.
4473
4474 When the position is after the text then "column" is the
4475 length of the text in bytes plus one.
4476
4477 If the mouse is over a popup window then that window is used.
4478
4479 When using |getchar()| the Vim variables |v:mouse_lnum|,
4480 |v:mouse_col| and |v:mouse_winid| also provide these values.
4481
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004482 Return type: dict<number>
4483
4484
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004485getmouseshape() *getmouseshape()*
4486 Returns the name of the currently showing mouse pointer.
4487 When the |+mouseshape| feature is not supported or the shape
4488 is unknown an empty string is returned.
4489 This function is mainly intended for testing.
4490
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004491 Return type: |String|
4492
4493
4494getpid() *getpid()*
4495 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004496 On Unix and MS-Windows this is a unique number, until Vim
4497 exits.
4498
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004499 Return type: |Number|
4500
4501
4502getpos({expr}) *getpos()*
zeertzjq02f3eba2024-06-12 20:45:24 +02004503 Get the position for String {expr}.
4504 The accepted values for {expr} are: *E1209*
4505 . The cursor position.
4506 $ The last line in the current buffer.
4507 'x Position of mark x (if the mark is not set, 0 is
zeertzjqd353d272024-06-13 23:00:25 +08004508 returned for all values).
zeertzjq02f3eba2024-06-12 20:45:24 +02004509 w0 First line visible in current window (one if the
4510 display isn't updated, e.g. in silent Ex mode).
4511 w$ Last line visible in current window (this is one
4512 less than "w0" if no lines are visible).
4513 v When not in Visual mode, returns the cursor
4514 position. In Visual mode, returns the other end
4515 of the Visual area. A good way to think about
4516 this is that in Visual mode "v" and "." complement
4517 each other. While "." refers to the cursor
4518 position, "v" refers to where |v_o| would move the
4519 cursor. As a result, you can use "v" and "."
4520 together to work on all of a selection in
4521 characterwise Visual mode. If the cursor is at
4522 the end of a characterwise Visual area, "v" refers
4523 to the start of the same Visual area. And if the
4524 cursor is at the start of a characterwise Visual
4525 area, "v" refers to the end of the same Visual
4526 area. "v" differs from |'<| and |'>| in that it's
4527 updated right away.
4528 Note that a mark in another file can be used. The line number
4529 then applies to another buffer.
4530
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004531 The result is a |List| with four numbers:
4532 [bufnum, lnum, col, off]
4533 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4534 is the buffer number of the mark.
4535 "lnum" and "col" are the position in the buffer. The first
4536 column is 1.
4537 The "off" number is zero, unless 'virtualedit' is used. Then
4538 it is the offset in screen columns from the start of the
4539 character. E.g., a position within a <Tab> or after the last
4540 character.
zeertzjq02f3eba2024-06-12 20:45:24 +02004541
4542 For getting the cursor position see |getcurpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004543 The column number in the returned List is the byte position
4544 within the line. To get the character position in the line,
4545 use |getcharpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02004546
4547 Note that for '< and '> Visual mode matters: when it is "V"
4548 (visual line mode) the column of '< is zero and the column of
4549 '> is a large number equal to |v:maxcol|.
naohiro ono56200ee2022-01-01 14:59:44 +00004550 A very large column number equal to |v:maxcol| can be returned,
4551 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004552 If {expr} is invalid, returns a list with all zeros.
zeertzjq02f3eba2024-06-12 20:45:24 +02004553
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004554 This can be used to save and restore the position of a mark: >
4555 let save_a_mark = getpos("'a")
4556 ...
4557 call setpos("'a", save_a_mark)
zeertzjqd353d272024-06-13 23:00:25 +08004558<
4559 Also see |getcharpos()|, |getcurpos()| and |setpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004560
4561 Can also be used as a |method|: >
4562 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004563<
4564 Return type: list<number>
4565
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004566
4567getqflist([{what}]) *getqflist()*
4568 Returns a |List| with all the current quickfix errors. Each
4569 list item is a dictionary with these entries:
4570 bufnr number of buffer that has the file name, use
4571 bufname() to get the name
4572 module module name
4573 lnum line number in the buffer (first line is 1)
4574 end_lnum
4575 end of line number if the item is multiline
4576 col column number (first column is 1)
4577 end_col end of column number if the item has range
4578 vcol |TRUE|: "col" is visual column
4579 |FALSE|: "col" is byte index
4580 nr error number
h-east84ac2122024-06-17 18:12:30 +02004581 pattern search pattern used to locate the error
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004582 text description of the error
4583 type type of the error, 'E', '1', etc.
4584 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004585 user_data
4586 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004587 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004588
4589 When there is no error list or it's empty, an empty list is
4590 returned. Quickfix list entries with a non-existing buffer
4591 number are returned with "bufnr" set to zero (Note: some
4592 functions accept buffer number zero for the alternate buffer,
4593 you may need to explicitly check for zero).
4594
4595 Useful application: Find pattern matches in multiple files and
4596 do something with them: >
4597 :vimgrep /theword/jg *.c
4598 :for d in getqflist()
4599 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4600 :endfor
4601<
4602 If the optional {what} dictionary argument is supplied, then
4603 returns only the items listed in {what} as a dictionary. The
4604 following string items are supported in {what}:
4605 changedtick get the total number of changes made
4606 to the list |quickfix-changedtick|
4607 context get the |quickfix-context|
4608 efm errorformat to use when parsing "lines". If
4609 not present, then the 'errorformat' option
4610 value is used.
4611 id get information for the quickfix list with
4612 |quickfix-ID|; zero means the id for the
4613 current list or the list specified by "nr"
4614 idx get information for the quickfix entry at this
4615 index in the list specified by 'id' or 'nr'.
4616 If set to zero, then uses the current entry.
4617 See |quickfix-index|
4618 items quickfix list entries
4619 lines parse a list of lines using 'efm' and return
4620 the resulting entries. Only a |List| type is
4621 accepted. The current quickfix list is not
4622 modified. See |quickfix-parse|.
4623 nr get information for this quickfix list; zero
4624 means the current quickfix list and "$" means
4625 the last quickfix list
4626 qfbufnr number of the buffer displayed in the quickfix
4627 window. Returns 0 if the quickfix buffer is
4628 not present. See |quickfix-buffer|.
4629 size number of entries in the quickfix list
4630 title get the list title |quickfix-title|
4631 winid get the quickfix |window-ID|
4632 all all of the above quickfix properties
4633 Non-string items in {what} are ignored. To get the value of a
4634 particular item, set it to zero.
4635 If "nr" is not present then the current quickfix list is used.
4636 If both "nr" and a non-zero "id" are specified, then the list
4637 specified by "id" is used.
4638 To get the number of lists in the quickfix stack, set "nr" to
4639 "$" in {what}. The "nr" value in the returned dictionary
4640 contains the quickfix stack size.
4641 When "lines" is specified, all the other items except "efm"
4642 are ignored. The returned dictionary contains the entry
4643 "items" with the list of entries.
4644
4645 The returned dictionary contains the following entries:
4646 changedtick total number of changes made to the
4647 list |quickfix-changedtick|
4648 context quickfix list context. See |quickfix-context|
4649 If not present, set to "".
4650 id quickfix list ID |quickfix-ID|. If not
4651 present, set to 0.
4652 idx index of the quickfix entry in the list. If not
4653 present, set to 0.
4654 items quickfix list entries. If not present, set to
4655 an empty list.
4656 nr quickfix list number. If not present, set to 0
4657 qfbufnr number of the buffer displayed in the quickfix
4658 window. If not present, set to 0.
4659 size number of entries in the quickfix list. If not
4660 present, set to 0.
4661 title quickfix list title text. If not present, set
4662 to "".
4663 winid quickfix |window-ID|. If not present, set to 0
4664
4665 Examples (See also |getqflist-examples|): >
4666 :echo getqflist({'all': 1})
4667 :echo getqflist({'nr': 2, 'title': 1})
4668 :echo getqflist({'lines' : ["F1:10:L10"]})
4669<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004670 Return type: list<dict<any>> or list<any>
4671
4672
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004673getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4674 The result is a String, which is the contents of register
4675 {regname}. Example: >
4676 :let cliptext = getreg('*')
4677< When register {regname} was not set the result is an empty
4678 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004679 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004680
4681 getreg('=') returns the last evaluated value of the expression
4682 register. (For use in maps.)
4683 getreg('=', 1) returns the expression itself, so that it can
4684 be restored with |setreg()|. For other registers the extra
4685 argument is ignored, thus you can always give it.
4686
4687 If {list} is present and |TRUE|, the result type is changed
4688 to |List|. Each list item is one text line. Use it if you care
4689 about zero bytes possibly present inside register: without
4690 third argument both NLs and zero bytes are represented as NLs
4691 (see |NL-used-for-Nul|).
4692 When the register was not set an empty list is returned.
4693
4694 If {regname} is "", the unnamed register '"' is used.
4695 If {regname} is not specified, |v:register| is used.
4696 In |Vim9-script| {regname} must be one character.
4697
4698 Can also be used as a |method|: >
4699 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004700<
4701 Return type: |String|
4702
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004703
4704getreginfo([{regname}]) *getreginfo()*
4705 Returns detailed information about register {regname} as a
4706 Dictionary with the following entries:
4707 regcontents List of lines contained in register
4708 {regname}, like
4709 |getreg|({regname}, 1, 1).
4710 regtype the type of register {regname}, as in
4711 |getregtype()|.
4712 isunnamed Boolean flag, v:true if this register
4713 is currently pointed to by the unnamed
4714 register.
4715 points_to for the unnamed register, gives the
4716 single letter name of the register
4717 currently pointed to (see |quotequote|).
4718 For example, after deleting a line
4719 with `dd`, this field will be "1",
4720 which is the register that got the
4721 deleted text.
4722
4723 The {regname} argument is a string. If {regname} is invalid
4724 or not set, an empty Dictionary will be returned.
4725 If {regname} is "" or "@", the unnamed register '"' is used.
4726 If {regname} is not specified, |v:register| is used.
4727 The returned Dictionary can be passed to |setreg()|.
4728 In |Vim9-script| {regname} must be one character.
4729
4730 Can also be used as a |method|: >
4731 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004732<
4733 Return type: dict<any>
4734
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004735
Shougo Matsushita19b71882024-02-28 22:48:12 +01004736getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004737 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01004738 buffer.
4739
4740 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004741 See |getpos()| for the format of the list. It's possible
4742 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01004743 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01004744
4745 The optional argument {opts} is a Dict and supports the
4746 following items:
4747
zeertzjqafc22952024-05-24 19:07:12 +02004748 type Specify the region's selection type.
4749 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02004750 except that the width can be omitted
4751 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02004752 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01004753
zeertzjq87410ab2024-03-02 06:00:23 +08004754 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02004755 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08004756 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01004757
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004758 You can get the last selection type by |visualmode()|.
4759 If Visual mode is active, use |mode()| to get the Visual mode
4760 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08004761 This function is useful to get text starting and ending in
4762 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004763
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004764 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004765 Note that:
4766 - Order of {pos1} and {pos2} doesn't matter, it will always
4767 return content from the upper left position to the lower
4768 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08004769 - If 'virtualedit' is enabled and the region is past the end
4770 of the lines, resulting lines are padded with spaces.
4771 - If the region is blockwise and it starts or ends in the
4772 middle of a multi-cell character, it is not included but
4773 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004774 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01004775 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004776 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01004777 - It is evaluated in current window context, which makes a
4778 difference if the buffer is displayed in a window with
4779 different 'virtualedit' or 'list' values.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004780
4781 Examples: >
4782 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01004783 \ <Cmd>echow getregion(
4784 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004785<
4786 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01004787 getpos('.')->getregion(getpos("'a"))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004788
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004789<
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004790getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
4791 Same as |getregion()|, but returns a list of positions
4792 describing the buffer text segments bound by {pos1} and
4793 {pos2}.
4794 The segments are a pair of positions for every line: >
4795 [[{start_pos}, {end_pos}], ...]
4796<
4797 The position is a |List| with four numbers:
4798 [bufnum, lnum, col, off]
4799 "bufnum" is the buffer number.
4800 "lnum" and "col" are the position in the buffer. The first
4801 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02004802 If the "off" number of a starting position is non-zero, it is
4803 the offset in screen columns from the start of the character.
4804 E.g., a position within a <Tab> or after the last character.
4805 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02004806 the offset of the character's first cell not included in the
4807 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004808
zeertzjq2b09de92024-05-24 07:48:51 +02004809 Apart from the options supported by |getregion()|, {opts} also
4810 supports the following:
4811
4812 eol If |TRUE|, indicate positions beyond
4813 the end of a line with "col" values
4814 one more than the length of the line.
4815 If |FALSE|, positions are limited
4816 within their lines, and if a line is
4817 empty or the selection is entirely
4818 beyond the end of a line, a "col"
4819 value of 0 is used for both positions.
4820 (default: |FALSE|)
4821
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004822 Can also be used as a |method|: >
4823 getpos('.')->getregionpos(getpos("'a"))
4824<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004825 Return type: list<string>
4826
4827
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004828getregtype([{regname}]) *getregtype()*
4829 The result is a String, which is type of register {regname}.
4830 The value will be one of:
4831 "v" for |characterwise| text
4832 "V" for |linewise| text
4833 "<CTRL-V>{width}" for |blockwise-visual| text
4834 "" for an empty or unknown register
4835 <CTRL-V> is one character with value 0x16.
4836 The {regname} argument is a string. If {regname} is "", the
4837 unnamed register '"' is used. If {regname} is not specified,
4838 |v:register| is used.
4839 In |Vim9-script| {regname} must be one character.
4840
4841 Can also be used as a |method|: >
4842 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004843<
4844 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004845
Bram Moolenaar71badf92023-04-22 22:40:14 +01004846getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004847 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01004848 scripts in the order they were sourced, like what
4849 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004850
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004851 The optional Dict argument {opts} supports the following
4852 optional items:
4853 name Script name match pattern. If specified,
4854 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01004855 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004856 "name" are returned.
4857 sid Script ID |<SID>|. If specified, only
4858 information about the script with ID "sid" is
4859 returned and "name" is ignored.
4860
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004861 Each item in the returned List is a |Dict| with the following
4862 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004863 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01004864 `import autoload` but was not actually sourced
4865 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004866 functions List of script-local function names defined in
4867 the script. Present only when a particular
4868 script is specified using the "sid" item in
4869 {opts}.
4870 name Vim script file name.
4871 sid Script ID |<SID>|.
4872 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01004873 this script name links to, if any, otherwise
4874 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004875 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00004876 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004877 specified using the "sid" item in {opts}.
4878 Note that this is a copy, the value of
4879 script-local variables cannot be changed using
4880 this dictionary.
h_east59858792023-10-25 22:47:05 +09004881 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01004882
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004883 Examples: >
4884 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08004885 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004886<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004887 Return type: list<dict<any>>
4888
4889
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004890gettabinfo([{tabnr}]) *gettabinfo()*
4891 If {tabnr} is not specified, then information about all the
4892 tab pages is returned as a |List|. Each List item is a
4893 |Dictionary|. Otherwise, {tabnr} specifies the tab page
4894 number and information about that one is returned. If the tab
4895 page does not exist an empty List is returned.
4896
4897 Each List item is a |Dictionary| with the following entries:
4898 tabnr tab page number.
4899 variables a reference to the dictionary with
4900 tabpage-local variables
4901 windows List of |window-ID|s in the tab page.
4902
4903 Can also be used as a |method|: >
4904 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004905<
4906 Return type: list<dict<any>>
4907
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004908
4909gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
4910 Get the value of a tab-local variable {varname} in tab page
4911 {tabnr}. |t:var|
4912 Tabs are numbered starting with one.
4913 The {varname} argument is a string. When {varname} is empty a
4914 dictionary with all tab-local variables is returned.
4915 Note that the name without "t:" must be used.
4916 When the tab or variable doesn't exist {def} or an empty
4917 string is returned, there is no error message.
4918
4919 Can also be used as a |method|: >
4920 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004921<
4922 Return type: any, depending on {varname}
4923
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004924
4925gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
4926 Get the value of window-local variable {varname} in window
4927 {winnr} in tab page {tabnr}.
4928 The {varname} argument is a string. When {varname} is empty a
4929 dictionary with all window-local variables is returned.
4930 When {varname} is equal to "&" get the values of all
4931 window-local options in a |Dictionary|.
4932 Otherwise, when {varname} starts with "&" get the value of a
4933 window-local option.
4934 Note that {varname} must be the name without "w:".
4935 Tabs are numbered starting with one. For the current tabpage
4936 use |getwinvar()|.
4937 {winnr} can be the window number or the |window-ID|.
4938 When {winnr} is zero the current window is used.
4939 This also works for a global option, buffer-local option and
4940 window-local option, but it doesn't work for a global variable
4941 or buffer-local variable.
4942 When the tab, window or variable doesn't exist {def} or an
4943 empty string is returned, there is no error message.
4944 Examples: >
4945 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004946 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004947<
4948 To obtain all window-local variables use: >
4949 gettabwinvar({tabnr}, {winnr}, '&')
4950
4951< Can also be used as a |method|: >
4952 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004953<
4954 Return type: any, depending on {varname}
4955
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004956
4957gettagstack([{winnr}]) *gettagstack()*
4958 The result is a Dict, which is the tag stack of window {winnr}.
4959 {winnr} can be the window number or the |window-ID|.
4960 When {winnr} is not specified, the current window is used.
4961 When window {winnr} doesn't exist, an empty Dict is returned.
4962
4963 The returned dictionary contains the following entries:
4964 curidx Current index in the stack. When at
4965 top of the stack, set to (length + 1).
4966 Index of bottom of the stack is 1.
4967 items List of items in the stack. Each item
4968 is a dictionary containing the
4969 entries described below.
4970 length Number of entries in the stack.
4971
4972 Each item in the stack is a dictionary with the following
4973 entries:
4974 bufnr buffer number of the current jump
4975 from cursor position before the tag jump.
4976 See |getpos()| for the format of the
4977 returned list.
4978 matchnr current matching tag number. Used when
4979 multiple matching tags are found for a
4980 name.
4981 tagname name of the tag
4982
4983 See |tagstack| for more information about the tag stack.
4984
4985 Can also be used as a |method|: >
4986 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004987<
4988 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004989
4990
Christ van Willegence0ef912024-06-20 23:41:59 +02004991gettext({text} [, {package}]) *gettext()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004992 Translate String {text} if possible.
4993 This is mainly for use in the distributed Vim scripts. When
4994 generating message translations the {text} is extracted by
4995 xgettext, the translator can add the translated message in the
4996 .po file and Vim will lookup the translation when gettext() is
4997 called.
4998 For {text} double quoted strings are preferred, because
4999 xgettext does not understand escaping in single quoted
5000 strings.
Christ van Willegence0ef912024-06-20 23:41:59 +02005001 When the {package} is specified, the translation is looked up
5002 for that specific package. You need to specify the path to
5003 look for translations with the |bindtextdomain()| function.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005004
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005005 Return type: |String|
5006
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005007
5008getwininfo([{winid}]) *getwininfo()*
5009 Returns information about windows as a |List| with Dictionaries.
5010
5011 If {winid} is given Information about the window with that ID
5012 is returned, as a |List| with one item. If the window does not
5013 exist the result is an empty list.
5014
5015 Without {winid} information about all the windows in all the
5016 tab pages is returned.
5017
5018 Each List item is a |Dictionary| with the following entries:
5019 botline last complete displayed buffer line
5020 bufnr number of buffer in the window
5021 height window height (excluding winbar)
5022 loclist 1 if showing a location list
5023 {only with the +quickfix feature}
5024 quickfix 1 if quickfix or location list window
5025 {only with the +quickfix feature}
5026 terminal 1 if a terminal window
5027 {only with the +terminal feature}
5028 tabnr tab page number
5029 topline first displayed buffer line
5030 variables a reference to the dictionary with
5031 window-local variables
5032 width window width
5033 winbar 1 if the window has a toolbar, 0
5034 otherwise
5035 wincol leftmost screen column of the window;
5036 "col" from |win_screenpos()|
5037 textoff number of columns occupied by any
5038 'foldcolumn', 'signcolumn' and line
5039 number in front of the text
5040 winid |window-ID|
5041 winnr window number
5042 winrow topmost screen line of the window;
5043 "row" from |win_screenpos()|
5044
5045 Can also be used as a |method|: >
5046 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005047<
5048 Return type: list<dict<any>>
5049
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005050
5051getwinpos([{timeout}]) *getwinpos()*
5052 The result is a |List| with two numbers, the result of
5053 |getwinposx()| and |getwinposy()| combined:
5054 [x-pos, y-pos]
5055 {timeout} can be used to specify how long to wait in msec for
5056 a response from the terminal. When omitted 100 msec is used.
5057 Use a longer time for a remote terminal.
5058 When using a value less than 10 and no response is received
5059 within that time, a previously reported position is returned,
5060 if available. This can be used to poll for the position and
5061 do some work in the meantime: >
5062 while 1
5063 let res = getwinpos(1)
5064 if res[0] >= 0
5065 break
5066 endif
5067 " Do some work here
5068 endwhile
5069<
5070
5071 Can also be used as a |method|: >
5072 GetTimeout()->getwinpos()
5073<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005074 Return type: list<number>
5075
5076
5077getwinposx() *getwinposx()*
5078 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005079 the left hand side of the GUI Vim window. Also works for an
5080 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005081 The result will be -1 if the information is not available
5082 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005083 The value can be used with `:winpos`.
5084
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005085 Return type: |Number|
5086
5087
5088getwinposy() *getwinposy()*
5089 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005090 the top of the GUI Vim window. Also works for an xterm (uses
5091 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005092 The result will be -1 if the information is not available
5093 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005094 The value can be used with `:winpos`.
5095
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005096 Return type: |Number|
5097
5098
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005099getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5100 Like |gettabwinvar()| for the current tabpage.
5101 Examples: >
5102 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005103 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005104
5105< Can also be used as a |method|: >
5106 GetWinnr()->getwinvar(varname)
5107<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005108 Return type: any, depending on {varname}
5109
5110
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005111glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5112 Expand the file wildcards in {expr}. See |wildcards| for the
5113 use of special characters.
5114
5115 Unless the optional {nosuf} argument is given and is |TRUE|,
5116 the 'suffixes' and 'wildignore' options apply: Names matching
5117 one of the patterns in 'wildignore' will be skipped and
5118 'suffixes' affect the ordering of matches.
5119 'wildignorecase' always applies.
5120
5121 When {list} is present and it is |TRUE| the result is a |List|
5122 with all matching files. The advantage of using a List is,
5123 you also get filenames containing newlines correctly.
5124 Otherwise the result is a String and when there are several
5125 matches, they are separated by <NL> characters.
5126
5127 If the expansion fails, the result is an empty String or List.
5128
5129 You can also use |readdir()| if you need to do complicated
5130 things, such as limiting the number of matches.
5131
5132 A name for a non-existing file is not included. A symbolic
5133 link is only included if it points to an existing file.
5134 However, when the {alllinks} argument is present and it is
5135 |TRUE| then all symbolic links are included.
5136
5137 For most systems backticks can be used to get files names from
5138 any external command. Example: >
5139 :let tagfiles = glob("`find . -name tags -print`")
5140 :let &tags = substitute(tagfiles, "\n", ",", "g")
5141< The result of the program inside the backticks should be one
5142 item per line. Spaces inside an item are allowed.
5143
5144 See |expand()| for expanding special Vim variables. See
5145 |system()| for getting the raw output of an external command.
5146
5147 Can also be used as a |method|: >
5148 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005149<
5150 Return type: |String| or list<string> or list<any> depending
5151 on {list}
5152
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005153
5154glob2regpat({string}) *glob2regpat()*
5155 Convert a file pattern, as used by glob(), into a search
5156 pattern. The result can be used to match with a string that
5157 is a file name. E.g. >
5158 if filename =~ glob2regpat('Make*.mak')
5159< This is equivalent to: >
5160 if filename =~ '^Make.*\.mak$'
5161< When {string} is an empty string the result is "^$", match an
5162 empty string.
5163 Note that the result depends on the system. On MS-Windows
5164 a backslash usually means a path separator.
5165
5166 Can also be used as a |method|: >
5167 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005168<
5169 Return type: |String|
5170
5171 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005172globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5173 Perform glob() for String {expr} on all directories in {path}
5174 and concatenate the results. Example: >
5175 :echo globpath(&rtp, "syntax/c.vim")
5176<
5177 {path} is a comma-separated list of directory names. Each
5178 directory name is prepended to {expr} and expanded like with
5179 |glob()|. A path separator is inserted when needed.
5180 To add a comma inside a directory name escape it with a
5181 backslash. Note that on MS-Windows a directory may have a
5182 trailing backslash, remove it if you put a comma after it.
5183 If the expansion fails for one of the directories, there is no
5184 error message.
5185
5186 Unless the optional {nosuf} argument is given and is |TRUE|,
5187 the 'suffixes' and 'wildignore' options apply: Names matching
5188 one of the patterns in 'wildignore' will be skipped and
5189 'suffixes' affect the ordering of matches.
5190
5191 When {list} is present and it is |TRUE| the result is a |List|
5192 with all matching files. The advantage of using a List is, you
5193 also get filenames containing newlines correctly. Otherwise
5194 the result is a String and when there are several matches,
5195 they are separated by <NL> characters. Example: >
5196 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5197<
5198 {alllinks} is used as with |glob()|.
5199
5200 The "**" item can be used to search in a directory tree.
5201 For example, to find all "README.txt" files in the directories
5202 in 'runtimepath' and below: >
5203 :echo globpath(&rtp, "**/README.txt")
5204< Upwards search and limiting the depth of "**" is not
5205 supported, thus using 'path' will not always work properly.
5206
5207 Can also be used as a |method|, the base is passed as the
5208 second argument: >
5209 GetExpr()->globpath(&rtp)
5210<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005211 Return type: |String| or list<string> or list<any> depending
5212 on {list}
5213
5214
5215has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005216 When {check} is omitted or is zero: The result is a Number,
5217 which is 1 if the feature {feature} is supported, zero
5218 otherwise. The {feature} argument is a string, case is
5219 ignored. See |feature-list| below.
5220
5221 When {check} is present and not zero: The result is a Number,
5222 which is 1 if the feature {feature} could ever be supported,
5223 zero otherwise. This is useful to check for a typo in
5224 {feature} and to detect dead code. Keep in mind that an older
5225 Vim version will not know about a feature added later and
5226 features that have been abandoned will not be known by the
5227 current Vim version.
5228
5229 Also see |exists()| and |exists_compiled()|.
5230
5231 Note that to skip code that has a syntax error when the
5232 feature is not available, Vim may skip the rest of the line
5233 and miss a following `endif`. Therefore put the `endif` on a
5234 separate line: >
5235 if has('feature')
5236 let x = this->breaks->without->the->feature
5237 endif
5238< If the `endif` would be moved to the second line as "| endif" it
5239 would not be found.
5240
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005241 Return type: |Number|
5242
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005243
5244has_key({dict}, {key}) *has_key()*
5245 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005246 has an entry with key {key}. FALSE otherwise.
5247 The {key} argument is a string. In |Vim9| script a number is
5248 also accepted (and converted to a string) but no other types.
5249 In legacy script the usual automatic conversion to string is
5250 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005251
5252 Can also be used as a |method|: >
5253 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005254<
5255 Return type: |Number|
5256
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005257
5258haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5259 The result is a Number:
5260 1 when the window has set a local directory via |:lcd|
5261 2 when the tab-page has set a local directory via |:tcd|
5262 0 otherwise.
5263
5264 Without arguments use the current window.
5265 With {winnr} use this window in the current tab page.
5266 With {winnr} and {tabnr} use the window in the specified tab
5267 page.
5268 {winnr} can be the window number or the |window-ID|.
5269 If {winnr} is -1 it is ignored and only the tabpage is used.
5270 Return 0 if the arguments are invalid.
5271 Examples: >
5272 if haslocaldir() == 1
5273 " window local directory case
5274 elseif haslocaldir() == 2
5275 " tab-local directory case
5276 else
5277 " global directory case
5278 endif
5279
5280 " current window
5281 :echo haslocaldir()
5282 :echo haslocaldir(0)
5283 :echo haslocaldir(0, 0)
5284 " window n in current tab page
5285 :echo haslocaldir(n)
5286 :echo haslocaldir(n, 0)
5287 " window n in tab page m
5288 :echo haslocaldir(n, m)
5289 " tab page m
5290 :echo haslocaldir(-1, m)
5291<
5292 Can also be used as a |method|: >
5293 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005294<
5295 Return type: |Number|
5296
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005297
5298hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5299 The result is a Number, which is TRUE if there is a mapping
5300 that contains {what} in somewhere in the rhs (what it is
5301 mapped to) and this mapping exists in one of the modes
5302 indicated by {mode}.
5303 The arguments {what} and {mode} are strings.
5304 When {abbr} is there and it is |TRUE| use abbreviations
5305 instead of mappings. Don't forget to specify Insert and/or
5306 Command-line mode.
5307 Both the global mappings and the mappings local to the current
5308 buffer are checked for a match.
5309 If no matching mapping is found FALSE is returned.
5310 The following characters are recognized in {mode}:
5311 n Normal mode
5312 v Visual and Select mode
5313 x Visual mode
5314 s Select mode
5315 o Operator-pending mode
5316 i Insert mode
5317 l Language-Argument ("r", "f", "t", etc.)
5318 c Command-line mode
5319 When {mode} is omitted, "nvo" is used.
5320
5321 This function is useful to check if a mapping already exists
5322 to a function in a Vim script. Example: >
5323 :if !hasmapto('\ABCdoit')
5324 : map <Leader>d \ABCdoit
5325 :endif
5326< This installs the mapping to "\ABCdoit" only if there isn't
5327 already a mapping to "\ABCdoit".
5328
5329 Can also be used as a |method|: >
5330 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005331<
5332 Return type: |Number|
5333
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005334
5335histadd({history}, {item}) *histadd()*
5336 Add the String {item} to the history {history} which can be
5337 one of: *hist-names*
5338 "cmd" or ":" command line history
5339 "search" or "/" search pattern history
5340 "expr" or "=" typed expression history
5341 "input" or "@" input line history
5342 "debug" or ">" debug command history
5343 empty the current or last used history
5344 The {history} string does not need to be the whole name, one
5345 character is sufficient.
5346 If {item} does already exist in the history, it will be
5347 shifted to become the newest entry.
5348 The result is a Number: TRUE if the operation was successful,
5349 otherwise FALSE is returned.
5350
5351 Example: >
5352 :call histadd("input", strftime("%Y %b %d"))
5353 :let date=input("Enter date: ")
5354< This function is not available in the |sandbox|.
5355
5356 Can also be used as a |method|, the base is passed as the
5357 second argument: >
5358 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005359<
5360 Return type: |Number|
5361
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005362
5363histdel({history} [, {item}]) *histdel()*
5364 Clear {history}, i.e. delete all its entries. See |hist-names|
5365 for the possible values of {history}.
5366
5367 If the parameter {item} evaluates to a String, it is used as a
5368 regular expression. All entries matching that expression will
5369 be removed from the history (if there are any).
5370 Upper/lowercase must match, unless "\c" is used |/\c|.
5371 If {item} evaluates to a Number, it will be interpreted as
5372 an index, see |:history-indexing|. The respective entry will
5373 be removed if it exists.
5374
5375 The result is TRUE for a successful operation, otherwise FALSE
5376 is returned.
5377
5378 Examples:
5379 Clear expression register history: >
5380 :call histdel("expr")
5381<
5382 Remove all entries starting with "*" from the search history: >
5383 :call histdel("/", '^\*')
5384<
5385 The following three are equivalent: >
5386 :call histdel("search", histnr("search"))
5387 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005388 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005389<
5390 To delete the last search pattern and use the last-but-one for
5391 the "n" command and 'hlsearch': >
5392 :call histdel("search", -1)
5393 :let @/ = histget("search", -1)
5394<
5395 Can also be used as a |method|: >
5396 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005397<
5398 Return type: |Number|
5399
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005400
5401histget({history} [, {index}]) *histget()*
5402 The result is a String, the entry with Number {index} from
5403 {history}. See |hist-names| for the possible values of
5404 {history}, and |:history-indexing| for {index}. If there is
5405 no such entry, an empty String is returned. When {index} is
5406 omitted, the most recent item from the history is used.
5407
5408 Examples:
5409 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005410 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005411
5412< Define an Ex command ":H {num}" that supports re-execution of
5413 the {num}th entry from the output of |:history|. >
5414 :command -nargs=1 H execute histget("cmd", 0+<args>)
5415<
5416 Can also be used as a |method|: >
5417 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005418<
5419 Return type: |String|
5420
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005421
5422histnr({history}) *histnr()*
5423 The result is the Number of the current entry in {history}.
5424 See |hist-names| for the possible values of {history}.
5425 If an error occurred, -1 is returned.
5426
5427 Example: >
5428 :let inp_index = histnr("expr")
5429
5430< Can also be used as a |method|: >
5431 GetHistory()->histnr()
5432<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005433 Return type: |Number|
5434
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005435hlexists({name}) *hlexists()*
5436 The result is a Number, which is TRUE if a highlight group
5437 called {name} exists. This is when the group has been
5438 defined in some way. Not necessarily when highlighting has
5439 been defined for it, it may also have been used for a syntax
5440 item.
5441 *highlight_exists()*
5442 Obsolete name: highlight_exists().
5443
5444 Can also be used as a |method|: >
5445 GetName()->hlexists()
5446<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005447 Return type: |Number|
5448
5449
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005450hlget([{name} [, {resolve}]]) *hlget()*
5451 Returns a List of all the highlight group attributes. If the
5452 optional {name} is specified, then returns a List with only
5453 the attributes of the specified highlight group. Returns an
5454 empty List if the highlight group {name} is not present.
5455
5456 If the optional {resolve} argument is set to v:true and the
5457 highlight group {name} is linked to another group, then the
5458 link is resolved recursively and the attributes of the
5459 resolved highlight group are returned.
5460
5461 Each entry in the returned List is a Dictionary with the
5462 following items:
5463 cleared boolean flag, set to v:true if the highlight
5464 group attributes are cleared or not yet
5465 specified. See |highlight-clear|.
5466 cterm cterm attributes. See |highlight-cterm|.
5467 ctermbg cterm background color.
5468 See |highlight-ctermbg|.
5469 ctermfg cterm foreground color.
5470 See |highlight-ctermfg|.
5471 ctermul cterm underline color. See |highlight-ctermul|.
5472 default boolean flag, set to v:true if the highlight
5473 group link is a default link. See
5474 |highlight-default|.
5475 font highlight group font. See |highlight-font|.
5476 gui gui attributes. See |highlight-gui|.
5477 guibg gui background color. See |highlight-guibg|.
5478 guifg gui foreground color. See |highlight-guifg|.
5479 guisp gui special color. See |highlight-guisp|.
5480 id highlight group ID.
5481 linksto linked highlight group name.
5482 See |:highlight-link|.
5483 name highlight group name. See |group-name|.
5484 start start terminal keycode. See |highlight-start|.
5485 stop stop terminal keycode. See |highlight-stop|.
5486 term term attributes. See |highlight-term|.
5487
5488 The 'term', 'cterm' and 'gui' items in the above Dictionary
5489 have a dictionary value with the following optional boolean
5490 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5491 'reverse', 'inverse' and 'strikethrough'.
5492
5493 Example(s): >
5494 :echo hlget()
5495 :echo hlget('ModeMsg')
5496 :echo hlget('Number', v:true)
5497<
5498 Can also be used as a |method|: >
5499 GetName()->hlget()
5500<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005501 Return type: list<dict<any>>
5502
5503
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005504hlset({list}) *hlset()*
5505 Creates or modifies the attributes of a List of highlight
5506 groups. Each item in {list} is a dictionary containing the
5507 attributes of a highlight group. See |hlget()| for the list of
5508 supported items in this dictionary.
5509
5510 In addition to the items described in |hlget()|, the following
5511 additional items are supported in the dictionary:
5512
5513 force boolean flag to force the creation of
5514 a link for an existing highlight group
5515 with attributes.
5516
5517 The highlight group is identified using the 'name' item and
5518 the 'id' item (if supplied) is ignored. If a highlight group
5519 with a specified name doesn't exist, then it is created.
5520 Otherwise the attributes of an existing highlight group are
5521 modified.
5522
5523 If an empty dictionary value is used for the 'term' or 'cterm'
5524 or 'gui' entries, then the corresponding attributes are
5525 cleared. If the 'cleared' item is set to v:true, then all the
5526 attributes of the highlight group are cleared.
5527
5528 The 'linksto' item can be used to link a highlight group to
5529 another highlight group. See |:highlight-link|.
5530
5531 Returns zero for success, -1 for failure.
5532
5533 Example(s): >
5534 " add bold attribute to the Visual highlight group
5535 :call hlset([#{name: 'Visual',
5536 \ term: #{reverse: 1 , bold: 1}}])
5537 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5538 :let l = hlget()
5539 :call hlset(l)
5540 " clear the Search highlight group
5541 :call hlset([#{name: 'Search', cleared: v:true}])
5542 " clear the 'term' attributes for a highlight group
5543 :call hlset([#{name: 'Title', term: {}}])
5544 " create the MyHlg group linking it to DiffAdd
5545 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5546 " remove the MyHlg group link
5547 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5548 " clear the attributes and a link
5549 :call hlset([#{name: 'MyHlg', cleared: v:true,
5550 \ linksto: 'NONE'}])
5551<
5552 Can also be used as a |method|: >
5553 GetAttrList()->hlset()
5554<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005555 Return type: |Number|
5556
5557hlID({name}) *hlID()*
5558 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005559 with name {name}. When the highlight group doesn't exist,
5560 zero is returned.
5561 This can be used to retrieve information about the highlight
5562 group. For example, to get the background color of the
5563 "Comment" group: >
5564 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5565< *highlightID()*
5566 Obsolete name: highlightID().
5567
5568 Can also be used as a |method|: >
5569 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005570<
5571 Return type: |Number|
5572
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005573
5574hostname() *hostname()*
5575 The result is a String, which is the name of the machine on
5576 which Vim is currently running. Machine names greater than
5577 256 characters long are truncated.
5578
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005579 Return type: |String|
5580
5581
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005582iconv({string}, {from}, {to}) *iconv()*
5583 The result is a String, which is the text {string} converted
5584 from encoding {from} to encoding {to}.
5585 When the conversion completely fails an empty string is
5586 returned. When some characters could not be converted they
5587 are replaced with "?".
5588 The encoding names are whatever the iconv() library function
5589 can accept, see ":!man 3 iconv".
5590 Most conversions require Vim to be compiled with the |+iconv|
5591 feature. Otherwise only UTF-8 to latin1 conversion and back
5592 can be done.
5593 This can be used to display messages with special characters,
5594 no matter what 'encoding' is set to. Write the message in
5595 UTF-8 and use: >
5596 echo iconv(utf8_str, "utf-8", &enc)
5597< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5598 from/to UCS-2 is automatically changed to use UTF-8. You
5599 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5600
5601 Can also be used as a |method|: >
5602 GetText()->iconv('latin1', 'utf-8')
5603<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005604 Return type: |String|
5605
5606
5607indent({lnum}) *indent()*
5608 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005609 current buffer. The indent is counted in spaces, the value
5610 of 'tabstop' is relevant. {lnum} is used just like in
5611 |getline()|.
5612 When {lnum} is invalid -1 is returned. In |Vim9| script an
5613 error is given.
5614
5615 Can also be used as a |method|: >
5616 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005617<
5618 Return type: |Number|
5619
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005620
5621index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005622 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005623 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005624
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005625 If {object} is a |List| return the lowest index where the item
5626 has a value equal to {expr}. There is no automatic
5627 conversion, so the String "4" is different from the Number 4.
5628 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005629 of 'ignorecase' is not used here, case matters as indicated by
5630 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005631
5632 If {object} is |Blob| return the lowest index where the byte
5633 value is equal to {expr}.
5634
5635 If {start} is given then start looking at the item with index
5636 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005637
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005638 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5639 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005640
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005641 -1 is returned when {expr} is not found in {object}.
5642 Example: >
5643 :let idx = index(words, "the")
5644 :if index(numbers, 123) >= 0
5645
5646< Can also be used as a |method|: >
5647 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005648<
5649 Return type: |Number|
5650
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005651
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005652indexof({object}, {expr} [, {opts}]) *indexof()*
5653 Returns the index of an item in {object} where {expr} is
5654 v:true. {object} must be a |List| or a |Blob|.
5655
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005656 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005657 List until the expression is v:true and return the index of
5658 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005659
5660 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005661 Blob until the expression is v:true and return the index of
5662 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005663
5664 {expr} must be a |string| or |Funcref|.
5665
5666 If {expr} is a |string|: If {object} is a |List|, inside
5667 {expr} |v:key| has the index of the current List item and
5668 |v:val| has the value of the item. If {object} is a |Blob|,
5669 inside {expr} |v:key| has the index of the current byte and
5670 |v:val| has the byte value.
5671
5672 If {expr} is a |Funcref| it must take two arguments:
5673 1. the key or the index of the current item.
5674 2. the value of the current item.
5675 The function must return |TRUE| if the item is found and the
5676 search should stop.
5677
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005678 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005679 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005680 startidx start evaluating {expr} at the item with this
5681 index; may be negative for an item relative to
5682 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005683 Returns -1 when {expr} evaluates to v:false for all the items.
5684 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005685 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
5686 :echo indexof(l, "v:val.n == 20")
5687 :echo indexof(l, {i, v -> v.n == 30})
5688 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005689
5690< Can also be used as a |method|: >
5691 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005692<
5693 Return type: |Number|
5694
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005695
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005696input({prompt} [, {text} [, {completion}]]) *input()*
5697 The result is a String, which is whatever the user typed on
5698 the command-line. The {prompt} argument is either a prompt
5699 string, or a blank string (for no prompt). A '\n' can be used
5700 in the prompt to start a new line.
5701 The highlighting set with |:echohl| is used for the prompt.
5702 The input is entered just like a command-line, with the same
5703 editing commands and mappings. There is a separate history
5704 for lines typed for input().
5705 Example: >
5706 :if input("Coffee or beer? ") == "beer"
5707 : echo "Cheers!"
5708 :endif
5709<
5710 If the optional {text} argument is present and not empty, this
5711 is used for the default reply, as if the user typed this.
5712 Example: >
5713 :let color = input("Color? ", "white")
5714
5715< The optional {completion} argument specifies the type of
5716 completion supported for the input. Without it completion is
5717 not performed. The supported completion types are the same as
5718 that can be supplied to a user-defined command using the
5719 "-complete=" argument. Refer to |:command-completion| for
5720 more information. Example: >
5721 let fname = input("File: ", "", "file")
5722<
5723 NOTE: This function must not be used in a startup file, for
5724 the versions that only run in GUI mode (e.g., the Win32 GUI).
5725 Note: When input() is called from within a mapping it will
5726 consume remaining characters from that mapping, because a
5727 mapping is handled like the characters were typed.
5728 Use |inputsave()| before input() and |inputrestore()|
5729 after input() to avoid that. Another solution is to avoid
5730 that further characters follow in the mapping, e.g., by using
5731 |:execute| or |:normal|.
5732
5733 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005734 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005735 :function GetFoo()
5736 : call inputsave()
5737 : let g:Foo = input("enter search pattern: ")
5738 : call inputrestore()
5739 :endfunction
5740
5741< Can also be used as a |method|: >
5742 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005743<
5744 Return type: |String|
5745
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005746
5747inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
5748 Like |input()|, but when the GUI is running and text dialogs
5749 are supported, a dialog window pops up to input the text.
5750 Example: >
5751 :let n = inputdialog("value for shiftwidth", shiftwidth())
5752 :if n != ""
5753 : let &sw = n
5754 :endif
5755< When the dialog is cancelled {cancelreturn} is returned. When
5756 omitted an empty string is returned.
5757 Hitting <Enter> works like pressing the OK button. Hitting
5758 <Esc> works like pressing the Cancel button.
5759 NOTE: Command-line completion is not supported.
5760
5761 Can also be used as a |method|: >
5762 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005763<
5764 Return type: |String|
5765
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005766
5767inputlist({textlist}) *inputlist()*
5768 {textlist} must be a |List| of strings. This |List| is
5769 displayed, one string per line. The user will be prompted to
5770 enter a number, which is returned.
5771 The user can also select an item by clicking on it with the
5772 mouse, if the mouse is enabled in the command line ('mouse' is
5773 "a" or includes "c"). For the first string 0 is returned.
5774 When clicking above the first item a negative number is
5775 returned. When clicking on the prompt one more than the
5776 length of {textlist} is returned.
5777 Make sure {textlist} has less than 'lines' entries, otherwise
5778 it won't work. It's a good idea to put the entry number at
5779 the start of the string. And put a prompt in the first item.
5780 Example: >
5781 let color = inputlist(['Select color:', '1. red',
5782 \ '2. green', '3. blue'])
5783
5784< Can also be used as a |method|: >
5785 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005786<
5787 Return type: |Number|
5788
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005789
5790inputrestore() *inputrestore()*
5791 Restore typeahead that was saved with a previous |inputsave()|.
5792 Should be called the same number of times inputsave() is
5793 called. Calling it more often is harmless though.
5794 Returns TRUE when there is nothing to restore, FALSE otherwise.
5795
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005796 Return type: |Number|
5797
5798
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005799inputsave() *inputsave()*
5800 Preserve typeahead (also from mappings) and clear it, so that
5801 a following prompt gets input from the user. Should be
5802 followed by a matching inputrestore() after the prompt. Can
5803 be used several times, in which case there must be just as
5804 many inputrestore() calls.
5805 Returns TRUE when out of memory, FALSE otherwise.
5806
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005807 Return type: |Number|
5808
5809
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005810inputsecret({prompt} [, {text}]) *inputsecret()*
5811 This function acts much like the |input()| function with but
5812 two exceptions:
5813 a) the user's response will be displayed as a sequence of
5814 asterisks ("*") thereby keeping the entry secret, and
5815 b) the user's response will not be recorded on the input
5816 |history| stack.
5817 The result is a String, which is whatever the user actually
5818 typed on the command-line in response to the issued prompt.
5819 NOTE: Command-line completion is not supported.
5820
5821 Can also be used as a |method|: >
5822 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005823<
5824 Return type: |String|
5825
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005826
5827insert({object}, {item} [, {idx}]) *insert()*
5828 When {object} is a |List| or a |Blob| insert {item} at the start
5829 of it.
5830
5831 If {idx} is specified insert {item} before the item with index
5832 {idx}. If {idx} is zero it goes before the first item, just
5833 like omitting {idx}. A negative {idx} is also possible, see
5834 |list-index|. -1 inserts just before the last item.
5835
5836 Returns the resulting |List| or |Blob|. Examples: >
5837 :let mylist = insert([2, 3, 5], 1)
5838 :call insert(mylist, 4, -1)
5839 :call insert(mylist, 6, len(mylist))
5840< The last example can be done simpler with |add()|.
5841 Note that when {item} is a |List| it is inserted as a single
5842 item. Use |extend()| to concatenate |Lists|.
5843
5844 Can also be used as a |method|: >
5845 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005846<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005847 Return type: |Number|
5848
5849
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005850 *instanceof()* *E614* *E616* *E693*
5851instanceof({object}, {class})
5852 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01005853 argument is a direct or indirect instance of a |Class|,
5854 |Interface|, or class |:type| alias specified by {class}.
5855 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005856 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02005857 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01005858 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02005859
5860< Can also be used as a |method|: >
5861 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005862<
5863 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02005864
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005865interrupt() *interrupt()*
5866 Interrupt script execution. It works more or less like the
5867 user typing CTRL-C, most commands won't execute and control
5868 returns to the user. This is useful to abort execution
5869 from lower down, e.g. in an autocommand. Example: >
5870 :function s:check_typoname(file)
5871 : if fnamemodify(a:file, ':t') == '['
5872 : echomsg 'Maybe typo'
5873 : call interrupt()
5874 : endif
5875 :endfunction
5876 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005877<
5878 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005879
5880invert({expr}) *invert()*
5881 Bitwise invert. The argument is converted to a number. A
5882 List, Dict or Float argument causes an error. Example: >
5883 :let bits = invert(bits)
5884< Can also be used as a |method|: >
5885 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005886<
5887 Return type: |Number|
5888
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005889
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005890isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01005891 The result is a Number, which is |TRUE| when {path} is an
5892 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005893 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01005894 On MS-Windows, it is considered absolute when it starts with an
5895 optional drive prefix and is followed by a '\' or '/'. UNC paths
5896 are always absolute.
5897 Example: >
5898 echo isabsolutepath('/usr/share/') " 1
5899 echo isabsolutepath('./foobar') " 0
5900 echo isabsolutepath('C:\Windows') " 1
5901 echo isabsolutepath('foobar') " 0
5902 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005903<
LemonBoydca1d402022-04-28 15:26:33 +01005904 Can also be used as a |method|: >
5905 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005906<
5907 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01005908
5909
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005910isdirectory({directory}) *isdirectory()*
5911 The result is a Number, which is |TRUE| when a directory
5912 with the name {directory} exists. If {directory} doesn't
5913 exist, or isn't a directory, the result is |FALSE|. {directory}
5914 is any expression, which is used as a String.
5915
5916 Can also be used as a |method|: >
5917 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005918<
5919 Return type: |Number|
5920
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005921
5922isinf({expr}) *isinf()*
5923 Return 1 if {expr} is a positive infinity, or -1 a negative
5924 infinity, otherwise 0. >
5925 :echo isinf(1.0 / 0.0)
5926< 1 >
5927 :echo isinf(-1.0 / 0.0)
5928< -1
5929
5930 Can also be used as a |method|: >
5931 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005932<
5933 Return type: |Number|
5934
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005935
5936islocked({expr}) *islocked()* *E786*
5937 The result is a Number, which is |TRUE| when {expr} is the
5938 name of a locked variable.
5939 The string argument {expr} must be the name of a variable,
5940 |List| item or |Dictionary| entry, not the variable itself!
5941 Example: >
5942 :let alist = [0, ['a', 'b'], 2, 3]
5943 :lockvar 1 alist
5944 :echo islocked('alist') " 1
5945 :echo islocked('alist[1]') " 0
5946
Bram Moolenaar9da17d72022-02-09 21:50:44 +00005947< When {expr} is a variable that does not exist -1 is returned.
5948 If {expr} uses a range, list or dict index that is out of
5949 range or does not exist you get an error message. Use
5950 |exists()| to check for existence.
5951 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005952
5953 Can also be used as a |method|: >
5954 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005955<
5956 Return type: |Number|
5957
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005958
5959isnan({expr}) *isnan()*
5960 Return |TRUE| if {expr} is a float with value NaN. >
5961 echo isnan(0.0 / 0.0)
5962< 1
5963
5964 Can also be used as a |method|: >
5965 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005966<
5967 Return type: |Number|
5968
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005969
5970items({dict}) *items()*
5971 Return a |List| with all the key-value pairs of {dict}. Each
5972 |List| item is a list with two items: the key of a {dict}
5973 entry and the value of this entry. The |List| is in arbitrary
5974 order. Also see |keys()| and |values()|.
5975 Example: >
5976 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005977 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005978 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01005979<
5980 A List or a String argument is also supported. In these
5981 cases, items() returns a List with the index and the value at
5982 the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005983
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01005984 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005985 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005986<
5987 Return type: list<list<any>> or list<any>
5988
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005989
5990job_ functions are documented here: |job-functions-details|
5991
5992
5993join({list} [, {sep}]) *join()*
5994 Join the items in {list} together into one String.
5995 When {sep} is specified it is put in between the items. If
5996 {sep} is omitted a single space is used.
5997 Note that {sep} is not added at the end. You might want to
5998 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005999 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006000< String items are used as-is. |Lists| and |Dictionaries| are
6001 converted into a string like with |string()|.
6002 The opposite function is |split()|.
6003
6004 Can also be used as a |method|: >
6005 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006006<
6007 Return type: |String|
6008
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006009
6010js_decode({string}) *js_decode()*
6011 This is similar to |json_decode()| with these differences:
6012 - Object key names do not have to be in quotes.
6013 - Strings can be in single quotes.
6014 - Empty items in an array (between two commas) are allowed and
6015 result in v:none items.
6016
6017 Can also be used as a |method|: >
6018 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006019<
6020 Return type: any, depending on {varname}
6021
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006022
6023js_encode({expr}) *js_encode()*
6024 This is similar to |json_encode()| with these differences:
6025 - Object key names are not in quotes.
6026 - v:none items in an array result in an empty item between
6027 commas.
6028 For example, the Vim object:
6029 [1,v:none,{"one":1},v:none] ~
6030 Will be encoded as:
6031 [1,,{one:1},,] ~
6032 While json_encode() would produce:
6033 [1,null,{"one":1},null] ~
6034 This encoding is valid for JavaScript. It is more efficient
6035 than JSON, especially when using an array with optional items.
6036
6037 Can also be used as a |method|: >
6038 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006039<
6040 Return type: |String|
6041
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006042
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006043json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006044 This parses a JSON formatted string and returns the equivalent
6045 in Vim values. See |json_encode()| for the relation between
6046 JSON and Vim values.
6047 The decoding is permissive:
6048 - A trailing comma in an array and object is ignored, e.g.
6049 "[1, 2, ]" is the same as "[1, 2]".
6050 - Integer keys are accepted in objects, e.g. {1:2} is the
6051 same as {"1":2}.
6052 - More floating point numbers are recognized, e.g. "1." for
6053 "1.0", or "001.2" for "1.2". Special floating point values
6054 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6055 are accepted.
6056 - Leading zeroes in integer numbers are ignored, e.g. "012"
6057 for "12" or "-012" for "-12".
6058 - Capitalization is ignored in literal names null, true or
6059 false, e.g. "NULL" for "null", "True" for "true".
6060 - Control characters U+0000 through U+001F which are not
6061 escaped in strings are accepted, e.g. " " (tab
6062 character in string) for "\t".
6063 - An empty JSON expression or made of only spaces is accepted
6064 and results in v:none.
6065 - Backslash in an invalid 2-character sequence escape is
6066 ignored, e.g. "\a" is decoded as "a".
6067 - A correct surrogate pair in JSON strings should normally be
6068 a 12 character sequence such as "\uD834\uDD1E", but
6069 json_decode() silently accepts truncated surrogate pairs
6070 such as "\uD834" or "\uD834\u"
6071 *E938*
6072 A duplicate key in an object, valid in rfc7159, is not
6073 accepted by json_decode() as the result must be a valid Vim
6074 type, e.g. this fails: {"a":"b", "a":"c"}
6075
6076 Can also be used as a |method|: >
6077 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006078<
6079 Return type: any, depending on {varname}
6080
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006081
6082json_encode({expr}) *json_encode()*
6083 Encode {expr} as JSON and return this as a string.
6084 The encoding is specified in:
6085 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006086 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006087 |Number| decimal number
6088 |Float| floating point number
6089 Float nan "NaN"
6090 Float inf "Infinity"
6091 Float -inf "-Infinity"
6092 |String| in double quotes (possibly null)
6093 |Funcref| not possible, error
6094 |List| as an array (possibly null); when
6095 used recursively: []
6096 |Dict| as an object (possibly null); when
6097 used recursively: {}
6098 |Blob| as an array of the individual bytes
6099 v:false "false"
6100 v:true "true"
6101 v:none "null"
6102 v:null "null"
6103 Note that NaN and Infinity are passed on as values. This is
6104 missing in the JSON standard, but several implementations do
6105 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006106 If a string contains an illegal character then the replacement
6107 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006108
6109 Can also be used as a |method|: >
6110 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006111<
6112 Return type: |String|
6113
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006114
6115keys({dict}) *keys()*
6116 Return a |List| with all the keys of {dict}. The |List| is in
6117 arbitrary order. Also see |items()| and |values()|.
6118
6119 Can also be used as a |method|: >
6120 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006121<
6122 Return type: list<string>
6123
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006124
zeertzjqcdc83932022-09-12 13:38:41 +01006125keytrans({string}) *keytrans()*
6126 Turn the internal byte representation of keys into a form that
6127 can be used for |:map|. E.g. >
6128 :let xx = "\<C-Home>"
6129 :echo keytrans(xx)
6130< <C-Home>
6131
6132 Can also be used as a |method|: >
6133 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006134<
6135 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006136
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006137
6138len({expr}) *len()* *E701*
6139 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006140 When {expr} is a String or a Number the length in bytes is
6141 used, as with |strlen()|.
6142 When {expr} is a |List| the number of items in the |List| is
6143 returned.
6144 When {expr} is a |Blob| the number of bytes is returned.
6145 When {expr} is a |Dictionary| the number of entries in the
6146 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006147 When {expr} is an |Object|, invokes the len() method in the
6148 object (if present) to get the length (|object-len()|).
6149 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006150
6151 Can also be used as a |method|: >
6152 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006153<
6154 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006155
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006156
6157 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006158libcall({libname}, {funcname}, {argument})
6159 Call function {funcname} in the run-time library {libname}
6160 with single argument {argument}.
6161 This is useful to call functions in a library that you
6162 especially made to be used with Vim. Since only one argument
6163 is possible, calling standard library functions is rather
6164 limited.
6165 The result is the String returned by the function. If the
6166 function returns NULL, this will appear as an empty string ""
6167 to Vim.
6168 If the function returns a number, use libcallnr()!
6169 If {argument} is a number, it is passed to the function as an
6170 int; if {argument} is a string, it is passed as a
6171 null-terminated string.
6172 This function will fail in |restricted-mode|.
6173
6174 libcall() allows you to write your own 'plug-in' extensions to
6175 Vim without having to recompile the program. It is NOT a
6176 means to call system functions! If you try to do so Vim will
6177 very probably crash.
6178
6179 For Win32, the functions you write must be placed in a DLL
6180 and use the normal C calling convention (NOT Pascal which is
6181 used in Windows System DLLs). The function must take exactly
6182 one parameter, either a character pointer or a long integer,
6183 and must return a character pointer or NULL. The character
6184 pointer returned must point to memory that will remain valid
6185 after the function has returned (e.g. in static data in the
6186 DLL). If it points to allocated memory, that memory will
6187 leak away. Using a static buffer in the function should work,
6188 it's then freed when the DLL is unloaded.
6189
6190 WARNING: If the function returns a non-valid pointer, Vim may
6191 crash! This also happens if the function returns a number,
6192 because Vim thinks it's a pointer.
6193 For Win32 systems, {libname} should be the filename of the DLL
6194 without the ".DLL" suffix. A full path is only required if
6195 the DLL is not in the usual places.
6196 For Unix: When compiling your own plugins, remember that the
6197 object code must be compiled as position-independent ('PIC').
6198 {only in Win32 and some Unix versions, when the |+libcall|
6199 feature is present}
6200 Examples: >
6201 :echo libcall("libc.so", "getenv", "HOME")
6202
6203< Can also be used as a |method|, the base is passed as the
6204 third argument: >
6205 GetValue()->libcall("libc.so", "getenv")
6206<
6207 *libcallnr()*
6208libcallnr({libname}, {funcname}, {argument})
6209 Just like |libcall()|, but used for a function that returns an
6210 int instead of a string.
6211 {only in Win32 on some Unix versions, when the |+libcall|
6212 feature is present}
6213 Examples: >
6214 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6215 :call libcallnr("libc.so", "printf", "Hello World!\n")
6216 :call libcallnr("libc.so", "sleep", 10)
6217<
6218 Can also be used as a |method|, the base is passed as the
6219 third argument: >
6220 GetValue()->libcallnr("libc.so", "printf")
6221<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006222 Return type: |String|
6223
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006224
6225line({expr} [, {winid}]) *line()*
6226 The result is a Number, which is the line number of the file
6227 position given with {expr}. The {expr} argument is a string.
zeertzjq02f3eba2024-06-12 20:45:24 +02006228 See |getpos()| for accepted positions.
6229
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006230 To get the column number use |col()|. To get both use
6231 |getpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02006232
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006233 With the optional {winid} argument the values are obtained for
6234 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02006235
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006236 Returns 0 for invalid values of {expr} and {winid}.
zeertzjq02f3eba2024-06-12 20:45:24 +02006237
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006238 Examples: >
6239 line(".") line number of the cursor
6240 line(".", winid) idem, in window "winid"
6241 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006242 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006243<
6244 To jump to the last known position when opening a file see
6245 |last-position-jump|.
6246
6247 Can also be used as a |method|: >
6248 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006249<
6250 Return type: |Number|
6251
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006252
6253line2byte({lnum}) *line2byte()*
6254 Return the byte count from the start of the buffer for line
6255 {lnum}. This includes the end-of-line character, depending on
6256 the 'fileformat' option for the current buffer. The first
6257 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6258 This can also be used to get the byte count for the line just
6259 below the last line: >
6260 line2byte(line("$") + 1)
6261< This is the buffer size plus one. If 'fileencoding' is empty
6262 it is the file size plus one. {lnum} is used like with
6263 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6264 feature has been disabled at compile time, -1 is returned.
6265 Also see |byte2line()|, |go| and |:goto|.
6266
6267 Can also be used as a |method|: >
6268 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006269<
6270 Return type: |Number|
6271
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006272
6273lispindent({lnum}) *lispindent()*
6274 Get the amount of indent for line {lnum} according the lisp
6275 indenting rules, as with 'lisp'.
6276 The indent is counted in spaces, the value of 'tabstop' is
6277 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006278 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006279 error is given.
6280
6281 Can also be used as a |method|: >
6282 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006283<
6284 Return type: |Number|
6285
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006286
6287list2blob({list}) *list2blob()*
6288 Return a Blob concatenating all the number values in {list}.
6289 Examples: >
6290 list2blob([1, 2, 3, 4]) returns 0z01020304
6291 list2blob([]) returns 0z
6292< Returns an empty Blob on error. If one of the numbers is
6293 negative or more than 255 error *E1239* is given.
6294
6295 |blob2list()| does the opposite.
6296
6297 Can also be used as a |method|: >
6298 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006299<
6300 Return type: |Blob|
6301
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006302
6303list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006304 Convert each number in {list} to a character string and
6305 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006306 list2str([32]) returns " "
6307 list2str([65, 66, 67]) returns "ABC"
6308< The same can be done (slowly) with: >
6309 join(map(list, {nr, val -> nr2char(val)}), '')
6310< |str2list()| does the opposite.
6311
6312 When {utf8} is omitted or zero, the current 'encoding' is used.
6313 When {utf8} is TRUE, always return UTF-8 characters.
6314 With UTF-8 composing characters work as expected: >
6315 list2str([97, 769]) returns "á"
6316<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006317 Returns an empty string on error.
6318
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006319 Can also be used as a |method|: >
6320 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006321<
6322 Return type: |String|
6323
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006324
6325listener_add({callback} [, {buf}]) *listener_add()*
6326 Add a callback function that will be invoked when changes have
6327 been made to buffer {buf}.
6328 {buf} refers to a buffer name or number. For the accepted
6329 values, see |bufname()|. When {buf} is omitted the current
6330 buffer is used.
6331 Returns a unique ID that can be passed to |listener_remove()|.
6332
6333 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006334 bufnr the buffer that was changed
6335 start first changed line number
6336 end first line number below the change
6337 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006338 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006339 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006340
6341 Example: >
6342 func Listener(bufnr, start, end, added, changes)
6343 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6344 endfunc
6345 call listener_add('Listener', bufnr)
6346
Bram Moolenaar944697a2022-02-20 19:48:20 +00006347< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006348 dictionary with these entries:
6349 lnum the first line number of the change
6350 end the first line below the change
6351 added number of lines added; negative if lines were
6352 deleted
6353 col first column in "lnum" that was affected by
6354 the change; one if unknown or the whole line
6355 was affected; this is a byte index, first
6356 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006357 When lines are inserted (not when a line is split, e.g. by
6358 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006359 lnum line above which the new line is added
6360 end equal to "lnum"
6361 added number of lines inserted
6362 col 1
6363 When lines are deleted the values are:
6364 lnum the first deleted line
6365 end the line below the first deleted line, before
6366 the deletion was done
6367 added negative, number of lines deleted
6368 col 1
6369 When lines are changed:
6370 lnum the first changed line
6371 end the line below the last changed line
6372 added 0
6373 col first column with a change or 1
6374
6375 The entries are in the order the changes were made, thus the
6376 most recent change is at the end. The line numbers are valid
6377 when the callback is invoked, but later changes may make them
6378 invalid, thus keeping a copy for later might not work.
6379
6380 The {callback} is invoked just before the screen is updated,
6381 when |listener_flush()| is called or when a change is being
6382 made that changes the line count in a way it causes a line
6383 number in the list of changes to become invalid.
6384
6385 The {callback} is invoked with the text locked, see
6386 |textlock|. If you do need to make changes to the buffer, use
6387 a timer to do this later |timer_start()|.
6388
6389 The {callback} is not invoked when the buffer is first loaded.
6390 Use the |BufReadPost| autocmd event to handle the initial text
6391 of a buffer.
6392 The {callback} is also not invoked when the buffer is
6393 unloaded, use the |BufUnload| autocmd event for that.
6394
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006395 Returns zero if {callback} or {buf} is invalid.
6396
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006397 Can also be used as a |method|, the base is passed as the
6398 second argument: >
6399 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006400<
6401 Return type: |Number|
6402
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006403
6404listener_flush([{buf}]) *listener_flush()*
6405 Invoke listener callbacks for buffer {buf}. If there are no
6406 pending changes then no callbacks are invoked.
6407
6408 {buf} refers to a buffer name or number. For the accepted
6409 values, see |bufname()|. When {buf} is omitted the current
6410 buffer is used.
6411
6412 Can also be used as a |method|: >
6413 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006414<
6415 Return type: |Number|
6416
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006417
6418listener_remove({id}) *listener_remove()*
6419 Remove a listener previously added with listener_add().
6420 Returns FALSE when {id} could not be found, TRUE when {id} was
6421 removed.
6422
6423 Can also be used as a |method|: >
6424 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006425<
6426 Return type: |Number|
6427
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006428
6429localtime() *localtime()*
6430 Return the current time, measured as seconds since 1st Jan
6431 1970. See also |strftime()|, |strptime()| and |getftime()|.
6432
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006433 Return type: |Number|
6434
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006435
6436log({expr}) *log()*
6437 Return the natural logarithm (base e) of {expr} as a |Float|.
6438 {expr} must evaluate to a |Float| or a |Number| in the range
6439 (0, inf].
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 log(10)
6443< 2.302585 >
6444 :echo log(exp(5))
6445< 5.0
6446
6447 Can also be used as a |method|: >
6448 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006449<
6450 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006451
6452
6453log10({expr}) *log10()*
6454 Return the logarithm of Float {expr} to base 10 as a |Float|.
6455 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006456 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006457 Examples: >
6458 :echo log10(1000)
6459< 3.0 >
6460 :echo log10(0.01)
6461< -2.0
6462
6463 Can also be used as a |method|: >
6464 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006465<
6466 Return type: |Float|
6467
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006468
6469luaeval({expr} [, {expr}]) *luaeval()*
6470 Evaluate Lua expression {expr} and return its result converted
6471 to Vim data structures. Second {expr} may hold additional
6472 argument accessible as _A inside first {expr}.
6473 Strings are returned as they are.
6474 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006475 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006476 Dictionaries and lists obtained by vim.eval() are returned
6477 as-is.
6478 Other objects are returned as zero without any errors.
6479 See |lua-luaeval| for more details.
6480 Note that in a `:def` function local variables are not visible
6481 to {expr}.
6482
6483 Can also be used as a |method|: >
6484 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006485<
6486 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006487
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006488 {only available when compiled with the |+lua| feature}
6489
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006490
6491map({expr1}, {expr2}) *map()*
6492 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006493 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006494 item in {expr1} with the result of evaluating {expr2}.
6495 For a |Blob| each byte is replaced.
6496 For a |String|, each character, including composing
6497 characters, is replaced.
6498 If the item type changes you may want to use |mapnew()| to
6499 create a new List or Dictionary. This is required when using
6500 Vim9 script.
6501
6502 {expr2} must be a |String| or |Funcref|.
6503
6504 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6505 of the current item. For a |Dictionary| |v:key| has the key
6506 of the current item and for a |List| |v:key| has the index of
6507 the current item. For a |Blob| |v:key| has the index of the
6508 current byte. For a |String| |v:key| has the index of the
6509 current character.
6510 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006511 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006512< This puts "> " before and " <" after each item in "mylist".
6513
6514 Note that {expr2} is the result of an expression and is then
6515 used as an expression again. Often it is good to use a
6516 |literal-string| to avoid having to double backslashes. You
6517 still have to double ' quotes
6518
6519 If {expr2} is a |Funcref| it is called with two arguments:
6520 1. The key or the index of the current item.
6521 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006522 With a legacy script lambda you don't get an error if it only
6523 accepts one argument, but with a Vim9 lambda you get "E1106:
6524 One argument too many", the number of arguments must match.
6525
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006526 The function must return the new value of the item. Example
6527 that changes each value by "key-value": >
6528 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006529 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006530 endfunc
6531 call map(myDict, function('KeyValue'))
6532< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006533 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006534< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006535 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006536< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006537 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006538<
6539 The operation is done in-place for a |List| and |Dictionary|.
6540 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006541 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006542
6543< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6544 or a new |Blob| or |String|.
6545 When an error is encountered while evaluating {expr2} no
6546 further items in {expr1} are processed.
6547 When {expr2} is a Funcref errors inside a function are ignored,
6548 unless it was defined with the "abort" flag.
6549
6550 Can also be used as a |method|: >
6551 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006552<
6553 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6554 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006555
6556
6557maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6558 When {dict} is omitted or zero: Return the rhs of mapping
6559 {name} in mode {mode}. The returned String has special
6560 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006561 listing. When {dict} is TRUE a dictionary is returned, see
6562 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006563
6564 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006565 returned if {dict} is FALSE, otherwise returns an empty Dict.
6566 When the mapping for {name} is empty, then "<Nop>" is
6567 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006568
6569 The {name} can have special key names, like in the ":map"
6570 command.
6571
6572 {mode} can be one of these strings:
6573 "n" Normal
6574 "v" Visual (including Select)
6575 "o" Operator-pending
6576 "i" Insert
6577 "c" Cmd-line
6578 "s" Select
6579 "x" Visual
6580 "l" langmap |language-mapping|
6581 "t" Terminal-Job
6582 "" Normal, Visual and Operator-pending
6583 When {mode} is omitted, the modes for "" are used.
6584
6585 When {abbr} is there and it is |TRUE| use abbreviations
6586 instead of mappings.
6587
6588 When {dict} is there and it is |TRUE| return a dictionary
6589 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006590 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006591 "lhs" The {lhs} of the mapping as it would be typed
6592 "lhsraw" The {lhs} of the mapping as raw bytes
6593 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6594 form, only present when it differs from "lhsraw"
6595 "rhs" The {rhs} of the mapping as typed.
6596 "silent" 1 for a |:map-silent| mapping, else 0.
6597 "noremap" 1 if the {rhs} of the mapping is not remappable.
6598 "script" 1 if mapping was defined with <script>.
6599 "expr" 1 for an expression mapping (|:map-<expr>|).
6600 "buffer" 1 for a buffer local mapping (|:map-local|).
6601 "mode" Modes for which the mapping is defined. In
6602 addition to the modes mentioned above, these
6603 characters will be used:
6604 " " Normal, Visual and Operator-pending
6605 "!" Insert and Commandline mode
6606 (|mapmode-ic|)
6607 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006608 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006609 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006610 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006611 "lnum" The line number in "sid", zero if unknown.
6612 "nowait" Do not wait for other, longer mappings.
6613 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006614 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006615 "mode_bits" Vim's internal binary representation of "mode".
6616 |mapset()| ignores this; only "mode" is used.
6617 See |maplist()| for usage examples. The values
6618 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006619
6620 The dictionary can be used to restore a mapping with
6621 |mapset()|.
6622
6623 The mappings local to the current buffer are checked first,
6624 then the global mappings.
6625 This function can be used to map a key even when it's already
6626 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006627 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006628
6629< Can also be used as a |method|: >
6630 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006631<
6632 Return type: |String| or dict<any> depending on {dict}
6633
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006634
6635mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6636 Check if there is a mapping that matches with {name} in mode
6637 {mode}. See |maparg()| for {mode} and special names in
6638 {name}.
6639 When {abbr} is there and it is |TRUE| use abbreviations
6640 instead of mappings.
6641 A match happens with a mapping that starts with {name} and
6642 with a mapping which is equal to the start of {name}.
6643
6644 matches mapping "a" "ab" "abc" ~
6645 mapcheck("a") yes yes yes
6646 mapcheck("abc") yes yes yes
6647 mapcheck("ax") yes no no
6648 mapcheck("b") no no no
6649
6650 The difference with maparg() is that mapcheck() finds a
6651 mapping that matches with {name}, while maparg() only finds a
6652 mapping for {name} exactly.
6653 When there is no mapping that starts with {name}, an empty
6654 String is returned. If there is one, the RHS of that mapping
6655 is returned. If there are several mappings that start with
6656 {name}, the RHS of one of them is returned. This will be
6657 "<Nop>" if the RHS is empty.
6658 The mappings local to the current buffer are checked first,
6659 then the global mappings.
6660 This function can be used to check if a mapping can be added
6661 without being ambiguous. Example: >
6662 :if mapcheck("_vv") == ""
6663 : map _vv :set guifont=7x13<CR>
6664 :endif
6665< This avoids adding the "_vv" mapping when there already is a
6666 mapping for "_v" or for "_vvv".
6667
6668 Can also be used as a |method|: >
6669 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006670<
6671 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006672
6673
Ernie Rael09661202022-04-25 14:40:44 +01006674maplist([{abbr}]) *maplist()*
6675 Returns a |List| of all mappings. Each List item is a |Dict|,
6676 the same as what is returned by |maparg()|, see
6677 |mapping-dict|. When {abbr} is there and it is |TRUE| use
6678 abbreviations instead of mappings.
6679
6680 Example to show all mappings with 'MultiMatch' in rhs: >
6681 vim9script
6682 echo maplist()->filter(
6683 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01006684< It can be tricky to find mappings for particular |:map-modes|.
6685 |mapping-dict|'s "mode_bits" can simplify this. For example,
6686 the mode_bits for Normal, Insert or Command-line modes are
6687 0x19. To find all the mappings available in those modes you
6688 can do: >
6689 vim9script
6690 var saved_maps = []
6691 for m in maplist()
6692 if and(m.mode_bits, 0x19) != 0
6693 saved_maps->add(m)
6694 endif
6695 endfor
6696 echo saved_maps->mapnew((_, m) => m.lhs)
6697< The values of the mode_bits are defined in Vim's src/vim.h
6698 file and they can be discovered at runtime using
6699 |:map-commands| and "maplist()". Example: >
6700 vim9script
6701 omap xyzzy <Nop>
6702 var op_bit = maplist()->filter(
6703 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
6704 ounmap xyzzy
6705 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006706<
6707 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01006708
6709
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006710mapnew({expr1}, {expr2}) *mapnew()*
6711 Like |map()| but instead of replacing items in {expr1} a new
6712 List or Dictionary is created and returned. {expr1} remains
6713 unchanged. Items can still be changed by {expr2}, if you
6714 don't want that use |deepcopy()| first.
6715
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006716 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6717 depending on {expr1}
6718
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006719
6720mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01006721mapset({dict})
6722 Restore a mapping from a dictionary, possibly returned by
6723 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
6724 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006725 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01006726 feature allows copying mappings from one buffer to another.
6727 The dict.mode value may restore a single mapping that covers
6728 more than one mode, like with mode values of '!', ' ', 'nox',
6729 or 'v'. *E1276*
6730
6731 In the first form, {mode} and {abbr} should be the same as
6732 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006733 {mode} is used to define the mode in which the mapping is set,
6734 not the "mode" entry in {dict}.
6735 Example for saving and restoring a mapping: >
6736 let save_map = maparg('K', 'n', 0, 1)
6737 nnoremap K somethingelse
6738 ...
6739 call mapset('n', 0, save_map)
6740< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01006741 e.g. with `:map!`, you need to save/restore the mapping for
6742 all of them, when they might differ.
6743
6744 In the second form, with {dict} as the only argument, mode
6745 and abbr are taken from the dict.
6746 Example: >
6747 vim9script
6748 var save_maps = maplist()->filter(
6749 (_, m) => m.lhs == 'K')
6750 nnoremap K somethingelse
6751 cnoremap K somethingelse2
6752 # ...
6753 unmap K
6754 for d in save_maps
6755 mapset(d)
6756 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006757<
6758 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006759
6760
6761match({expr}, {pat} [, {start} [, {count}]]) *match()*
6762 When {expr} is a |List| then this returns the index of the
6763 first item where {pat} matches. Each item is used as a
6764 String, |Lists| and |Dictionaries| are used as echoed.
6765
6766 Otherwise, {expr} is used as a String. The result is a
6767 Number, which gives the index (byte offset) in {expr} where
6768 {pat} matches.
6769
6770 A match at the first character or |List| item returns zero.
6771 If there is no match -1 is returned.
6772
6773 For getting submatches see |matchlist()|.
6774 Example: >
6775 :echo match("testing", "ing") " results in 4
6776 :echo match([1, 'x'], '\a') " results in 1
6777< See |string-match| for how {pat} is used.
6778 *strpbrk()*
6779 Vim doesn't have a strpbrk() function. But you can do: >
6780 :let sepidx = match(line, '[.,;: \t]')
6781< *strcasestr()*
6782 Vim doesn't have a strcasestr() function. But you can add
6783 "\c" to the pattern to ignore case: >
6784 :let idx = match(haystack, '\cneedle')
6785<
6786 If {start} is given, the search starts from byte index
6787 {start} in a String or item {start} in a |List|.
6788 The result, however, is still the index counted from the
6789 first character/item. Example: >
6790 :echo match("testing", "ing", 2)
6791< result is again "4". >
6792 :echo match("testing", "ing", 4)
6793< result is again "4". >
6794 :echo match("testing", "t", 2)
6795< result is "3".
6796 For a String, if {start} > 0 then it is like the string starts
6797 {start} bytes later, thus "^" will match at {start}. Except
6798 when {count} is given, then it's like matches before the
6799 {start} byte are ignored (this is a bit complicated to keep it
6800 backwards compatible).
6801 For a String, if {start} < 0, it will be set to 0. For a list
6802 the index is counted from the end.
6803 If {start} is out of range ({start} > strlen({expr}) for a
6804 String or {start} > len({expr}) for a |List|) -1 is returned.
6805
6806 When {count} is given use the {count}'th match. When a match
6807 is found in a String the search for the next one starts one
6808 character further. Thus this example results in 1: >
6809 echo match("testing", "..", 0, 2)
6810< In a |List| the search continues in the next item.
6811 Note that when {count} is added the way {start} works changes,
6812 see above.
6813
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01006814 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006815 See |pattern| for the patterns that are accepted.
6816 The 'ignorecase' option is used to set the ignore-caseness of
6817 the pattern. 'smartcase' is NOT used. The matching is always
6818 done like 'magic' is set and 'cpoptions' is empty.
6819 Note that a match at the start is preferred, thus when the
6820 pattern is using "*" (any number of matches) it tends to find
6821 zero matches at the start instead of a number of matches
6822 further down in the text.
6823
6824 Can also be used as a |method|: >
6825 GetText()->match('word')
6826 GetList()->match('word')
6827<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006828 Return type: |Number|
6829
6830
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006831 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006832matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
6833 Defines a pattern to be highlighted in the current window (a
6834 "match"). It will be highlighted with {group}. Returns an
6835 identification number (ID), which can be used to delete the
6836 match using |matchdelete()|. The ID is bound to the window.
6837 Matching is case sensitive and magic, unless case sensitivity
6838 or magicness are explicitly overridden in {pattern}. The
6839 'magic', 'smartcase' and 'ignorecase' options are not used.
6840 The "Conceal" value is special, it causes the match to be
6841 concealed.
6842
6843 The optional {priority} argument assigns a priority to the
6844 match. A match with a high priority will have its
6845 highlighting overrule that of a match with a lower priority.
6846 A priority is specified as an integer (negative numbers are no
6847 exception). If the {priority} argument is not specified, the
6848 default priority is 10. The priority of 'hlsearch' is zero,
6849 hence all matches with a priority greater than zero will
6850 overrule it. Syntax highlighting (see 'syntax') is a separate
6851 mechanism, and regardless of the chosen priority a match will
6852 always overrule syntax highlighting.
6853
6854 The optional {id} argument allows the request for a specific
6855 match ID. If a specified ID is already taken, an error
6856 message will appear and the match will not be added. An ID
6857 is specified as a positive integer (zero excluded). IDs 1, 2
6858 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01006859 respectively. 3 is reserved for use by the |matchparen|
6860 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01006861 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01006862 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006863
6864 The optional {dict} argument allows for further custom
6865 values. Currently this is used to specify a match specific
6866 conceal character that will be shown for |hl-Conceal|
6867 highlighted matches. The dict can have the following members:
6868
6869 conceal Special character to show instead of the
6870 match (only for |hl-Conceal| highlighted
6871 matches, see |:syn-cchar|)
6872 window Instead of the current window use the
6873 window with this number or window ID.
6874
6875 The number of matches is not limited, as it is the case with
6876 the |:match| commands.
6877
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006878 Returns -1 on error.
6879
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006880 Example: >
6881 :highlight MyGroup ctermbg=green guibg=green
6882 :let m = matchadd("MyGroup", "TODO")
6883< Deletion of the pattern: >
6884 :call matchdelete(m)
6885
6886< A list of matches defined by |matchadd()| and |:match| are
6887 available from |getmatches()|. All matches can be deleted in
6888 one operation by |clearmatches()|.
6889
6890 Can also be used as a |method|: >
6891 GetGroup()->matchadd('TODO')
6892<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006893 Return type: |Number|
6894
6895
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006896 *matchaddpos()*
6897matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
6898 Same as |matchadd()|, but requires a list of positions {pos}
6899 instead of a pattern. This command is faster than |matchadd()|
6900 because it does not require to handle regular expressions and
6901 sets buffer line boundaries to redraw screen. It is supposed
6902 to be used when fast match additions and deletions are
6903 required, for example to highlight matching parentheses.
6904
6905 {pos} is a list of positions. Each position can be one of
6906 these:
6907 - A number. This whole line will be highlighted. The first
6908 line has number 1.
6909 - A list with one number, e.g., [23]. The whole line with this
6910 number will be highlighted.
6911 - A list with two numbers, e.g., [23, 11]. The first number is
6912 the line number, the second one is the column number (first
6913 column is 1, the value must correspond to the byte index as
6914 |col()| would return). The character at this position will
6915 be highlighted.
6916 - A list with three numbers, e.g., [23, 11, 3]. As above, but
6917 the third number gives the length of the highlight in bytes.
6918
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006919 Returns -1 on error.
6920
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006921 Example: >
6922 :highlight MyGroup ctermbg=green guibg=green
6923 :let m = matchaddpos("MyGroup", [[23, 24], 34])
6924< Deletion of the pattern: >
6925 :call matchdelete(m)
6926
6927< Matches added by |matchaddpos()| are returned by
6928 |getmatches()|.
6929
6930 Can also be used as a |method|: >
6931 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006932<
6933 Return type: |Number|
6934
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006935
6936matcharg({nr}) *matcharg()*
6937 Selects the {nr} match item, as set with a |:match|,
6938 |:2match| or |:3match| command.
6939 Return a |List| with two elements:
6940 The name of the highlight group used
6941 The pattern used.
6942 When {nr} is not 1, 2 or 3 returns an empty |List|.
6943 When there is no match item set returns ['', ''].
6944 This is useful to save and restore a |:match|.
6945 Highlighting matches using the |:match| commands are limited
6946 to three matches. |matchadd()| does not have this limitation.
6947
6948 Can also be used as a |method|: >
6949 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006950<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006951 Return type: list<string>
6952
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006953 *matchbufline()*
6954matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
6955 Returns the |List| of matches in lines from {lnum} to {end} in
6956 buffer {buf} where {pat} matches.
6957
6958 {lnum} and {end} can either be a line number or the string "$"
6959 to refer to the last line in {buf}.
6960
6961 The {dict} argument supports following items:
6962 submatches include submatch information (|/\(|)
6963
6964 For each match, a |Dict| with the following items is returned:
6965 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08006966 lnum line number where there is a match
6967 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006968 Note that there can be multiple matches in a single line.
6969
6970 This function works only for loaded buffers. First call
6971 |bufload()| if needed.
6972
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01006973 See |match-pattern| for information about the effect of some
6974 option settings on the pattern.
6975
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006976 When {buf} is not a valid buffer, the buffer is not loaded or
6977 {lnum} or {end} is not valid then an error is given and an
6978 empty |List| is returned.
6979
6980 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08006981 " Assuming line 3 in buffer 5 contains "a"
6982 :echo matchbufline(5, '\<\k\+\>', 3, 3)
6983 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
6984 " Assuming line 4 in buffer 10 contains "tik tok"
6985 :echo matchbufline(10, '\<\k\+\>', 1, 4)
6986 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006987<
6988 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08006989 "\1", "\2", etc. are also returned. Example: >
6990 " Assuming line 2 in buffer 2 contains "acd"
6991 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006992 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08006993 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006994< The "submatches" List always contains 9 items. If a submatch
6995 is not found, then an empty string is returned for that
6996 submatch.
6997
6998 Can also be used as a |method|: >
6999 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007000<
7001 Return type: list<dict<any>> or list<any>
7002
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007003
7004matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
7005 Deletes a match with ID {id} previously defined by |matchadd()|
7006 or one of the |:match| commands. Returns 0 if successful,
7007 otherwise -1. See example for |matchadd()|. All matches can
7008 be deleted in one operation by |clearmatches()|.
7009 If {win} is specified, use the window with this number or
7010 window ID instead of the current window.
7011
7012 Can also be used as a |method|: >
7013 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007014<
7015 Return type: |Number|
7016
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007017
7018matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
7019 Same as |match()|, but return the index of first character
7020 after the match. Example: >
7021 :echo matchend("testing", "ing")
7022< results in "7".
7023 *strspn()* *strcspn()*
7024 Vim doesn't have a strspn() or strcspn() function, but you can
7025 do it with matchend(): >
7026 :let span = matchend(line, '[a-zA-Z]')
7027 :let span = matchend(line, '[^a-zA-Z]')
7028< Except that -1 is returned when there are no matches.
7029
7030 The {start}, if given, has the same meaning as for |match()|. >
7031 :echo matchend("testing", "ing", 2)
7032< results in "7". >
7033 :echo matchend("testing", "ing", 5)
7034< result is "-1".
7035 When {expr} is a |List| the result is equal to |match()|.
7036
7037 Can also be used as a |method|: >
7038 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007039<
7040 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007041
7042
7043matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7044 If {list} is a list of strings, then returns a |List| with all
7045 the strings in {list} that fuzzy match {str}. The strings in
7046 the returned list are sorted based on the matching score.
7047
7048 The optional {dict} argument always supports the following
7049 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007050 matchseq When this item is present return only matches
7051 that contain the characters in {str} in the
7052 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007053 limit Maximum number of matches in {list} to be
7054 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007055
7056 If {list} is a list of dictionaries, then the optional {dict}
7057 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007058 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007059 {str}. The value of this item should be a
7060 string.
7061 text_cb |Funcref| that will be called for every item
7062 in {list} to get the text for fuzzy matching.
7063 This should accept a dictionary item as the
7064 argument and return the text for that item to
7065 use for fuzzy matching.
7066
7067 {str} is treated as a literal string and regular expression
7068 matching is NOT supported. The maximum supported {str} length
7069 is 256.
7070
7071 When {str} has multiple words each separated by white space,
7072 then the list of strings that have all the words is returned.
7073
7074 If there are no matching strings or there is an error, then an
7075 empty list is returned. If length of {str} is greater than
7076 256, then returns an empty list.
7077
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007078 When {limit} is given, matchfuzzy() will find up to this
7079 number of matches in {list} and return them in sorted order.
7080
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007081 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007082 matching strings.
7083
7084 Example: >
7085 :echo matchfuzzy(["clay", "crow"], "cay")
7086< results in ["clay"]. >
7087 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7088< results in a list of buffer names fuzzy matching "ndl". >
7089 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7090< results in a list of buffer information dicts with buffer
7091 names fuzzy matching "ndl". >
7092 :echo getbufinfo()->matchfuzzy("spl",
7093 \ {'text_cb' : {v -> v.name}})
7094< results in a list of buffer information dicts with buffer
7095 names fuzzy matching "spl". >
7096 :echo v:oldfiles->matchfuzzy("test")
7097< results in a list of file names fuzzy matching "test". >
7098 :let l = readfile("buffer.c")->matchfuzzy("str")
7099< results in a list of lines in "buffer.c" fuzzy matching "str". >
7100 :echo ['one two', 'two one']->matchfuzzy('two one')
7101< results in ['two one', 'one two']. >
7102 :echo ['one two', 'two one']->matchfuzzy('two one',
7103 \ {'matchseq': 1})
7104< results in ['two one'].
7105
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007106 Return type: list<string> or list<any>
7107
7108
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007109matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7110 Same as |matchfuzzy()|, but returns the list of matched
7111 strings, the list of character positions where characters
7112 in {str} matches and a list of matching scores. You can
7113 use |byteidx()| to convert a character position to a byte
7114 position.
7115
7116 If {str} matches multiple times in a string, then only the
7117 positions for the best match is returned.
7118
7119 If there are no matching strings or there is an error, then a
7120 list with three empty list items is returned.
7121
7122 Example: >
7123 :echo matchfuzzypos(['testing'], 'tsg')
7124< results in [['testing'], [[0, 2, 6]], [99]] >
7125 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7126< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7127 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7128< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7129
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007130 Return type: list<list<any>>
7131
7132
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007133matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7134 Same as |match()|, but return a |List|. The first item in the
7135 list is the matched string, same as what matchstr() would
7136 return. Following items are submatches, like "\1", "\2", etc.
7137 in |:substitute|. When an optional submatch didn't match an
7138 empty string is used. Example: >
7139 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7140< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7141 When there is no match an empty list is returned.
7142
7143 You can pass in a List, but that is not very useful.
7144
7145 Can also be used as a |method|: >
7146 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007147<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007148 Return type: list<string> or list<any>
7149
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007150 *matchstrlist()*
7151matchstrlist({list}, {pat} [, {dict}])
7152 Returns the |List| of matches in {list} where {pat} matches.
7153 {list} is a |List| of strings. {pat} is matched against each
7154 string in {list}.
7155
7156 The {dict} argument supports following items:
7157 submatches include submatch information (|/\(|)
7158
7159 For each match, a |Dict| with the following items is returned:
7160 byteidx starting byte index of the match.
7161 idx index in {list} of the match.
7162 text matched string
7163 submatches a List of submatches. Present only if
7164 "submatches" is set to v:true in {dict}.
7165
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007166 See |match-pattern| for information about the effect of some
7167 option settings on the pattern.
7168
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007169 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007170 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7171 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7172 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7173 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007174<
7175 If "submatches" is present and is v:true, then submatches like
7176 "\1", "\2", etc. are also returned. Example: >
7177 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7178 \ #{submatches: v:true})
7179 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7180< The "submatches" List always contains 9 items. If a submatch
7181 is not found, then an empty string is returned for that
7182 submatch.
7183
7184 Can also be used as a |method|: >
7185 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007186<
7187 Return type: list<dict<any>> or list<any>
7188
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007189
7190matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7191 Same as |match()|, but return the matched string. Example: >
7192 :echo matchstr("testing", "ing")
7193< results in "ing".
7194 When there is no match "" is returned.
7195 The {start}, if given, has the same meaning as for |match()|. >
7196 :echo matchstr("testing", "ing", 2)
7197< results in "ing". >
7198 :echo matchstr("testing", "ing", 5)
7199< result is "".
7200 When {expr} is a |List| then the matching item is returned.
7201 The type isn't changed, it's not necessarily a String.
7202
7203 Can also be used as a |method|: >
7204 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007205<
7206 Return type: |String|
7207
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007208
7209matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7210 Same as |matchstr()|, but return the matched string, the start
7211 position and the end position of the match. Example: >
7212 :echo matchstrpos("testing", "ing")
7213< results in ["ing", 4, 7].
7214 When there is no match ["", -1, -1] is returned.
7215 The {start}, if given, has the same meaning as for |match()|. >
7216 :echo matchstrpos("testing", "ing", 2)
7217< results in ["ing", 4, 7]. >
7218 :echo matchstrpos("testing", "ing", 5)
7219< result is ["", -1, -1].
7220 When {expr} is a |List| then the matching item, the index
7221 of first item where {pat} matches, the start position and the
7222 end position of the match are returned. >
7223 :echo matchstrpos([1, '__x'], '\a')
7224< result is ["x", 1, 2, 3].
7225 The type isn't changed, it's not necessarily a String.
7226
7227 Can also be used as a |method|: >
7228 GetText()->matchstrpos('word')
7229<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007230 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007231
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007232
7233max({expr}) *max()*
7234 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007235 echo max([apples, pears, oranges])
7236
7237< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7238 it returns the maximum of all values in the Dictionary.
7239 If {expr} is neither a List nor a Dictionary, or one of the
7240 items in {expr} cannot be used as a Number this results in
7241 an error. An empty |List| or |Dictionary| results in zero.
7242
7243 Can also be used as a |method|: >
7244 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007245<
7246 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007247
7248
7249menu_info({name} [, {mode}]) *menu_info()*
7250 Return information about the specified menu {name} in
7251 mode {mode}. The menu name should be specified without the
7252 shortcut character ('&'). If {name} is "", then the top-level
7253 menu names are returned.
7254
7255 {mode} can be one of these strings:
7256 "n" Normal
7257 "v" Visual (including Select)
7258 "o" Operator-pending
7259 "i" Insert
7260 "c" Cmd-line
7261 "s" Select
7262 "x" Visual
7263 "t" Terminal-Job
7264 "" Normal, Visual and Operator-pending
7265 "!" Insert and Cmd-line
7266 When {mode} is omitted, the modes for "" are used.
7267
7268 Returns a |Dictionary| containing the following items:
7269 accel menu item accelerator text |menu-text|
7270 display display name (name without '&')
7271 enabled v:true if this menu item is enabled
7272 Refer to |:menu-enable|
7273 icon name of the icon file (for toolbar)
7274 |toolbar-icon|
7275 iconidx index of a built-in icon
7276 modes modes for which the menu is defined. In
7277 addition to the modes mentioned above, these
7278 characters will be used:
7279 " " Normal, Visual and Operator-pending
7280 name menu item name.
7281 noremenu v:true if the {rhs} of the menu item is not
7282 remappable else v:false.
7283 priority menu order priority |menu-priority|
7284 rhs right-hand-side of the menu item. The returned
7285 string has special characters translated like
7286 in the output of the ":menu" command listing.
7287 When the {rhs} of a menu item is empty, then
7288 "<Nop>" is returned.
7289 script v:true if script-local remapping of {rhs} is
7290 allowed else v:false. See |:menu-script|.
7291 shortcut shortcut key (character after '&' in
7292 the menu name) |menu-shortcut|
7293 silent v:true if the menu item is created
7294 with <silent> argument |:menu-silent|
7295 submenus |List| containing the names of
7296 all the submenus. Present only if the menu
7297 item has submenus.
7298
7299 Returns an empty dictionary if the menu item is not found.
7300
7301 Examples: >
7302 :echo menu_info('Edit.Cut')
7303 :echo menu_info('File.Save', 'n')
7304
7305 " Display the entire menu hierarchy in a buffer
7306 func ShowMenu(name, pfx)
7307 let m = menu_info(a:name)
7308 call append(line('$'), a:pfx .. m.display)
7309 for child in m->get('submenus', [])
7310 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7311 \ a:pfx .. ' ')
7312 endfor
7313 endfunc
7314 new
7315 for topmenu in menu_info('').submenus
7316 call ShowMenu(topmenu, '')
7317 endfor
7318<
7319 Can also be used as a |method|: >
7320 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007321<
7322 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007323
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007324min({expr}) *min()*
7325 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007326 echo min([apples, pears, oranges])
7327
7328< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7329 it returns the minimum of all values in the Dictionary.
7330 If {expr} is neither a List nor a Dictionary, or one of the
7331 items in {expr} cannot be used as a Number this results in
7332 an error. An empty |List| or |Dictionary| results in zero.
7333
7334 Can also be used as a |method|: >
7335 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007336<
7337 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007338
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007339
7340mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007341 Create directory {name}.
7342
Bram Moolenaar938ae282023-02-20 20:44:55 +00007343 When {flags} is present it must be a string. An empty string
7344 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007345
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007346 {flags} can contain these character flags:
7347 "p" intermediate directories will be created as necessary
7348 "D" {name} will be deleted at the end of the current
Christian Brabandtc509c002024-06-14 20:22:05 +02007349 function, but not recursively |:defer|
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007350 "R" {name} will be deleted recursively at the end of the
Christian Brabandtc509c002024-06-14 20:22:05 +02007351 current function |:defer|
Bram Moolenaar938ae282023-02-20 20:44:55 +00007352
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007353 Note that when {name} has more than one part and "p" is used
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007354 some directories may already exist. Only the first one that
7355 is created and what it contains is scheduled to be deleted.
7356 E.g. when using: >
7357 call mkdir('subdir/tmp/autoload', 'pR')
7358< and "subdir" already exists then "subdir/tmp" will be
7359 scheduled for deletion, like with: >
7360 defer delete('subdir/tmp', 'rf')
7361< Note that if scheduling the defer fails the directory is not
7362 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007363
7364 If {prot} is given it is used to set the protection bits of
7365 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7366 the user, readable for others). Use 0o700 to make it
7367 unreadable for others. This is only used for the last part of
7368 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
7369 created with 0o755.
7370 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007371 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007372
7373< This function is not available in the |sandbox|.
7374
7375 There is no error if the directory already exists and the "p"
7376 flag is passed (since patch 8.0.1708). However, without the
7377 "p" option the call will fail.
7378
7379 The function result is a Number, which is TRUE if the call was
7380 successful or FALSE if the directory creation failed or partly
7381 failed.
7382
7383 Not available on all systems. To check use: >
7384 :if exists("*mkdir")
7385
7386< Can also be used as a |method|: >
7387 GetName()->mkdir()
7388<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007389 Return type: |Number|
7390
7391
7392mode([{expr}]) *mode()*
7393 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007394 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007395 a non-empty String (|non-zero-arg|), then the full mode is
7396 returned, otherwise only the first letter is returned.
7397 Also see |state()|.
7398
7399 n Normal
7400 no Operator-pending
7401 nov Operator-pending (forced characterwise |o_v|)
7402 noV Operator-pending (forced linewise |o_V|)
7403 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7404 CTRL-V is one character
7405 niI Normal using |i_CTRL-O| in |Insert-mode|
7406 niR Normal using |i_CTRL-O| in |Replace-mode|
7407 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7408 nt Terminal-Normal (insert goes to Terminal-Job mode)
7409 v Visual by character
7410 vs Visual by character using |v_CTRL-O| in Select mode
7411 V Visual by line
7412 Vs Visual by line using |v_CTRL-O| in Select mode
7413 CTRL-V Visual blockwise
7414 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7415 s Select by character
7416 S Select by line
7417 CTRL-S Select blockwise
7418 i Insert
7419 ic Insert mode completion |compl-generic|
7420 ix Insert mode |i_CTRL-X| completion
7421 R Replace |R|
7422 Rc Replace mode completion |compl-generic|
7423 Rx Replace mode |i_CTRL-X| completion
7424 Rv Virtual Replace |gR|
7425 Rvc Virtual Replace mode completion |compl-generic|
7426 Rvx Virtual Replace mode |i_CTRL-X| completion
7427 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007428 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007429 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007430 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007431 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007432 ce Normal Ex mode |Q|
7433 r Hit-enter prompt
7434 rm The -- more -- prompt
7435 r? A |:confirm| query of some sort
7436 ! Shell or external command is executing
7437 t Terminal-Job mode: keys go to the job
7438
7439 This is useful in the 'statusline' option or when used
7440 with |remote_expr()| In most other places it always returns
7441 "c" or "n".
7442 Note that in the future more modes and more specific modes may
7443 be added. It's better not to compare the whole string but only
7444 the leading character(s).
7445 Also see |visualmode()|.
7446
7447 Can also be used as a |method|: >
7448 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007449<
7450 Return type: |String|
7451
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007452
7453mzeval({expr}) *mzeval()*
7454 Evaluate MzScheme expression {expr} and return its result
7455 converted to Vim data structures.
7456 Numbers and strings are returned as they are.
7457 Pairs (including lists and improper lists) and vectors are
7458 returned as Vim |Lists|.
7459 Hash tables are represented as Vim |Dictionary| type with keys
7460 converted to strings.
7461 All other types are converted to string with display function.
7462 Examples: >
7463 :mz (define l (list 1 2 3))
7464 :mz (define h (make-hash)) (hash-set! h "list" l)
7465 :echo mzeval("l")
7466 :echo mzeval("h")
7467<
7468 Note that in a `:def` function local variables are not visible
7469 to {expr}.
7470
7471 Can also be used as a |method|: >
7472 GetExpr()->mzeval()
7473<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007474 Return type: any, depending on {expr}
7475
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007476 {only available when compiled with the |+mzscheme| feature}
7477
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007478
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007479nextnonblank({lnum}) *nextnonblank()*
7480 Return the line number of the first line at or below {lnum}
7481 that is not blank. Example: >
7482 if getline(nextnonblank(1)) =~ "Java"
7483< When {lnum} is invalid or there is no non-blank line at or
7484 below it, zero is returned.
7485 {lnum} is used like with |getline()|.
7486 See also |prevnonblank()|.
7487
7488 Can also be used as a |method|: >
7489 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007490<
7491 Return type: |Number|
7492
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007493
7494nr2char({expr} [, {utf8}]) *nr2char()*
7495 Return a string with a single character, which has the number
7496 value {expr}. Examples: >
7497 nr2char(64) returns "@"
7498 nr2char(32) returns " "
7499< When {utf8} is omitted or zero, the current 'encoding' is used.
7500 Example for "utf-8": >
7501 nr2char(300) returns I with bow character
7502< When {utf8} is TRUE, always return UTF-8 characters.
7503 Note that a NUL character in the file is specified with
7504 nr2char(10), because NULs are represented with newline
7505 characters. nr2char(0) is a real NUL and terminates the
7506 string, thus results in an empty string.
7507 To turn a list of character numbers into a string: >
7508 let list = [65, 66, 67]
7509 let str = join(map(list, {_, val -> nr2char(val)}), '')
7510< Result: "ABC"
7511
7512 Can also be used as a |method|: >
7513 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007514<
7515 Return type: |String|
7516
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007517
7518or({expr}, {expr}) *or()*
7519 Bitwise OR on the two arguments. The arguments are converted
7520 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007521 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007522 Example: >
7523 :let bits = or(bits, 0x80)
7524< Can also be used as a |method|: >
7525 :let bits = bits->or(0x80)
7526
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007527< Rationale: The reason this is a function and not using the "|"
7528 character like many languages, is that Vi has always used "|"
7529 to separate commands. In many places it would not be clear if
7530 "|" is an operator or a command separator.
7531
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007532 Return type: |Number|
7533
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007534
7535pathshorten({path} [, {len}]) *pathshorten()*
7536 Shorten directory names in the path {path} and return the
7537 result. The tail, the file name, is kept as-is. The other
7538 components in the path are reduced to {len} letters in length.
7539 If {len} is omitted or smaller than 1 then 1 is used (single
7540 letters). Leading '~' and '.' characters are kept. Examples: >
7541 :echo pathshorten('~/.vim/autoload/myfile.vim')
7542< ~/.v/a/myfile.vim ~
7543>
7544 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7545< ~/.vi/au/myfile.vim ~
7546 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007547 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007548
7549 Can also be used as a |method|: >
7550 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007551<
7552 Return type: |String|
7553
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007554
7555perleval({expr}) *perleval()*
7556 Evaluate Perl expression {expr} in scalar context and return
7557 its result converted to Vim data structures. If value can't be
7558 converted, it is returned as a string Perl representation.
7559 Note: If you want an array or hash, {expr} must return a
7560 reference to it.
7561 Example: >
7562 :echo perleval('[1 .. 4]')
7563< [1, 2, 3, 4]
7564
7565 Note that in a `:def` function local variables are not visible
7566 to {expr}.
7567
7568 Can also be used as a |method|: >
7569 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007570<
7571 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007572
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007573 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007574
7575
7576popup_ functions are documented here: |popup-functions|
7577
7578
7579pow({x}, {y}) *pow()*
7580 Return the power of {x} to the exponent {y} as a |Float|.
7581 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007582 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007583 Examples: >
7584 :echo pow(3, 3)
7585< 27.0 >
7586 :echo pow(2, 16)
7587< 65536.0 >
7588 :echo pow(32, 0.20)
7589< 2.0
7590
7591 Can also be used as a |method|: >
7592 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007593<
7594 Return type: |Number|
7595
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007596
7597prevnonblank({lnum}) *prevnonblank()*
7598 Return the line number of the first line at or above {lnum}
7599 that is not blank. Example: >
7600 let ind = indent(prevnonblank(v:lnum - 1))
7601< When {lnum} is invalid or there is no non-blank line at or
7602 above it, zero is returned.
7603 {lnum} is used like with |getline()|.
7604 Also see |nextnonblank()|.
7605
7606 Can also be used as a |method|: >
7607 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007608<
7609 Return type: |Number|
7610
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007611
7612printf({fmt}, {expr1} ...) *printf()*
7613 Return a String with {fmt}, where "%" items are replaced by
7614 the formatted form of their respective arguments. Example: >
7615 printf("%4d: E%d %.30s", lnum, errno, msg)
7616< May result in:
7617 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7618
7619 When used as a |method| the base is passed as the second
7620 argument: >
7621 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007622<
7623 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007624
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007625 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007626 %s string
7627 %6S string right-aligned in 6 display cells
7628 %6s string right-aligned in 6 bytes
7629 %.9s string truncated to 9 bytes
7630 %c single byte
7631 %d decimal number
7632 %5d decimal number padded with spaces to 5 characters
7633 %x hex number
7634 %04x hex number padded with zeros to at least 4 characters
7635 %X hex number using upper case letters
7636 %o octal number
7637 %08b binary number padded with zeros to at least 8 chars
7638 %f floating point number as 12.23, inf, -inf or nan
7639 %F floating point number as 12.23, INF, -INF or NAN
7640 %e floating point number as 1.23e3, inf, -inf or nan
7641 %E floating point number as 1.23E3, INF, -INF or NAN
7642 %g floating point number, as %f or %e depending on value
7643 %G floating point number, as %F or %E depending on value
7644 %% the % character itself
7645
7646 Conversion specifications start with '%' and end with the
7647 conversion type. All other characters are copied unchanged to
7648 the result.
7649
7650 The "%" starts a conversion specification. The following
7651 arguments appear in sequence:
7652
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007653 % [pos-argument] [flags] [field-width] [.precision] type
7654
7655 pos-argument
7656 At most one positional argument specifier. These
7657 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007658
7659 flags
7660 Zero or more of the following flags:
7661
7662 # The value should be converted to an "alternate
7663 form". For c, d, and s conversions, this option
7664 has no effect. For o conversions, the precision
7665 of the number is increased to force the first
7666 character of the output string to a zero (except
7667 if a zero value is printed with an explicit
7668 precision of zero).
7669 For b and B conversions, a non-zero result has
7670 the string "0b" (or "0B" for B conversions)
7671 prepended to it.
7672 For x and X conversions, a non-zero result has
7673 the string "0x" (or "0X" for X conversions)
7674 prepended to it.
7675
7676 0 (zero) Zero padding. For all conversions the converted
7677 value is padded on the left with zeros rather
7678 than blanks. If a precision is given with a
7679 numeric conversion (d, b, B, o, x, and X), the 0
7680 flag is ignored.
7681
7682 - A negative field width flag; the converted value
7683 is to be left adjusted on the field boundary.
7684 The converted value is padded on the right with
7685 blanks, rather than on the left with blanks or
7686 zeros. A - overrides a 0 if both are given.
7687
7688 ' ' (space) A blank should be left before a positive
7689 number produced by a signed conversion (d).
7690
7691 + A sign must always be placed before a number
7692 produced by a signed conversion. A + overrides
7693 a space if both are used.
7694
7695 field-width
7696 An optional decimal digit string specifying a minimum
7697 field width. If the converted value has fewer bytes
7698 than the field width, it will be padded with spaces on
7699 the left (or right, if the left-adjustment flag has
7700 been given) to fill out the field width. For the S
7701 conversion the count is in cells.
7702
7703 .precision
7704 An optional precision, in the form of a period '.'
7705 followed by an optional digit string. If the digit
7706 string is omitted, the precision is taken as zero.
7707 This gives the minimum number of digits to appear for
7708 d, o, x, and X conversions, the maximum number of
7709 bytes to be printed from a string for s conversions,
7710 or the maximum number of cells to be printed from a
7711 string for S conversions.
7712 For floating point it is the number of digits after
7713 the decimal point.
7714
7715 type
7716 A character that specifies the type of conversion to
7717 be applied, see below.
7718
7719 A field width or precision, or both, may be indicated by an
7720 asterisk '*' instead of a digit string. In this case, a
7721 Number argument supplies the field width or precision. A
7722 negative field width is treated as a left adjustment flag
7723 followed by a positive field width; a negative precision is
7724 treated as though it were missing. Example: >
7725 :echo printf("%d: %.*s", nr, width, line)
7726< This limits the length of the text used from "line" to
7727 "width" bytes.
7728
Dominique Pellé17dca3c2023-12-14 20:36:32 +01007729 If the argument to be formatted is specified using a
7730 positional argument specifier, and a '*' is used to indicate
7731 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007732 precision, the argument(s) to be used must also be specified
7733 using a {n$} positional argument specifier. See |printf-$|.
7734
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007735 The conversion specifiers and their meanings are:
7736
7737 *printf-d* *printf-b* *printf-B* *printf-o*
7738 *printf-x* *printf-X*
7739 dbBoxX The Number argument is converted to signed decimal
7740 (d), unsigned binary (b and B), unsigned octal (o), or
7741 unsigned hexadecimal (x and X) notation. The letters
7742 "abcdef" are used for x conversions; the letters
7743 "ABCDEF" are used for X conversions.
7744 The precision, if any, gives the minimum number of
7745 digits that must appear; if the converted value
7746 requires fewer digits, it is padded on the left with
7747 zeros.
7748 In no case does a non-existent or small field width
7749 cause truncation of a numeric field; if the result of
7750 a conversion is wider than the field width, the field
7751 is expanded to contain the conversion result.
7752 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02007753 The 'l' modifier indicates the argument is a long
7754 integer. The size will be 32 bits or 64 bits
7755 depending on your platform.
7756 The "ll" modifier indicates the argument is 64 bits.
7757 The b and B conversion specifiers never take a width
7758 modifier and always assume their argument is a 64 bit
7759 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007760 Generally, these modifiers are not useful. They are
7761 ignored when type is known from the argument.
7762
7763 i alias for d
7764 D alias for ld
7765 U alias for lu
7766 O alias for lo
7767
7768 *printf-c*
7769 c The Number argument is converted to a byte, and the
7770 resulting character is written.
7771
7772 *printf-s*
7773 s The text of the String argument is used. If a
7774 precision is specified, no more bytes than the number
7775 specified are used.
7776 If the argument is not a String type, it is
7777 automatically converted to text with the same format
7778 as ":echo".
7779 *printf-S*
7780 S The text of the String argument is used. If a
7781 precision is specified, no more display cells than the
7782 number specified are used.
7783
7784 *printf-f* *E807*
7785 f F The Float argument is converted into a string of the
7786 form 123.456. The precision specifies the number of
7787 digits after the decimal point. When the precision is
7788 zero the decimal point is omitted. When the precision
7789 is not specified 6 is used. A really big number
7790 (out of range or dividing by zero) results in "inf"
7791 or "-inf" with %f (INF or -INF with %F).
7792 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
7793 Example: >
7794 echo printf("%.2f", 12.115)
7795< 12.12
7796 Note that roundoff depends on the system libraries.
7797 Use |round()| when in doubt.
7798
7799 *printf-e* *printf-E*
7800 e E The Float argument is converted into a string of the
7801 form 1.234e+03 or 1.234E+03 when using 'E'. The
7802 precision specifies the number of digits after the
7803 decimal point, like with 'f'.
7804
7805 *printf-g* *printf-G*
7806 g G The Float argument is converted like with 'f' if the
7807 value is between 0.001 (inclusive) and 10000000.0
7808 (exclusive). Otherwise 'e' is used for 'g' and 'E'
7809 for 'G'. When no precision is specified superfluous
7810 zeroes and '+' signs are removed, except for the zero
7811 immediately after the decimal point. Thus 10000000.0
7812 results in 1.0e7.
7813
7814 *printf-%*
7815 % A '%' is written. No argument is converted. The
7816 complete conversion specification is "%%".
7817
7818 When a Number argument is expected a String argument is also
7819 accepted and automatically converted.
7820 When a Float or String argument is expected a Number argument
7821 is also accepted and automatically converted.
7822 Any other argument type results in an error message.
7823
7824 *E766* *E767*
7825 The number of {exprN} arguments must exactly match the number
7826 of "%" items. If there are not sufficient or too many
7827 arguments an error is given. Up to 18 arguments can be used.
7828
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007829 *printf-$*
7830 In certain languages, error and informative messages are
7831 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02007832 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007833 having a different word order, positional arguments may be
7834 used to indicate this. For instance: >
7835
h_east596a9f22023-11-21 21:24:23 +09007836 #, c-format
7837 msgid "%s returning %s"
7838 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007839<
h_east596a9f22023-11-21 21:24:23 +09007840 In this example, the sentence has its 2 string arguments
7841 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007842
h_east596a9f22023-11-21 21:24:23 +09007843 echo printf(
7844 "In The Netherlands, vim's creator's name is: %1$s %2$s",
7845 "Bram", "Moolenaar")
7846< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007847
h_east596a9f22023-11-21 21:24:23 +09007848 echo printf(
7849 "In Belgium, vim's creator's name is: %2$s %1$s",
7850 "Bram", "Moolenaar")
7851< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007852
7853 Width (and precision) can be specified using the '*' specifier.
7854 In this case, you must specify the field width position in the
7855 argument list. >
7856
h_east596a9f22023-11-21 21:24:23 +09007857 echo printf("%1$*2$.*3$d", 1, 2, 3)
7858< 001 >
7859 echo printf("%2$*3$.*1$d", 1, 2, 3)
7860< 2 >
7861 echo printf("%3$*1$.*2$d", 1, 2, 3)
7862< 03 >
7863 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
7864< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007865
7866 You can mix specifying the width and/or precision directly
7867 and via positional arguments: >
7868
h_east596a9f22023-11-21 21:24:23 +09007869 echo printf("%1$4.*2$f", 1.4142135, 6)
7870< 1.414214 >
7871 echo printf("%1$*2$.4f", 1.4142135, 6)
7872< 1.4142 >
7873 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
7874< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007875
Christ van Willegenc35fc032024-03-14 18:30:41 +01007876 You will get an overflow error |E1510|, when the field-width
7877 or precision will result in a string longer than 6400 chars.
7878
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007879 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007880 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09007881 echo printf("%s%1$s", "One", "Two")
7882< E1500: Cannot mix positional and non-positional arguments:
7883 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007884
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007885 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007886 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09007887 echo printf("%3$s%1$s", "One", "Two", "Three")
7888< E1501: format argument 2 unused in $-style format:
7889 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007890
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007891 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007892 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09007893 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
7894< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007895
7896 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09007897 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
7898< E1502: Positional argument 2 used as field width reused as
7899 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007900
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007901 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007902 When a positional argument is used, but not the correct number
7903 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09007904 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
7905< E1503: Positional argument 3 out of bounds: %1$d at width
7906 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007907
7908 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09007909 echo printf("%01$*2$.*3$d %4$d", 1, 2)
7910< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
7911 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007912
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007913 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007914 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09007915 echo printf("%1$s %2$s %1$s", "One", "Two")
7916< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007917
7918 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09007919 echo printf("%1$s %2$s %1$d", "One", "Two")
7920< E1504: Positional argument 1 type used inconsistently:
7921 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007922
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007923 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007924 Various other errors that lead to a format string being
7925 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09007926 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
7927< E1505: Invalid format specifier: %1$d at width %2$d is:
7928 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007929
Christ van Willegenea746f92023-10-05 20:48:36 +02007930 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08007931 This internal error indicates that the logic to parse a
7932 positional format argument ran into a problem that couldn't be
7933 otherwise reported. Please file a bug against Vim if you run
7934 into this, copying the exact format string and parameters that
7935 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02007936
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007937 Return type: |String|
7938
Christ van Willegenea746f92023-10-05 20:48:36 +02007939
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007940prompt_getprompt({buf}) *prompt_getprompt()*
7941 Returns the effective prompt text for buffer {buf}. {buf} can
7942 be a buffer name or number. See |prompt-buffer|.
7943
7944 If the buffer doesn't exist or isn't a prompt buffer, an empty
7945 string is returned.
7946
7947 Can also be used as a |method|: >
7948 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007949<
7950 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007951
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007952 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007953
7954
7955prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
7956 Set prompt callback for buffer {buf} to {expr}. When {expr}
7957 is an empty string the callback is removed. This has only
7958 effect if {buf} has 'buftype' set to "prompt".
7959
7960 The callback is invoked when pressing Enter. The current
7961 buffer will always be the prompt buffer. A new line for a
7962 prompt is added before invoking the callback, thus the prompt
7963 for which the callback was invoked will be in the last but one
7964 line.
7965 If the callback wants to add text to the buffer, it must
7966 insert it above the last line, since that is where the current
7967 prompt is. This can also be done asynchronously.
7968 The callback is invoked with one argument, which is the text
7969 that was entered at the prompt. This can be an empty string
7970 if the user only typed Enter.
7971 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007972 func s:TextEntered(text)
7973 if a:text == 'exit' || a:text == 'quit'
7974 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01007975 " Reset 'modified' to allow the buffer to be closed.
7976 " We assume there is nothing useful to be saved.
7977 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007978 close
7979 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01007980 " Do something useful with "a:text". In this example
7981 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007982 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007983 endif
7984 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01007985 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007986
7987< Can also be used as a |method|: >
7988 GetBuffer()->prompt_setcallback(callback)
7989
7990< {only available when compiled with the |+channel| feature}
7991
7992prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
7993 Set a callback for buffer {buf} to {expr}. When {expr} is an
7994 empty string the callback is removed. This has only effect if
7995 {buf} has 'buftype' set to "prompt".
7996
7997 This callback will be invoked when pressing CTRL-C in Insert
7998 mode. Without setting a callback Vim will exit Insert mode,
7999 as in any buffer.
8000
8001 Can also be used as a |method|: >
8002 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008003<
8004 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008005
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008006 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008007
8008prompt_setprompt({buf}, {text}) *prompt_setprompt()*
8009 Set prompt for buffer {buf} to {text}. You most likely want
8010 {text} to end in a space.
8011 The result is only visible if {buf} has 'buftype' set to
8012 "prompt". Example: >
8013 call prompt_setprompt(bufnr(), 'command: ')
8014<
8015 Can also be used as a |method|: >
8016 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008017<
8018 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008019
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008020 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008021
8022prop_ functions are documented here: |text-prop-functions|
8023
8024pum_getpos() *pum_getpos()*
8025 If the popup menu (see |ins-completion-menu|) is not visible,
8026 returns an empty |Dictionary|, otherwise, returns a
8027 |Dictionary| with the following keys:
8028 height nr of items visible
8029 width screen cells
8030 row top screen row (0 first row)
8031 col leftmost screen column (0 first col)
8032 size total nr of items
8033 scrollbar |TRUE| if scrollbar is visible
8034
8035 The values are the same as in |v:event| during
8036 |CompleteChanged|.
8037
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008038 Return type: dict<any>
8039
8040
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008041pumvisible() *pumvisible()*
8042 Returns non-zero when the popup menu is visible, zero
8043 otherwise. See |ins-completion-menu|.
8044 This can be used to avoid some things that would remove the
8045 popup menu.
8046
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008047 Return type: |Number|
8048
8049
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008050py3eval({expr}) *py3eval()*
8051 Evaluate Python expression {expr} and return its result
8052 converted to Vim data structures.
8053 Numbers and strings are returned as they are (strings are
8054 copied though, Unicode strings are additionally converted to
8055 'encoding').
8056 Lists are represented as Vim |List| type.
8057 Dictionaries are represented as Vim |Dictionary| type with
8058 keys converted to strings.
8059 Note that in a `:def` function local variables are not visible
8060 to {expr}.
8061
8062 Can also be used as a |method|: >
8063 GetExpr()->py3eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008064<
8065 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008066
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008067 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008068
8069 *E858* *E859*
8070pyeval({expr}) *pyeval()*
8071 Evaluate Python expression {expr} and return its result
8072 converted to Vim data structures.
8073 Numbers and strings are returned as they are (strings are
8074 copied though).
8075 Lists are represented as Vim |List| type.
8076 Dictionaries are represented as Vim |Dictionary| type,
8077 non-string keys result in error.
8078 Note that in a `:def` function local variables are not visible
8079 to {expr}.
8080
8081 Can also be used as a |method|: >
8082 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008083<
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| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008087
8088pyxeval({expr}) *pyxeval()*
8089 Evaluate Python expression {expr} and return its result
8090 converted to Vim data structures.
8091 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8092 See also: |pyeval()|, |py3eval()|
8093
8094 Can also be used as a |method|: >
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008095 < GetExpr()->pyxeval()
8096<
8097 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008098
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008099 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008100 |+python3| feature}
8101
8102rand([{expr}]) *rand()* *random*
8103 Return a pseudo-random Number generated with an xoshiro128**
8104 algorithm using seed {expr}. The returned number is 32 bits,
8105 also on 64 bits systems, for consistency.
8106 {expr} can be initialized by |srand()| and will be updated by
8107 rand(). If {expr} is omitted, an internal seed value is used
8108 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008109 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008110
8111 Examples: >
8112 :echo rand()
8113 :let seed = srand()
8114 :echo rand(seed)
8115 :echo rand(seed) % 16 " random number 0 - 15
8116<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008117 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008118
8119 *E726* *E727*
8120range({expr} [, {max} [, {stride}]]) *range()*
8121 Returns a |List| with Numbers:
8122 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8123 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8124 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8125 {max}] (increasing {expr} with {stride} each time, not
8126 producing a value past {max}).
8127 When the maximum is one before the start the result is an
8128 empty list. When the maximum is more than one before the
8129 start this is an error.
8130 Examples: >
8131 range(4) " [0, 1, 2, 3]
8132 range(2, 4) " [2, 3, 4]
8133 range(2, 9, 3) " [2, 5, 8]
8134 range(2, -2, -1) " [2, 1, 0, -1, -2]
8135 range(0) " []
8136 range(2, 0) " error!
8137<
8138 Can also be used as a |method|: >
8139 GetExpr()->range()
8140<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008141 Return type: list<number>
8142
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008143
K.Takata11df3ae2022-10-19 14:02:40 +01008144readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008145 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008146 If {offset} is specified, read the file from the specified
8147 offset. If it is a negative value, it is used as an offset
8148 from the end of the file. E.g., to read the last 12 bytes: >
8149 readblob('file.bin', -12)
8150< If {size} is specified, only the specified size will be read.
8151 E.g. to read the first 100 bytes of a file: >
8152 readblob('file.bin', 0, 100)
8153< If {size} is -1 or omitted, the whole data starting from
8154 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008155 This can be also used to read the data from a character device
8156 on Unix when {size} is explicitly set. Only if the device
8157 supports seeking {offset} can be used. Otherwise it should be
8158 zero. E.g. to read 10 bytes from a serial console: >
8159 readblob('/dev/ttyS0', 0, 10)
8160< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008161 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008162 When the offset is beyond the end of the file the result is an
8163 empty blob.
8164 When trying to read more bytes than are available the result
8165 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008166 Also see |readfile()| and |writefile()|.
8167
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008168 Return type: |Blob|
8169
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008170
8171readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8172 Return a list with file and directory names in {directory}.
8173 You can also use |glob()| if you don't need to do complicated
8174 things, such as limiting the number of matches.
8175 The list will be sorted (case sensitive), see the {dict}
8176 argument below for changing the sort order.
8177
8178 When {expr} is omitted all entries are included.
8179 When {expr} is given, it is evaluated to check what to do:
8180 If {expr} results in -1 then no further entries will
8181 be handled.
8182 If {expr} results in 0 then this entry will not be
8183 added to the list.
8184 If {expr} results in 1 then this entry will be added
8185 to the list.
8186 The entries "." and ".." are always excluded.
8187 Each time {expr} is evaluated |v:val| is set to the entry name.
8188 When {expr} is a function the name is passed as the argument.
8189 For example, to get a list of files ending in ".txt": >
8190 readdir(dirname, {n -> n =~ '.txt$'})
8191< To skip hidden and backup files: >
8192 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008193< *E857*
8194 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008195 values. Currently this is used to specify if and how sorting
8196 should be performed. The dict can have the following members:
8197
8198 sort How to sort the result returned from the system.
8199 Valid values are:
8200 "none" do not sort (fastest method)
8201 "case" sort case sensitive (byte value of
8202 each character, technically, using
8203 strcmp()) (default)
8204 "icase" sort case insensitive (technically
8205 using strcasecmp())
8206 "collate" sort using the collation order
8207 of the "POSIX" or "C" |locale|
8208 (technically using strcoll())
8209 Other values are silently ignored.
8210
8211 For example, to get a list of all files in the current
8212 directory without sorting the individual entries: >
8213 readdir('.', '1', #{sort: 'none'})
8214< If you want to get a directory tree: >
8215 function! s:tree(dir)
8216 return {a:dir : map(readdir(a:dir),
8217 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008218 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008219 endfunction
8220 echo s:tree(".")
8221<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008222 Returns an empty List on error.
8223
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008224 Can also be used as a |method|: >
8225 GetDirName()->readdir()
8226<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008227 Return type: list<string> or list<any>
8228
8229
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008230readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8231 Extended version of |readdir()|.
8232 Return a list of Dictionaries with file and directory
8233 information in {directory}.
8234 This is useful if you want to get the attributes of file and
8235 directory at the same time as getting a list of a directory.
8236 This is much faster than calling |readdir()| then calling
8237 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8238 each file and directory especially on MS-Windows.
8239 The list will by default be sorted by name (case sensitive),
8240 the sorting can be changed by using the optional {dict}
8241 argument, see |readdir()|.
8242
8243 The Dictionary for file and directory information has the
8244 following items:
8245 group Group name of the entry. (Only on Unix)
8246 name Name of the entry.
8247 perm Permissions of the entry. See |getfperm()|.
8248 size Size of the entry. See |getfsize()|.
8249 time Timestamp of the entry. See |getftime()|.
8250 type Type of the entry.
8251 On Unix, almost same as |getftype()| except:
8252 Symlink to a dir "linkd"
8253 Other symlink "link"
8254 On MS-Windows:
8255 Normal file "file"
8256 Directory "dir"
8257 Junction "junction"
8258 Symlink to a dir "linkd"
8259 Other symlink "link"
8260 Other reparse point "reparse"
8261 user User name of the entry's owner. (Only on Unix)
8262 On Unix, if the entry is a symlink, the Dictionary includes
8263 the information of the target (except the "type" item).
8264 On MS-Windows, it includes the information of the symlink
8265 itself because of performance reasons.
8266
8267 When {expr} is omitted all entries are included.
8268 When {expr} is given, it is evaluated to check what to do:
8269 If {expr} results in -1 then no further entries will
8270 be handled.
8271 If {expr} results in 0 then this entry will not be
8272 added to the list.
8273 If {expr} results in 1 then this entry will be added
8274 to the list.
8275 The entries "." and ".." are always excluded.
8276 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8277 of the entry.
8278 When {expr} is a function the entry is passed as the argument.
8279 For example, to get a list of files ending in ".txt": >
8280 readdirex(dirname, {e -> e.name =~ '.txt$'})
8281<
8282 For example, to get a list of all files in the current
8283 directory without sorting the individual entries: >
8284 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008285<
8286 Can also be used as a |method|: >
8287 GetDirName()->readdirex()
8288<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008289 Return type: list<dict<any>> or list<any>
8290
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008291
8292 *readfile()*
8293readfile({fname} [, {type} [, {max}]])
8294 Read file {fname} and return a |List|, each line of the file
8295 as an item. Lines are broken at NL characters. Macintosh
8296 files separated with CR will result in a single long line
8297 (unless a NL appears somewhere).
8298 All NUL characters are replaced with a NL character.
8299 When {type} contains "b" binary mode is used:
8300 - When the last line ends in a NL an extra empty list item is
8301 added.
8302 - No CR characters are removed.
8303 Otherwise:
8304 - CR characters that appear before a NL are removed.
8305 - Whether the last line ends in a NL or not does not matter.
8306 - When 'encoding' is Unicode any UTF-8 byte order mark is
8307 removed from the text.
8308 When {max} is given this specifies the maximum number of lines
8309 to be read. Useful if you only want to check the first ten
8310 lines of a file: >
8311 :for line in readfile(fname, '', 10)
8312 : if line =~ 'Date' | echo line | endif
8313 :endfor
8314< When {max} is negative -{max} lines from the end of the file
8315 are returned, or as many as there are.
8316 When {max} is zero the result is an empty list.
8317 Note that without {max} the whole file is read into memory.
8318 Also note that there is no recognition of encoding. Read a
8319 file into a buffer if you need to.
8320 Deprecated (use |readblob()| instead): When {type} contains
8321 "B" a |Blob| is returned with the binary data of the file
8322 unmodified.
8323 When the file can't be opened an error message is given and
8324 the result is an empty list.
8325 Also see |writefile()|.
8326
8327 Can also be used as a |method|: >
8328 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008329<
8330 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008331
8332reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8333 {func} is called for every item in {object}, which can be a
8334 |String|, |List| or a |Blob|. {func} is called with two
8335 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008336 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008337
8338 {initial} is the initial result. When omitted, the first item
8339 in {object} is used and {func} is first called for the second
8340 item. If {initial} is not given and {object} is empty no
8341 result can be computed, an E998 error is given.
8342
8343 Examples: >
8344 echo reduce([1, 3, 5], { acc, val -> acc + val })
8345 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8346 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8347 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8348<
8349 Can also be used as a |method|: >
8350 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008351<
8352 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8353 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008354
8355
8356reg_executing() *reg_executing()*
8357 Returns the single letter name of the register being executed.
8358 Returns an empty string when no register is being executed.
8359 See |@|.
8360
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008361 Return type: |String|
8362
8363
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008364reg_recording() *reg_recording()*
8365 Returns the single letter name of the register being recorded.
8366 Returns an empty string when not recording. See |q|.
8367
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008368 Return type: |String|
8369
8370
8371reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008372reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008373reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008374 Return an item that represents a time value. The item is a
8375 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008376 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008377 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008378 string or |reltimefloat()| to convert to a Float. For
8379 example, to see the time spent in function Work(): >
8380 var startTime = reltime()
8381 Work()
8382 echo startTime->reltime()->reltimestr()
8383<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008384 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008385 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008386 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008387 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008388 specified in the argument.
8389 With two arguments it returns the time passed between {start}
8390 and {end}.
8391
8392 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008393 reltime(). If there is an error an empty List is returned in
8394 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008395
8396 Can also be used as a |method|: >
8397 GetStart()->reltime()
8398<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008399 Return type: list<number>
8400
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008401 {only available when compiled with the |+reltime| feature}
8402
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008403
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008404reltimefloat({time}) *reltimefloat()*
8405 Return a Float that represents the time value of {time}.
8406 Example: >
8407 let start = reltime()
8408 call MyFunction()
8409 let seconds = reltimefloat(reltime(start))
8410< See the note of reltimestr() about overhead.
8411 Also see |profiling|.
8412 If there is an error 0.0 is returned in legacy script, in Vim9
8413 script an error is given.
8414
8415 Can also be used as a |method|: >
8416 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008417<
8418 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008419
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008420 {only available when compiled with the |+reltime| feature}
8421
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008422
8423reltimestr({time}) *reltimestr()*
8424 Return a String that represents the time value of {time}.
8425 This is the number of seconds, a dot and the number of
8426 microseconds. Example: >
8427 let start = reltime()
8428 call MyFunction()
8429 echo reltimestr(reltime(start))
8430< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008431 The accuracy depends on the system. Use reltimefloat() for the
8432 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008433 Leading spaces are used to make the string align nicely. You
8434 can use split() to remove it. >
8435 echo split(reltimestr(reltime(start)))[0]
8436< Also see |profiling|.
8437 If there is an error an empty string is returned in legacy
8438 script, in Vim9 script an error is given.
8439
8440 Can also be used as a |method|: >
8441 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008442<
8443 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008444
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008445 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008446
8447 *remote_expr()* *E449*
8448remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008449 Send the {string} to {server}. The {server} argument is a
8450 string, also see |{server}|.
8451
8452 The string is sent as an expression and the result is returned
8453 after evaluation. The result must be a String or a |List|. A
8454 |List| is turned into a String by joining the items with a
8455 line break in between (not at the end), like with join(expr,
8456 "\n").
8457
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008458 If {idvar} is present and not empty, it is taken as the name
8459 of a variable and a {serverid} for later use with
8460 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008461
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008462 If {timeout} is given the read times out after this many
8463 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008464
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008465 See also |clientserver| |RemoteReply|.
8466 This function is not available in the |sandbox|.
8467 {only available when compiled with the |+clientserver| feature}
8468 Note: Any errors will cause a local error message to be issued
8469 and the result will be the empty string.
8470
8471 Variables will be evaluated in the global namespace,
8472 independent of a function currently being active. Except
8473 when in debug mode, then local function variables and
8474 arguments can be evaluated.
8475
8476 Examples: >
8477 :echo remote_expr("gvim", "2+2")
8478 :echo remote_expr("gvim1", "b:current_syntax")
8479<
8480 Can also be used as a |method|: >
8481 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008482<
8483 Return type: |String| or list<{type}>
8484
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008485
8486remote_foreground({server}) *remote_foreground()*
8487 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008488 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008489 This works like: >
8490 remote_expr({server}, "foreground()")
8491< Except that on Win32 systems the client does the work, to work
8492 around the problem that the OS doesn't always allow the server
8493 to bring itself to the foreground.
8494 Note: This does not restore the window if it was minimized,
8495 like foreground() does.
8496 This function is not available in the |sandbox|.
8497
8498 Can also be used as a |method|: >
8499 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008500<
8501 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008502
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008503 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008504 Win32 console version}
8505
8506
8507remote_peek({serverid} [, {retvar}]) *remote_peek()*
8508 Returns a positive number if there are available strings
8509 from {serverid}. Copies any reply string into the variable
8510 {retvar} if specified. {retvar} must be a string with the
8511 name of a variable.
8512 Returns zero if none are available.
8513 Returns -1 if something is wrong.
8514 See also |clientserver|.
8515 This function is not available in the |sandbox|.
8516 {only available when compiled with the |+clientserver| feature}
8517 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008518 :let repl = ""
8519 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008520
8521< Can also be used as a |method|: >
8522 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008523<
8524 Return type: |Number|
8525
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008526
8527remote_read({serverid}, [{timeout}]) *remote_read()*
8528 Return the oldest available reply from {serverid} and consume
8529 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008530 reply is available. Returns an empty string, if a reply is
8531 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008532 See also |clientserver|.
8533 This function is not available in the |sandbox|.
8534 {only available when compiled with the |+clientserver| feature}
8535 Example: >
8536 :echo remote_read(id)
8537
8538< Can also be used as a |method|: >
8539 ServerId()->remote_read()
8540<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008541 Return type: |String|
8542
8543
8544remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008545 Send the {string} to {server}. The {server} argument is a
8546 string, also see |{server}|.
8547
8548 The string is sent as input keys and the function returns
8549 immediately. At the Vim server the keys are not mapped
8550 |:map|.
8551
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008552 If {idvar} is present, it is taken as the name of a variable
8553 and a {serverid} for later use with remote_read() is stored
8554 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008555
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008556 See also |clientserver| |RemoteReply|.
8557 This function is not available in the |sandbox|.
8558 {only available when compiled with the |+clientserver| feature}
8559
8560 Note: Any errors will be reported in the server and may mess
8561 up the display.
8562 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008563 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008564 \ remote_read(serverid)
8565
8566 :autocmd NONE RemoteReply *
8567 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008568 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008569 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8570<
8571 Can also be used as a |method|: >
8572 ServerName()->remote_send(keys)
8573<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008574 Return type: |String|
8575
8576
8577remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008578 Become the server {name}. {name} must be a non-empty string.
8579 This fails if already running as a server, when |v:servername|
8580 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008581
8582 Can also be used as a |method|: >
8583 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008584<
8585 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008586
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008587 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008588
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008589
8590remove({list}, {idx}) *remove()*
8591remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008592 Without {end}: Remove the item at {idx} from |List| {list} and
8593 return the item.
8594 With {end}: Remove items from {idx} to {end} (inclusive) and
8595 return a |List| with these items. When {idx} points to the same
8596 item as {end} a list with one item is returned. When {end}
8597 points to an item before {idx} this is an error.
8598 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008599 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008600 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008601 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008602 :call remove(mylist, 0, 9)
8603<
8604 Use |delete()| to remove a file.
8605
8606 Can also be used as a |method|: >
8607 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008608<
8609 Return type: any, depending on {list}
8610
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008611
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008612remove({blob}, {idx})
8613remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008614 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8615 return the byte.
8616 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8617 return a |Blob| with these bytes. When {idx} points to the same
8618 byte as {end} a |Blob| with one byte is returned. When {end}
8619 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008620 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008621 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008622 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008623 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008624<
8625 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008626
8627remove({dict}, {key})
8628 Remove the entry from {dict} with key {key} and return it.
8629 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008630 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008631< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008632 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008633
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008634 Return type: any, depending on {dict}
8635
8636
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008637rename({from}, {to}) *rename()*
8638 Rename the file by the name {from} to the name {to}. This
8639 should also work to move files across file systems. The
8640 result is a Number, which is 0 if the file was renamed
8641 successfully, and non-zero when the renaming failed.
8642 NOTE: If {to} exists it is overwritten without warning.
8643 This function is not available in the |sandbox|.
8644
8645 Can also be used as a |method|: >
8646 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008647<
8648 Return type: |Number|
8649
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008650
8651repeat({expr}, {count}) *repeat()*
8652 Repeat {expr} {count} times and return the concatenated
8653 result. Example: >
8654 :let separator = repeat('-', 80)
8655< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01008656 When {expr} is a |List| or a |Blob| the result is {expr}
8657 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008658 :let longlist = repeat(['a', 'b'], 3)
8659< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
8660
8661 Can also be used as a |method|: >
8662 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008663<
8664 Return type: |String|, |Blob| or list<{type}> depending on
8665 {expr}
8666
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008667
8668resolve({filename}) *resolve()* *E655*
8669 On MS-Windows, when {filename} is a shortcut (a .lnk file),
8670 returns the path the shortcut points to in a simplified form.
8671 When {filename} is a symbolic link or junction point, return
8672 the full path to the target. If the target of junction is
8673 removed, return {filename}.
8674 On Unix, repeat resolving symbolic links in all path
8675 components of {filename} and return the simplified result.
8676 To cope with link cycles, resolving of symbolic links is
8677 stopped after 100 iterations.
8678 On other systems, return the simplified {filename}.
8679 The simplification step is done as by |simplify()|.
8680 resolve() keeps a leading path component specifying the
8681 current directory (provided the result is still a relative
8682 path name) and also keeps a trailing path separator.
8683
8684 Can also be used as a |method|: >
8685 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008686<
8687 Return type: |String|
8688
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008689
8690reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01008691 Reverse the order of items in {object}. {object} can be a
8692 |List|, a |Blob| or a |String|. For a List and a Blob the
8693 items are reversed in-place and {object} is returned.
8694 For a String a new String is returned.
8695 Returns zero if {object} is not a List, Blob or a String.
8696 If you want a List or Blob to remain unmodified make a copy
8697 first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008698 :let revlist = reverse(copy(mylist))
8699< Can also be used as a |method|: >
8700 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008701<
8702 Return type: |String|, |Blob| or list<{type}> depending on
8703 {object}
8704
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008705
8706round({expr}) *round()*
8707 Round off {expr} to the nearest integral value and return it
8708 as a |Float|. If {expr} lies halfway between two integral
8709 values, then use the larger one (away from zero).
8710 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008711 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008712 Examples: >
8713 echo round(0.456)
8714< 0.0 >
8715 echo round(4.5)
8716< 5.0 >
8717 echo round(-4.5)
8718< -5.0
8719
8720 Can also be used as a |method|: >
8721 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008722<
8723 Return type: |Float|
8724
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008725
8726rubyeval({expr}) *rubyeval()*
8727 Evaluate Ruby expression {expr} and return its result
8728 converted to Vim data structures.
8729 Numbers, floats and strings are returned as they are (strings
8730 are copied though).
8731 Arrays are represented as Vim |List| type.
8732 Hashes are represented as Vim |Dictionary| type.
8733 Other objects are represented as strings resulted from their
8734 "Object#to_s" method.
8735 Note that in a `:def` function local variables are not visible
8736 to {expr}.
8737
8738 Can also be used as a |method|: >
8739 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008740<
8741 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008742
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008743 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008744
8745screenattr({row}, {col}) *screenattr()*
8746 Like |screenchar()|, but return the attribute. This is a rather
8747 arbitrary number that can only be used to compare to the
8748 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008749 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008750
8751 Can also be used as a |method|: >
8752 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008753<
8754 Return type: |Number|
8755
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008756
8757screenchar({row}, {col}) *screenchar()*
8758 The result is a Number, which is the character at position
8759 [row, col] on the screen. This works for every possible
8760 screen position, also status lines, window separators and the
8761 command line. The top left position is row one, column one
8762 The character excludes composing characters. For double-byte
8763 encodings it may only be the first byte.
8764 This is mainly to be used for testing.
8765 Returns -1 when row or col is out of range.
8766
8767 Can also be used as a |method|: >
8768 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008769<
8770 Return type: |Number|
8771
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008772
8773screenchars({row}, {col}) *screenchars()*
8774 The result is a |List| of Numbers. The first number is the same
8775 as what |screenchar()| returns. Further numbers are
8776 composing characters on top of the base character.
8777 This is mainly to be used for testing.
8778 Returns an empty List when row or col is out of range.
8779
8780 Can also be used as a |method|: >
8781 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008782<
8783 Return type: list<number> or list<any>
8784
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008785
8786screencol() *screencol()*
8787 The result is a Number, which is the current screen column of
8788 the cursor. The leftmost column has number 1.
8789 This function is mainly used for testing.
8790
8791 Note: Always returns the current screen column, thus if used
8792 in a command (e.g. ":echo screencol()") it will return the
8793 column inside the command line, which is 1 when the command is
8794 executed. To get the cursor position in the file use one of
8795 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008796 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008797 nnoremap <silent> GG :echom screencol()<CR>
8798 nnoremap GG <Cmd>echom screencol()<CR>
8799<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008800 Return type: |Number|
8801
8802
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008803screenpos({winid}, {lnum}, {col}) *screenpos()*
8804 The result is a Dict with the screen position of the text
8805 character in window {winid} at buffer line {lnum} and column
8806 {col}. {col} is a one-based byte index.
8807 The Dict has these members:
8808 row screen row
8809 col first screen column
8810 endcol last screen column
8811 curscol cursor screen column
8812 If the specified position is not visible, all values are zero.
8813 The "endcol" value differs from "col" when the character
8814 occupies more than one screen cell. E.g. for a Tab "col" can
8815 be 1 and "endcol" can be 8.
8816 The "curscol" value is where the cursor would be placed. For
8817 a Tab it would be the same as "endcol", while for a double
8818 width character it would be the same as "col".
8819 The |conceal| feature is ignored here, the column numbers are
8820 as if 'conceallevel' is zero. You can set the cursor to the
8821 right position and use |screencol()| to get the value with
8822 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008823 If the position is in a closed fold the screen position of the
8824 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008825 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008826
8827 Can also be used as a |method|: >
8828 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008829<
8830 Return type: dict<number> or dict<any>
8831
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008832
8833screenrow() *screenrow()*
8834 The result is a Number, which is the current screen row of the
8835 cursor. The top line has number one.
8836 This function is mainly used for testing.
8837 Alternatively you can use |winline()|.
8838
8839 Note: Same restrictions as with |screencol()|.
8840
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008841 Return type: |Number|
8842
8843
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008844screenstring({row}, {col}) *screenstring()*
8845 The result is a String that contains the base character and
8846 any composing characters at position [row, col] on the screen.
8847 This is like |screenchars()| but returning a String with the
8848 characters.
8849 This is mainly to be used for testing.
8850 Returns an empty String when row or col is out of range.
8851
8852 Can also be used as a |method|: >
8853 GetRow()->screenstring(col)
8854<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008855 Return type: |String|
8856
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008857 *search()*
8858search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
8859 Search for regexp pattern {pattern}. The search starts at the
8860 cursor position (you can use |cursor()| to set it).
8861
8862 When a match has been found its line number is returned.
8863 If there is no match a 0 is returned and the cursor doesn't
8864 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01008865 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008866
8867 {flags} is a String, which can contain these character flags:
8868 'b' search Backward instead of forward
8869 'c' accept a match at the Cursor position
8870 'e' move to the End of the match
8871 'n' do Not move the cursor
8872 'p' return number of matching sub-Pattern (see below)
8873 's' Set the ' mark at the previous location of the cursor
8874 'w' Wrap around the end of the file
8875 'W' don't Wrap around the end of the file
8876 'z' start searching at the cursor column instead of zero
8877 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
8878
8879 If the 's' flag is supplied, the ' mark is set, only if the
8880 cursor is moved. The 's' flag cannot be combined with the 'n'
8881 flag.
8882
8883 'ignorecase', 'smartcase' and 'magic' are used.
8884
8885 When the 'z' flag is not given, forward searching always
8886 starts in column zero and then matches before the cursor are
8887 skipped. When the 'c' flag is present in 'cpo' the next
8888 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01008889 search starts one column after the start of the match. This
8890 matters for overlapping matches. See |cpo-c|. You can also
8891 insert "\ze" to change where the match ends, see |/\ze|.
8892
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008893 When searching backwards and the 'z' flag is given then the
8894 search starts in column zero, thus no match in the current
8895 line will be found (unless wrapping around the end of the
8896 file).
8897
8898 When the {stopline} argument is given then the search stops
8899 after searching this line. This is useful to restrict the
8900 search to a range of lines. Examples: >
8901 let match = search('(', 'b', line("w0"))
8902 let end = search('END', '', line("w$"))
8903< When {stopline} is used and it is not zero this also implies
8904 that the search does not wrap around the end of the file.
8905 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01008906 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008907 When the {timeout} argument is given the search stops when
8908 more than this many milliseconds have passed. Thus when
8909 {timeout} is 500 the search stops after half a second.
8910 The value must not be negative. A zero value is like not
8911 giving the argument.
8912 {only available when compiled with the |+reltime| feature}
8913
8914 If the {skip} expression is given it is evaluated with the
8915 cursor positioned on the start of a match. If it evaluates to
8916 non-zero this match is skipped. This can be used, for
8917 example, to skip a match in a comment or a string.
8918 {skip} can be a string, which is evaluated as an expression, a
8919 function reference or a lambda.
8920 When {skip} is omitted or empty, every match is accepted.
8921 When evaluating {skip} causes an error the search is aborted
8922 and -1 returned.
8923 *search()-sub-match*
8924 With the 'p' flag the returned value is one more than the
8925 first sub-match in \(\). One if none of them matched but the
8926 whole pattern did match.
8927 To get the column number too use |searchpos()|.
8928
8929 The cursor will be positioned at the match, unless the 'n'
8930 flag is used.
8931
8932 Example (goes over all files in the argument list): >
8933 :let n = 1
8934 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008935 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008936 : " start at the last char in the file and wrap for the
8937 : " first search to find match at start of file
8938 : normal G$
8939 : let flags = "w"
8940 : while search("foo", flags) > 0
8941 : s/foo/bar/g
8942 : let flags = "W"
8943 : endwhile
8944 : update " write the file if modified
8945 : let n = n + 1
8946 :endwhile
8947<
8948 Example for using some flags: >
8949 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
8950< This will search for the keywords "if", "else", and "endif"
8951 under or after the cursor. Because of the 'p' flag, it
8952 returns 1, 2, or 3 depending on which keyword is found, or 0
8953 if the search fails. With the cursor on the first word of the
8954 line:
8955 if (foo == 0) | let foo = foo + 1 | endif ~
8956 the function returns 1. Without the 'c' flag, the function
8957 finds the "endif" and returns 3. The same thing happens
8958 without the 'e' flag if the cursor is on the "f" of "if".
8959 The 'n' flag tells the function not to move the cursor.
8960
8961 Can also be used as a |method|: >
8962 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008963<
8964 Return type: |Number|
8965
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008966
8967searchcount([{options}]) *searchcount()*
8968 Get or update the last search count, like what is displayed
8969 without the "S" flag in 'shortmess'. This works even if
8970 'shortmess' does contain the "S" flag.
8971
8972 This returns a |Dictionary|. The dictionary is empty if the
8973 previous pattern was not set and "pattern" was not specified.
8974
8975 key type meaning ~
8976 current |Number| current position of match;
8977 0 if the cursor position is
8978 before the first match
8979 exact_match |Boolean| 1 if "current" is matched on
8980 "pos", otherwise 0
8981 total |Number| total count of matches found
8982 incomplete |Number| 0: search was fully completed
8983 1: recomputing was timed out
8984 2: max count exceeded
8985
8986 For {options} see further down.
8987
8988 To get the last search count when |n| or |N| was pressed, call
8989 this function with `recompute: 0` . This sometimes returns
8990 wrong information because |n| and |N|'s maximum count is 99.
8991 If it exceeded 99 the result must be max count + 1 (100). If
8992 you want to get correct information, specify `recompute: 1`: >
8993
8994 " result == maxcount + 1 (100) when many matches
8995 let result = searchcount(#{recompute: 0})
8996
8997 " Below returns correct result (recompute defaults
8998 " to 1)
8999 let result = searchcount()
9000<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01009001 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009002 function! LastSearchCount() abort
9003 let result = searchcount(#{recompute: 0})
9004 if empty(result)
9005 return ''
9006 endif
9007 if result.incomplete ==# 1 " timed out
9008 return printf(' /%s [?/??]', @/)
9009 elseif result.incomplete ==# 2 " max count exceeded
9010 if result.total > result.maxcount &&
9011 \ result.current > result.maxcount
9012 return printf(' /%s [>%d/>%d]', @/,
9013 \ result.current, result.total)
9014 elseif result.total > result.maxcount
9015 return printf(' /%s [%d/>%d]', @/,
9016 \ result.current, result.total)
9017 endif
9018 endif
9019 return printf(' /%s [%d/%d]', @/,
9020 \ result.current, result.total)
9021 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009022 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009023
9024 " Or if you want to show the count only when
9025 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009026 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009027 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9028<
9029 You can also update the search count, which can be useful in a
9030 |CursorMoved| or |CursorMovedI| autocommand: >
9031
9032 autocmd CursorMoved,CursorMovedI *
9033 \ let s:searchcount_timer = timer_start(
9034 \ 200, function('s:update_searchcount'))
9035 function! s:update_searchcount(timer) abort
9036 if a:timer ==# s:searchcount_timer
9037 call searchcount(#{
9038 \ recompute: 1, maxcount: 0, timeout: 100})
9039 redrawstatus
9040 endif
9041 endfunction
9042<
9043 This can also be used to count matched texts with specified
9044 pattern in the current buffer using "pattern": >
9045
9046 " Count '\<foo\>' in this buffer
9047 " (Note that it also updates search count)
9048 let result = searchcount(#{pattern: '\<foo\>'})
9049
9050 " To restore old search count by old pattern,
9051 " search again
9052 call searchcount()
9053<
9054 {options} must be a |Dictionary|. It can contain:
9055 key type meaning ~
9056 recompute |Boolean| if |TRUE|, recompute the count
9057 like |n| or |N| was executed.
9058 otherwise returns the last
9059 computed result (when |n| or
9060 |N| was used when "S" is not
9061 in 'shortmess', or this
9062 function was called).
9063 (default: |TRUE|)
9064 pattern |String| recompute if this was given
9065 and different with |@/|.
9066 this works as same as the
9067 below command is executed
9068 before calling this function >
9069 let @/ = pattern
9070< (default: |@/|)
9071 timeout |Number| 0 or negative number is no
9072 timeout. timeout milliseconds
9073 for recomputing the result
9074 (default: 0)
9075 maxcount |Number| 0 or negative number is no
9076 limit. max count of matched
9077 text while recomputing the
9078 result. if search exceeded
9079 total count, "total" value
9080 becomes `maxcount + 1`
9081 (default: 99)
9082 pos |List| `[lnum, col, off]` value
9083 when recomputing the result.
9084 this changes "current" result
9085 value. see |cursor()|,
9086 |getpos()|
9087 (default: cursor's position)
9088
9089 Can also be used as a |method|: >
9090 GetSearchOpts()->searchcount()
9091<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009092 Return type: dict<number>
9093
9094
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009095searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9096 Search for the declaration of {name}.
9097
9098 With a non-zero {global} argument it works like |gD|, find
9099 first match in the file. Otherwise it works like |gd|, find
9100 first match in the function.
9101
9102 With a non-zero {thisblock} argument matches in a {} block
9103 that ends before the cursor position are ignored. Avoids
9104 finding variable declarations only valid in another scope.
9105
9106 Moves the cursor to the found match.
9107 Returns zero for success, non-zero for failure.
9108 Example: >
9109 if searchdecl('myvar') == 0
9110 echo getline('.')
9111 endif
9112<
9113 Can also be used as a |method|: >
9114 GetName()->searchdecl()
9115<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009116 Return type: |Number|
9117
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009118 *searchpair()*
9119searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9120 [, {stopline} [, {timeout}]]]])
9121 Search for the match of a nested start-end pair. This can be
9122 used to find the "endif" that matches an "if", while other
9123 if/endif pairs in between are ignored.
9124 The search starts at the cursor. The default is to search
9125 forward, include 'b' in {flags} to search backward.
9126 If a match is found, the cursor is positioned at it and the
9127 line number is returned. If no match is found 0 or -1 is
9128 returned and the cursor doesn't move. No error message is
9129 given.
9130
9131 {start}, {middle} and {end} are patterns, see |pattern|. They
9132 must not contain \( \) pairs. Use of \%( \) is allowed. When
9133 {middle} is not empty, it is found when searching from either
9134 direction, but only when not in a nested start-end pair. A
9135 typical use is: >
9136 searchpair('\<if\>', '\<else\>', '\<endif\>')
9137< By leaving {middle} empty the "else" is skipped.
9138
9139 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9140 |search()|. Additionally:
9141 'r' Repeat until no more matches found; will find the
9142 outer pair. Implies the 'W' flag.
9143 'm' Return number of matches instead of line number with
9144 the match; will be > 1 when 'r' is used.
9145 Note: it's nearly always a good idea to use the 'W' flag, to
9146 avoid wrapping around the end of the file.
9147
9148 When a match for {start}, {middle} or {end} is found, the
9149 {skip} expression is evaluated with the cursor positioned on
9150 the start of the match. It should return non-zero if this
9151 match is to be skipped. E.g., because it is inside a comment
9152 or a string.
9153 When {skip} is omitted or empty, every match is accepted.
9154 When evaluating {skip} causes an error the search is aborted
9155 and -1 returned.
9156 {skip} can be a string, a lambda, a funcref or a partial.
9157 Anything else makes the function fail.
9158 In a `:def` function when the {skip} argument is a string
9159 constant it is compiled into instructions.
9160
9161 For {stopline} and {timeout} see |search()|.
9162
9163 The value of 'ignorecase' is used. 'magic' is ignored, the
9164 patterns are used like it's on.
9165
9166 The search starts exactly at the cursor. A match with
9167 {start}, {middle} or {end} at the next character, in the
9168 direction of searching, is the first one found. Example: >
9169 if 1
9170 if 2
9171 endif 2
9172 endif 1
9173< When starting at the "if 2", with the cursor on the "i", and
9174 searching forwards, the "endif 2" is found. When starting on
9175 the character just before the "if 2", the "endif 1" will be
9176 found. That's because the "if 2" will be found first, and
9177 then this is considered to be a nested if/endif from "if 2" to
9178 "endif 2".
9179 When searching backwards and {end} is more than one character,
9180 it may be useful to put "\zs" at the end of the pattern, so
9181 that when the cursor is inside a match with the end it finds
9182 the matching start.
9183
9184 Example, to find the "endif" command in a Vim script: >
9185
9186 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9187 \ 'getline(".") =~ "^\\s*\""')
9188
9189< The cursor must be at or after the "if" for which a match is
9190 to be found. Note that single-quote strings are used to avoid
9191 having to double the backslashes. The skip expression only
9192 catches comments at the start of a line, not after a command.
9193 Also, a word "en" or "if" halfway a line is considered a
9194 match.
9195 Another example, to search for the matching "{" of a "}": >
9196
9197 :echo searchpair('{', '', '}', 'bW')
9198
9199< This works when the cursor is at or before the "}" for which a
9200 match is to be found. To reject matches that syntax
9201 highlighting recognized as strings: >
9202
9203 :echo searchpair('{', '', '}', 'bW',
9204 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9205<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009206 Return type: |Number|
9207
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009208 *searchpairpos()*
9209searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9210 [, {stopline} [, {timeout}]]]])
9211 Same as |searchpair()|, but returns a |List| with the line and
9212 column position of the match. The first element of the |List|
9213 is the line number and the second element is the byte index of
9214 the column position of the match. If no match is found,
9215 returns [0, 0]. >
9216
9217 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9218<
9219 See |match-parens| for a bigger and more useful example.
9220
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009221 Return type: list<number>
9222
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009223 *searchpos()*
9224searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9225 Same as |search()|, but returns a |List| with the line and
9226 column position of the match. The first element of the |List|
9227 is the line number and the second element is the byte index of
9228 the column position of the match. If no match is found,
9229 returns [0, 0].
9230 Example: >
9231 :let [lnum, col] = searchpos('mypattern', 'n')
9232
9233< When the 'p' flag is given then there is an extra item with
9234 the sub-pattern match number |search()-sub-match|. Example: >
9235 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9236< In this example "submatch" is 2 when a lowercase letter is
9237 found |/\l|, 3 when an uppercase letter is found |/\u|.
9238
9239 Can also be used as a |method|: >
9240 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009241<
9242 Return type: list<number>
9243
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009244
9245server2client({clientid}, {string}) *server2client()*
9246 Send a reply string to {clientid}. The most recent {clientid}
9247 that sent a string can be retrieved with expand("<client>").
9248 {only available when compiled with the |+clientserver| feature}
9249 Returns zero for success, -1 for failure.
9250 Note:
9251 This id has to be stored before the next command can be
9252 received. I.e. before returning from the received command and
9253 before calling any commands that waits for input.
9254 See also |clientserver|.
9255 Example: >
9256 :echo server2client(expand("<client>"), "HELLO")
9257
9258< Can also be used as a |method|: >
9259 GetClientId()->server2client(string)
9260<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009261 Return type: |Number|
9262
9263
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009264serverlist() *serverlist()*
9265 Return a list of available server names, one per line.
9266 When there are no servers or the information is not available
9267 an empty string is returned. See also |clientserver|.
9268 {only available when compiled with the |+clientserver| feature}
9269 Example: >
9270 :echo serverlist()
9271<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009272 Return type: |String|
9273
9274
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009275setbufline({buf}, {lnum}, {text}) *setbufline()*
9276 Set line {lnum} to {text} in buffer {buf}. This works like
9277 |setline()| for the specified buffer.
9278
9279 This function works only for loaded buffers. First call
9280 |bufload()| if needed.
9281
9282 To insert lines use |appendbufline()|.
9283 Any text properties in {lnum} are cleared.
9284
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009285 {text} can be a string to set one line, or a List of strings
9286 to set multiple lines. If the List extends below the last
9287 line then those lines are added. If the List is empty then
9288 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009289
9290 For the use of {buf}, see |bufname()| above.
9291
9292 {lnum} is used like with |setline()|.
9293 Use "$" to refer to the last line in buffer {buf}.
9294 When {lnum} is just below the last line the {text} will be
9295 added below the last line.
9296
9297 When {buf} is not a valid buffer, the buffer is not loaded or
9298 {lnum} is not valid then 1 is returned. In |Vim9| script an
9299 error is given.
9300 On success 0 is returned.
9301
9302 Can also be used as a |method|, the base is passed as the
9303 third argument: >
9304 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009305<
9306 Return type: |Number|
9307
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009308
9309setbufvar({buf}, {varname}, {val}) *setbufvar()*
9310 Set option or local variable {varname} in buffer {buf} to
9311 {val}.
9312 This also works for a global or local window option, but it
9313 doesn't work for a global or local window variable.
9314 For a local window option the global value is unchanged.
9315 For the use of {buf}, see |bufname()| above.
9316 The {varname} argument is a string.
9317 Note that the variable name without "b:" must be used.
9318 Examples: >
9319 :call setbufvar(1, "&mod", 1)
9320 :call setbufvar("todo", "myvar", "foobar")
9321< This function is not available in the |sandbox|.
9322
9323 Can also be used as a |method|, the base is passed as the
9324 third argument: >
9325 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009326<
9327 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009328
9329
9330setcellwidths({list}) *setcellwidths()*
9331 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009332 tells Vim how wide characters are when displayed in the
9333 terminal, counted in screen cells. The values override
9334 'ambiwidth'. Example: >
9335 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009336 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009337 \ [0x2194, 0x2199, 2],
9338 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009339
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009340< The {list} argument is a List of Lists with each three
9341 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9342 {low} and {high} can be the same, in which case this refers to
9343 one character. Otherwise it is the range of characters from
9344 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009345 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009346
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009347 {width} must be either 1 or 2, indicating the character width
9348 in screen cells. *E1112*
9349 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009350 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009351
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009352 If the new value causes 'fillchars' or 'listchars' to become
9353 invalid it is rejected and an error is given.
9354
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009355 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009356 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009357
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009358< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009359 the effect for known emoji characters. Move the cursor
9360 through the text to check if the cell widths of your terminal
9361 match with what Vim knows about each emoji. If it doesn't
9362 look right you need to adjust the {list} argument.
9363
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009364 Return type: |Number|
9365
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009366
9367setcharpos({expr}, {list}) *setcharpos()*
9368 Same as |setpos()| but uses the specified column number as the
9369 character index instead of the byte index in the line.
9370
9371 Example:
9372 With the text "여보세요" in line 8: >
9373 call setcharpos('.', [0, 8, 4, 0])
9374< positions the cursor on the fourth character '요'. >
9375 call setpos('.', [0, 8, 4, 0])
9376< positions the cursor on the second character '보'.
9377
9378 Can also be used as a |method|: >
9379 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009380<
9381 Return type: |Number|
9382
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009383
9384setcharsearch({dict}) *setcharsearch()*
9385 Set the current character search information to {dict},
9386 which contains one or more of the following entries:
9387
9388 char character which will be used for a subsequent
9389 |,| or |;| command; an empty string clears the
9390 character search
9391 forward direction of character search; 1 for forward,
9392 0 for backward
9393 until type of character search; 1 for a |t| or |T|
9394 character search, 0 for an |f| or |F|
9395 character search
9396
9397 This can be useful to save/restore a user's character search
9398 from a script: >
9399 :let prevsearch = getcharsearch()
9400 :" Perform a command which clobbers user's search
9401 :call setcharsearch(prevsearch)
9402< Also see |getcharsearch()|.
9403
9404 Can also be used as a |method|: >
9405 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009406<
9407 Return type: dict<any>
9408
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009409
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009410setcmdline({str} [, {pos}]) *setcmdline()*
9411 Set the command line to {str} and set the cursor position to
9412 {pos}.
9413 If {pos} is omitted, the cursor is positioned after the text.
9414 Returns 0 when successful, 1 when not editing the command
9415 line.
9416
9417 Can also be used as a |method|: >
9418 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009419<
9420 Return type: |Number|
9421
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009422
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009423setcmdpos({pos}) *setcmdpos()*
9424 Set the cursor position in the command line to byte position
9425 {pos}. The first position is 1.
9426 Use |getcmdpos()| to obtain the current position.
9427 Only works while editing the command line, thus you must use
9428 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9429 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9430 set after the command line is set to the expression. For
9431 |c_CTRL-R_=| it is set after evaluating the expression but
9432 before inserting the resulting text.
9433 When the number is too big the cursor is put at the end of the
9434 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009435 Returns 0 when successful, 1 when not editing the command
9436 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009437
9438 Can also be used as a |method|: >
9439 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009440<
9441 Return type: |Number|
9442
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009443
9444setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9445setcursorcharpos({list})
9446 Same as |cursor()| but uses the specified column number as the
9447 character index instead of the byte index in the line.
9448
9449 Example:
9450 With the text "여보세요" in line 4: >
9451 call setcursorcharpos(4, 3)
9452< positions the cursor on the third character '세'. >
9453 call cursor(4, 3)
9454< positions the cursor on the first character '여'.
9455
9456 Can also be used as a |method|: >
9457 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009458<
9459 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009460
9461
9462setenv({name}, {val}) *setenv()*
9463 Set environment variable {name} to {val}. Example: >
9464 call setenv('HOME', '/home/myhome')
9465
9466< When {val} is |v:null| the environment variable is deleted.
9467 See also |expr-env|.
9468
9469 Can also be used as a |method|, the base is passed as the
9470 second argument: >
9471 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009472<
9473 Return type: |Number|
9474
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009475
9476setfperm({fname}, {mode}) *setfperm()* *chmod*
9477 Set the file permissions for {fname} to {mode}.
9478 {mode} must be a string with 9 characters. It is of the form
9479 "rwxrwxrwx", where each group of "rwx" flags represent, in
9480 turn, the permissions of the owner of the file, the group the
9481 file belongs to, and other users. A '-' character means the
9482 permission is off, any other character means on. Multi-byte
9483 characters are not supported.
9484
9485 For example "rw-r-----" means read-write for the user,
9486 readable by the group, not accessible by others. "xx-x-----"
9487 would do the same thing.
9488
9489 Returns non-zero for success, zero for failure.
9490
9491 Can also be used as a |method|: >
9492 GetFilename()->setfperm(mode)
9493<
9494 To read permissions see |getfperm()|.
9495
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009496 Return type: |Number|
9497
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009498
9499setline({lnum}, {text}) *setline()*
9500 Set line {lnum} of the current buffer to {text}. To insert
9501 lines use |append()|. To set lines in another buffer use
Christian Brabandt946f61c2024-06-17 13:17:58 +02009502 |setbufline()|.
9503 Any text properties in {lnum} are cleared |text-prop-cleared|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009504
9505 {lnum} is used like with |getline()|.
9506 When {lnum} is just below the last line the {text} will be
9507 added below the last line.
9508 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009509 converted to a String. When {text} is an empty List then
9510 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009511
9512 If this succeeds, FALSE is returned. If this fails (most likely
9513 because {lnum} is invalid) TRUE is returned.
9514 In |Vim9| script an error is given if {lnum} is invalid.
9515
9516 Example: >
9517 :call setline(5, strftime("%c"))
9518
9519< When {text} is a |List| then line {lnum} and following lines
9520 will be set to the items in the list. Example: >
9521 :call setline(5, ['aaa', 'bbb', 'ccc'])
9522< This is equivalent to: >
9523 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9524 : call setline(n, l)
9525 :endfor
9526
9527< Note: The '[ and '] marks are not set.
9528
9529 Can also be used as a |method|, the base is passed as the
9530 second argument: >
9531 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009532<
9533 Return type: |Number|
9534
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009535
9536setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9537 Create or replace or add to the location list for window {nr}.
9538 {nr} can be the window number or the |window-ID|.
9539 When {nr} is zero the current window is used.
9540
9541 For a location list window, the displayed location list is
9542 modified. For an invalid window number {nr}, -1 is returned.
9543 Otherwise, same as |setqflist()|.
9544 Also see |location-list|.
9545
9546 For {action} see |setqflist-action|.
9547
9548 If the optional {what} dictionary argument is supplied, then
9549 only the items listed in {what} are set. Refer to |setqflist()|
9550 for the list of supported keys in {what}.
9551
9552 Can also be used as a |method|, the base is passed as the
9553 second argument: >
9554 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009555<
9556 Return type: |Number|
9557
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009558
9559setmatches({list} [, {win}]) *setmatches()*
9560 Restores a list of matches saved by |getmatches()| for the
9561 current window. Returns 0 if successful, otherwise -1. All
9562 current matches are cleared before the list is restored. See
9563 example for |getmatches()|.
9564 If {win} is specified, use the window with this number or
9565 window ID instead of the current window.
9566
9567 Can also be used as a |method|: >
9568 GetMatches()->setmatches()
9569<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009570 Return type: |Number|
9571
9572
9573setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009574 Set the position for String {expr}. Possible values:
9575 . the cursor
9576 'x mark x
9577
9578 {list} must be a |List| with four or five numbers:
9579 [bufnum, lnum, col, off]
9580 [bufnum, lnum, col, off, curswant]
9581
9582 "bufnum" is the buffer number. Zero can be used for the
9583 current buffer. When setting an uppercase mark "bufnum" is
9584 used for the mark position. For other marks it specifies the
9585 buffer to set the mark in. You can use the |bufnr()| function
9586 to turn a file name into a buffer number.
9587 For setting the cursor and the ' mark "bufnum" is ignored,
9588 since these are associated with a window, not a buffer.
9589 Does not change the jumplist.
9590
9591 "lnum" and "col" are the position in the buffer. The first
9592 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9593 smaller than 1 then 1 is used. To use the character count
9594 instead of the byte count, use |setcharpos()|.
9595
9596 The "off" number is only used when 'virtualedit' is set. Then
9597 it is the offset in screen columns from the start of the
9598 character. E.g., a position within a <Tab> or after the last
9599 character.
9600
9601 The "curswant" number is only used when setting the cursor
9602 position. It sets the preferred column for when moving the
9603 cursor vertically. When the "curswant" number is missing the
9604 preferred column is not set. When it is present and setting a
9605 mark position it is not used.
9606
9607 Note that for '< and '> changing the line number may result in
9608 the marks to be effectively be swapped, so that '< is always
9609 before '>.
9610
9611 Returns 0 when the position could be set, -1 otherwise.
9612 An error message is given if {expr} is invalid.
9613
9614 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9615
9616 This does not restore the preferred column for moving
9617 vertically; if you set the cursor position with this, |j| and
9618 |k| motions will jump to previous columns! Use |cursor()| to
9619 also set the preferred column. Also see the "curswant" key in
9620 |winrestview()|.
9621
9622 Can also be used as a |method|: >
9623 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009624<
9625 Return type: |Number|
9626
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009627
9628setqflist({list} [, {action} [, {what}]]) *setqflist()*
9629 Create or replace or add to the quickfix list.
9630
9631 If the optional {what} dictionary argument is supplied, then
9632 only the items listed in {what} are set. The first {list}
9633 argument is ignored. See below for the supported items in
9634 {what}.
9635 *setqflist-what*
9636 When {what} is not present, the items in {list} are used. Each
9637 item must be a dictionary. Non-dictionary items in {list} are
9638 ignored. Each dictionary item can contain the following
9639 entries:
9640
9641 bufnr buffer number; must be the number of a valid
9642 buffer
9643 filename name of a file; only used when "bufnr" is not
9644 present or it is invalid.
9645 module name of a module; if given it will be used in
9646 quickfix error window instead of the filename.
9647 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00009648 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009649 pattern search pattern used to locate the error
9650 col column number
9651 vcol when non-zero: "col" is visual column
9652 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00009653 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009654 nr error number
9655 text description of the error
9656 type single-character error type, 'E', 'W', etc.
9657 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +02009658 user_data custom data associated with the item, can be
9659 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009660
9661 The "col", "vcol", "nr", "type" and "text" entries are
9662 optional. Either "lnum" or "pattern" entry can be used to
9663 locate a matching error line.
9664 If the "filename" and "bufnr" entries are not present or
9665 neither the "lnum" or "pattern" entries are present, then the
9666 item will not be handled as an error line.
9667 If both "pattern" and "lnum" are present then "pattern" will
9668 be used.
9669 If the "valid" entry is not supplied, then the valid flag is
9670 set when "bufnr" is a valid buffer or "filename" exists.
9671 If you supply an empty {list}, the quickfix list will be
9672 cleared.
9673 Note that the list is not exactly the same as what
9674 |getqflist()| returns.
9675
9676 {action} values: *setqflist-action* *E927*
9677 'a' The items from {list} are added to the existing
9678 quickfix list. If there is no existing list, then a
9679 new list is created.
9680
9681 'r' The items from the current quickfix list are replaced
9682 with the items from {list}. This can also be used to
9683 clear the list: >
9684 :call setqflist([], 'r')
9685<
9686 'f' All the quickfix lists in the quickfix stack are
9687 freed.
9688
9689 If {action} is not present or is set to ' ', then a new list
9690 is created. The new quickfix list is added after the current
9691 quickfix list in the stack and all the following lists are
9692 freed. To add a new quickfix list at the end of the stack,
9693 set "nr" in {what} to "$".
9694
9695 The following items can be specified in dictionary {what}:
9696 context quickfix list context. See |quickfix-context|
9697 efm errorformat to use when parsing text from
9698 "lines". If this is not present, then the
9699 'errorformat' option value is used.
9700 See |quickfix-parse|
9701 id quickfix list identifier |quickfix-ID|
9702 idx index of the current entry in the quickfix
9703 list specified by 'id' or 'nr'. If set to '$',
9704 then the last entry in the list is set as the
9705 current entry. See |quickfix-index|
9706 items list of quickfix entries. Same as the {list}
9707 argument.
9708 lines use 'errorformat' to parse a list of lines and
9709 add the resulting entries to the quickfix list
9710 {nr} or {id}. Only a |List| value is supported.
9711 See |quickfix-parse|
9712 nr list number in the quickfix stack; zero
9713 means the current quickfix list and "$" means
9714 the last quickfix list.
9715 quickfixtextfunc
9716 function to get the text to display in the
9717 quickfix window. The value can be the name of
9718 a function or a funcref or a lambda. Refer to
9719 |quickfix-window-function| for an explanation
9720 of how to write the function and an example.
9721 title quickfix list title text. See |quickfix-title|
9722 Unsupported keys in {what} are ignored.
9723 If the "nr" item is not present, then the current quickfix list
9724 is modified. When creating a new quickfix list, "nr" can be
9725 set to a value one greater than the quickfix stack size.
9726 When modifying a quickfix list, to guarantee that the correct
9727 list is modified, "id" should be used instead of "nr" to
9728 specify the list.
9729
9730 Examples (See also |setqflist-examples|): >
9731 :call setqflist([], 'r', {'title': 'My search'})
9732 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
9733 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
9734<
9735 Returns zero for success, -1 for failure.
9736
9737 This function can be used to create a quickfix list
9738 independent of the 'errorformat' setting. Use a command like
9739 `:cc 1` to jump to the first position.
9740
9741 Can also be used as a |method|, the base is passed as the
9742 second argument: >
9743 GetErrorlist()->setqflist()
9744<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009745 Return type: |Number|
9746
9747
9748setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009749 Set the register {regname} to {value}.
9750 If {regname} is "" or "@", the unnamed register '"' is used.
9751 The {regname} argument is a string. In |Vim9-script|
9752 {regname} must be one character.
9753
9754 {value} may be any value returned by |getreg()| or
9755 |getreginfo()|, including a |List| or |Dict|.
9756 If {options} contains "a" or {regname} is upper case,
9757 then the value is appended.
9758
9759 {options} can also contain a register type specification:
9760 "c" or "v" |characterwise| mode
9761 "l" or "V" |linewise| mode
9762 "b" or "<CTRL-V>" |blockwise-visual| mode
9763 If a number immediately follows "b" or "<CTRL-V>" then this is
9764 used as the width of the selection - if it is not specified
9765 then the width of the block is set to the number of characters
9766 in the longest line (counting a <Tab> as 1 character).
9767
9768 If {options} contains no register settings, then the default
9769 is to use character mode unless {value} ends in a <NL> for
9770 string {value} and linewise mode for list {value}. Blockwise
9771 mode is never selected automatically.
9772 Returns zero for success, non-zero for failure.
9773
9774 *E883*
9775 Note: you may not use |List| containing more than one item to
9776 set search and expression registers. Lists containing no
9777 items act like empty strings.
9778
9779 Examples: >
9780 :call setreg(v:register, @*)
9781 :call setreg('*', @%, 'ac')
9782 :call setreg('a', "1\n2\n3", 'b5')
9783 :call setreg('"', { 'points_to': 'a'})
9784
9785< This example shows using the functions to save and restore a
9786 register: >
9787 :let var_a = getreginfo()
9788 :call setreg('a', var_a)
9789< or: >
9790 :let var_a = getreg('a', 1, 1)
9791 :let var_amode = getregtype('a')
9792 ....
9793 :call setreg('a', var_a, var_amode)
9794< Note: you may not reliably restore register value
9795 without using the third argument to |getreg()| as without it
9796 newlines are represented as newlines AND Nul bytes are
9797 represented as newlines as well, see |NL-used-for-Nul|.
9798
9799 You can also change the type of a register by appending
9800 nothing: >
9801 :call setreg('a', '', 'al')
9802
9803< Can also be used as a |method|, the base is passed as the
9804 second argument: >
9805 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009806<
9807 Return type: |Number|
9808
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009809
9810settabvar({tabnr}, {varname}, {val}) *settabvar()*
9811 Set tab-local variable {varname} to {val} in tab page {tabnr}.
9812 |t:var|
9813 The {varname} argument is a string.
9814 Note that autocommands are blocked, side effects may not be
9815 triggered, e.g. when setting 'filetype'.
9816 Note that the variable name without "t:" must be used.
9817 Tabs are numbered starting with one.
9818 This function is not available in the |sandbox|.
9819
9820 Can also be used as a |method|, the base is passed as the
9821 third argument: >
9822 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009823<
9824 Return type: |Number|
9825
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009826
9827settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
9828 Set option or local variable {varname} in window {winnr} to
9829 {val}.
9830 Tabs are numbered starting with one. For the current tabpage
9831 use |setwinvar()|.
9832 {winnr} can be the window number or the |window-ID|.
9833 When {winnr} is zero the current window is used.
9834 Note that autocommands are blocked, side effects may not be
9835 triggered, e.g. when setting 'filetype' or 'syntax'.
9836 This also works for a global or local buffer option, but it
9837 doesn't work for a global or local buffer variable.
9838 For a local buffer option the global value is unchanged.
9839 Note that the variable name without "w:" must be used.
9840 Examples: >
9841 :call settabwinvar(1, 1, "&list", 0)
9842 :call settabwinvar(3, 2, "myvar", "foobar")
9843< This function is not available in the |sandbox|.
9844
9845 Can also be used as a |method|, the base is passed as the
9846 fourth argument: >
9847 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009848<
9849 Return type: |Number|
9850
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009851
9852settagstack({nr}, {dict} [, {action}]) *settagstack()*
9853 Modify the tag stack of the window {nr} using {dict}.
9854 {nr} can be the window number or the |window-ID|.
9855
9856 For a list of supported items in {dict}, refer to
9857 |gettagstack()|. "curidx" takes effect before changing the tag
9858 stack.
9859 *E962*
9860 How the tag stack is modified depends on the {action}
9861 argument:
9862 - If {action} is not present or is set to 'r', then the tag
9863 stack is replaced.
9864 - If {action} is set to 'a', then new entries from {dict} are
9865 pushed (added) onto the tag stack.
9866 - If {action} is set to 't', then all the entries from the
9867 current entry in the tag stack or "curidx" in {dict} are
9868 removed and then new entries are pushed to the stack.
9869
9870 The current index is set to one after the length of the tag
9871 stack after the modification.
9872
9873 Returns zero for success, -1 for failure.
9874
9875 Examples (for more examples see |tagstack-examples|):
9876 Empty the tag stack of window 3: >
9877 call settagstack(3, {'items' : []})
9878
9879< Save and restore the tag stack: >
9880 let stack = gettagstack(1003)
9881 " do something else
9882 call settagstack(1003, stack)
9883 unlet stack
9884<
9885 Can also be used as a |method|, the base is passed as the
9886 second argument: >
9887 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009888<
9889 Return type: |Number|
9890
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009891
9892setwinvar({winnr}, {varname}, {val}) *setwinvar()*
9893 Like |settabwinvar()| for the current tab page.
9894 Examples: >
9895 :call setwinvar(1, "&list", 0)
9896 :call setwinvar(2, "myvar", "foobar")
9897
9898< Can also be used as a |method|, the base is passed as the
9899 third argument: >
9900 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009901<
9902 Return type: |Number|
9903
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009904
9905sha256({string}) *sha256()*
9906 Returns a String with 64 hex characters, which is the SHA256
9907 checksum of {string}.
9908
9909 Can also be used as a |method|: >
9910 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009911<
9912 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009913
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009914 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009915
9916shellescape({string} [, {special}]) *shellescape()*
9917 Escape {string} for use as a shell command argument.
9918 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +00009919 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009920 in single quotes and will double up all internal single
9921 quotes.
9922 On MS-Windows, when 'shellslash' is not set, it will enclose
9923 {string} in double quotes and double all double quotes within
9924 {string}.
9925 Otherwise it will enclose {string} in single quotes and
9926 replace all "'" with "'\''".
9927
Enno5faeb602024-05-15 21:54:19 +02009928 The {special} argument adds additional escaping of keywords
9929 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +09009930 number or a non-empty String (|non-zero-arg|), then special
9931 items such as "!", "%", "#" and "<cword>" (as listed in
9932 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +02009933 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009934
9935 The "!" character will be escaped (again with a |non-zero-arg|
9936 {special}) when 'shell' contains "csh" in the tail. That is
9937 because for csh and tcsh "!" is used for history replacement
9938 even when inside single quotes.
9939
9940 With a |non-zero-arg| {special} the <NL> character is also
9941 escaped. When 'shell' containing "csh" in the tail it's
9942 escaped a second time.
9943
9944 The "\" character will be escaped when 'shell' contains "fish"
9945 in the tail. That is because for fish "\" is used as an escape
9946 character inside single quotes.
9947
9948 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009949 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009950< This results in a directory listing for the file under the
9951 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009952 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009953< See also |::S|.
9954
9955 Can also be used as a |method|: >
9956 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009957<
9958 Return type: |String|
9959
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009960
9961shiftwidth([{col}]) *shiftwidth()*
9962 Returns the effective value of 'shiftwidth'. This is the
9963 'shiftwidth' value unless it is zero, in which case it is the
9964 'tabstop' value. This function was introduced with patch
9965 7.3.694 in 2012, everybody should have it by now (however it
9966 did not allow for the optional {col} argument until 8.1.542).
9967
9968 When there is one argument {col} this is used as column number
9969 for which to return the 'shiftwidth' value. This matters for the
9970 'vartabstop' feature. If the 'vartabstop' setting is enabled and
9971 no {col} argument is given, column 1 will be assumed.
9972
9973 Can also be used as a |method|: >
9974 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009975<
9976 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009977
9978sign_ functions are documented here: |sign-functions-details|
9979
9980
9981simplify({filename}) *simplify()*
9982 Simplify the file name as much as possible without changing
9983 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
9984 Unix) are not resolved. If the first path component in
9985 {filename} designates the current directory, this will be
9986 valid for the result as well. A trailing path separator is
9987 not removed either. On Unix "//path" is unchanged, but
9988 "///path" is simplified to "/path" (this follows the Posix
9989 standard).
9990 Example: >
9991 simplify("./dir/.././/file/") == "./file/"
9992< Note: The combination "dir/.." is only removed if "dir" is
9993 a searchable directory or does not exist. On Unix, it is also
9994 removed when "dir" is a symbolic link within the same
9995 directory. In order to resolve all the involved symbolic
9996 links before simplifying the path name, use |resolve()|.
9997
9998 Can also be used as a |method|: >
9999 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010000<
10001 Return type: |String|
10002
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010003
10004sin({expr}) *sin()*
10005 Return the sine of {expr}, measured in radians, as a |Float|.
10006 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010007 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010008 Examples: >
10009 :echo sin(100)
10010< -0.506366 >
10011 :echo sin(-4.01)
10012< 0.763301
10013
10014 Can also be used as a |method|: >
10015 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010016<
10017 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010018
10019
10020sinh({expr}) *sinh()*
10021 Return the hyperbolic sine of {expr} as a |Float| in the range
10022 [-inf, inf].
10023 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010024 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010025 Examples: >
10026 :echo sinh(0.5)
10027< 0.521095 >
10028 :echo sinh(-0.9)
10029< -1.026517
10030
10031 Can also be used as a |method|: >
10032 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010033<
10034 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010035
10036
10037slice({expr}, {start} [, {end}]) *slice()*
10038 Similar to using a |slice| "expr[start : end]", but "end" is
10039 used exclusive. And for a string the indexes are used as
10040 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010041 |vim9script|. Also, composing characters are treated as a
10042 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010043 When {end} is omitted the slice continues to the last item.
10044 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010045 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010046
10047 Can also be used as a |method|: >
10048 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010049<
10050 Return type: list<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010051
10052
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010053sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010054 Sort the items in {list} in-place. Returns {list}.
10055
10056 If you want a list to remain unmodified make a copy first: >
10057 :let sortedlist = sort(copy(mylist))
10058
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010059< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010060 string representation of each item to sort on. Numbers sort
10061 after Strings, |Lists| after Numbers. For sorting text in the
10062 current buffer use |:sort|.
10063
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010064 When {how} is given and it is 'i' then case is ignored.
10065 In legacy script, for backwards compatibility, the value one
10066 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010067
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010068 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010069 locale is used for ordering. Implementation details: strcoll()
10070 is used to compare strings. See |:language| check or set the
10071 collation locale. |v:collate| can also be used to check the
10072 current locale. Sorting using the locale typically ignores
10073 case. Example: >
10074 " ö is sorted similarly to o with English locale.
10075 :language collate en_US.UTF8
10076 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10077< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10078>
10079 " ö is sorted after z with Swedish locale.
10080 :language collate sv_SE.UTF8
10081 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10082< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10083 This does not work properly on Mac.
10084
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010085 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010086 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010087 strtod() function to parse numbers. Strings, Lists, Dicts and
10088 Funcrefs will be considered as being 0). Note that this won't
10089 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010090
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010091 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010092 sorted numerical. This is like 'n' but a string containing
10093 digits will be used as the number they represent.
10094
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010095 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010096 sorted numerical. All values must be a Number or a Float.
10097
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010098 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010099 is called to compare items. The function is invoked with two
10100 items as argument and must return zero if they are equal, 1 or
10101 bigger if the first one sorts after the second one, -1 or
10102 smaller if the first one sorts before the second one.
10103
10104 {dict} is for functions with the "dict" attribute. It will be
10105 used to set the local variable "self". |Dictionary-function|
10106
10107 The sort is stable, items which compare equal (as number or as
10108 string) will keep their relative position. E.g., when sorting
10109 on numbers, text strings will sort next to each other, in the
10110 same order as they were originally.
10111
10112 Can also be used as a |method|: >
10113 mylist->sort()
10114
10115< Also see |uniq()|.
10116
10117 Example: >
10118 func MyCompare(i1, i2)
10119 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10120 endfunc
10121 eval mylist->sort("MyCompare")
10122< A shorter compare version for this specific simple case, which
10123 ignores overflow: >
10124 func MyCompare(i1, i2)
10125 return a:i1 - a:i2
10126 endfunc
10127< For a simple expression you can use a lambda: >
10128 eval mylist->sort({i1, i2 -> i1 - i2})
10129<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010130 Return type: list<{type}>
10131
10132
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010133sound_clear() *sound_clear()*
10134 Stop playing all sounds.
10135
10136 On some Linux systems you may need the libcanberra-pulse
10137 package, otherwise sound may not stop.
10138
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010139 Return type: |Number|
10140
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010141 {only available when compiled with the |+sound| feature}
10142
10143 *sound_playevent()*
10144sound_playevent({name} [, {callback}])
10145 Play a sound identified by {name}. Which event names are
10146 supported depends on the system. Often the XDG sound names
10147 are used. On Ubuntu they may be found in
10148 /usr/share/sounds/freedesktop/stereo. Example: >
10149 call sound_playevent('bell')
10150< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10151 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10152 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010153 On macOS, {name} refers to files located in
10154 /System/Library/Sounds (e.g. "Tink"). It will also work for
10155 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010156
10157 When {callback} is specified it is invoked when the sound is
10158 finished. The first argument is the sound ID, the second
10159 argument is the status:
10160 0 sound was played to the end
10161 1 sound was interrupted
10162 2 error occurred after sound started
10163 Example: >
10164 func Callback(id, status)
10165 echomsg "sound " .. a:id .. " finished with " .. a:status
10166 endfunc
10167 call sound_playevent('bell', 'Callback')
10168
10169< MS-Windows: {callback} doesn't work for this function.
10170
10171 Returns the sound ID, which can be passed to `sound_stop()`.
10172 Returns zero if the sound could not be played.
10173
10174 Can also be used as a |method|: >
10175 GetSoundName()->sound_playevent()
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 *sound_playfile()*
10182sound_playfile({path} [, {callback}])
10183 Like `sound_playevent()` but play sound file {path}. {path}
10184 must be a full path. On Ubuntu you may find files to play
10185 with this command: >
10186 :!find /usr/share/sounds -type f | grep -v index.theme
10187
10188< Can also be used as a |method|: >
10189 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010190<
10191 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010192
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010193 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010194
10195
10196sound_stop({id}) *sound_stop()*
10197 Stop playing sound {id}. {id} must be previously returned by
10198 `sound_playevent()` or `sound_playfile()`.
10199
10200 On some Linux systems you may need the libcanberra-pulse
10201 package, otherwise sound may not stop.
10202
10203 On MS-Windows, this does not work for event sound started by
10204 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10205
10206 Can also be used as a |method|: >
10207 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010208<
10209 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010210
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010211 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010212
10213 *soundfold()*
10214soundfold({word})
10215 Return the sound-folded equivalent of {word}. Uses the first
10216 language in 'spelllang' for the current window that supports
10217 soundfolding. 'spell' must be set. When no sound folding is
10218 possible the {word} is returned unmodified.
10219 This can be used for making spelling suggestions. Note that
10220 the method can be quite slow.
10221
10222 Can also be used as a |method|: >
10223 GetWord()->soundfold()
10224<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010225 Return type: |String|
10226
10227
10228spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010229 Without argument: The result is the badly spelled word under
10230 or after the cursor. The cursor is moved to the start of the
10231 bad word. When no bad word is found in the cursor line the
10232 result is an empty string and the cursor doesn't move.
10233
10234 With argument: The result is the first word in {sentence} that
10235 is badly spelled. If there are no spelling mistakes the
10236 result is an empty string.
10237
10238 The return value is a list with two items:
10239 - The badly spelled word or an empty string.
10240 - The type of the spelling error:
10241 "bad" spelling mistake
10242 "rare" rare word
10243 "local" word only valid in another region
10244 "caps" word should start with Capital
10245 Example: >
10246 echo spellbadword("the quik brown fox")
10247< ['quik', 'bad'] ~
10248
10249 The spelling information for the current window and the value
10250 of 'spelllang' are used.
10251
10252 Can also be used as a |method|: >
10253 GetText()->spellbadword()
10254<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010255 Return type: list<string>
10256
10257
10258spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010259 Return a |List| with spelling suggestions to replace {word}.
10260 When {max} is given up to this number of suggestions are
10261 returned. Otherwise up to 25 suggestions are returned.
10262
10263 When the {capital} argument is given and it's non-zero only
10264 suggestions with a leading capital will be given. Use this
10265 after a match with 'spellcapcheck'.
10266
10267 {word} can be a badly spelled word followed by other text.
10268 This allows for joining two words that were split. The
10269 suggestions also include the following text, thus you can
10270 replace a line.
10271
10272 {word} may also be a good word. Similar words will then be
10273 returned. {word} itself is not included in the suggestions,
10274 although it may appear capitalized.
10275
10276 The spelling information for the current window is used. The
10277 values of 'spelllang' and 'spellsuggest' are used.
10278
10279 Can also be used as a |method|: >
10280 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010281<
10282 Return type: list<string> or list<any>
10283
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010284
10285split({string} [, {pattern} [, {keepempty}]]) *split()*
10286 Make a |List| out of {string}. When {pattern} is omitted or
10287 empty each white-separated sequence of characters becomes an
10288 item.
10289 Otherwise the string is split where {pattern} matches,
10290 removing the matched characters. 'ignorecase' is not used
10291 here, add \c to ignore case. |/\c|
10292 When the first or last item is empty it is omitted, unless the
10293 {keepempty} argument is given and it's non-zero.
10294 Other empty items are kept when {pattern} matches at least one
10295 character or when {keepempty} is non-zero.
10296 Example: >
10297 :let words = split(getline('.'), '\W\+')
10298< To split a string in individual characters: >
10299 :for c in split(mystring, '\zs')
10300< If you want to keep the separator you can also use '\zs' at
10301 the end of the pattern: >
10302 :echo split('abc:def:ghi', ':\zs')
10303< ['abc:', 'def:', 'ghi'] ~
10304 Splitting a table where the first element can be empty: >
10305 :let items = split(line, ':', 1)
10306< The opposite function is |join()|.
10307
10308 Can also be used as a |method|: >
10309 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010310<
10311 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010312
10313sqrt({expr}) *sqrt()*
10314 Return the non-negative square root of Float {expr} as a
10315 |Float|.
10316 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010317 is negative the result is NaN (Not a Number). Returns 0.0 if
10318 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010319 Examples: >
10320 :echo sqrt(100)
10321< 10.0 >
10322 :echo sqrt(-4.01)
10323< nan
10324 "nan" may be different, it depends on system libraries.
10325
10326 Can also be used as a |method|: >
10327 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010328<
10329 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010330
10331
10332srand([{expr}]) *srand()*
10333 Initialize seed used by |rand()|:
10334 - If {expr} is not given, seed values are initialized by
10335 reading from /dev/urandom, if possible, or using time(NULL)
10336 a.k.a. epoch time otherwise; this only has second accuracy.
10337 - If {expr} is given it must be a Number. It is used to
10338 initialize the seed values. This is useful for testing or
10339 when a predictable sequence is intended.
10340
10341 Examples: >
10342 :let seed = srand()
10343 :let seed = srand(userinput)
10344 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010345<
10346 Return type: list<number>
10347
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010348
10349state([{what}]) *state()*
10350 Return a string which contains characters indicating the
10351 current state. Mostly useful in callbacks that want to do
10352 work that may not always be safe. Roughly this works like:
10353 - callback uses state() to check if work is safe to do.
10354 Yes: then do it right away.
10355 No: add to work queue and add a |SafeState| and/or
10356 |SafeStateAgain| autocommand (|SafeState| triggers at
10357 toplevel, |SafeStateAgain| triggers after handling
10358 messages and callbacks).
10359 - When SafeState or SafeStateAgain is triggered and executes
10360 your autocommand, check with `state()` if the work can be
10361 done now, and if yes remove it from the queue and execute.
10362 Remove the autocommand if the queue is now empty.
10363 Also see |mode()|.
10364
10365 When {what} is given only characters in this string will be
10366 added. E.g, this checks if the screen has scrolled: >
10367 if state('s') == ''
10368 " screen has not scrolled
10369<
10370 These characters indicate the state, generally indicating that
10371 something is busy:
10372 m halfway a mapping, :normal command, feedkeys() or
10373 stuffed command
10374 o operator pending, e.g. after |d|
10375 a Insert mode autocomplete active
10376 x executing an autocommand
10377 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10378 ch_readraw() when reading json
10379 S not triggering SafeState or SafeStateAgain, e.g. after
10380 |f| or a count
10381 c callback invoked, including timer (repeats for
10382 recursiveness up to "ccc")
10383 s screen has scrolled for messages
10384
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010385 Return type: |String|
10386
10387
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010388str2float({string} [, {quoted}]) *str2float()*
10389 Convert String {string} to a Float. This mostly works the
10390 same as when using a floating point number in an expression,
10391 see |floating-point-format|. But it's a bit more permissive.
10392 E.g., "1e40" is accepted, while in an expression you need to
10393 write "1.0e40". The hexadecimal form "0x123" is also
10394 accepted, but not others, like binary or octal.
10395 When {quoted} is present and non-zero then embedded single
10396 quotes before the dot are ignored, thus "1'000.0" is a
10397 thousand.
10398 Text after the number is silently ignored.
10399 The decimal point is always '.', no matter what the locale is
10400 set to. A comma ends the number: "12,345.67" is converted to
10401 12.0. You can strip out thousands separators with
10402 |substitute()|: >
10403 let f = str2float(substitute(text, ',', '', 'g'))
10404<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010405 Returns 0.0 if the conversion fails.
10406
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010407 Can also be used as a |method|: >
10408 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010409<
10410 Return type: |Float|
10411
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010412
10413str2list({string} [, {utf8}]) *str2list()*
10414 Return a list containing the number values which represent
10415 each character in String {string}. Examples: >
10416 str2list(" ") returns [32]
10417 str2list("ABC") returns [65, 66, 67]
10418< |list2str()| does the opposite.
10419
10420 When {utf8} is omitted or zero, the current 'encoding' is used.
10421 When {utf8} is TRUE, always treat the String as UTF-8
10422 characters. With UTF-8 composing characters are handled
10423 properly: >
10424 str2list("á") returns [97, 769]
10425
10426< Can also be used as a |method|: >
10427 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010428<
10429 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010430
10431
10432str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10433 Convert string {string} to a number.
10434 {base} is the conversion base, it can be 2, 8, 10 or 16.
10435 When {quoted} is present and non-zero then embedded single
10436 quotes are ignored, thus "1'000'000" is a million.
10437
10438 When {base} is omitted base 10 is used. This also means that
10439 a leading zero doesn't cause octal conversion to be used, as
10440 with the default String to Number conversion. Example: >
10441 let nr = str2nr('0123')
10442<
10443 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10444 different base the result will be zero. Similarly, when
10445 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10446 {base} is 2 a leading "0b" or "0B" is ignored.
10447 Text after the number is silently ignored.
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 Can also be used as a |method|: >
10452 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010453<
10454 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010455
10456
10457strcharlen({string}) *strcharlen()*
10458 The result is a Number, which is the number of characters
10459 in String {string}. Composing characters are ignored.
10460 |strchars()| can count the number of characters, counting
10461 composing characters separately.
10462
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010463 Returns 0 if {string} is empty or on error.
10464
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010465 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10466
10467 Can also be used as a |method|: >
10468 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010469<
10470 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010471
10472
10473strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10474 Like |strpart()| but using character index and length instead
10475 of byte index and length.
10476 When {skipcc} is omitted or zero, composing characters are
10477 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010478 When {skipcc} set to 1, composing characters are treated as a
10479 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010480 When a character index is used where a character does not
10481 exist it is omitted and counted as one character. For
10482 example: >
10483 strcharpart('abc', -1, 2)
10484< results in 'a'.
10485
Bram Moolenaard592deb2022-06-17 15:42:40 +010010486 Returns an empty string on error.
10487
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010488 Can also be used as a |method|: >
10489 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010490<
10491 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010492
10493
10494strchars({string} [, {skipcc}]) *strchars()*
10495 The result is a Number, which is the number of characters
10496 in String {string}.
10497 When {skipcc} is omitted or zero, composing characters are
10498 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010499 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010500 |strcharlen()| always does this.
10501
Bram Moolenaard592deb2022-06-17 15:42:40 +010010502 Returns zero on error.
10503
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010504 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10505
10506 {skipcc} is only available after 7.4.755. For backward
10507 compatibility, you can define a wrapper function: >
10508 if has("patch-7.4.755")
10509 function s:strchars(str, skipcc)
10510 return strchars(a:str, a:skipcc)
10511 endfunction
10512 else
10513 function s:strchars(str, skipcc)
10514 if a:skipcc
10515 return strlen(substitute(a:str, ".", "x", "g"))
10516 else
10517 return strchars(a:str)
10518 endif
10519 endfunction
10520 endif
10521<
10522 Can also be used as a |method|: >
10523 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010524<
10525 Return type: |Number|
10526
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010527
10528strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10529 The result is a Number, which is the number of display cells
10530 String {string} occupies on the screen when it starts at {col}
10531 (first column is zero). When {col} is omitted zero is used.
10532 Otherwise it is the screen column where to start. This
10533 matters for Tab characters.
10534 The option settings of the current window are used. This
10535 matters for anything that's displayed differently, such as
10536 'tabstop' and 'display'.
10537 When {string} contains characters with East Asian Width Class
10538 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010539 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010540 Also see |strlen()|, |strwidth()| and |strchars()|.
10541
10542 Can also be used as a |method|: >
10543 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010544<
10545 Return type: |Number|
10546
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010547
10548strftime({format} [, {time}]) *strftime()*
10549 The result is a String, which is a formatted date and time, as
10550 specified by the {format} string. The given {time} is used,
10551 or the current time if no time is given. The accepted
10552 {format} depends on your system, thus this is not portable!
10553 See the manual page of the C function strftime() for the
10554 format. The maximum length of the result is 80 characters.
10555 See also |localtime()|, |getftime()| and |strptime()|.
10556 The language can be changed with the |:language| command.
10557 Examples: >
10558 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10559 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10560 :echo strftime("%y%m%d %T") 970427 11:53:55
10561 :echo strftime("%H:%M") 11:55
10562 :echo strftime("%c", getftime("file.c"))
10563 Show mod time of file.c.
10564< Not available on all systems. To check use: >
10565 :if exists("*strftime")
10566
10567< Can also be used as a |method|: >
10568 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010569<
10570 Return type: |String|
10571
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010572
10573strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010574 Get a Number corresponding to the character at {index} in
10575 {str}. This uses a zero-based character index, not a byte
10576 index. Composing characters are considered separate
10577 characters here. Use |nr2char()| to convert the Number to a
10578 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010579 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010580 Also see |strcharpart()| and |strchars()|.
10581
10582 Can also be used as a |method|: >
10583 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010584<
10585 Return type: |Number|
10586
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010587
10588stridx({haystack}, {needle} [, {start}]) *stridx()*
10589 The result is a Number, which gives the byte index in
10590 {haystack} of the first occurrence of the String {needle}.
10591 If {start} is specified, the search starts at index {start}.
10592 This can be used to find a second match: >
10593 :let colon1 = stridx(line, ":")
10594 :let colon2 = stridx(line, ":", colon1 + 1)
10595< The search is done case-sensitive.
10596 For pattern searches use |match()|.
10597 -1 is returned if the {needle} does not occur in {haystack}.
10598 See also |strridx()|.
10599 Examples: >
10600 :echo stridx("An Example", "Example") 3
10601 :echo stridx("Starting point", "Start") 0
10602 :echo stridx("Starting point", "start") -1
10603< *strstr()* *strchr()*
10604 stridx() works similar to the C function strstr(). When used
10605 with a single character it works similar to strchr().
10606
10607 Can also be used as a |method|: >
10608 GetHaystack()->stridx(needle)
10609<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010610 Return type: |Number|
10611
10612
10613string({expr}) *string()*
10614 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010615 Float, String, Blob or a composition of them, then the result
10616 can be parsed back with |eval()|.
10617 {expr} type result ~
10618 String 'string' (single quotes are doubled)
10619 Number 123
10620 Float 123.123456 or 1.123456e8
10621 Funcref function('name')
10622 Blob 0z00112233.44556677.8899
10623 List [item, item]
10624 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000010625 Class class SomeName
10626 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010010627 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020010628 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010629
10630 When a |List| or |Dictionary| has a recursive reference it is
10631 replaced by "[...]" or "{...}". Using eval() on the result
10632 will then fail.
10633
mityu7f0bba22024-03-29 10:14:41 +010010634 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010635 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010010636 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010637
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010638 Can also be used as a |method|: >
10639 mylist->string()
10640
10641< Also see |strtrans()|.
10642
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010643 Return type: |String|
10644
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010645
10646strlen({string}) *strlen()*
10647 The result is a Number, which is the length of the String
10648 {string} in bytes.
10649 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010650 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010651 If you want to count the number of multibyte characters use
10652 |strchars()|.
10653 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
10654
10655 Can also be used as a |method|: >
10656 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010657<
10658 Return type: |Number|
10659
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010660
10661strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
10662 The result is a String, which is part of {src}, starting from
10663 byte {start}, with the byte length {len}.
10664 When {chars} is present and TRUE then {len} is the number of
10665 characters positions (composing characters are not counted
10666 separately, thus "1" means one base character and any
10667 following composing characters).
10668 To count {start} as characters instead of bytes use
10669 |strcharpart()|.
10670
10671 When bytes are selected which do not exist, this doesn't
10672 result in an error, the bytes are simply omitted.
10673 If {len} is missing, the copy continues from {start} till the
10674 end of the {src}. >
10675 strpart("abcdefg", 3, 2) == "de"
10676 strpart("abcdefg", -2, 4) == "ab"
10677 strpart("abcdefg", 5, 4) == "fg"
10678 strpart("abcdefg", 3) == "defg"
10679
10680< Note: To get the first character, {start} must be 0. For
10681 example, to get the character under the cursor: >
10682 strpart(getline("."), col(".") - 1, 1, v:true)
10683<
Bram Moolenaard592deb2022-06-17 15:42:40 +010010684 Returns an empty string on error.
10685
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010686 Can also be used as a |method|: >
10687 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010688<
10689 Return type: |String|
10690
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010691
10692strptime({format}, {timestring}) *strptime()*
10693 The result is a Number, which is a unix timestamp representing
10694 the date and time in {timestring}, which is expected to match
10695 the format specified in {format}.
10696
10697 The accepted {format} depends on your system, thus this is not
10698 portable! See the manual page of the C function strptime()
10699 for the format. Especially avoid "%c". The value of $TZ also
10700 matters.
10701
10702 If the {timestring} cannot be parsed with {format} zero is
10703 returned. If you do not know the format of {timestring} you
10704 can try different {format} values until you get a non-zero
10705 result.
10706
10707 See also |strftime()|.
10708 Examples: >
10709 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
10710< 862156163 >
10711 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
10712< Sun Apr 27 11:53:55 1997 >
10713 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
10714< Sun Apr 27 12:53:55 1997
10715
10716 Can also be used as a |method|: >
10717 GetFormat()->strptime(timestring)
10718<
10719 Not available on all systems. To check use: >
10720 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010721<
10722 Return type: |Number|
10723
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010724
10725strridx({haystack}, {needle} [, {start}]) *strridx()*
10726 The result is a Number, which gives the byte index in
10727 {haystack} of the last occurrence of the String {needle}.
10728 When {start} is specified, matches beyond this index are
10729 ignored. This can be used to find a match before a previous
10730 match: >
10731 :let lastcomma = strridx(line, ",")
10732 :let comma2 = strridx(line, ",", lastcomma - 1)
10733< The search is done case-sensitive.
10734 For pattern searches use |match()|.
10735 -1 is returned if the {needle} does not occur in {haystack}.
10736 If the {needle} is empty the length of {haystack} is returned.
10737 See also |stridx()|. Examples: >
10738 :echo strridx("an angry armadillo", "an") 3
10739< *strrchr()*
10740 When used with a single character it works similar to the C
10741 function strrchr().
10742
10743 Can also be used as a |method|: >
10744 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010745<
10746 Return type: |Number|
10747
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010748
10749strtrans({string}) *strtrans()*
10750 The result is a String, which is {string} with all unprintable
10751 characters translated into printable characters |'isprint'|.
10752 Like they are shown in a window. Example: >
10753 echo strtrans(@a)
10754< This displays a newline in register a as "^@" instead of
10755 starting a new line.
10756
Bram Moolenaard592deb2022-06-17 15:42:40 +010010757 Returns an empty string on error.
10758
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010759 Can also be used as a |method|: >
10760 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010761<
10762 Return type: |String|
10763
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010764
Christian Brabandt67672ef2023-04-24 21:09:54 +010010765strutf16len({string} [, {countcc}]) *strutf16len()*
10766 The result is a Number, which is the number of UTF-16 code
10767 units in String {string} (after converting it to UTF-16).
10768
10769 When {countcc} is TRUE, composing characters are counted
10770 separately.
10771 When {countcc} is omitted or FALSE, composing characters are
10772 ignored.
10773
10774 Returns zero on error.
10775
10776 Also see |strlen()| and |strcharlen()|.
10777 Examples: >
10778 echo strutf16len('a') returns 1
10779 echo strutf16len('©') returns 1
10780 echo strutf16len('😊') returns 2
10781 echo strutf16len('ą́') returns 1
10782 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090010783<
Christian Brabandt67672ef2023-04-24 21:09:54 +010010784 Can also be used as a |method|: >
10785 GetText()->strutf16len()
10786<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010787 Return type: |Number|
10788
10789
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010790strwidth({string}) *strwidth()*
10791 The result is a Number, which is the number of display cells
10792 String {string} occupies. A Tab character is counted as one
10793 cell, alternatively use |strdisplaywidth()|.
10794 When {string} contains characters with East Asian Width Class
10795 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010796 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010797 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
10798
10799 Can also be used as a |method|: >
10800 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010801<
10802 Return type: |Number|
10803
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010804
10805submatch({nr} [, {list}]) *submatch()* *E935*
10806 Only for an expression in a |:substitute| command or
10807 substitute() function.
10808 Returns the {nr}'th submatch of the matched text. When {nr}
10809 is 0 the whole matched text is returned.
10810 Note that a NL in the string can stand for a line break of a
10811 multi-line match or a NUL character in the text.
10812 Also see |sub-replace-expression|.
10813
10814 If {list} is present and non-zero then submatch() returns
10815 a list of strings, similar to |getline()| with two arguments.
10816 NL characters in the text represent NUL characters in the
10817 text.
10818 Only returns more than one item for |:substitute|, inside
10819 |substitute()| this list will always contain one or zero
10820 items, since there are no real line breaks.
10821
10822 When substitute() is used recursively only the submatches in
10823 the current (deepest) call can be obtained.
10824
Bram Moolenaard592deb2022-06-17 15:42:40 +010010825 Returns an empty string or list on error.
10826
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010827 Examples: >
10828 :s/\d\+/\=submatch(0) + 1/
10829 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
10830< This finds the first number in the line and adds one to it.
10831 A line break is included as a newline character.
10832
10833 Can also be used as a |method|: >
10834 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010835<
10836 Return type: |String| or list<string> depending on {list}
10837
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010838
10839substitute({string}, {pat}, {sub}, {flags}) *substitute()*
10840 The result is a String, which is a copy of {string}, in which
10841 the first match of {pat} is replaced with {sub}.
10842 When {flags} is "g", all matches of {pat} in {string} are
10843 replaced. Otherwise {flags} should be "".
10844
10845 This works like the ":substitute" command (without any flags).
10846 But the matching with {pat} is always done like the 'magic'
10847 option is set and 'cpoptions' is empty (to make scripts
10848 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
10849 if you want to ignore or match case and ignore 'ignorecase'.
10850 'smartcase' is not used. See |string-match| for how {pat} is
10851 used.
10852
10853 A "~" in {sub} is not replaced with the previous {sub}.
10854 Note that some codes in {sub} have a special meaning
10855 |sub-replace-special|. For example, to replace something with
10856 "\n" (two characters), use "\\\\n" or '\\n'.
10857
10858 When {pat} does not match in {string}, {string} is returned
10859 unmodified.
10860
10861 Example: >
10862 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
10863< This removes the last component of the 'path' option. >
10864 :echo substitute("testing", ".*", "\\U\\0", "")
10865< results in "TESTING".
10866
10867 When {sub} starts with "\=", the remainder is interpreted as
10868 an expression. See |sub-replace-expression|. Example: >
10869 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010870 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010871
10872< When {sub} is a Funcref that function is called, with one
10873 optional argument. Example: >
10874 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
10875< The optional argument is a list which contains the whole
10876 matched string and up to nine submatches, like what
10877 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010878 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010879
Bram Moolenaard592deb2022-06-17 15:42:40 +010010880< Returns an empty string on error.
10881
10882 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010883 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010884<
10885 Return type: |String|
10886
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010887
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000010888swapfilelist() *swapfilelist()*
10889 Returns a list of swap file names, like what "vim -r" shows.
10890 See the |-r| command argument. The 'directory' option is used
10891 for the directories to inspect. If you only want to get a
10892 list of swap files in the current directory then temporarily
10893 set 'directory' to a dot: >
10894 let save_dir = &directory
10895 let &directory = '.'
10896 let swapfiles = swapfilelist()
10897 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010898<
10899 Return type: list<string>
10900
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000010901
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010902swapinfo({fname}) *swapinfo()*
10903 The result is a dictionary, which holds information about the
10904 swapfile {fname}. The available fields are:
10905 version Vim version
10906 user user name
10907 host host name
10908 fname original file name
10909 pid PID of the Vim process that created the swap
10910 file
10911 mtime last modification time in seconds
10912 inode Optional: INODE number of the file
10913 dirty 1 if file was modified, 0 if not
10914 Note that "user" and "host" are truncated to at most 39 bytes.
10915 In case of failure an "error" item is added with the reason:
10916 Cannot open file: file not found or in accessible
10917 Cannot read file: cannot read first block
10918 Not a swap file: does not contain correct block ID
10919 Magic number mismatch: Info in first block is invalid
10920
10921 Can also be used as a |method|: >
10922 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010923<
10924 Return type: dict<any> or dict<string>
10925
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010926
10927swapname({buf}) *swapname()*
10928 The result is the swap file path of the buffer {expr}.
10929 For the use of {buf}, see |bufname()| above.
10930 If buffer {buf} is the current buffer, the result is equal to
10931 |:swapname| (unless there is no swap file).
10932 If buffer {buf} has no swap file, returns an empty string.
10933
10934 Can also be used as a |method|: >
10935 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010936<
10937 Return type: |String|
10938
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010939
10940synID({lnum}, {col}, {trans}) *synID()*
10941 The result is a Number, which is the syntax ID at the position
10942 {lnum} and {col} in the current window.
10943 The syntax ID can be used with |synIDattr()| and
10944 |synIDtrans()| to obtain syntax information about text.
10945
10946 {col} is 1 for the leftmost column, {lnum} is 1 for the first
10947 line. 'synmaxcol' applies, in a longer line zero is returned.
10948 Note that when the position is after the last character,
10949 that's where the cursor can be in Insert mode, synID() returns
10950 zero. {lnum} is used like with |getline()|.
10951
10952 When {trans} is |TRUE|, transparent items are reduced to the
10953 item that they reveal. This is useful when wanting to know
10954 the effective color. When {trans} is |FALSE|, the transparent
10955 item is returned. This is useful when wanting to know which
10956 syntax item is effective (e.g. inside parens).
10957 Warning: This function can be very slow. Best speed is
10958 obtained by going through the file in forward direction.
10959
Bram Moolenaard592deb2022-06-17 15:42:40 +010010960 Returns zero on error.
10961
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010962 Example (echoes the name of the syntax item under the cursor): >
10963 :echo synIDattr(synID(line("."), col("."), 1), "name")
10964<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010965 Return type: |Number|
10966
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010967
10968synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
10969 The result is a String, which is the {what} attribute of
10970 syntax ID {synID}. This can be used to obtain information
10971 about a syntax item.
10972 {mode} can be "gui", "cterm" or "term", to get the attributes
10973 for that mode. When {mode} is omitted, or an invalid value is
10974 used, the attributes for the currently active highlighting are
10975 used (GUI, cterm or term).
10976 Use synIDtrans() to follow linked highlight groups.
10977 {what} result
10978 "name" the name of the syntax item
10979 "fg" foreground color (GUI: color name used to set
10980 the color, cterm: color number as a string,
10981 term: empty string)
10982 "bg" background color (as with "fg")
10983 "font" font name (only available in the GUI)
10984 |highlight-font|
10985 "sp" special color for the GUI (as with "fg")
10986 |highlight-guisp|
10987 "ul" underline color for cterm: number as a string
10988 "fg#" like "fg", but for the GUI and the GUI is
10989 running the name in "#RRGGBB" form
10990 "bg#" like "fg#" for "bg"
10991 "sp#" like "fg#" for "sp"
10992 "bold" "1" if bold
10993 "italic" "1" if italic
10994 "reverse" "1" if reverse
10995 "inverse" "1" if inverse (= reverse)
10996 "standout" "1" if standout
10997 "underline" "1" if underlined
10998 "undercurl" "1" if undercurled
10999 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010011000 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011001
Bram Moolenaard592deb2022-06-17 15:42:40 +010011002 Returns an empty string on error.
11003
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011004 Example (echoes the color of the syntax item under the
11005 cursor): >
11006 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
11007<
11008 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: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011012
11013
11014synIDtrans({synID}) *synIDtrans()*
11015 The result is a Number, which is the translated syntax ID of
11016 {synID}. This is the syntax group ID of what is being used to
11017 highlight the character. Highlight links given with
11018 ":highlight link" are followed.
11019
Bram Moolenaard592deb2022-06-17 15:42:40 +010011020 Returns zero on error.
11021
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011022 Can also be used as a |method|: >
11023 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011024<
11025 Return type: |Number|
11026
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011027
11028synconcealed({lnum}, {col}) *synconcealed()*
11029 The result is a |List| with currently three items:
11030 1. The first item in the list is 0 if the character at the
11031 position {lnum} and {col} is not part of a concealable
11032 region, 1 if it is. {lnum} is used like with |getline()|.
11033 2. The second item in the list is a string. If the first item
11034 is 1, the second item contains the text which will be
11035 displayed in place of the concealed text, depending on the
11036 current setting of 'conceallevel' and 'listchars'.
11037 3. The third and final item in the list is a number
11038 representing the specific syntax region matched in the
11039 line. When the character is not concealed the value is
11040 zero. This allows detection of the beginning of a new
11041 concealable region if there are two consecutive regions
11042 with the same replacement character. For an example, if
11043 the text is "123456" and both "23" and "45" are concealed
11044 and replaced by the character "X", then:
11045 call returns ~
11046 synconcealed(lnum, 1) [0, '', 0]
11047 synconcealed(lnum, 2) [1, 'X', 1]
11048 synconcealed(lnum, 3) [1, 'X', 1]
11049 synconcealed(lnum, 4) [1, 'X', 2]
11050 synconcealed(lnum, 5) [1, 'X', 2]
11051 synconcealed(lnum, 6) [0, '', 0]
11052
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011053 Note: Doesn't consider |matchadd()| highlighting items,
11054 since syntax and matching highlighting are two different
11055 mechanisms |syntax-vs-match|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011056<
11057 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011058
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011059
11060synstack({lnum}, {col}) *synstack()*
11061 Return a |List|, which is the stack of syntax items at the
11062 position {lnum} and {col} in the current window. {lnum} is
11063 used like with |getline()|. Each item in the List is an ID
11064 like what |synID()| returns.
11065 The first item in the List is the outer region, following are
11066 items contained in that one. The last one is what |synID()|
11067 returns, unless not the whole item is highlighted or it is a
11068 transparent item.
11069 This function is useful for debugging a syntax file.
11070 Example that shows the syntax stack under the cursor: >
11071 for id in synstack(line("."), col("."))
11072 echo synIDattr(id, "name")
11073 endfor
11074< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011075 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011076 character in a line and the first column in an empty line are
11077 valid positions.
11078
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011079 Return type: list<number> or list<any>
11080
11081
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011082system({expr} [, {input}]) *system()* *E677*
11083 Get the output of the shell command {expr} as a |String|. See
11084 |systemlist()| to get the output as a |List|.
11085
11086 When {input} is given and is a |String| this string is written
11087 to a file and passed as stdin to the command. The string is
11088 written as-is, you need to take care of using the correct line
11089 separators yourself.
11090 If {input} is given and is a |List| it is written to the file
11091 in a way |writefile()| does with {binary} set to "b" (i.e.
11092 with a newline between each list item with newlines inside
11093 list items converted to NULs).
11094 When {input} is given and is a number that is a valid id for
11095 an existing buffer then the content of the buffer is written
11096 to the file line by line, each line terminated by a NL and
11097 NULs characters where the text has a NL.
11098
11099 Pipes are not used, the 'shelltemp' option is not used.
11100
11101 When prepended by |:silent| the terminal will not be set to
11102 cooked mode. This is meant to be used for commands that do
11103 not need the user to type. It avoids stray characters showing
11104 up on the screen which require |CTRL-L| to remove. >
11105 :silent let f = system('ls *.vim')
11106<
11107 Note: Use |shellescape()| or |::S| with |expand()| or
11108 |fnamemodify()| to escape special characters in a command
11109 argument. Newlines in {expr} may cause the command to fail.
11110 The characters in 'shellquote' and 'shellxquote' may also
11111 cause trouble.
11112 This is not to be used for interactive commands.
11113
11114 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011115 :let files = system('ls ' .. shellescape(expand('%:h')))
11116 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011117
11118< To make the result more system-independent, the shell output
11119 is filtered to replace <CR> with <NL> for Macintosh, and
11120 <CR><NL> with <NL> for DOS-like systems.
11121 To avoid the string being truncated at a NUL, all NUL
11122 characters are replaced with SOH (0x01).
11123
11124 The command executed is constructed using several options:
11125 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11126 ({tmp} is an automatically generated file name).
11127 For Unix, braces are put around {expr} to allow for
11128 concatenated commands.
11129
11130 The command will be executed in "cooked" mode, so that a
11131 CTRL-C will interrupt the command (on Unix at least).
11132
11133 The resulting error code can be found in |v:shell_error|.
11134 This function will fail in |restricted-mode|.
11135
11136 Note that any wrong value in the options mentioned above may
11137 make the function fail. It has also been reported to fail
11138 when using a security agent application.
11139 Unlike ":!cmd" there is no automatic check for changed files.
11140 Use |:checktime| to force a check.
11141
11142 Can also be used as a |method|: >
11143 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011144<
11145 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011146
11147
11148systemlist({expr} [, {input}]) *systemlist()*
11149 Same as |system()|, but returns a |List| with lines (parts of
11150 output separated by NL) with NULs transformed into NLs. Output
11151 is the same as |readfile()| will output with {binary} argument
11152 set to "b", except that there is no extra empty item when the
11153 result ends in a NL.
11154 Note that on MS-Windows you may get trailing CR characters.
11155
11156 To see the difference between "echo hello" and "echo -n hello"
11157 use |system()| and |split()|: >
11158 echo system('echo hello')->split('\n', 1)
11159<
11160 Returns an empty string on error.
11161
11162 Can also be used as a |method|: >
11163 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011164<
11165 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011166
11167
11168tabpagebuflist([{arg}]) *tabpagebuflist()*
11169 The result is a |List|, where each item is the number of the
11170 buffer associated with each window in the current tab page.
11171 {arg} specifies the number of the tab page to be used. When
11172 omitted the current tab page is used.
11173 When {arg} is invalid the number zero is returned.
11174 To get a list of all buffers in all tabs use this: >
11175 let buflist = []
11176 for i in range(tabpagenr('$'))
11177 call extend(buflist, tabpagebuflist(i + 1))
11178 endfor
11179< Note that a buffer may appear in more than one window.
11180
11181 Can also be used as a |method|: >
11182 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011183<
11184 Return type: list<number>
11185
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011186
11187tabpagenr([{arg}]) *tabpagenr()*
11188 The result is a Number, which is the number of the current
11189 tab page. The first tab page has number 1.
11190
11191 The optional argument {arg} supports the following values:
11192 $ the number of the last tab page (the tab page
11193 count).
11194 # the number of the last accessed tab page
11195 (where |g<Tab>| goes to). if there is no
11196 previous tab page 0 is returned.
11197 The number can be used with the |:tab| command.
11198
Bram Moolenaard592deb2022-06-17 15:42:40 +010011199 Returns zero on error.
11200
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011201 Return type: |Number|
11202
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011203
11204tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11205 Like |winnr()| but for tab page {tabarg}.
11206 {tabarg} specifies the number of tab page to be used.
11207 {arg} is used like with |winnr()|:
11208 - When omitted the current window number is returned. This is
11209 the window which will be used when going to this tab page.
11210 - When "$" the number of windows is returned.
11211 - When "#" the previous window nr is returned.
11212 Useful examples: >
11213 tabpagewinnr(1) " current window of tab page 1
11214 tabpagewinnr(4, '$') " number of windows in tab page 4
11215< When {tabarg} is invalid zero is returned.
11216
11217 Can also be used as a |method|: >
11218 GetTabpage()->tabpagewinnr()
11219<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011220 Return type: |Number|
11221
11222
11223tagfiles() *tagfiles()*
11224 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011225 for the current buffer. This is the 'tags' option expanded.
11226
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011227 Return type: list<string> or list<any>
11228
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011229
11230taglist({expr} [, {filename}]) *taglist()*
11231 Returns a |List| of tags matching the regular expression {expr}.
11232
11233 If {filename} is passed it is used to prioritize the results
11234 in the same way that |:tselect| does. See |tag-priority|.
11235 {filename} should be the full path of the file.
11236
11237 Each list item is a dictionary with at least the following
11238 entries:
11239 name Name of the tag.
11240 filename Name of the file where the tag is
11241 defined. It is either relative to the
11242 current directory or a full path.
11243 cmd Ex command used to locate the tag in
11244 the file.
11245 kind Type of the tag. The value for this
11246 entry depends on the language specific
11247 kind values. Only available when
11248 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011249 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011250 static A file specific tag. Refer to
11251 |static-tag| for more information.
11252 More entries may be present, depending on the content of the
11253 tags file: access, implementation, inherits and signature.
11254 Refer to the ctags documentation for information about these
11255 fields. For C code the fields "struct", "class" and "enum"
11256 may appear, they give the name of the entity the tag is
11257 contained in.
11258
11259 The ex-command "cmd" can be either an ex search pattern, a
11260 line number or a line number followed by a byte number.
11261
11262 If there are no matching tags, then an empty list is returned.
11263
11264 To get an exact tag match, the anchors '^' and '$' should be
11265 used in {expr}. This also make the function work faster.
11266 Refer to |tag-regexp| for more information about the tag
11267 search regular expression pattern.
11268
11269 Refer to |'tags'| for information about how the tags file is
11270 located by Vim. Refer to |tags-file-format| for the format of
11271 the tags file generated by the different ctags tools.
11272
11273 Can also be used as a |method|: >
11274 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011275<
11276 Return type: list<dict<any>> or list<any>
11277
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011278
11279tan({expr}) *tan()*
11280 Return the tangent of {expr}, measured in radians, as a |Float|
11281 in the range [-inf, inf].
11282 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011283 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011284 Examples: >
11285 :echo tan(10)
11286< 0.648361 >
11287 :echo tan(-4.01)
11288< -1.181502
11289
11290 Can also be used as a |method|: >
11291 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011292<
11293 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011294
11295
11296tanh({expr}) *tanh()*
11297 Return the hyperbolic tangent of {expr} as a |Float| in the
11298 range [-1, 1].
11299 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011300 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011301 Examples: >
11302 :echo tanh(0.5)
11303< 0.462117 >
11304 :echo tanh(-1)
11305< -0.761594
11306
11307 Can also be used as a |method|: >
11308 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011309<
11310 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011311
11312
11313tempname() *tempname()* *temp-file-name*
11314 The result is a String, which is the name of a file that
11315 doesn't exist. It can be used for a temporary file. The name
11316 is different for at least 26 consecutive calls. Example: >
11317 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011318 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011319< For Unix, the file will be in a private directory |tempfile|
11320 that is recursively deleted when Vim exits, on other systems
11321 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011322 For MS-Windows forward slashes are used when the 'shellslash'
11323 option is set, or when 'shellcmdflag' starts with '-' and
11324 'shell' does not contain powershell or pwsh.
11325
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011326 Return type: |String|
11327
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011328
11329term_ functions are documented here: |terminal-function-details|
11330
11331
11332terminalprops() *terminalprops()*
11333 Returns a |Dictionary| with properties of the terminal that Vim
11334 detected from the response to |t_RV| request. See
11335 |v:termresponse| for the response itself. If |v:termresponse|
11336 is empty most values here will be 'u' for unknown.
11337 cursor_style whether sending |t_RS| works **
11338 cursor_blink_mode whether sending |t_RC| works **
11339 underline_rgb whether |t_8u| works **
11340 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011341 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011342
11343 ** value 'u' for unknown, 'y' for yes, 'n' for no
11344
11345 If the |+termresponse| feature is missing then the result is
11346 an empty dictionary.
11347
11348 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11349 current cursor style.
11350 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11351 request the cursor blink status.
11352 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11353 is not empty, Vim will detect the working of sending |t_RS|
11354 and |t_RC| on startup.
11355
11356 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11357 This avoids sending it to xterm, which would clear the colors.
11358
11359 For "mouse" the value 'u' is unknown
11360
11361 Also see:
11362 - 'ambiwidth' - detected by using |t_u7|.
11363 - |v:termstyleresp| and |v:termblinkresp| for the response to
11364 |t_RS| and |t_RC|.
11365
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011366 Return type: dict<string>
11367
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011368
11369test_ functions are documented here: |test-functions-details|
11370
11371
11372 *timer_info()*
11373timer_info([{id}])
11374 Return a list with information about timers.
11375 When {id} is given only information about this timer is
11376 returned. When timer {id} does not exist an empty list is
11377 returned.
11378 When {id} is omitted information about all timers is returned.
11379
11380 For each timer the information is stored in a |Dictionary| with
11381 these items:
11382 "id" the timer ID
11383 "time" time the timer was started with
11384 "remaining" time until the timer fires
11385 "repeat" number of times the timer will still fire;
11386 -1 means forever
11387 "callback" the callback
11388 "paused" 1 if the timer is paused, 0 otherwise
11389
11390 Can also be used as a |method|: >
11391 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011392<
11393 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011394
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011395 {only available when compiled with the |+timers| feature}
11396
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011397
11398timer_pause({timer}, {paused}) *timer_pause()*
11399 Pause or unpause a timer. A paused timer does not invoke its
11400 callback when its time expires. Unpausing a timer may cause
11401 the callback to be invoked almost immediately if enough time
11402 has passed.
11403
11404 Pausing a timer is useful to avoid the callback to be called
11405 for a short time.
11406
11407 If {paused} evaluates to a non-zero Number or a non-empty
11408 String, then the timer is paused, otherwise it is unpaused.
11409 See |non-zero-arg|.
11410
11411 Can also be used as a |method|: >
11412 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011413<
11414 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011415
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011416 {only available when compiled with the |+timers| feature}
11417
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011418
11419 *timer_start()* *timer* *timers*
11420timer_start({time}, {callback} [, {options}])
11421 Create a timer and return the timer ID.
11422
11423 {time} is the waiting time in milliseconds. This is the
11424 minimum time before invoking the callback. When the system is
11425 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011426 Zero can be used to execute the callback when Vim is back in
11427 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011428
11429 {callback} is the function to call. It can be the name of a
11430 function or a |Funcref|. It is called with one argument, which
11431 is the timer ID. The callback is only invoked when Vim is
11432 waiting for input.
11433 If you want to show a message look at |popup_notification()|
11434 to avoid interfering with what the user is doing.
11435
11436 {options} is a dictionary. Supported entries:
11437 "repeat" Number of times to repeat calling the
11438 callback. -1 means forever. When not present
11439 the callback will be called once.
11440 If the timer causes an error three times in a
11441 row the repeat is cancelled. This avoids that
11442 Vim becomes unusable because of all the error
11443 messages.
11444
Bram Moolenaard592deb2022-06-17 15:42:40 +010011445 Returns -1 on error.
11446
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011447 Example: >
11448 func MyHandler(timer)
11449 echo 'Handler called'
11450 endfunc
11451 let timer = timer_start(500, 'MyHandler',
11452 \ {'repeat': 3})
11453< This will invoke MyHandler() three times at 500 msec
11454 intervals.
11455
11456 Can also be used as a |method|: >
11457 GetMsec()->timer_start(callback)
11458
11459< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011460
11461 Return type: |Number|
11462
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011463 {only available when compiled with the |+timers| feature}
11464
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011465
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011466timer_stop({timer}) *timer_stop()*
11467 Stop a timer. The timer callback will no longer be invoked.
11468 {timer} is an ID returned by timer_start(), thus it must be a
11469 Number. If {timer} does not exist there is no error.
11470
11471 Can also be used as a |method|: >
11472 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011473<
11474 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011475
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011476 {only available when compiled with the |+timers| feature}
11477
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011478
11479timer_stopall() *timer_stopall()*
11480 Stop all timers. The timer callbacks will no longer be
11481 invoked. Useful if a timer is misbehaving. If there are no
11482 timers there is no error.
11483
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011484 Return type: |Number|
11485
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011486 {only available when compiled with the |+timers| feature}
11487
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011488
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011489tolower({expr}) *tolower()*
11490 The result is a copy of the String given, with all uppercase
11491 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011492 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011493
11494 Can also be used as a |method|: >
11495 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011496<
11497 Return type: |String|
11498
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011499
11500toupper({expr}) *toupper()*
11501 The result is a copy of the String given, with all lowercase
11502 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011503 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011504
11505 Can also be used as a |method|: >
11506 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011507<
11508 Return type: |String|
11509
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011510
11511tr({src}, {fromstr}, {tostr}) *tr()*
11512 The result is a copy of the {src} string with all characters
11513 which appear in {fromstr} replaced by the character in that
11514 position in the {tostr} string. Thus the first character in
11515 {fromstr} is translated into the first character in {tostr}
11516 and so on. Exactly like the unix "tr" command.
11517 This code also deals with multibyte characters properly.
11518
Bram Moolenaard592deb2022-06-17 15:42:40 +010011519 Returns an empty string on error.
11520
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011521 Examples: >
11522 echo tr("hello there", "ht", "HT")
11523< returns "Hello THere" >
11524 echo tr("<blob>", "<>", "{}")
11525< returns "{blob}"
11526
11527 Can also be used as a |method|: >
11528 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011529<
11530 Return type: |String|
11531
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011532
11533trim({text} [, {mask} [, {dir}]]) *trim()*
11534 Return {text} as a String where any character in {mask} is
11535 removed from the beginning and/or end of {text}.
11536
Illia Bobyr80799172023-10-17 18:00:50 +020011537 If {mask} is not given, or is an empty string, {mask} is all
11538 characters up to 0x20, which includes Tab, space, NL and CR,
11539 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011540
11541 The optional {dir} argument specifies where to remove the
11542 characters:
11543 0 remove from the beginning and end of {text}
11544 1 remove only at the beginning of {text}
11545 2 remove only at the end of {text}
11546 When omitted both ends are trimmed.
11547
11548 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011549 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011550
11551 Examples: >
11552 echo trim(" some text ")
11553< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011554 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011555< returns "RESERVE_TAIL" >
11556 echo trim("rm<Xrm<>X>rrm", "rm<>")
11557< returns "Xrm<>X" (characters in the middle are not removed) >
11558 echo trim(" vim ", " ", 2)
11559< returns " vim"
11560
11561 Can also be used as a |method|: >
11562 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011563<
11564 Return type: |String|
11565
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011566
11567trunc({expr}) *trunc()*
11568 Return the largest integral value with magnitude less than or
11569 equal to {expr} as a |Float| (truncate towards zero).
11570 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011571 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011572 Examples: >
11573 echo trunc(1.456)
11574< 1.0 >
11575 echo trunc(-5.456)
11576< -5.0 >
11577 echo trunc(4.0)
11578< 4.0
11579
11580 Can also be used as a |method|: >
11581 Compute()->trunc()
11582<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011583 Return type: |Float|
11584
11585
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011586 *type()*
11587type({expr}) The result is a Number representing the type of {expr}.
11588 Instead of using the number directly, it is better to use the
11589 v:t_ variable that has the value:
11590 Number: 0 |v:t_number|
11591 String: 1 |v:t_string|
11592 Funcref: 2 |v:t_func|
11593 List: 3 |v:t_list|
11594 Dictionary: 4 |v:t_dict|
11595 Float: 5 |v:t_float|
11596 Boolean: 6 |v:t_bool| (v:false and v:true)
11597 None: 7 |v:t_none| (v:null and v:none)
11598 Job: 8 |v:t_job|
11599 Channel: 9 |v:t_channel|
11600 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090011601 Class: 12 |v:t_class|
11602 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010011603 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011604 Enum: 15 |v:t_enum|
11605 EnumValue: 16 |v:t_enumvalue|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011606 For backward compatibility, this method can be used: >
11607 :if type(myvar) == type(0)
11608 :if type(myvar) == type("")
11609 :if type(myvar) == type(function("tr"))
11610 :if type(myvar) == type([])
11611 :if type(myvar) == type({})
11612 :if type(myvar) == type(0.0)
11613 :if type(myvar) == type(v:false)
11614 :if type(myvar) == type(v:none)
11615< To check if the v:t_ variables exist use this: >
11616 :if exists('v:t_number')
11617
11618< Can also be used as a |method|: >
11619 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011620<
11621 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011622
11623
11624typename({expr}) *typename()*
11625 Return a string representation of the type of {expr}.
11626 Example: >
11627 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000011628< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011629
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011630 Return type: |String|
11631
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011632
11633undofile({name}) *undofile()*
11634 Return the name of the undo file that would be used for a file
11635 with name {name} when writing. This uses the 'undodir'
11636 option, finding directories that exist. It does not check if
11637 the undo file exists.
11638 {name} is always expanded to the full path, since that is what
11639 is used internally.
11640 If {name} is empty undofile() returns an empty string, since a
11641 buffer without a file name will not write an undo file.
11642 Useful in combination with |:wundo| and |:rundo|.
11643 When compiled without the |+persistent_undo| option this always
11644 returns an empty string.
11645
11646 Can also be used as a |method|: >
11647 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011648<
11649 Return type: |String|
11650
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011651
Devin J. Pohly5fee1112023-04-23 20:26:59 -050011652undotree([{buf}]) *undotree()*
11653 Return the current state of the undo tree for the current
11654 buffer, or for a specific buffer if {buf} is given. The
11655 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011656 "seq_last" The highest undo sequence number used.
11657 "seq_cur" The sequence number of the current position in
11658 the undo tree. This differs from "seq_last"
11659 when some changes were undone.
11660 "time_cur" Time last used for |:earlier| and related
11661 commands. Use |strftime()| to convert to
11662 something readable.
11663 "save_last" Number of the last file write. Zero when no
11664 write yet.
11665 "save_cur" Number of the current position in the undo
11666 tree.
11667 "synced" Non-zero when the last undo block was synced.
11668 This happens when waiting from input from the
11669 user. See |undo-blocks|.
11670 "entries" A list of dictionaries with information about
11671 undo blocks.
11672
11673 The first item in the "entries" list is the oldest undo item.
11674 Each List item is a |Dictionary| with these items:
11675 "seq" Undo sequence number. Same as what appears in
11676 |:undolist|.
11677 "time" Timestamp when the change happened. Use
11678 |strftime()| to convert to something readable.
11679 "newhead" Only appears in the item that is the last one
11680 that was added. This marks the last change
11681 and where further changes will be added.
11682 "curhead" Only appears in the item that is the last one
11683 that was undone. This marks the current
11684 position in the undo tree, the block that will
11685 be used by a redo command. When nothing was
11686 undone after the last change this item will
11687 not appear anywhere.
11688 "save" Only appears on the last block before a file
11689 write. The number is the write count. The
11690 first write has number 1, the last one the
11691 "save_last" mentioned above.
11692 "alt" Alternate entry. This is again a List of undo
11693 blocks. Each item may again have an "alt"
11694 item.
11695
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011696 Return type: dict<any>
11697
11698
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011699uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
11700 Remove second and succeeding copies of repeated adjacent
11701 {list} items in-place. Returns {list}. If you want a list
11702 to remain unmodified make a copy first: >
11703 :let newlist = uniq(copy(mylist))
11704< The default compare function uses the string representation of
11705 each item. For the use of {func} and {dict} see |sort()|.
11706
Bram Moolenaard592deb2022-06-17 15:42:40 +010011707 Returns zero if {list} is not a |List|.
11708
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011709 Can also be used as a |method|: >
11710 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010011711<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011712 Return type: list<{type}>
11713
11714
Christian Brabandt67672ef2023-04-24 21:09:54 +010011715 *utf16idx()*
11716utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011717 Same as |charidx()| but returns the UTF-16 code unit index of
11718 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010011719
11720 When {charidx} is present and TRUE, {idx} is used as the
11721 character index in the String {string} instead of as the byte
11722 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010011723 An {idx} in the middle of a UTF-8 sequence is rounded
11724 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010011725
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011726 Returns -1 if the arguments are invalid or if there are less
11727 than {idx} bytes in {string}. If there are exactly {idx} bytes
11728 the length of the string in UTF-16 code units is returned.
11729
Christian Brabandt67672ef2023-04-24 21:09:54 +010011730 See |byteidx()| and |byteidxcomp()| for getting the byte index
11731 from the UTF-16 index and |charidx()| for getting the
11732 character index from the UTF-16 index.
11733 Refer to |string-offset-encoding| for more information.
11734 Examples: >
11735 echo utf16idx('a😊😊', 3) returns 2
11736 echo utf16idx('a😊😊', 7) returns 4
11737 echo utf16idx('a😊😊', 1, 0, 1) returns 2
11738 echo utf16idx('a😊😊', 2, 0, 1) returns 4
11739 echo utf16idx('aą́c', 6) returns 2
11740 echo utf16idx('aą́c', 6, 1) returns 4
11741 echo utf16idx('a😊😊', 9) returns -1
11742<
11743 Can also be used as a |method|: >
11744 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011745<
11746 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010011747
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011748
11749values({dict}) *values()*
11750 Return a |List| with all the values of {dict}. The |List| is
11751 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011752 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011753
11754 Can also be used as a |method|: >
11755 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011756<
11757 Return type: list<any>
11758
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011759
zeertzjq825cf812023-08-17 22:55:25 +020011760virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011761 The result is a Number, which is the screen column of the file
11762 position given with {expr}. That is, the last screen position
11763 occupied by the character at that position, when the screen
11764 would be of unlimited width. When there is a <Tab> at the
11765 position, the returned Number will be the column at the end of
11766 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
11767 set to 8, it returns 8. |conceal| is ignored.
11768 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011769
zeertzjq02f3eba2024-06-12 20:45:24 +020011770 For the use of {expr} see |getpos()| and |col()|.
zeertzjqd353d272024-06-13 23:00:25 +080011771 When {expr} is "$", it means the end of the cursor line, so
11772 the result is the number of cells in the cursor line plus one.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011773
11774 When 'virtualedit' is used {expr} can be [lnum, col, off],
11775 where "off" is the offset in screen columns from the start of
11776 the character. E.g., a position within a <Tab> or after the
11777 last character. When "off" is omitted zero is used. When
11778 Virtual editing is active in the current mode, a position
11779 beyond the end of the line can be returned. Also see
11780 |'virtualedit'|
11781
zeertzjq825cf812023-08-17 22:55:25 +020011782 If {list} is present and non-zero then virtcol() returns a
11783 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010011784 character.
11785
zeertzjq825cf812023-08-17 22:55:25 +020011786 With the optional {winid} argument the values are obtained for
11787 that window instead of the current window.
11788
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011789 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +020011790
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011791 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010011792 " With text "foo^Lbar" and cursor on the "^L":
11793
11794 virtcol(".") " returns 5
11795 virtcol(".", 1) " returns [4, 5]
11796 virtcol("$") " returns 9
11797
11798 " With text " there", with 't at 'h':
11799
11800 virtcol("'t") " returns 6
zeertzjq02f3eba2024-06-12 20:45:24 +020011801<
11802 The first column is 1. 0 or [0, 0] is returned for an error.
11803
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011804 A more advanced example that echoes the maximum length of
11805 all lines: >
11806 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
11807
11808< Can also be used as a |method|: >
11809 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011810<
11811 Return type: |Number|
11812
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011813
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011814virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
11815 The result is a Number, which is the byte index of the
11816 character in window {winid} at buffer line {lnum} and virtual
11817 column {col}.
11818
zeertzjqb583eda2023-10-14 11:32:28 +020011819 If buffer line {lnum} is an empty line, 0 is returned.
11820
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011821 If {col} is greater than the last virtual column in line
11822 {lnum}, then the byte index of the character at the last
11823 virtual column is returned.
11824
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020011825 For a multi-byte character, the column number of the first
11826 byte in the character is returned.
11827
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011828 The {winid} argument can be the window number or the
11829 |window-ID|. If this is zero, then the current window is used.
11830
11831 Returns -1 if the window {winid} doesn't exist or the buffer
11832 line {lnum} or virtual column {col} is invalid.
11833
11834 See also |screenpos()|, |virtcol()| and |col()|.
11835
11836 Can also be used as a |method|: >
11837 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011838<
11839 Return type: |Number|
11840
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011841
11842visualmode([{expr}]) *visualmode()*
11843 The result is a String, which describes the last Visual mode
11844 used in the current buffer. Initially it returns an empty
11845 string, but once Visual mode has been used, it returns "v",
11846 "V", or "<CTRL-V>" (a single CTRL-V character) for
11847 character-wise, line-wise, or block-wise Visual mode
11848 respectively.
11849 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011850 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011851< This enters the same Visual mode as before. It is also useful
11852 in scripts if you wish to act differently depending on the
11853 Visual mode that was used.
11854 If Visual mode is active, use |mode()| to get the Visual mode
11855 (e.g., in a |:vmap|).
11856 If {expr} is supplied and it evaluates to a non-zero Number or
11857 a non-empty String, then the Visual mode will be cleared and
11858 the old value is returned. See |non-zero-arg|.
11859
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011860 Return type: |String|
11861
11862
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011863wildmenumode() *wildmenumode()*
11864 Returns |TRUE| when the wildmenu is active and |FALSE|
11865 otherwise. See 'wildmenu' and 'wildmode'.
11866 This can be used in mappings to handle the 'wildcharm' option
11867 gracefully. (Makes only sense with |mapmode-c| mappings).
11868
11869 For example to make <c-j> work like <down> in wildmode, use: >
11870 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
11871<
11872 (Note, this needs the 'wildcharm' option set appropriately).
11873
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011874 Return type: |Number|
11875
11876
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011877win_execute({id}, {command} [, {silent}]) *win_execute()*
11878 Like `execute()` but in the context of window {id}.
11879 The window will temporarily be made the current window,
11880 without triggering autocommands or changing directory. When
11881 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010011882 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011883 Example: >
11884 call win_execute(winid, 'set syntax=python')
11885< Doing the same with `setwinvar()` would not trigger
11886 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011887 *E994*
11888 Not all commands are allowed in popup windows.
11889 When window {id} does not exist then no error is given and
11890 an empty string is returned.
11891
11892 Can also be used as a |method|, the base is passed as the
11893 second argument: >
11894 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011895<
11896 Return type: |String|
11897
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011898
11899win_findbuf({bufnr}) *win_findbuf()*
11900 Returns a |List| with |window-ID|s for windows that contain
11901 buffer {bufnr}. When there is none the list is empty.
11902
11903 Can also be used as a |method|: >
11904 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011905<
11906 Return type: list<number> or list<any>
11907
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011908
11909win_getid([{win} [, {tab}]]) *win_getid()*
11910 Get the |window-ID| for the specified window.
11911 When {win} is missing use the current window.
11912 With {win} this is the window number. The top window has
11913 number 1.
11914 Without {tab} use the current tab, otherwise the tab with
11915 number {tab}. The first tab has number one.
11916 Return zero if the window cannot be found.
11917
11918 Can also be used as a |method|: >
11919 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011920<
11921 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011922
11923
11924win_gettype([{nr}]) *win_gettype()*
11925 Return the type of the window:
11926 "autocmd" autocommand window. Temporary window
11927 used to execute autocommands.
11928 "command" command-line window |cmdwin|
11929 (empty) normal window
11930 "loclist" |location-list-window|
11931 "popup" popup window |popup|
11932 "preview" preview window |preview-window|
11933 "quickfix" |quickfix-window|
11934 "unknown" window {nr} not found
11935
11936 When {nr} is omitted return the type of the current window.
11937 When {nr} is given return the type of this window by number or
11938 |window-ID|.
11939
11940 Also see the 'buftype' option. When running a terminal in a
11941 popup window then 'buftype' is "terminal" and win_gettype()
11942 returns "popup".
11943
11944 Can also be used as a |method|: >
11945 GetWinid()->win_gettype()
11946<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011947 Return type: |String|
11948
11949
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011950win_gotoid({expr}) *win_gotoid()*
11951 Go to window with ID {expr}. This may also change the current
11952 tabpage.
11953 Return TRUE if successful, FALSE if the window cannot be found.
11954
11955 Can also be used as a |method|: >
11956 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011957<
11958 Return type: |Number|
11959
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011960
11961win_id2tabwin({expr}) *win_id2tabwin()*
11962 Return a list with the tab number and window number of window
11963 with ID {expr}: [tabnr, winnr].
11964 Return [0, 0] if the window cannot be found.
11965
11966 Can also be used as a |method|: >
11967 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011968<
11969 Return type: list<number>
11970
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011971
11972win_id2win({expr}) *win_id2win()*
11973 Return the window number of window with ID {expr}.
11974 Return 0 if the window cannot be found in the current tabpage.
11975
11976 Can also be used as a |method|: >
11977 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011978<
11979 Return type: |Number|
11980
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011981
Daniel Steinbergee630312022-01-10 13:36:34 +000011982win_move_separator({nr}, {offset}) *win_move_separator()*
11983 Move window {nr}'s vertical separator (i.e., the right border)
11984 by {offset} columns, as if being dragged by the mouse. {nr}
11985 can be a window number or |window-ID|. A positive {offset}
11986 moves right and a negative {offset} moves left. Moving a
11987 window's vertical separator will change the width of the
11988 window and the width of other windows adjacent to the vertical
11989 separator. The magnitude of movement may be smaller than
11990 specified (e.g., as a consequence of maintaining
11991 'winminwidth'). Returns TRUE if the window can be found and
11992 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011993 This will fail for the rightmost window and a full-width
11994 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000011995 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000011996
11997 Can also be used as a |method|: >
11998 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011999<
12000 Return type: |Number|
12001
Daniel Steinbergee630312022-01-10 13:36:34 +000012002
12003win_move_statusline({nr}, {offset}) *win_move_statusline()*
12004 Move window {nr}'s status line (i.e., the bottom border) by
12005 {offset} rows, as if being dragged by the mouse. {nr} can be a
12006 window number or |window-ID|. A positive {offset} moves down
12007 and a negative {offset} moves up. Moving a window's status
12008 line will change the height of the window and the height of
12009 other windows adjacent to the status line. The magnitude of
12010 movement may be smaller than specified (e.g., as a consequence
12011 of maintaining 'winminheight'). Returns TRUE if the window can
12012 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012013 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000012014
12015 Can also be used as a |method|: >
12016 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012017<
12018 Return type: |Number|
12019
Daniel Steinbergee630312022-01-10 13:36:34 +000012020
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012021win_screenpos({nr}) *win_screenpos()*
12022 Return the screen position of window {nr} as a list with two
12023 numbers: [row, col]. The first window always has position
12024 [1, 1], unless there is a tabline, then it is [2, 1].
12025 {nr} can be the window number or the |window-ID|. Use zero
12026 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012027 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012028
12029 Can also be used as a |method|: >
12030 GetWinid()->win_screenpos()
12031<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012032 Return type: list<number>
12033
12034
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012035win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012036 Temporarily switch to window {target}, then move window {nr}
12037 to a new split adjacent to {target}.
12038 Unlike commands such as |:split|, no new windows are created
12039 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012040
12041 Both {nr} and {target} can be window numbers or |window-ID|s.
12042 Both must be in the current tab page.
12043
12044 Returns zero for success, non-zero for failure.
12045
12046 {options} is a |Dictionary| with the following optional entries:
12047 "vertical" When TRUE, the split is created vertically,
12048 like with |:vsplit|.
12049 "rightbelow" When TRUE, the split is made below or to the
12050 right (if vertical). When FALSE, it is done
12051 above or to the left (if vertical). When not
12052 present, the values of 'splitbelow' and
12053 'splitright' are used.
12054
12055 Can also be used as a |method|: >
12056 GetWinid()->win_splitmove(target)
12057<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012058 Return type: |Number|
12059
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012060
12061 *winbufnr()*
12062winbufnr({nr}) The result is a Number, which is the number of the buffer
12063 associated with window {nr}. {nr} can be the window number or
12064 the |window-ID|.
12065 When {nr} is zero, the number of the buffer in the current
12066 window is returned.
12067 When window {nr} doesn't exist, -1 is returned.
12068 Example: >
12069 :echo "The file in the current window is " . bufname(winbufnr(0))
12070<
12071 Can also be used as a |method|: >
12072 FindWindow()->winbufnr()->bufname()
12073<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012074 Return type: |Number|
12075
12076
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012077 *wincol()*
12078wincol() The result is a Number, which is the virtual column of the
12079 cursor in the window. This is counting screen cells from the
12080 left side of the window. The leftmost column is one.
12081
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012082 Return type: |Number|
12083
12084
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012085 *windowsversion()*
12086windowsversion()
12087 The result is a String. For MS-Windows it indicates the OS
12088 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12089 Windows XP is "5.1". For non-MS-Windows systems the result is
12090 an empty string.
12091
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012092 Return type: |String|
12093
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012094winheight({nr}) *winheight()*
12095 The result is a Number, which is the height of window {nr}.
12096 {nr} can be the window number or the |window-ID|.
12097 When {nr} is zero, the height of the current window is
12098 returned. When window {nr} doesn't exist, -1 is returned.
12099 An existing window always has a height of zero or more.
12100 This excludes any window toolbar line.
12101 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012102 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012103
12104< Can also be used as a |method|: >
12105 GetWinid()->winheight()
12106<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012107 Return type: |Number|
12108
12109
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012110winlayout([{tabnr}]) *winlayout()*
12111 The result is a nested List containing the layout of windows
12112 in a tabpage.
12113
12114 Without {tabnr} use the current tabpage, otherwise the tabpage
12115 with number {tabnr}. If the tabpage {tabnr} is not found,
12116 returns an empty list.
12117
12118 For a leaf window, it returns:
12119 ['leaf', {winid}]
12120 For horizontally split windows, which form a column, it
12121 returns:
12122 ['col', [{nested list of windows}]]
12123 For vertically split windows, which form a row, it returns:
12124 ['row', [{nested list of windows}]]
12125
12126 Example: >
12127 " Only one window in the tab page
12128 :echo winlayout()
12129 ['leaf', 1000]
12130 " Two horizontally split windows
12131 :echo winlayout()
12132 ['col', [['leaf', 1000], ['leaf', 1001]]]
12133 " The second tab page, with three horizontally split
12134 " windows, with two vertically split windows in the
12135 " middle window
12136 :echo winlayout(2)
12137 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12138 ['leaf', 1001]]], ['leaf', 1000]]]
12139<
12140 Can also be used as a |method|: >
12141 GetTabnr()->winlayout()
12142<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012143 Return type: list<any>
12144
12145
12146winline() *winline()*
12147 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012148 in the window. This is counting screen lines from the top of
12149 the window. The first line is one.
12150 If the cursor was moved the view on the file will be updated
12151 first, this may cause a scroll.
12152
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012153 Return type: |Number|
12154
12155
12156winnr([{arg}]) *winnr()*
12157 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012158 window. The top window has number 1.
12159 Returns zero for a popup window.
12160
12161 The optional argument {arg} supports the following values:
12162 $ the number of the last window (the window
12163 count).
12164 # the number of the last accessed window (where
12165 |CTRL-W_p| goes to). If there is no previous
12166 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012167 returned. May refer to the current window in
12168 some cases (e.g. when evaluating 'statusline'
12169 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012170 {N}j the number of the Nth window below the
12171 current window (where |CTRL-W_j| goes to).
12172 {N}k the number of the Nth window above the current
12173 window (where |CTRL-W_k| goes to).
12174 {N}h the number of the Nth window left of the
12175 current window (where |CTRL-W_h| goes to).
12176 {N}l the number of the Nth window right of the
12177 current window (where |CTRL-W_l| goes to).
12178 The number can be used with |CTRL-W_w| and ":wincmd w"
12179 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012180 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012181 Also see |tabpagewinnr()| and |win_getid()|.
12182 Examples: >
12183 let window_count = winnr('$')
12184 let prev_window = winnr('#')
12185 let wnum = winnr('3k')
12186
12187< Can also be used as a |method|: >
12188 GetWinval()->winnr()
12189<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012190 Return type: |Number|
12191
12192
12193winrestcmd() *winrestcmd()*
12194 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012195 the current window sizes. Only works properly when no windows
12196 are opened or closed and the current window and tab page is
12197 unchanged.
12198 Example: >
12199 :let cmd = winrestcmd()
12200 :call MessWithWindowSizes()
12201 :exe cmd
12202<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012203 Return type: |String|
12204
12205
12206winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012207 Uses the |Dictionary| returned by |winsaveview()| to restore
12208 the view of the current window.
12209 Note: The {dict} does not have to contain all values, that are
12210 returned by |winsaveview()|. If values are missing, those
12211 settings won't be restored. So you can use: >
12212 :call winrestview({'curswant': 4})
12213<
12214 This will only set the curswant value (the column the cursor
12215 wants to move on vertical movements) of the cursor to column 5
12216 (yes, that is 5), while all other settings will remain the
12217 same. This is useful, if you set the cursor position manually.
12218
12219 If you have changed the values the result is unpredictable.
12220 If the window size changed the result won't be the same.
12221
12222 Can also be used as a |method|: >
12223 GetView()->winrestview()
12224<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012225 Return type: |Number|
12226
12227
12228winsaveview() *winsaveview()*
12229 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012230 the view of the current window. Use |winrestview()| to
12231 restore the view.
12232 This is useful if you have a mapping that jumps around in the
12233 buffer and you want to go back to the original view.
12234 This does not save fold information. Use the 'foldenable'
12235 option to temporarily switch off folding, so that folds are
12236 not opened when moving around. This may have side effects.
12237 The return value includes:
12238 lnum cursor line number
12239 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012240 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012241 returns)
12242 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012243 curswant column for vertical movement (Note:
12244 the first column is zero, as opposed
12245 to what |getcurpos()| returns). After
12246 |$| command it will be a very large
12247 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012248 topline first line in the window
12249 topfill filler lines, only in diff mode
12250 leftcol first column displayed; only used when
12251 'wrap' is off
12252 skipcol columns skipped
12253 Note that no option values are saved.
12254
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012255 Return type: dict<number>
12256
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012257
12258winwidth({nr}) *winwidth()*
12259 The result is a Number, which is the width of window {nr}.
12260 {nr} can be the window number or the |window-ID|.
12261 When {nr} is zero, the width of the current window is
12262 returned. When window {nr} doesn't exist, -1 is returned.
12263 An existing window always has a width of zero or more.
12264 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012265 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012266 :if winwidth(0) <= 50
12267 : 50 wincmd |
12268 :endif
12269< For getting the terminal or screen size, see the 'columns'
12270 option.
12271
12272 Can also be used as a |method|: >
12273 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012274<
12275 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012276
12277
12278wordcount() *wordcount()*
12279 The result is a dictionary of byte/chars/word statistics for
12280 the current buffer. This is the same info as provided by
12281 |g_CTRL-G|
12282 The return value includes:
12283 bytes Number of bytes in the buffer
12284 chars Number of chars in the buffer
12285 words Number of words in the buffer
12286 cursor_bytes Number of bytes before cursor position
12287 (not in Visual mode)
12288 cursor_chars Number of chars before cursor position
12289 (not in Visual mode)
12290 cursor_words Number of words before cursor position
12291 (not in Visual mode)
12292 visual_bytes Number of bytes visually selected
12293 (only in Visual mode)
12294 visual_chars Number of chars visually selected
12295 (only in Visual mode)
12296 visual_words Number of words visually selected
12297 (only in Visual mode)
12298
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012299 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012300
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012301
12302writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012303 When {object} is a |List| write it to file {fname}. Each list
12304 item is separated with a NL. Each list item must be a String
12305 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012306 All NL characters are replaced with a NUL character.
12307 Inserting CR characters needs to be done before passing {list}
12308 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012309
12310 When {object} is a |Blob| write the bytes to file {fname}
12311 unmodified, also when binary mode is not specified.
12312
12313 {flags} must be a String. These characters are recognized:
12314
12315 'b' Binary mode is used: There will not be a NL after the
12316 last list item. An empty item at the end does cause the
12317 last line in the file to end in a NL.
12318
12319 'a' Append mode is used, lines are appended to the file: >
12320 :call writefile(["foo"], "event.log", "a")
12321 :call writefile(["bar"], "event.log", "a")
12322<
12323 'D' Delete the file when the current function ends. This
12324 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012325 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012326< Fails when not in a function. Also see |:defer|.
12327
12328 's' fsync() is called after writing the file. This flushes
12329 the file to disk, if possible. This takes more time but
12330 avoids losing the file if the system crashes.
12331
12332 'S' fsync() is not called, even when 'fsync' is set.
12333
12334 When {flags} does not contain "S" or "s" then fsync() is
12335 called if the 'fsync' option is set.
12336
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012337 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012338
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012339 When the write fails -1 is returned, otherwise 0. There is an
12340 error message if the file can't be created or when writing
12341 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012342
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012343 Also see |readfile()|.
12344 To copy a file byte for byte: >
12345 :let fl = readfile("foo", "b")
12346 :call writefile(fl, "foocopy", "b")
12347
12348< Can also be used as a |method|: >
12349 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012350<
12351 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012352
12353
12354xor({expr}, {expr}) *xor()*
12355 Bitwise XOR on the two arguments. The arguments are converted
12356 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012357 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012358 Example: >
12359 :let bits = xor(bits, 0x80)
12360<
12361 Can also be used as a |method|: >
12362 :let bits = bits->xor(0x80)
12363<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012364 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012365
12366==============================================================================
123673. Feature list *feature-list*
12368
12369There are three types of features:
123701. Features that are only supported when they have been enabled when Vim
12371 was compiled |+feature-list|. Example: >
12372 :if has("cindent")
12373< *gui_running*
123742. Features that are only supported when certain conditions have been met.
12375 Example: >
12376 :if has("gui_running")
12377< *has-patch*
123783. Beyond a certain version or at a certain version and including a specific
12379 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12380 later, or it is version 7.4 and patch 248 was included. Example: >
12381 :if has("patch-7.4.248")
12382< Note that it's possible for patch 248 to be omitted even though 249 is
12383 included. Only happens when cherry-picking patches.
12384 Note that this form only works for patch 7.4.237 and later, before that
12385 you need to check for the patch and the v:version. Example (checking
12386 version 6.2.148 or later): >
12387 :if v:version > 602 || (v:version == 602 && has("patch148"))
12388
12389Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12390use: `if exists('+shellslash')`
12391
12392
12393acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012394all_builtin_terms Compiled with all builtin terminals enabled. (always
12395 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012396amiga Amiga version of Vim.
12397arabic Compiled with Arabic support |Arabic|.
12398arp Compiled with ARP support (Amiga).
12399autocmd Compiled with autocommand support. (always true)
12400autochdir Compiled with support for 'autochdir'
12401autoservername Automatically enable |clientserver|
12402balloon_eval Compiled with |balloon-eval| support.
12403balloon_multiline GUI supports multiline balloons.
12404beos BeOS version of Vim.
12405browse Compiled with |:browse| support, and browse() will
12406 work.
12407browsefilter Compiled with support for |browsefilter|.
12408bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012409builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012410byte_offset Compiled with support for 'o' in 'statusline'
12411channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012412cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012413clientserver Compiled with remote invocation support |clientserver|.
12414clipboard Compiled with 'clipboard' support.
12415clipboard_working Compiled with 'clipboard' support and it can be used.
12416cmdline_compl Compiled with |cmdline-completion| support.
12417cmdline_hist Compiled with |cmdline-history| support.
12418cmdline_info Compiled with 'showcmd' and 'ruler' support.
12419comments Compiled with |'comments'| support.
12420compatible Compiled to be very Vi compatible.
12421conpty Platform where |ConPTY| can be used.
12422cryptv Compiled with encryption support |encryption|.
12423cscope Compiled with |cscope| support.
12424cursorbind Compiled with |'cursorbind'| (always true)
12425debug Compiled with "DEBUG" defined.
12426dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012427dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012428dialog_gui Compiled with GUI dialog support.
12429diff Compiled with |vimdiff| and 'diff' support.
12430digraphs Compiled with support for digraphs.
12431directx Compiled with support for DirectX and 'renderoptions'.
12432dnd Compiled with support for the "~ register |quote_~|.
12433drop_file Compiled with |drop_file| support.
12434ebcdic Compiled on a machine with ebcdic character set.
12435emacs_tags Compiled with support for Emacs tags.
12436eval Compiled with expression evaluation support. Always
12437 true, of course!
12438ex_extra |+ex_extra| (always true)
12439extra_search Compiled with support for |'incsearch'| and
12440 |'hlsearch'|
12441farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012442file_in_path Compiled with support for |gf| and |<cfile>| (always
12443 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012444filterpipe When 'shelltemp' is off pipes are used for shell
12445 read/write/filter commands
12446find_in_path Compiled with support for include file searches
12447 |+find_in_path|.
12448float Compiled with support for |Float|.
12449fname_case Case in file names matters (for Amiga and MS-Windows
12450 this is not present).
12451folding Compiled with |folding| support.
12452footer Compiled with GUI footer support. |gui-footer|
12453fork Compiled to use fork()/exec() instead of system().
12454gettext Compiled with message translation |multi-lang|
12455gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012456gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012457gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12458gui_gtk Compiled with GTK+ GUI (any version).
12459gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12460gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12461gui_haiku Compiled with Haiku GUI.
12462gui_mac Compiled with Macintosh GUI.
12463gui_motif Compiled with Motif GUI.
12464gui_photon Compiled with Photon GUI.
12465gui_running Vim is running in the GUI, or it will start soon.
12466gui_win32 Compiled with MS-Windows Win32 GUI.
12467gui_win32s idem, and Win32s system being used (Windows 3.1)
12468haiku Haiku version of Vim.
12469hangul_input Compiled with Hangul input support. |hangul|
12470hpux HP-UX version of Vim.
12471iconv Can use iconv() for conversion.
12472insert_expand Compiled with support for CTRL-X expansion commands in
12473 Insert mode. (always true)
12474job Compiled with support for |channel| and |job|
12475ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012476jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012477keymap Compiled with 'keymap' support.
12478lambda Compiled with |lambda| support.
12479langmap Compiled with 'langmap' support.
12480libcall Compiled with |libcall()| support.
12481linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12482 'breakindent' support.
12483linux Linux version of Vim.
12484lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012485 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012486listcmds Compiled with commands for the buffer list |:files|
12487 and the argument list |arglist|.
12488localmap Compiled with local mappings and abbr. |:map-local|
12489lua Compiled with Lua interface |Lua|.
12490mac Any Macintosh version of Vim cf. osx
12491macunix Synonym for osxdarwin
12492menu Compiled with support for |:menu|.
12493mksession Compiled with support for |:mksession|.
12494modify_fname Compiled with file name modifiers. |filename-modifiers|
12495 (always true)
12496mouse Compiled with support for mouse.
12497mouse_dec Compiled with support for Dec terminal mouse.
12498mouse_gpm Compiled with support for gpm (Linux console mouse)
12499mouse_gpm_enabled GPM mouse is working
12500mouse_netterm Compiled with support for netterm mouse.
12501mouse_pterm Compiled with support for qnx pterm mouse.
12502mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12503mouse_sgr Compiled with support for sgr mouse.
12504mouse_urxvt Compiled with support for urxvt mouse.
12505mouse_xterm Compiled with support for xterm mouse.
12506mouseshape Compiled with support for 'mouseshape'.
12507multi_byte Compiled with support for 'encoding' (always true)
12508multi_byte_encoding 'encoding' is set to a multibyte encoding.
12509multi_byte_ime Compiled with support for IME input method.
12510multi_lang Compiled with support for multiple languages.
12511mzscheme Compiled with MzScheme interface |mzscheme|.
12512nanotime Compiled with sub-second time stamp checks.
12513netbeans_enabled Compiled with support for |netbeans| and connected.
12514netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012515num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012516ole Compiled with OLE automation support for Win32.
12517osx Compiled for macOS cf. mac
12518osxdarwin Compiled for macOS, with |mac-darwin-feature|
12519packages Compiled with |packages| support.
12520path_extra Compiled with up/downwards search in 'path' and 'tags'
12521perl Compiled with Perl interface.
12522persistent_undo Compiled with support for persistent undo history.
12523postscript Compiled with PostScript file printing.
12524printer Compiled with |:hardcopy| support.
12525profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012526prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012527python Python 2.x interface available. |has-python|
12528python_compiled Compiled with Python 2.x interface. |has-python|
12529python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12530python3 Python 3.x interface available. |has-python|
12531python3_compiled Compiled with Python 3.x interface. |has-python|
12532python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012533python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012534pythonx Python 2.x and/or 3.x interface available. |python_x|
12535qnx QNX version of Vim.
12536quickfix Compiled with |quickfix| support.
12537reltime Compiled with |reltime()| support.
12538rightleft Compiled with 'rightleft' support.
12539ruby Compiled with Ruby interface |ruby|.
12540scrollbind Compiled with 'scrollbind' support. (always true)
12541showcmd Compiled with 'showcmd' support.
12542signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012543smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012544sodium Compiled with libsodium for better crypt support
12545sound Compiled with sound support, e.g. `sound_playevent()`
12546spell Compiled with spell checking support |spell|.
12547startuptime Compiled with |--startuptime| support.
12548statusline Compiled with support for 'statusline', 'rulerformat'
12549 and special formats of 'titlestring' and 'iconstring'.
12550sun SunOS version of Vim.
12551sun_workshop Support for Sun |workshop| has been removed.
12552syntax Compiled with syntax highlighting support |syntax|.
12553syntax_items There are active syntax highlighting items for the
12554 current buffer.
12555system Compiled to use system() instead of fork()/exec().
12556tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012557 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012558tag_old_static Support for old static tags was removed, see
12559 |tag-old-static|.
12560tcl Compiled with Tcl interface.
12561termguicolors Compiled with true color in terminal support.
12562terminal Compiled with |terminal| support.
12563terminfo Compiled with terminfo instead of termcap.
12564termresponse Compiled with support for |t_RV| and |v:termresponse|.
12565textobjects Compiled with support for |text-objects|.
12566textprop Compiled with support for |text-properties|.
12567tgetent Compiled with tgetent support, able to use a termcap
12568 or terminfo file.
12569timers Compiled with |timer_start()| support.
12570title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012571 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012572toolbar Compiled with support for |gui-toolbar|.
12573ttyin input is a terminal (tty)
12574ttyout output is a terminal (tty)
12575unix Unix version of Vim. *+unix*
12576unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
12577user_commands User-defined commands. (always true)
12578vartabs Compiled with variable tabstop support |'vartabstop'|.
12579vcon Win32: Virtual console support is working, can use
12580 'termguicolors'. Also see |+vtp|.
12581vertsplit Compiled with vertically split windows |:vsplit|.
12582 (always true)
12583vim_starting True while initial source'ing takes place. |startup|
12584 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000012585vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012586viminfo Compiled with viminfo support.
12587vimscript-1 Compiled Vim script version 1 support
12588vimscript-2 Compiled Vim script version 2 support
12589vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010012590vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012591virtualedit Compiled with 'virtualedit' option. (always true)
12592visual Compiled with Visual mode. (always true)
12593visualextra Compiled with extra Visual mode commands. (always
12594 true) |blockwise-operators|.
12595vms VMS version of Vim.
12596vreplace Compiled with |gR| and |gr| commands. (always true)
12597vtp Compiled for vcon support |+vtp| (check vcon to find
12598 out if it works in the current console).
12599wildignore Compiled with 'wildignore' option.
12600wildmenu Compiled with 'wildmenu' option.
12601win16 old version for MS-Windows 3.1 (always false)
12602win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
12603 64 bits)
12604win32unix Win32 version of Vim, using Unix files (Cygwin)
12605win64 Win64 version of Vim (MS-Windows 64 bit).
12606win95 Win32 version for MS-Windows 95/98/ME (always false)
12607winaltkeys Compiled with 'winaltkeys' option.
12608windows Compiled with support for more than one window.
12609 (always true)
12610writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020012611xattr Compiled with extended attributes support |xattr|
12612 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012613xfontset Compiled with X fontset support |xfontset|.
12614xim Compiled with X input method support |xim|.
12615xpm Compiled with pixmap support.
12616xpm_w32 Compiled with pixmap support for Win32. (Only for
12617 backward compatibility. Use "xpm" instead.)
12618xsmp Compiled with X session management support.
12619xsmp_interact Compiled with interactive X session management support.
12620xterm_clipboard Compiled with support for xterm clipboard.
12621xterm_save Compiled with support for saving and restoring the
12622 xterm screen.
12623x11 Compiled with X11 support.
12624
12625
12626==============================================================================
126274. Matching a pattern in a String *string-match*
12628
12629This is common between several functions. A regexp pattern as explained at
12630|pattern| is normally used to find a match in the buffer lines. When a
12631pattern is used to find a match in a String, almost everything works in the
12632same way. The difference is that a String is handled like it is one line.
12633When it contains a "\n" character, this is not seen as a line break for the
12634pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
12635>
12636 :let a = "aaaa\nxxxx"
12637 :echo matchstr(a, "..\n..")
12638 aa
12639 xx
12640 :echo matchstr(a, "a.x")
12641 a
12642 x
12643
12644Don't forget that "^" will only match at the first character of the String and
12645"$" at the last character of the string. They don't match after or before a
12646"\n".
12647
12648 vim:tw=78:ts=8:noet:ft=help:norl: