blob: 0061e9efc662a1bb2bb116eaa6f20e536d5fe874 [file] [log] [blame]
Christian Brabandt946f61c2024-06-17 13:17:58 +02001*builtin.txt* For Vim version 9.1. Last change: 2024 Jun 17
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7Builtin functions *builtin-functions*
8
Bram Moolenaarf269eab2022-10-03 18:04:35 +01009Note: Expression evaluation can be disabled at compile time, the builtin
10functions are not available then. See |+eval| and |no-eval-feature|.
11
12For functions grouped by what they are used for see |function-list|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000013
141. Overview |builtin-function-list|
152. Details |builtin-function-details|
163. Feature list |feature-list|
174. Matching a pattern in a String |string-match|
18
19==============================================================================
201. Overview *builtin-function-list*
21
22Use CTRL-] on the function name to jump to the full explanation.
23
24USAGE RESULT DESCRIPTION ~
25
26abs({expr}) Float or Number absolute value of {expr}
27acos({expr}) Float arc cosine of {expr}
28add({object}, {item}) List/Blob append {item} to {object}
29and({expr}, {expr}) Number bitwise AND
30append({lnum}, {text}) Number append {text} below line {lnum}
31appendbufline({expr}, {lnum}, {text})
32 Number append {text} below line {lnum}
33 in buffer {expr}
34argc([{winid}]) Number number of files in the argument list
35argidx() Number current index in the argument list
36arglistid([{winnr} [, {tabnr}]]) Number argument list id
37argv({nr} [, {winid}]) String {nr} entry of the argument list
38argv([-1, {winid}]) List the argument list
39asin({expr}) Float arc sine of {expr}
40assert_beeps({cmd}) Number assert {cmd} causes a beep
41assert_equal({exp}, {act} [, {msg}])
42 Number assert {exp} is equal to {act}
43assert_equalfile({fname-one}, {fname-two} [, {msg}])
44 Number assert file contents are equal
45assert_exception({error} [, {msg}])
46 Number assert {error} is in v:exception
47assert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]])
48 Number assert {cmd} fails
49assert_false({actual} [, {msg}])
50 Number assert {actual} is false
51assert_inrange({lower}, {upper}, {actual} [, {msg}])
52 Number assert {actual} is inside the range
53assert_match({pat}, {text} [, {msg}])
54 Number assert {pat} matches {text}
55assert_nobeep({cmd}) Number assert {cmd} does not cause a beep
56assert_notequal({exp}, {act} [, {msg}])
57 Number assert {exp} is not equal {act}
58assert_notmatch({pat}, {text} [, {msg}])
59 Number assert {pat} not matches {text}
60assert_report({msg}) Number report a test failure
61assert_true({actual} [, {msg}]) Number assert {actual} is true
62atan({expr}) Float arc tangent of {expr}
63atan2({expr1}, {expr2}) Float arc tangent of {expr1} / {expr2}
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +010064autocmd_add({acmds}) Bool add a list of autocmds and groups
65autocmd_delete({acmds}) Bool delete a list of autocmds and groups
66autocmd_get([{opts}]) List return a list of autocmds
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000067balloon_gettext() String current text in the balloon
68balloon_show({expr}) none show {expr} inside the balloon
69balloon_split({msg}) List split {msg} as used for a balloon
70blob2list({blob}) List convert {blob} into a list of numbers
71browse({save}, {title}, {initdir}, {default})
72 String put up a file requester
73browsedir({title}, {initdir}) String put up a directory requester
74bufadd({name}) Number add a buffer to the buffer list
75bufexists({buf}) Number |TRUE| if buffer {buf} exists
76buflisted({buf}) Number |TRUE| if buffer {buf} is listed
77bufload({buf}) Number load buffer {buf} if not loaded yet
78bufloaded({buf}) Number |TRUE| if buffer {buf} is loaded
79bufname([{buf}]) String Name of the buffer {buf}
80bufnr([{buf} [, {create}]]) Number Number of the buffer {buf}
81bufwinid({buf}) Number window ID of buffer {buf}
82bufwinnr({buf}) Number window number of buffer {buf}
83byte2line({byte}) Number line number at byte count {byte}
Christian Brabandt67672ef2023-04-24 21:09:54 +010084byteidx({expr}, {nr} [, {utf16}])
85 Number byte index of {nr}'th char in {expr}
86byteidxcomp({expr}, {nr} [, {utf16}])
87 Number byte index of {nr}'th char in {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000088call({func}, {arglist} [, {dict}])
89 any call {func} with arguments {arglist}
90ceil({expr}) Float round {expr} up
91ch_canread({handle}) Number check if there is something to read
92ch_close({handle}) none close {handle}
93ch_close_in({handle}) none close in part of {handle}
94ch_evalexpr({handle}, {expr} [, {options}])
95 any evaluate {expr} on JSON {handle}
96ch_evalraw({handle}, {string} [, {options}])
97 any evaluate {string} on raw {handle}
98ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
99ch_getjob({channel}) Job get the Job of {channel}
100ch_info({handle}) String info about channel {handle}
101ch_log({msg} [, {handle}]) none write {msg} in the channel log file
102ch_logfile({fname} [, {mode}]) none start logging channel activity
103ch_open({address} [, {options}])
104 Channel open a channel to {address}
105ch_read({handle} [, {options}]) String read from {handle}
106ch_readblob({handle} [, {options}])
107 Blob read Blob from {handle}
108ch_readraw({handle} [, {options}])
109 String read raw from {handle}
110ch_sendexpr({handle}, {expr} [, {options}])
111 any send {expr} over JSON {handle}
112ch_sendraw({handle}, {expr} [, {options}])
113 any send {expr} over raw {handle}
114ch_setoptions({handle}, {options})
115 none set options for {handle}
116ch_status({handle} [, {options}])
117 String status of channel {handle}
118changenr() Number current change number
119char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr}
120charclass({string}) Number character class of {string}
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000121charcol({expr} [, {winid}]) Number column number of cursor or mark
Christian Brabandt67672ef2023-04-24 21:09:54 +0100122charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000123 Number char index of byte {idx} in {string}
124chdir({dir}) String change current working directory
125cindent({lnum}) Number C indent for line {lnum}
126clearmatches([{win}]) none clear all matches
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000127col({expr} [, {winid}]) Number column byte index of cursor or mark
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000128complete({startcol}, {matches}) none set Insert mode completion
129complete_add({expr}) Number add completion match
130complete_check() Number check for key typed during completion
131complete_info([{what}]) Dict get current completion information
132confirm({msg} [, {choices} [, {default} [, {type}]]])
133 Number number of choice picked by user
134copy({expr}) any make a shallow copy of {expr}
135cos({expr}) Float cosine of {expr}
136cosh({expr}) Float hyperbolic cosine of {expr}
137count({comp}, {expr} [, {ic} [, {start}]])
138 Number count how many {expr} are in {comp}
139cscope_connection([{num}, {dbpath} [, {prepend}]])
140 Number checks existence of cscope connection
141cursor({lnum}, {col} [, {off}])
142 Number move cursor to {lnum}, {col}, {off}
143cursor({list}) Number move cursor to position in {list}
144debugbreak({pid}) Number interrupt process being debugged
145deepcopy({expr} [, {noref}]) any make a full copy of {expr}
146delete({fname} [, {flags}]) Number delete the file or directory {fname}
147deletebufline({buf}, {first} [, {last}])
148 Number delete lines from buffer {buf}
149did_filetype() Number |TRUE| if FileType autocmd event used
Yegappan Lakshmananfa378352024-02-01 22:05:27 +0100150diff({fromlist}, {tolist} [, {options}])
151 List diff two Lists of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000152diff_filler({lnum}) Number diff filler lines about {lnum}
153diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
154digraph_get({chars}) String get the |digraph| of {chars}
155digraph_getlist([{listall}]) List get all |digraph|s
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200156digraph_set({chars}, {digraph}) Bool register |digraph|
157digraph_setlist({digraphlist}) Bool register multiple |digraph|s
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000158echoraw({expr}) none output {expr} as-is
159empty({expr}) Number |TRUE| if {expr} is empty
160environ() Dict return environment variables
Sean Dewarb0efa492023-07-08 10:35:19 +0100161err_teapot([{expr}]) none give E418, or E503 if {expr} is |TRUE|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000162escape({string}, {chars}) String escape {chars} in {string} with '\'
163eval({string}) any evaluate {string} into its value
164eventhandler() Number |TRUE| if inside an event handler
165executable({expr}) Number 1 if executable {expr} exists
166execute({command}) String execute {command} and get the output
167exepath({expr}) String full path of the command {expr}
168exists({expr}) Number |TRUE| if {expr} exists
169exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
170exp({expr}) Float exponential of {expr}
171expand({expr} [, {nosuf} [, {list}]])
172 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100173expandcmd({string} [, {options}])
174 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000175extend({expr1}, {expr2} [, {expr3}])
176 List/Dict insert items of {expr2} into {expr1}
177extendnew({expr1}, {expr2} [, {expr3}])
178 List/Dict like |extend()| but creates a new
179 List or Dictionary
180feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
Shougo Matsushita60c87432024-06-03 22:59:27 +0200181filecopy({from}, {to}) Number |TRUE| if copying file {from} to {to}
182 worked
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000183filereadable({file}) Number |TRUE| if {file} is a readable file
184filewritable({file}) Number |TRUE| if {file} is a writable file
185filter({expr1}, {expr2}) List/Dict/Blob/String
186 remove items from {expr1} where
187 {expr2} is 0
188finddir({name} [, {path} [, {count}]])
189 String find directory {name} in {path}
190findfile({name} [, {path} [, {count}]])
191 String find file {name} in {path}
192flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
193flattennew({list} [, {maxdepth}])
194 List flatten a copy of {list}
195float2nr({expr}) Number convert Float {expr} to a Number
196floor({expr}) Float round {expr} down
197fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
198fnameescape({fname}) String escape special characters in {fname}
199fnamemodify({fname}, {mods}) String modify file name
200foldclosed({lnum}) Number first line of fold at {lnum} if closed
201foldclosedend({lnum}) Number last line of fold at {lnum} if closed
202foldlevel({lnum}) Number fold level at {lnum}
203foldtext() String line displayed for closed fold
204foldtextresult({lnum}) String text for closed fold at {lnum}
Ernie Raele79e2072024-01-13 11:47:33 +0100205foreach({expr1}, {expr2}) List/Dict/Blob/String
206 for each item in {expr1} call {expr2}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000207foreground() Number bring the Vim window to the foreground
Bram Moolenaaraa534142022-09-15 21:46:02 +0100208fullcommand({name} [, {vim9}]) String get full command from {name}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000209funcref({name} [, {arglist}] [, {dict}])
210 Funcref reference to function {name}
211function({name} [, {arglist}] [, {dict}])
212 Funcref named reference to function {name}
213garbagecollect([{atexit}]) none free memory, breaking cyclic references
214get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
215get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
216get({func}, {what}) any get property of funcref/partial {func}
217getbufinfo([{buf}]) List information about buffers
218getbufline({buf}, {lnum} [, {end}])
219 List lines {lnum} to {end} of buffer {buf}
Bram Moolenaarce30ccc2022-11-21 19:57:04 +0000220getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000221getbufvar({buf}, {varname} [, {def}])
222 any variable {varname} in buffer {buf}
Kota Kato66bb9ae2023-01-17 18:31:56 +0000223getcellwidths() List get character cell width overrides
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000224getchangelist([{buf}]) List list of change list items
Doug Kearns9cd9e752024-04-07 17:42:17 +0200225getchar([{expr}]) Number or String
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000226 get one character from the user
227getcharmod() Number modifiers for the last typed character
228getcharpos({expr}) List position of cursor, mark, etc.
229getcharsearch() Dict last character search
Doug Kearns9cd9e752024-04-07 17:42:17 +0200230getcharstr([{expr}]) String get one character from the user
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100231getcmdcompltype() String return the type of the current
232 command-line completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000233getcmdline() String return the current command-line
234getcmdpos() Number return cursor position in command-line
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100235getcmdscreenpos() Number return cursor screen position in
236 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000237getcmdtype() String return current command-line type
238getcmdwintype() String return current command-line window type
239getcompletion({pat}, {type} [, {filtered}])
240 List list of cmdline completion matches
241getcurpos([{winnr}]) List position of the cursor
242getcursorcharpos([{winnr}]) List character position of the cursor
243getcwd([{winnr} [, {tabnr}]]) String get the current working directory
244getenv({name}) String return environment variable
245getfontname([{name}]) String name of font being used
246getfperm({fname}) String file permissions of file {fname}
247getfsize({fname}) Number size in bytes of file {fname}
248getftime({fname}) Number last modification time of file
249getftype({fname}) String description of type of file {fname}
250getimstatus() Number |TRUE| if the IME status is active
251getjumplist([{winnr} [, {tabnr}]])
252 List list of jump list items
253getline({lnum}) String line {lnum} of current buffer
254getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
255getloclist({nr}) List list of location list items
256getloclist({nr}, {what}) Dict get specific location list properties
257getmarklist([{buf}]) List list of global/local marks
258getmatches([{win}]) List list of current matches
259getmousepos() Dict last known mouse position
Bram Moolenaar24dc19c2022-11-14 19:49:15 +0000260getmouseshape() String current mouse shape name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000261getpid() Number process ID of Vim
262getpos({expr}) List position of cursor, mark, etc.
263getqflist() List list of quickfix items
264getqflist({what}) Dict get specific quickfix list properties
265getreg([{regname} [, 1 [, {list}]]])
266 String or List contents of a register
267getreginfo([{regname}]) Dict information about a register
Shougo Matsushita19b71882024-02-28 22:48:12 +0100268getregion({pos1}, {pos2} [, {opts}])
Shougo Matsushita3f905ab2024-02-21 00:02:45 +0100269 List get the text from {pos1} to {pos2}
Shougo Matsushitab4757e62024-05-07 20:49:24 +0200270getregionpos({pos1}, {pos2} [, {opts}])
271 List get a list of positions for a region
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000272getregtype([{regname}]) String type of a register
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +0100273getscriptinfo([{opts}]) List list of sourced scripts
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000274gettabinfo([{expr}]) List list of tab pages
275gettabvar({nr}, {varname} [, {def}])
276 any variable {varname} in tab {nr} or {def}
277gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
278 any {name} in {winnr} in tab page {tabnr}
279gettagstack([{nr}]) Dict get the tag stack of window {nr}
280gettext({text}) String lookup translation of {text}
281getwininfo([{winid}]) List list of info about each window
Bram Moolenaar938ae282023-02-20 20:44:55 +0000282getwinpos([{timeout}]) List X and Y coord in pixels of Vim window
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000283getwinposx() Number X coord in pixels of the Vim window
284getwinposy() Number Y coord in pixels of the Vim window
285getwinvar({nr}, {varname} [, {def}])
286 any variable {varname} in window {nr}
287glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
288 any expand file wildcards in {expr}
289glob2regpat({expr}) String convert a glob pat into a search pat
290globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
291 String do glob({expr}) for all dirs in {path}
292has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
293has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
294haslocaldir([{winnr} [, {tabnr}]])
295 Number |TRUE| if the window executed |:lcd|
296 or |:tcd|
297hasmapto({what} [, {mode} [, {abbr}]])
298 Number |TRUE| if mapping to {what} exists
299histadd({history}, {item}) Number add an item to a history
300histdel({history} [, {item}]) Number remove an item from a history
301histget({history} [, {index}]) String get the item {index} from a history
302histnr({history}) Number highest index of a history
303hlID({name}) Number syntax ID of highlight group {name}
304hlexists({name}) Number |TRUE| if highlight group {name} exists
305hlget([{name} [, {resolve}]]) List get highlight group attributes
306hlset({list}) Number set highlight group attributes
307hostname() String name of the machine Vim is running on
308iconv({expr}, {from}, {to}) String convert encoding of {expr}
309indent({lnum}) Number indent of line {lnum}
310index({object}, {expr} [, {start} [, {ic}]])
311 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100312indexof({object}, {expr} [, {opts}]])
313 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000314input({prompt} [, {text} [, {completion}]])
315 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100316inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000317 String like input() but in a GUI dialog
318inputlist({textlist}) Number let the user pick from a choice list
319inputrestore() Number restore typeahead
320inputsave() Number save and clear typeahead
321inputsecret({prompt} [, {text}]) String like input() but hiding the text
322insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
LemonBoyafe04662023-08-23 21:08:11 +0200323instanceof({object}, {class}) Number |TRUE| if {object} is an instance of {class}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000324interrupt() none interrupt script execution
325invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100326isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000327isdirectory({directory}) Number |TRUE| if {directory} is a directory
328isinf({expr}) Number determine if {expr} is infinity value
329 (positive or negative)
330islocked({expr}) Number |TRUE| if {expr} is locked
331isnan({expr}) Number |TRUE| if {expr} is NaN
332items({dict}) List key-value pairs in {dict}
333job_getchannel({job}) Channel get the channel handle for {job}
334job_info([{job}]) Dict get information about {job}
335job_setoptions({job}, {options}) none set options for {job}
336job_start({command} [, {options}])
337 Job start a job
338job_status({job}) String get the status of {job}
339job_stop({job} [, {how}]) Number stop {job}
340join({list} [, {sep}]) String join {list} items into one String
341js_decode({string}) any decode JS style JSON
342js_encode({expr}) String encode JS style JSON
343json_decode({string}) any decode JSON
344json_encode({expr}) String encode JSON
345keys({dict}) List keys in {dict}
zeertzjqcdc83932022-09-12 13:38:41 +0100346keytrans({string}) String translate internal keycodes to a form
347 that can be used by |:map|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000348len({expr}) Number the length of {expr}
349libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
350libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
351line({expr} [, {winid}]) Number line nr of cursor, last line or mark
352line2byte({lnum}) Number byte count of line {lnum}
353lispindent({lnum}) Number Lisp indent for line {lnum}
354list2blob({list}) Blob turn {list} of numbers into a Blob
355list2str({list} [, {utf8}]) String turn {list} of numbers into a String
356listener_add({callback} [, {buf}])
357 Number add a callback to listen to changes
358listener_flush([{buf}]) none invoke listener callbacks
359listener_remove({id}) none remove a listener callback
360localtime() Number current time
361log({expr}) Float natural logarithm (base e) of {expr}
362log10({expr}) Float logarithm of Float {expr} to base 10
363luaeval({expr} [, {expr}]) any evaluate |Lua| expression
364map({expr1}, {expr2}) List/Dict/Blob/String
365 change each item in {expr1} to {expr2}
366maparg({name} [, {mode} [, {abbr} [, {dict}]]])
367 String or Dict
368 rhs of mapping {name} in mode {mode}
369mapcheck({name} [, {mode} [, {abbr}]])
370 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100371maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000372mapnew({expr1}, {expr2}) List/Dict/Blob/String
373 like |map()| but creates a new List or
374 Dictionary
375mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
376match({expr}, {pat} [, {start} [, {count}]])
377 Number position where {pat} matches in {expr}
378matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
379 Number highlight {pattern} with {group}
380matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
381 Number highlight positions with {group}
382matcharg({nr}) List arguments of |:match|
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100383matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict})
384 List all the {pat} matches in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000385matchdelete({id} [, {win}]) Number delete match identified by {id}
386matchend({expr}, {pat} [, {start} [, {count}]])
387 Number position where {pat} ends in {expr}
388matchfuzzy({list}, {str} [, {dict}])
389 List fuzzy match {str} in {list}
390matchfuzzypos({list}, {str} [, {dict}])
391 List fuzzy match {str} in {list}
392matchlist({expr}, {pat} [, {start} [, {count}]])
393 List match and submatches of {pat} in {expr}
394matchstr({expr}, {pat} [, {start} [, {count}]])
395 String {count}'th match of {pat} in {expr}
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100396matchstrlist({list}, {pat} [, {dict})
397 List all the {pat} matches in {list}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000398matchstrpos({expr}, {pat} [, {start} [, {count}]])
399 List {count}'th match of {pat} in {expr}
400max({expr}) Number maximum value of items in {expr}
401menu_info({name} [, {mode}]) Dict get menu item information
402min({expr}) Number minimum value of items in {expr}
Bram Moolenaar938ae282023-02-20 20:44:55 +0000403mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000404 Number create directory {name}
Doug Kearns9cd9e752024-04-07 17:42:17 +0200405mode([{expr}]) String current editing mode
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000406mzeval({expr}) any evaluate |MzScheme| expression
407nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
408nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
409or({expr}, {expr}) Number bitwise OR
410pathshorten({expr} [, {len}]) String shorten directory names in a path
411perleval({expr}) any evaluate |Perl| expression
412popup_atcursor({what}, {options}) Number create popup window near the cursor
413popup_beval({what}, {options}) Number create popup window for 'ballooneval'
414popup_clear() none close all popup windows
415popup_close({id} [, {result}]) none close popup window {id}
416popup_create({what}, {options}) Number create a popup window
417popup_dialog({what}, {options}) Number create a popup window used as a dialog
418popup_filter_menu({id}, {key}) Number filter for a menu popup window
419popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100420popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000421popup_findinfo() Number get window ID of info popup window
422popup_findpreview() Number get window ID of preview popup window
423popup_getoptions({id}) Dict get options of popup window {id}
424popup_getpos({id}) Dict get position of popup window {id}
425popup_hide({id}) none hide popup menu {id}
426popup_list() List get a list of window IDs of all popups
427popup_locate({row}, {col}) Number get window ID of popup at position
428popup_menu({what}, {options}) Number create a popup window used as a menu
429popup_move({id}, {options}) none set position of popup window {id}
430popup_notification({what}, {options})
431 Number create a notification popup window
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200432popup_setbuf({id}, {buf}) Bool set the buffer for the popup window {id}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000433popup_setoptions({id}, {options})
434 none set options for popup window {id}
435popup_settext({id}, {text}) none set the text of popup window {id}
436popup_show({id}) none unhide popup window {id}
437pow({x}, {y}) Float {x} to the power of {y}
438prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
439printf({fmt}, {expr1}...) String format text
440prompt_getprompt({buf}) String get prompt text
441prompt_setcallback({buf}, {expr}) none set prompt callback function
442prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
443prompt_setprompt({buf}, {text}) none set prompt text
444prop_add({lnum}, {col}, {props}) none add one text property
445prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
446 none add multiple text properties
447prop_clear({lnum} [, {lnum-end} [, {props}]])
448 none remove all text properties
449prop_find({props} [, {direction}])
450 Dict search for a text property
451prop_list({lnum} [, {props}]) List text properties in {lnum}
452prop_remove({props} [, {lnum} [, {lnum-end}]])
453 Number remove a text property
454prop_type_add({name}, {props}) none define a new property type
455prop_type_change({name}, {props})
456 none change an existing property type
457prop_type_delete({name} [, {props}])
458 none delete a property type
459prop_type_get({name} [, {props}])
460 Dict get property type values
461prop_type_list([{props}]) List get list of property types
462pum_getpos() Dict position and size of pum if visible
463pumvisible() Number whether popup menu is visible
464py3eval({expr}) any evaluate |python3| expression
465pyeval({expr}) any evaluate |Python| expression
466pyxeval({expr}) any evaluate |python_x| expression
467rand([{expr}]) Number get pseudo-random number
468range({expr} [, {max} [, {stride}]])
469 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100470readblob({fname} [, {offset} [, {size}]])
471 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000472readdir({dir} [, {expr} [, {dict}]])
473 List file names in {dir} selected by {expr}
474readdirex({dir} [, {expr} [, {dict}]])
475 List file info in {dir} selected by {expr}
476readfile({fname} [, {type} [, {max}]])
477 List get list of lines from file {fname}
478reduce({object}, {func} [, {initial}])
479 any reduce {object} using {func}
480reg_executing() String get the executing register name
481reg_recording() String get the recording register name
482reltime([{start} [, {end}]]) List get time value
483reltimefloat({time}) Float turn the time value into a Float
484reltimestr({time}) String turn time value into a String
485remote_expr({server}, {string} [, {idvar} [, {timeout}]])
486 String send expression
487remote_foreground({server}) Number bring Vim server to the foreground
488remote_peek({serverid} [, {retvar}])
489 Number check for reply string
490remote_read({serverid} [, {timeout}])
491 String read reply string
492remote_send({server}, {string} [, {idvar}])
493 String send key sequence
494remote_startserver({name}) none become server {name}
495remove({list}, {idx} [, {end}]) any/List
496 remove items {idx}-{end} from {list}
497remove({blob}, {idx} [, {end}]) Number/Blob
498 remove bytes {idx}-{end} from {blob}
499remove({dict}, {key}) any remove entry {key} from {dict}
500rename({from}, {to}) Number rename (move) file from {from} to {to}
Bakudankun375141e2022-09-09 18:46:47 +0100501repeat({expr}, {count}) List/Blob/String
502 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000503resolve({filename}) String get filename a shortcut points to
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +0100504reverse({obj}) List/Blob/String
505 reverse {obj}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000506round({expr}) Float round off {expr}
507rubyeval({expr}) any evaluate |Ruby| expression
508screenattr({row}, {col}) Number attribute at screen position
509screenchar({row}, {col}) Number character at screen position
510screenchars({row}, {col}) List List of characters at screen position
511screencol() Number current cursor column
512screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
513screenrow() Number current cursor row
514screenstring({row}, {col}) String characters at screen position
515search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
516 Number search for {pattern}
517searchcount([{options}]) Dict get or update search stats
518searchdecl({name} [, {global} [, {thisblock}]])
519 Number search for variable declaration
520searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
521 Number search for other end of start/end pair
522searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
523 List search for other end of start/end pair
524searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
525 List search for {pattern}
526server2client({clientid}, {string})
527 Number send reply string
528serverlist() String get a list of available servers
529setbufline({expr}, {lnum}, {text})
530 Number set line {lnum} to {text} in buffer
531 {expr}
532setbufvar({buf}, {varname}, {val})
533 none set {varname} in buffer {buf} to {val}
534setcellwidths({list}) none set character cell width overrides
535setcharpos({expr}, {list}) Number set the {expr} position to {list}
536setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100537setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000538setcmdpos({pos}) Number set cursor position in command-line
539setcursorcharpos({list}) Number move cursor to position in {list}
540setenv({name}, {val}) none set environment variable
541setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
542setline({lnum}, {line}) Number set line {lnum} to {line}
543setloclist({nr}, {list} [, {action}])
544 Number modify location list using {list}
545setloclist({nr}, {list}, {action}, {what})
546 Number modify specific location list props
547setmatches({list} [, {win}]) Number restore a list of matches
548setpos({expr}, {list}) Number set the {expr} position to {list}
549setqflist({list} [, {action}]) Number modify quickfix list using {list}
550setqflist({list}, {action}, {what})
551 Number modify specific quickfix list props
552setreg({n}, {v} [, {opt}]) Number set register to value and type
553settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
554settabwinvar({tabnr}, {winnr}, {varname}, {val})
555 none set {varname} in window {winnr} in tab
556 page {tabnr} to {val}
557settagstack({nr}, {dict} [, {action}])
558 Number modify tag stack using {dict}
559setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
560sha256({string}) String SHA256 checksum of {string}
561shellescape({string} [, {special}])
562 String escape {string} for use as shell
563 command argument
564shiftwidth([{col}]) Number effective value of 'shiftwidth'
565sign_define({name} [, {dict}]) Number define or update a sign
566sign_define({list}) List define or update a list of signs
567sign_getdefined([{name}]) List get a list of defined signs
568sign_getplaced([{buf} [, {dict}]])
569 List get a list of placed signs
570sign_jump({id}, {group}, {buf})
571 Number jump to a sign
572sign_place({id}, {group}, {name}, {buf} [, {dict}])
573 Number place a sign
574sign_placelist({list}) List place a list of signs
575sign_undefine([{name}]) Number undefine a sign
576sign_undefine({list}) List undefine a list of signs
577sign_unplace({group} [, {dict}])
578 Number unplace a sign
579sign_unplacelist({list}) List unplace a list of signs
580simplify({filename}) String simplify filename as much as possible
581sin({expr}) Float sine of {expr}
582sinh({expr}) Float hyperbolic sine of {expr}
583slice({expr}, {start} [, {end}]) String, List or Blob
584 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000585sort({list} [, {how} [, {dict}]])
586 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000587sound_clear() none stop playing all sounds
588sound_playevent({name} [, {callback}])
589 Number play an event sound
590sound_playfile({path} [, {callback}])
591 Number play sound file {path}
592sound_stop({id}) none stop playing sound {id}
593soundfold({word}) String sound-fold {word}
594spellbadword() String badly spelled word at cursor
595spellsuggest({word} [, {max} [, {capital}]])
596 List spelling suggestions
597split({expr} [, {pat} [, {keepempty}]])
598 List make |List| from {pat} separated {expr}
599sqrt({expr}) Float square root of {expr}
600srand([{expr}]) List get seed for |rand()|
601state([{what}]) String current state of Vim
602str2float({expr} [, {quoted}]) Float convert String to Float
603str2list({expr} [, {utf8}]) List convert each character of {expr} to
604 ASCII/UTF-8 value
605str2nr({expr} [, {base} [, {quoted}]])
606 Number convert String to Number
607strcharlen({expr}) Number character length of the String {expr}
608strcharpart({str}, {start} [, {len} [, {skipcc}]])
609 String {len} characters of {str} at
610 character {start}
611strchars({expr} [, {skipcc}]) Number character count of the String {expr}
612strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
613strftime({format} [, {time}]) String format time with a specified format
614strgetchar({str}, {index}) Number get char {index} from {str}
615stridx({haystack}, {needle} [, {start}])
616 Number index of {needle} in {haystack}
617string({expr}) String String representation of {expr} value
618strlen({expr}) Number length of the String {expr}
619strpart({str}, {start} [, {len} [, {chars}]])
620 String {len} bytes/chars of {str} at
621 byte {start}
622strptime({format}, {timestring})
623 Number Convert {timestring} to unix timestamp
624strridx({haystack}, {needle} [, {start}])
625 Number last index of {needle} in {haystack}
626strtrans({expr}) String translate string to make it printable
Christian Brabandt67672ef2023-04-24 21:09:54 +0100627strutf16len({string} [, {countcc}])
628 Number number of UTF-16 code units in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000629strwidth({expr}) Number display cell length of the String {expr}
630submatch({nr} [, {list}]) String or List
631 specific match in ":s" or substitute()
632substitute({expr}, {pat}, {sub}, {flags})
633 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000634swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000635swapinfo({fname}) Dict information about swap file {fname}
636swapname({buf}) String swap file of buffer {buf}
637synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
638synIDattr({synID}, {what} [, {mode}])
639 String attribute {what} of syntax ID {synID}
640synIDtrans({synID}) Number translated syntax ID of {synID}
641synconcealed({lnum}, {col}) List info about concealing
642synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
643system({expr} [, {input}]) String output of shell command/filter {expr}
644systemlist({expr} [, {input}]) List output of shell command/filter {expr}
645tabpagebuflist([{arg}]) List list of buffer numbers in tab page
646tabpagenr([{arg}]) Number number of current or last tab page
647tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
648tagfiles() List tags files used
649taglist({expr} [, {filename}]) List list of tags matching {expr}
650tan({expr}) Float tangent of {expr}
651tanh({expr}) Float hyperbolic tangent of {expr}
652tempname() String name for a temporary file
653term_dumpdiff({filename}, {filename} [, {options}])
654 Number display difference between two dumps
655term_dumpload({filename} [, {options}])
656 Number displaying a screen dump
657term_dumpwrite({buf}, {filename} [, {options}])
658 none dump terminal window contents
659term_getaltscreen({buf}) Number get the alternate screen flag
660term_getansicolors({buf}) List get ANSI palette in GUI color mode
661term_getattr({attr}, {what}) Number get the value of attribute {what}
662term_getcursor({buf}) List get the cursor position of a terminal
663term_getjob({buf}) Job get the job associated with a terminal
664term_getline({buf}, {row}) String get a line of text from a terminal
665term_getscrolled({buf}) Number get the scroll count of a terminal
666term_getsize({buf}) List get the size of a terminal
667term_getstatus({buf}) String get the status of a terminal
668term_gettitle({buf}) String get the title of a terminal
669term_gettty({buf}, [{input}]) String get the tty name of a terminal
670term_list() List get the list of terminal buffers
671term_scrape({buf}, {row}) List get row of a terminal screen
672term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
673term_setansicolors({buf}, {colors})
674 none set ANSI palette in GUI color mode
675term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
676term_setkill({buf}, {how}) none set signal to stop job in terminal
677term_setrestore({buf}, {command}) none set command to restore terminal
678term_setsize({buf}, {rows}, {cols})
679 none set the size of a terminal
680term_start({cmd} [, {options}]) Number open a terminal window and run a job
681term_wait({buf} [, {time}]) Number wait for screen to be updated
682terminalprops() Dict properties of the terminal
683test_alloc_fail({id}, {countdown}, {repeat})
684 none make memory allocation fail
685test_autochdir() none enable 'autochdir' during startup
686test_feedinput({string}) none add key sequence to input buffer
687test_garbagecollect_now() none free memory right now for testing
688test_garbagecollect_soon() none free memory soon for testing
689test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000690test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000691test_ignore_error({expr}) none ignore a specific error
Christopher Plewright20b795e2022-12-20 20:01:58 +0000692test_mswin_event({event}, {args})
693 bool generate MS-Windows event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000694test_null_blob() Blob null value for testing
695test_null_channel() Channel null value for testing
696test_null_dict() Dict null value for testing
697test_null_function() Funcref null value for testing
698test_null_job() Job null value for testing
699test_null_list() List null value for testing
700test_null_partial() Funcref null value for testing
701test_null_string() String null value for testing
702test_option_not_set({name}) none reset flag indicating option was set
703test_override({expr}, {val}) none test with Vim internal overrides
704test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000705test_setmouse({row}, {col}) none set the mouse position for testing
706test_settime({expr}) none set current time for testing
Doug Kearns9cd9e752024-04-07 17:42:17 +0200707test_srand_seed([{seed}]) none set seed for testing srand()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000708test_unknown() any unknown value for testing
709test_void() any void value for testing
710timer_info([{id}]) List information about timers
711timer_pause({id}, {pause}) none pause or unpause a timer
712timer_start({time}, {callback} [, {options}])
713 Number create a timer
714timer_stop({timer}) none stop a timer
715timer_stopall() none stop all timers
716tolower({expr}) String the String {expr} switched to lowercase
717toupper({expr}) String the String {expr} switched to uppercase
718tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
719 to chars in {tostr}
720trim({text} [, {mask} [, {dir}]])
721 String trim characters in {mask} from {text}
722trunc({expr}) Float truncate Float {expr}
723type({expr}) Number type of value {expr}
724typename({expr}) String representation of the type of {expr}
725undofile({name}) String undo file name for {name}
Devin J. Pohly5fee1112023-04-23 20:26:59 -0500726undotree([{buf}]) List undo file tree for buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000727uniq({list} [, {func} [, {dict}]])
728 List remove adjacent duplicates from a list
Christian Brabandt67672ef2023-04-24 21:09:54 +0100729utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
730 Number UTF-16 index of byte {idx} in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000731values({dict}) List values in {dict}
zeertzjq825cf812023-08-17 22:55:25 +0200732virtcol({expr} [, {list} [, {winid}])
733 Number or List
LemonBoy0f7a3e12022-05-26 12:10:37 +0100734 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100735virtcol2col({winid}, {lnum}, {col})
736 Number byte index of a character on screen
Doug Kearns9cd9e752024-04-07 17:42:17 +0200737visualmode([{expr}]) String last visual mode used
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000738wildmenumode() Number whether 'wildmenu' mode is active
739win_execute({id}, {command} [, {silent}])
740 String execute {command} in window {id}
741win_findbuf({bufnr}) List find windows containing {bufnr}
742win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
743win_gettype([{nr}]) String type of window {nr}
744win_gotoid({expr}) Number go to window with ID {expr}
745win_id2tabwin({expr}) List get tab and window nr from window ID
746win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000747win_move_separator({nr}) Number move window vertical separator
748win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000749win_screenpos({nr}) List get screen position of window {nr}
750win_splitmove({nr}, {target} [, {options}])
751 Number move window {nr} to split of {target}
752winbufnr({nr}) Number buffer number of window {nr}
753wincol() Number window column of the cursor
754windowsversion() String MS-Windows OS version
755winheight({nr}) Number height of window {nr}
756winlayout([{tabnr}]) List layout of windows in tab {tabnr}
757winline() Number window line of the cursor
758winnr([{expr}]) Number number of current window
759winrestcmd() String returns command to restore window sizes
760winrestview({dict}) none restore view of current window
761winsaveview() Dict save view of current window
762winwidth({nr}) Number width of window {nr}
763wordcount() Dict get byte/char/word statistics
764writefile({object}, {fname} [, {flags}])
765 Number write |Blob| or |List| of lines to file
766xor({expr}, {expr}) Number bitwise XOR
767
768==============================================================================
7692. Details *builtin-function-details*
770
771Not all functions are here, some have been moved to a help file covering the
772specific functionality.
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200773Return type specifies the type for |Vim9-script|, see |vim9-types|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000774
775abs({expr}) *abs()*
776 Return the absolute value of {expr}. When {expr} evaluates to
777 a |Float| abs() returns a |Float|. When {expr} can be
778 converted to a |Number| abs() returns a |Number|. Otherwise
779 abs() gives an error message and returns -1.
780 Examples: >
781 echo abs(1.456)
782< 1.456 >
783 echo abs(-5.456)
784< 5.456 >
785 echo abs(-4)
786< 4
787
788 Can also be used as a |method|: >
789 Compute()->abs()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200790<
791 Return type: |Number| or |Float| depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000792
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000793
794acos({expr}) *acos()*
795 Return the arc cosine of {expr} measured in radians, as a
796 |Float| in the range of [0, pi].
797 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100798 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000799 Examples: >
800 :echo acos(0)
801< 1.570796 >
802 :echo acos(-0.5)
803< 2.094395
804
805 Can also be used as a |method|: >
806 Compute()->acos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200807<
808 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000809
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000810
811add({object}, {expr}) *add()*
812 Append the item {expr} to |List| or |Blob| {object}. Returns
813 the resulting |List| or |Blob|. Examples: >
814 :let alist = add([1, 2, 3], item)
815 :call add(mylist, "woodstock")
816< Note that when {expr} is a |List| it is appended as a single
817 item. Use |extend()| to concatenate |Lists|.
818 When {object} is a |Blob| then {expr} must be a number.
819 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100820 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000821
822 Can also be used as a |method|: >
823 mylist->add(val1)->add(val2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200824<
825 Return type: list<{type}> (depending on the given |List|) or
826 |Blob|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000827
828
829and({expr}, {expr}) *and()*
830 Bitwise AND on the two arguments. The arguments are converted
831 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100832 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000833 Example: >
834 :let flag = and(bits, 0x80)
835< Can also be used as a |method|: >
836 :let flag = bits->and(0x80)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200837<
838 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000839
840
841append({lnum}, {text}) *append()*
842 When {text} is a |List|: Append each item of the |List| as a
843 text line below line {lnum} in the current buffer.
844 Otherwise append {text} as one text line below line {lnum} in
845 the current buffer.
846 Any type of item is accepted and converted to a String.
847 {lnum} can be zero to insert a line before the first one.
848 {lnum} is used like with |getline()|.
849 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000850 0 for success. When {text} is an empty list zero is returned,
851 no matter the value of {lnum}.
852 In |Vim9| script an invalid argument or negative number
853 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000854 :let failed = append(line('$'), "# THE END")
855 :let failed = append(0, ["Chapter 1", "the beginning"])
856
857< Can also be used as a |method| after a List, the base is
858 passed as the second argument: >
859 mylist->append(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200860<
861 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000862
863
864appendbufline({buf}, {lnum}, {text}) *appendbufline()*
865 Like |append()| but append the text in buffer {buf}.
866
867 This function works only for loaded buffers. First call
868 |bufload()| if needed.
869
870 For the use of {buf}, see |bufname()|.
871
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000872 {lnum} is the line number to append below. Note that using
873 |line()| would use the current buffer, not the one appending
874 to. Use "$" to append at the end of the buffer. Other string
875 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000876
877 On success 0 is returned, on failure 1 is returned.
878 In |Vim9| script an error is given for an invalid {lnum}.
879
880 If {buf} is not a valid buffer or {lnum} is not valid, an
881 error message is given. Example: >
882 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000883< However, when {text} is an empty list then no error is given
884 for an invalid {lnum}, since {lnum} isn't actually used.
885
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000886 Can also be used as a |method| after a List, the base is
887 passed as the second argument: >
888 mylist->appendbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200889<
890 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000891
892
893argc([{winid}]) *argc()*
894 The result is the number of files in the argument list. See
895 |arglist|.
896 If {winid} is not supplied, the argument list of the current
897 window is used.
898 If {winid} is -1, the global argument list is used.
899 Otherwise {winid} specifies the window of which the argument
900 list is used: either the window number or the window ID.
901 Returns -1 if the {winid} argument is invalid.
902
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200903 Return type: |Number|
904
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000905 *argidx()*
906argidx() The result is the current index in the argument list. 0 is
907 the first file. argc() - 1 is the last one. See |arglist|.
908
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200909 Return type: |Number|
910
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000911 *arglistid()*
912arglistid([{winnr} [, {tabnr}]])
913 Return the argument list ID. This is a number which
914 identifies the argument list being used. Zero is used for the
915 global argument list. See |arglist|.
916 Returns -1 if the arguments are invalid.
917
918 Without arguments use the current window.
919 With {winnr} only use this window in the current tab page.
920 With {winnr} and {tabnr} use the window in the specified tab
921 page.
922 {winnr} can be the window number or the |window-ID|.
923
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200924 Return type: |Number|
925
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000926 *argv()*
927argv([{nr} [, {winid}]])
928 The result is the {nr}th file in the argument list. See
929 |arglist|. "argv(0)" is the first one. Example: >
930 :let i = 0
931 :while i < argc()
932 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000933 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000934 : let i = i + 1
935 :endwhile
936< Without the {nr} argument, or when {nr} is -1, a |List| with
937 the whole |arglist| is returned.
938
939 The {winid} argument specifies the window ID, see |argc()|.
940 For the Vim command line arguments see |v:argv|.
941
Bram Moolenaar016188f2022-06-06 20:52:59 +0100942 Returns an empty string if {nr}th argument is not present in
943 the argument list. Returns an empty List if the {winid}
944 argument is invalid.
945
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200946 Return type: |String|
947
948
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000949asin({expr}) *asin()*
950 Return the arc sine of {expr} measured in radians, as a |Float|
951 in the range of [-pi/2, pi/2].
952 {expr} must evaluate to a |Float| or a |Number| in the range
953 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100954 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
955 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000956 Examples: >
957 :echo asin(0.8)
958< 0.927295 >
959 :echo asin(-0.5)
960< -0.523599
961
962 Can also be used as a |method|: >
963 Compute()->asin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200964<
965 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000966
967assert_ functions are documented here: |assert-functions-details|
968
969
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000970atan({expr}) *atan()*
971 Return the principal value of the arc tangent of {expr}, in
972 the range [-pi/2, +pi/2] radians, as a |Float|.
973 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100974 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000975 Examples: >
976 :echo atan(100)
977< 1.560797 >
978 :echo atan(-4.01)
979< -1.326405
980
981 Can also be used as a |method|: >
982 Compute()->atan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200983<
984 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000985
986
987atan2({expr1}, {expr2}) *atan2()*
988 Return the arc tangent of {expr1} / {expr2}, measured in
989 radians, as a |Float| in the range [-pi, pi].
990 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100991 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
992 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000993 Examples: >
994 :echo atan2(-1, 1)
995< -0.785398 >
996 :echo atan2(1, -1)
997< 2.356194
998
999 Can also be used as a |method|: >
1000 Compute()->atan2(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001001<
1002 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001003
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001004
1005autocmd_add({acmds}) *autocmd_add()*
1006 Adds a List of autocmds and autocmd groups.
1007
1008 The {acmds} argument is a List where each item is a Dict with
1009 the following optional items:
1010 bufnr buffer number to add a buffer-local autocmd.
1011 If this item is specified, then the "pattern"
1012 item is ignored.
1013 cmd Ex command to execute for this autocmd event
1014 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001015 This can be either a String with a single
1016 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001017 group autocmd group name. Refer to |autocmd-groups|.
1018 If this group doesn't exist then it is
1019 created. If not specified or empty, then the
1020 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001021 nested boolean flag, set to v:true to add a nested
1022 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +01001023 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001024 which executes only once. Refer to
1025 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001026 pattern autocmd pattern string. Refer to
1027 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001028 present, then this item is ignored. This can
1029 be a String with a single pattern or a List of
1030 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001031 replace boolean flag, set to v:true to remove all the
1032 commands associated with the specified autocmd
1033 event and group and add the {cmd}. This is
1034 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +01001035 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001036
1037 Returns v:true on success and v:false on failure.
1038 Examples: >
1039 " Create a buffer-local autocmd for buffer 5
1040 let acmd = {}
1041 let acmd.group = 'MyGroup'
1042 let acmd.event = 'BufEnter'
1043 let acmd.bufnr = 5
1044 let acmd.cmd = 'call BufEnterFunc()'
1045 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00001046<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001047 Can also be used as a |method|: >
1048 GetAutocmdList()->autocmd_add()
1049<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001050 Return type: |vim9-boolean|
1051
1052
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001053autocmd_delete({acmds}) *autocmd_delete()*
1054 Deletes a List of autocmds and autocmd groups.
1055
1056 The {acmds} argument is a List where each item is a Dict with
1057 the following optional items:
1058 bufnr buffer number to delete a buffer-local autocmd.
1059 If this item is specified, then the "pattern"
1060 item is ignored.
1061 cmd Ex command for this autocmd event
1062 event autocmd event name. Refer to |autocmd-events|.
1063 If '*' then all the autocmd events in this
1064 group are deleted.
1065 group autocmd group name. Refer to |autocmd-groups|.
1066 If not specified or empty, then the default
1067 group is used.
1068 nested set to v:true for a nested autocmd.
1069 Refer to |autocmd-nested|.
1070 once set to v:true for an autocmd which executes
1071 only once. Refer to |autocmd-once|.
1072 pattern autocmd pattern string. Refer to
1073 |autocmd-patterns|. If "bufnr" item is
1074 present, then this item is ignored.
1075
1076 If only {group} is specified in a {acmds} entry and {event},
1077 {pattern} and {cmd} are not specified, then that autocmd group
1078 is deleted.
1079
Bram Moolenaar016188f2022-06-06 20:52:59 +01001080 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001081 Examples: >
1082 " :autocmd! BufLeave *.vim
1083 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1084 call autocmd_delete([acmd]})
1085 " :autocmd! MyGroup1 BufLeave
1086 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1087 call autocmd_delete([acmd])
1088 " :autocmd! MyGroup2 BufEnter *.c
1089 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1090 \ pattern: '*.c'}
1091 " :autocmd! MyGroup2 * *.c
1092 let acmd = #{group: 'MyGroup2', event: '*',
1093 \ pattern: '*.c'}
1094 call autocmd_delete([acmd])
1095 " :autocmd! MyGroup3
1096 let acmd = #{group: 'MyGroup3'}
1097 call autocmd_delete([acmd])
1098<
1099 Can also be used as a |method|: >
1100 GetAutocmdList()->autocmd_delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001101<
1102 Return type: |vim9-boolean|
1103
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001104
1105autocmd_get([{opts}]) *autocmd_get()*
1106 Returns a |List| of autocmds. If {opts} is not supplied, then
1107 returns the autocmds for all the events in all the groups.
1108
1109 The optional {opts} Dict argument supports the following
1110 items:
1111 group Autocmd group name. If specified, returns only
1112 the autocmds defined in this group. If the
1113 specified group doesn't exist, results in an
1114 error message. If set to an empty string,
1115 then the default autocmd group is used.
1116 event Autocmd event name. If specified, returns only
1117 the autocmds defined for this event. If set
1118 to "*", then returns autocmds for all the
1119 events. If the specified event doesn't exist,
1120 results in an error message.
1121 pattern Autocmd pattern. If specified, returns only
1122 the autocmds defined for this pattern.
1123 A combination of the above three times can be supplied in
1124 {opts}.
1125
1126 Each Dict in the returned List contains the following items:
1127 bufnr For buffer-local autocmds, buffer number where
1128 the autocmd is defined.
1129 cmd Command executed for this autocmd.
1130 event Autocmd event name.
1131 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001132 nested Boolean flag, set to v:true for a nested
1133 autocmd. See |autocmd-nested|.
1134 once Boolean flag, set to v:true, if the autocmd
1135 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001136 pattern Autocmd pattern. For a buffer-local
1137 autocmd, this will be of the form "<buffer=n>".
1138 If there are multiple commands for an autocmd event in a
1139 group, then separate items are returned for each command.
1140
Bram Moolenaar016188f2022-06-06 20:52:59 +01001141 Returns an empty List if an autocmd with the specified group
1142 or event or pattern is not found.
1143
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001144 Examples: >
1145 " :autocmd MyGroup
1146 echo autocmd_get(#{group: 'Mygroup'})
1147 " :autocmd G BufUnload
1148 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1149 " :autocmd G * *.ts
1150 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1151 echo autocmd_get(acmd)
1152 " :autocmd Syntax
1153 echo autocmd_get(#{event: 'Syntax'})
1154 " :autocmd G BufEnter *.ts
1155 let acmd = #{group: 'G', event: 'BufEnter',
1156 \ pattern: '*.ts'}
1157 echo autocmd_get(acmd)
1158<
1159 Can also be used as a |method|: >
1160 Getopts()->autocmd_get()
1161<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001162 Return type: list<dict<any>>
1163
1164
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001165balloon_gettext() *balloon_gettext()*
1166 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001167 not used for the List. Returns an empty string if balloon
1168 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001169
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001170 Return type: |String|
1171
1172
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001173balloon_show({expr}) *balloon_show()*
1174 Show {expr} inside the balloon. For the GUI {expr} is used as
1175 a string. For a terminal {expr} can be a list, which contains
1176 the lines of the balloon. If {expr} is not a list it will be
1177 split with |balloon_split()|.
1178 If {expr} is an empty string any existing balloon is removed.
1179
1180 Example: >
1181 func GetBalloonContent()
1182 " ... initiate getting the content
1183 return ''
1184 endfunc
1185 set balloonexpr=GetBalloonContent()
1186
1187 func BalloonCallback(result)
1188 call balloon_show(a:result)
1189 endfunc
1190< Can also be used as a |method|: >
1191 GetText()->balloon_show()
1192<
1193 The intended use is that fetching the content of the balloon
1194 is initiated from 'balloonexpr'. It will invoke an
1195 asynchronous method, in which a callback invokes
1196 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001197 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001198
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001199 When showing a balloon is not possible then nothing happens,
1200 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001201 {only available when compiled with the |+balloon_eval| or
1202 |+balloon_eval_term| feature}
1203
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001204 Return type: |Number|
1205
1206
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001207balloon_split({msg}) *balloon_split()*
1208 Split String {msg} into lines to be displayed in a balloon.
1209 The splits are made for the current window size and optimize
1210 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001211 Returns a |List| with the split lines. Returns an empty List
1212 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001213 Can also be used as a |method|: >
1214 GetText()->balloon_split()->balloon_show()
1215
1216< {only available when compiled with the |+balloon_eval_term|
1217 feature}
1218
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001219 Return type: list<any> or list<string>
1220
1221
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001222blob2list({blob}) *blob2list()*
1223 Return a List containing the number value of each byte in Blob
1224 {blob}. Examples: >
1225 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1226 blob2list(0z) returns []
1227< Returns an empty List on error. |list2blob()| does the
1228 opposite.
1229
1230 Can also be used as a |method|: >
1231 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001232<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001233 Return type: list<any> or list<number>
1234
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001235 *browse()*
1236browse({save}, {title}, {initdir}, {default})
1237 Put up a file requester. This only works when "has("browse")"
1238 returns |TRUE| (only in some GUI versions).
1239 The input fields are:
1240 {save} when |TRUE|, select file to write
1241 {title} title for the requester
1242 {initdir} directory to start browsing in
1243 {default} default file name
1244 An empty string is returned when the "Cancel" button is hit,
1245 something went wrong, or browsing is not possible.
1246
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001247 Return type: |String|
1248
1249
1250browsedir({title}, {initdir}) *browsedir()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001251 Put up a directory requester. This only works when
1252 "has("browse")" returns |TRUE| (only in some GUI versions).
1253 On systems where a directory browser is not supported a file
1254 browser is used. In that case: select a file in the directory
1255 to be used.
1256 The input fields are:
1257 {title} title for the requester
1258 {initdir} directory to start browsing in
1259 When the "Cancel" button is hit, something went wrong, or
1260 browsing is not possible, an empty string is returned.
1261
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001262 Return type: |String|
1263
1264
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001265bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001266 Add a buffer to the buffer list with name {name} (must be a
1267 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001268 If a buffer for file {name} already exists, return that buffer
1269 number. Otherwise return the buffer number of the newly
1270 created buffer. When {name} is an empty string then a new
1271 buffer is always created.
1272 The buffer will not have 'buflisted' set and not be loaded
1273 yet. To add some text to the buffer use this: >
1274 let bufnr = bufadd('someName')
1275 call bufload(bufnr)
1276 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001277< Returns 0 on error.
1278 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001279 let bufnr = 'somename'->bufadd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001280<
1281 Return type: |Number|
1282
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001283
1284bufexists({buf}) *bufexists()*
1285 The result is a Number, which is |TRUE| if a buffer called
1286 {buf} exists.
1287 If the {buf} argument is a number, buffer numbers are used.
1288 Number zero is the alternate buffer for the current window.
1289
1290 If the {buf} argument is a string it must match a buffer name
1291 exactly. The name can be:
1292 - Relative to the current directory.
1293 - A full path.
1294 - The name of a buffer with 'buftype' set to "nofile".
1295 - A URL name.
1296 Unlisted buffers will be found.
1297 Note that help files are listed by their short name in the
1298 output of |:buffers|, but bufexists() requires using their
1299 long name to be able to find them.
1300 bufexists() may report a buffer exists, but to use the name
1301 with a |:buffer| command you may need to use |expand()|. Esp
1302 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1303 Use "bufexists(0)" to test for the existence of an alternate
1304 file name.
1305
1306 Can also be used as a |method|: >
1307 let exists = 'somename'->bufexists()
1308<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001309 Return type: |Number|
1310
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001311 Obsolete name: buffer_exists(). *buffer_exists()*
1312
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001313
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001314buflisted({buf}) *buflisted()*
1315 The result is a Number, which is |TRUE| if a buffer called
1316 {buf} exists and is listed (has the 'buflisted' option set).
1317 The {buf} argument is used like with |bufexists()|.
1318
1319 Can also be used as a |method|: >
1320 let listed = 'somename'->buflisted()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001321<
1322 Return type: |Number|
1323
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001324
1325bufload({buf}) *bufload()*
1326 Ensure the buffer {buf} is loaded. When the buffer name
1327 refers to an existing file then the file is read. Otherwise
1328 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001329 then there is no change. If the buffer is not related to a
Daniel Steinbergc2bd2052023-08-09 12:10:59 -04001330 file then no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001331 If there is an existing swap file for the file of the buffer,
1332 there will be no dialog, the buffer will be loaded anyway.
1333 The {buf} argument is used like with |bufexists()|.
1334
1335 Can also be used as a |method|: >
1336 eval 'somename'->bufload()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001337<
1338 Return type: |Number|
1339
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001340
1341bufloaded({buf}) *bufloaded()*
1342 The result is a Number, which is |TRUE| if a buffer called
1343 {buf} exists and is loaded (shown in a window or hidden).
1344 The {buf} argument is used like with |bufexists()|.
1345
1346 Can also be used as a |method|: >
1347 let loaded = 'somename'->bufloaded()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001348<
1349 Return type: |Number|
1350
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001351
1352bufname([{buf}]) *bufname()*
1353 The result is the name of a buffer. Mostly as it is displayed
1354 by the `:ls` command, but not using special names such as
1355 "[No Name]".
1356 If {buf} is omitted the current buffer is used.
1357 If {buf} is a Number, that buffer number's name is given.
1358 Number zero is the alternate buffer for the current window.
1359 If {buf} is a String, it is used as a |file-pattern| to match
1360 with the buffer names. This is always done like 'magic' is
1361 set and 'cpoptions' is empty. When there is more than one
1362 match an empty string is returned.
1363 "" or "%" can be used for the current buffer, "#" for the
1364 alternate buffer.
1365 A full match is preferred, otherwise a match at the start, end
1366 or middle of the buffer name is accepted. If you only want a
1367 full match then put "^" at the start and "$" at the end of the
1368 pattern.
1369 Listed buffers are found first. If there is a single match
1370 with a listed buffer, that one is returned. Next unlisted
1371 buffers are searched for.
1372 If the {buf} is a String, but you want to use it as a buffer
1373 number, force it to be a Number by adding zero to it: >
1374 :echo bufname("3" + 0)
1375< Can also be used as a |method|: >
1376 echo bufnr->bufname()
1377
1378< If the buffer doesn't exist, or doesn't have a name, an empty
1379 string is returned. >
1380 bufname("#") alternate buffer name
1381 bufname(3) name of buffer 3
1382 bufname("%") name of current buffer
1383 bufname("file2") name of buffer where "file2" matches.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001384<
1385 Return type: |String|
1386 *buffer_name()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001387 Obsolete name: buffer_name().
1388
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001389
1390bufnr([{buf} [, {create}]]) *bufnr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001391 The result is the number of a buffer, as it is displayed by
1392 the `:ls` command. For the use of {buf}, see |bufname()|
1393 above.
1394
1395 If the buffer doesn't exist, -1 is returned. Or, if the
1396 {create} argument is present and TRUE, a new, unlisted,
1397 buffer is created and its number is returned. Example: >
1398 let newbuf = bufnr('Scratch001', 1)
1399< Using an empty name uses the current buffer. To create a new
1400 buffer with an empty name use |bufadd()|.
1401
1402 bufnr("$") is the last buffer: >
1403 :let last_buffer = bufnr("$")
1404< The result is a Number, which is the highest buffer number
1405 of existing buffers. Note that not all buffers with a smaller
1406 number necessarily exist, because ":bwipeout" may have removed
1407 them. Use bufexists() to test for the existence of a buffer.
1408
1409 Can also be used as a |method|: >
1410 echo bufref->bufnr()
1411<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001412 Return type: |Number|
1413
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001414 Obsolete name: buffer_number(). *buffer_number()*
1415 *last_buffer_nr()*
1416 Obsolete name for bufnr("$"): last_buffer_nr().
1417
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001418
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001419bufwinid({buf}) *bufwinid()*
1420 The result is a Number, which is the |window-ID| of the first
1421 window associated with buffer {buf}. For the use of {buf},
1422 see |bufname()| above. If buffer {buf} doesn't exist or
1423 there is no such window, -1 is returned. Example: >
1424
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001425 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001426<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001427 Only deals with the current tab page. See |win_findbuf()| for
1428 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001429
1430 Can also be used as a |method|: >
1431 FindBuffer()->bufwinid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001432<
1433 Return type: |Number|
1434
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001435
1436bufwinnr({buf}) *bufwinnr()*
1437 Like |bufwinid()| but return the window number instead of the
1438 |window-ID|.
1439 If buffer {buf} doesn't exist or there is no such window, -1
1440 is returned. Example: >
1441
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001442 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001443
1444< The number can be used with |CTRL-W_w| and ":wincmd w"
1445 |:wincmd|.
1446
1447 Can also be used as a |method|: >
1448 FindBuffer()->bufwinnr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001449<
1450 Return type: |Number|
1451
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001452
1453byte2line({byte}) *byte2line()*
1454 Return the line number that contains the character at byte
1455 count {byte} in the current buffer. This includes the
1456 end-of-line character, depending on the 'fileformat' option
1457 for the current buffer. The first character has byte count
1458 one.
1459 Also see |line2byte()|, |go| and |:goto|.
1460
Bram Moolenaar016188f2022-06-06 20:52:59 +01001461 Returns -1 if the {byte} value is invalid.
1462
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001463 Can also be used as a |method|: >
1464 GetOffset()->byte2line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001465<
1466 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001467
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001468 {not available when compiled without the |+byte_offset|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001469 feature}
1470
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001471
Christian Brabandt67672ef2023-04-24 21:09:54 +01001472byteidx({expr}, {nr} [, {utf16}]) *byteidx()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001473 Return byte index of the {nr}'th character in the String
1474 {expr}. Use zero for the first character, it then returns
1475 zero.
1476 If there are no multibyte characters the returned value is
1477 equal to {nr}.
1478 Composing characters are not counted separately, their byte
1479 length is added to the preceding base character. See
1480 |byteidxcomp()| below for counting composing characters
1481 separately.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001482 When {utf16} is present and TRUE, {nr} is used as the UTF-16
1483 index in the String {expr} instead of as the character index.
1484 The UTF-16 index is the index in the string when it is encoded
1485 with 16-bit words. If the specified UTF-16 index is in the
1486 middle of a character (e.g. in a 4-byte character), then the
1487 byte index of the first byte in the character is returned.
1488 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001489 Example : >
1490 echo matchstr(str, ".", byteidx(str, 3))
1491< will display the fourth character. Another way to do the
1492 same: >
1493 let s = strpart(str, byteidx(str, 3))
1494 echo strpart(s, 0, byteidx(s, 1))
1495< Also see |strgetchar()| and |strcharpart()|.
1496
1497 If there are less than {nr} characters -1 is returned.
1498 If there are exactly {nr} characters the length of the string
1499 in bytes is returned.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001500 See |charidx()| and |utf16idx()| for getting the character and
1501 UTF-16 index respectively from the byte index.
1502 Examples: >
1503 echo byteidx('a😊😊', 2) returns 5
1504 echo byteidx('a😊😊', 2, 1) returns 1
1505 echo byteidx('a😊😊', 3, 1) returns 5
1506<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001507 Can also be used as a |method|: >
1508 GetName()->byteidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001509<
1510 Return type: |Number|
1511
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001512
Christian Brabandt67672ef2023-04-24 21:09:54 +01001513byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001514 Like byteidx(), except that a composing character is counted
1515 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001516 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001517 echo byteidx(s, 1)
1518 echo byteidxcomp(s, 1)
1519 echo byteidxcomp(s, 2)
1520< The first and third echo result in 3 ('e' plus composing
1521 character is 3 bytes), the second echo results in 1 ('e' is
1522 one byte).
1523 Only works differently from byteidx() when 'encoding' is set
1524 to a Unicode encoding.
1525
1526 Can also be used as a |method|: >
1527 GetName()->byteidxcomp(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001528<
1529 Return type: |Number|
1530
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001531
1532call({func}, {arglist} [, {dict}]) *call()* *E699*
1533 Call function {func} with the items in |List| {arglist} as
1534 arguments.
1535 {func} can either be a |Funcref| or the name of a function.
1536 a:firstline and a:lastline are set to the cursor line.
1537 Returns the return value of the called function.
1538 {dict} is for functions with the "dict" attribute. It will be
1539 used to set the local variable "self". |Dictionary-function|
1540
1541 Can also be used as a |method|: >
1542 GetFunc()->call([arg, arg], dict)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001543<
1544 Return type: any, depending on {func}
1545
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001546
1547ceil({expr}) *ceil()*
1548 Return the smallest integral value greater than or equal to
1549 {expr} as a |Float| (round up).
1550 {expr} must evaluate to a |Float| or a |Number|.
1551 Examples: >
1552 echo ceil(1.456)
1553< 2.0 >
1554 echo ceil(-5.456)
1555< -5.0 >
1556 echo ceil(4.0)
1557< 4.0
1558
Bram Moolenaar016188f2022-06-06 20:52:59 +01001559 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1560
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001561 Can also be used as a |method|: >
1562 Compute()->ceil()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001563<
1564 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001565
1566
1567ch_ functions are documented here: |channel-functions-details|
1568
1569
1570changenr() *changenr()*
1571 Return the number of the most recent change. This is the same
1572 number as what is displayed with |:undolist| and can be used
1573 with the |:undo| command.
1574 When a change was made it is the number of that change. After
1575 redo it is the number of the redone change. After undo it is
1576 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001577 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001578
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001579 Return type: |Number|
1580
1581
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001582char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001583 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001584 Examples: >
1585 char2nr(" ") returns 32
1586 char2nr("ABC") returns 65
1587< When {utf8} is omitted or zero, the current 'encoding' is used.
1588 Example for "utf-8": >
1589 char2nr("á") returns 225
1590 char2nr("á"[0]) returns 195
1591< When {utf8} is TRUE, always treat as UTF-8 characters.
1592 A combining character is a separate character.
1593 |nr2char()| does the opposite.
1594 To turn a string into a list of character numbers: >
1595 let str = "ABC"
1596 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1597< Result: [65, 66, 67]
1598
Bram Moolenaar016188f2022-06-06 20:52:59 +01001599 Returns 0 if {string} is not a |String|.
1600
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001601 Can also be used as a |method|: >
1602 GetChar()->char2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001603<
1604 Return type: |Number|
1605
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001606
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001607charclass({string}) *charclass()*
1608 Return the character class of the first character in {string}.
1609 The character class is one of:
1610 0 blank
1611 1 punctuation
1612 2 word character
1613 3 emoji
1614 other specific Unicode class
1615 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001616 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001617
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001618 Return type: |Number|
1619
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001620
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001621charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001622 Same as |col()| but returns the character index of the column
1623 position given with {expr} instead of the byte position.
1624
1625 Example:
1626 With the cursor on '세' in line 5 with text "여보세요": >
1627 charcol('.') returns 3
1628 col('.') returns 7
1629
1630< Can also be used as a |method|: >
1631 GetPos()->col()
1632<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001633 Return type: |Number|
1634
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001635 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001636charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001637 Return the character index of the byte at {idx} in {string}.
1638 The index of the first character is zero.
1639 If there are no multibyte characters the returned value is
1640 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001641
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001642 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001643 are not counted separately, their byte length is added to the
1644 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001645 When {countcc} is |TRUE|, then composing characters are
1646 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001647
1648 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1649 index in the String {expr} instead of as the byte index.
1650
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001651 Returns -1 if the arguments are invalid or if there are less
1652 than {idx} bytes. If there are exactly {idx} bytes the length
1653 of the string in characters is returned.
1654
1655 An error is given and -1 is returned if the first argument is
1656 not a string, the second argument is not a number or when the
1657 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001658
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001659 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001660 from the character index and |utf16idx()| for getting the
1661 UTF-16 index from the character index.
1662 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001663 Examples: >
1664 echo charidx('áb́ć', 3) returns 1
1665 echo charidx('áb́ć', 6, 1) returns 4
1666 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001667 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001668<
1669 Can also be used as a |method|: >
1670 GetName()->charidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001671<
1672 Return type: |Number|
1673
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001674
1675chdir({dir}) *chdir()*
1676 Change the current working directory to {dir}. The scope of
1677 the directory change depends on the directory of the current
1678 window:
1679 - If the current window has a window-local directory
1680 (|:lcd|), then changes the window local directory.
1681 - Otherwise, if the current tabpage has a local
1682 directory (|:tcd|) then changes the tabpage local
1683 directory.
1684 - Otherwise, changes the global directory.
1685 {dir} must be a String.
1686 If successful, returns the previous working directory. Pass
1687 this to another chdir() to restore the directory.
1688 On failure, returns an empty string.
1689
1690 Example: >
1691 let save_dir = chdir(newdir)
1692 if save_dir != ""
1693 " ... do some work
1694 call chdir(save_dir)
1695 endif
1696
1697< Can also be used as a |method|: >
1698 GetDir()->chdir()
1699<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001700 Return type: |String|
1701
1702
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001703cindent({lnum}) *cindent()*
1704 Get the amount of indent for line {lnum} according the C
1705 indenting rules, as with 'cindent'.
1706 The indent is counted in spaces, the value of 'tabstop' is
1707 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001708 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001709 See |C-indenting|.
1710
1711 Can also be used as a |method|: >
1712 GetLnum()->cindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001713<
1714 Return type: |Number|
1715
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001716
1717clearmatches([{win}]) *clearmatches()*
1718 Clears all matches previously defined for the current window
1719 by |matchadd()| and the |:match| commands.
1720 If {win} is specified, use the window with this number or
1721 window ID instead of the current window.
1722
1723 Can also be used as a |method|: >
1724 GetWin()->clearmatches()
1725<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001726 Return type: |Number|
1727
1728
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001729col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001730 The result is a Number, which is the byte index of the column
zeertzjq02f3eba2024-06-12 20:45:24 +02001731 position given with {expr}.
1732 For accepted positions see |getpos()|.
zeertzjqd353d272024-06-13 23:00:25 +08001733 When {expr} is "$", it means the end of the cursor line, so
1734 the result is the number of bytes in the cursor line plus one.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001735 Additionally {expr} can be [lnum, col]: a |List| with the line
1736 and column number. Most useful when the column is "$", to get
1737 the last column of a specific line. When "lnum" or "col" is
1738 out of range then col() returns zero.
zeertzjq02f3eba2024-06-12 20:45:24 +02001739
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001740 With the optional {winid} argument the values are obtained for
1741 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02001742
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001743 To get the line number use |line()|. To get both use
1744 |getpos()|.
1745 For the screen column position use |virtcol()|. For the
1746 character position use |charcol()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02001747
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001748 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +02001749
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001750 Examples: >
1751 col(".") column of cursor
1752 col("$") length of cursor line plus one
1753 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001754 col("'" .. markname) column of mark markname
zeertzjq02f3eba2024-06-12 20:45:24 +02001755<
1756 The first column is 1. Returns 0 if {expr} is invalid or when
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001757 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001758 For an uppercase mark the column may actually be in another
1759 buffer.
1760 For the cursor position, when 'virtualedit' is active, the
1761 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001762 line. Also, when using a <Cmd> mapping the cursor isn't
1763 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001764 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001765
1766< Can also be used as a |method|: >
1767 GetPos()->col()
1768<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001769 Return type: |Number|
1770
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001771
1772complete({startcol}, {matches}) *complete()* *E785*
1773 Set the matches for Insert mode completion.
1774 Can only be used in Insert mode. You need to use a mapping
1775 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1776 or with an expression mapping.
1777 {startcol} is the byte offset in the line where the completed
1778 text start. The text up to the cursor is the original text
1779 that will be replaced by the matches. Use col('.') for an
1780 empty string. "col('.') - 1" will replace one character by a
1781 match.
1782 {matches} must be a |List|. Each |List| item is one match.
1783 See |complete-items| for the kind of items that are possible.
1784 "longest" in 'completeopt' is ignored.
1785 Note that the after calling this function you need to avoid
1786 inserting anything that would cause completion to stop.
1787 The match can be selected with CTRL-N and CTRL-P as usual with
1788 Insert mode completion. The popup menu will appear if
1789 specified, see |ins-completion-menu|.
1790 Example: >
1791 inoremap <F5> <C-R>=ListMonths()<CR>
1792
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001793 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001794 call complete(col('.'), ['January', 'February', 'March',
1795 \ 'April', 'May', 'June', 'July', 'August', 'September',
1796 \ 'October', 'November', 'December'])
1797 return ''
1798 endfunc
1799< This isn't very useful, but it shows how it works. Note that
1800 an empty string is returned to avoid a zero being inserted.
1801
1802 Can also be used as a |method|, the base is passed as the
1803 second argument: >
1804 GetMatches()->complete(col('.'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001805<
1806 Return type: |Number|
1807
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001808
1809complete_add({expr}) *complete_add()*
1810 Add {expr} to the list of matches. Only to be used by the
1811 function specified with the 'completefunc' option.
1812 Returns 0 for failure (empty string or out of memory),
1813 1 when the match was added, 2 when the match was already in
1814 the list.
1815 See |complete-functions| for an explanation of {expr}. It is
1816 the same as one item in the list that 'omnifunc' would return.
1817
1818 Can also be used as a |method|: >
1819 GetMoreMatches()->complete_add()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001820<
1821 Return type: |Number|
1822
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001823
1824complete_check() *complete_check()*
1825 Check for a key typed while looking for completion matches.
1826 This is to be used when looking for matches takes some time.
1827 Returns |TRUE| when searching for matches is to be aborted,
1828 zero otherwise.
1829 Only to be used by the function specified with the
1830 'completefunc' option.
1831
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001832 Return type: |Number|
1833
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001834
1835complete_info([{what}]) *complete_info()*
1836 Returns a |Dictionary| with information about Insert mode
1837 completion. See |ins-completion|.
1838 The items are:
1839 mode Current completion mode name string.
1840 See |complete_info_mode| for the values.
1841 pum_visible |TRUE| if popup menu is visible.
1842 See |pumvisible()|.
1843 items List of completion matches. Each item is a
1844 dictionary containing the entries "word",
1845 "abbr", "menu", "kind", "info" and "user_data".
1846 See |complete-items|.
1847 selected Selected item index. First index is zero.
1848 Index is -1 if no item is selected (showing
1849 typed text only, or the last completion after
1850 no item is selected when using the <Up> or
1851 <Down> keys)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01001852 inserted Inserted string. [NOT IMPLEMENTED YET]
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001853
1854 *complete_info_mode*
1855 mode values are:
1856 "" Not in completion mode
1857 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1858 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1859 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1860 |i_CTRL-X_CTRL-Y|
1861 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1862 "files" File names |i_CTRL-X_CTRL-F|
1863 "tags" Tags |i_CTRL-X_CTRL-]|
1864 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1865 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1866 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1867 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1868 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1869 "function" User defined completion |i_CTRL-X_CTRL-U|
1870 "omni" Omni completion |i_CTRL-X_CTRL-O|
1871 "spell" Spelling suggestions |i_CTRL-X_s|
1872 "eval" |complete()| completion
1873 "unknown" Other internal modes
1874
1875 If the optional {what} list argument is supplied, then only
1876 the items listed in {what} are returned. Unsupported items in
1877 {what} are silently ignored.
1878
1879 To get the position and size of the popup menu, see
1880 |pum_getpos()|. It's also available in |v:event| during the
1881 |CompleteChanged| event.
1882
Bram Moolenaar016188f2022-06-06 20:52:59 +01001883 Returns an empty |Dictionary| on error.
1884
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001885 Examples: >
1886 " Get all items
1887 call complete_info()
1888 " Get only 'mode'
1889 call complete_info(['mode'])
1890 " Get only 'mode' and 'pum_visible'
1891 call complete_info(['mode', 'pum_visible'])
1892
1893< Can also be used as a |method|: >
1894 GetItems()->complete_info()
1895<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001896 Return type: dict<any>
1897
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001898 *confirm()*
1899confirm({msg} [, {choices} [, {default} [, {type}]]])
1900 confirm() offers the user a dialog, from which a choice can be
1901 made. It returns the number of the choice. For the first
1902 choice this is 1.
1903 Note: confirm() is only supported when compiled with dialog
glepnirdf461152024-04-04 22:23:29 +02001904 support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001905
1906 {msg} is displayed in a |dialog| with {choices} as the
1907 alternatives. When {choices} is missing or empty, "&OK" is
1908 used (and translated).
1909 {msg} is a String, use '\n' to include a newline. Only on
1910 some systems the string is wrapped when it doesn't fit.
1911
1912 {choices} is a String, with the individual choices separated
1913 by '\n', e.g. >
1914 confirm("Save changes?", "&Yes\n&No\n&Cancel")
1915< The letter after the '&' is the shortcut key for that choice.
1916 Thus you can type 'c' to select "Cancel". The shortcut does
1917 not need to be the first letter: >
1918 confirm("file has been modified", "&Save\nSave &All")
1919< For the console, the first letter of each choice is used as
1920 the default shortcut key. Case is ignored.
1921
1922 The optional {default} argument is the number of the choice
1923 that is made if the user hits <CR>. Use 1 to make the first
1924 choice the default one. Use 0 to not set a default. If
1925 {default} is omitted, 1 is used.
1926
1927 The optional {type} String argument gives the type of dialog.
1928 This is only used for the icon of the GTK, Mac, Motif and
1929 Win32 GUI. It can be one of these values: "Error",
1930 "Question", "Info", "Warning" or "Generic". Only the first
1931 character is relevant. When {type} is omitted, "Generic" is
1932 used.
1933
1934 If the user aborts the dialog by pressing <Esc>, CTRL-C,
1935 or another valid interrupt key, confirm() returns 0.
1936
1937 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01001938 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001939 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01001940 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001941 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001942 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001943 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001944 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001945 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01001946 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001947< In a GUI dialog, buttons are used. The layout of the buttons
1948 depends on the 'v' flag in 'guioptions'. If it is included,
1949 the buttons are always put vertically. Otherwise, confirm()
1950 tries to put the buttons in one horizontal line. If they
1951 don't fit, a vertical layout is used anyway. For some systems
1952 the horizontal layout is always used.
1953
1954 Can also be used as a |method|in: >
1955 BuildMessage()->confirm("&Yes\n&No")
1956<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001957 Return type: |Number|
1958
1959
1960copy({expr}) *copy()*
1961 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001962 different from using {expr} directly.
1963 When {expr} is a |List| a shallow copy is created. This means
1964 that the original |List| can be changed without changing the
1965 copy, and vice versa. But the items are identical, thus
1966 changing an item changes the contents of both |Lists|.
1967 A |Dictionary| is copied in a similar way as a |List|.
1968 Also see |deepcopy()|.
1969 Can also be used as a |method|: >
1970 mylist->copy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001971<
1972 Return type: any, depending on {expr}
1973
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001974
1975cos({expr}) *cos()*
1976 Return the cosine of {expr}, measured in radians, as a |Float|.
1977 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001978 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001979 Examples: >
1980 :echo cos(100)
1981< 0.862319 >
1982 :echo cos(-4.01)
1983< -0.646043
1984
1985 Can also be used as a |method|: >
1986 Compute()->cos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001987<
1988 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001989
1990
1991cosh({expr}) *cosh()*
1992 Return the hyperbolic cosine of {expr} as a |Float| in the range
1993 [1, inf].
1994 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001995 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001996 Examples: >
1997 :echo cosh(0.5)
1998< 1.127626 >
1999 :echo cosh(-0.5)
2000< -1.127626
2001
2002 Can also be used as a |method|: >
2003 Compute()->cosh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002004<
2005 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002006
2007
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07002008count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002009 Return the number of times an item with value {expr} appears
2010 in |String|, |List| or |Dictionary| {comp}.
2011
2012 If {start} is given then start with the item with this index.
2013 {start} can only be used with a |List|.
2014
2015 When {ic} is given and it's |TRUE| then case is ignored.
2016
2017 When {comp} is a string then the number of not overlapping
2018 occurrences of {expr} is returned. Zero is returned when
2019 {expr} is an empty string.
2020
2021 Can also be used as a |method|: >
2022 mylist->count(val)
2023<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002024 Return type: |Number|
2025
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002026 *cscope_connection()*
2027cscope_connection([{num} , {dbpath} [, {prepend}]])
2028 Checks for the existence of a |cscope| connection. If no
2029 parameters are specified, then the function returns:
2030 0, if cscope was not available (not compiled in), or
2031 if there are no cscope connections;
2032 1, if there is at least one cscope connection.
2033
2034 If parameters are specified, then the value of {num}
2035 determines how existence of a cscope connection is checked:
2036
2037 {num} Description of existence check
2038 ----- ------------------------------
2039 0 Same as no parameters (e.g., "cscope_connection()").
2040 1 Ignore {prepend}, and use partial string matches for
2041 {dbpath}.
2042 2 Ignore {prepend}, and use exact string matches for
2043 {dbpath}.
2044 3 Use {prepend}, use partial string matches for both
2045 {dbpath} and {prepend}.
2046 4 Use {prepend}, use exact string matches for both
2047 {dbpath} and {prepend}.
2048
2049 Note: All string comparisons are case sensitive!
2050
2051 Examples. Suppose we had the following (from ":cs show"): >
2052
2053 # pid database name prepend path
2054 0 27664 cscope.out /usr/local
2055<
2056 Invocation Return Val ~
2057 ---------- ---------- >
2058 cscope_connection() 1
2059 cscope_connection(1, "out") 1
2060 cscope_connection(2, "out") 0
2061 cscope_connection(3, "out") 0
2062 cscope_connection(3, "out", "local") 1
2063 cscope_connection(4, "out") 0
2064 cscope_connection(4, "out", "local") 0
2065 cscope_connection(4, "cscope.out", "/usr/local") 1
2066<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002067 Return type: |Number|
2068
2069
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002070cursor({lnum}, {col} [, {off}]) *cursor()*
2071cursor({list})
2072 Positions the cursor at the column (byte count) {col} in the
2073 line {lnum}. The first column is one.
2074
2075 When there is one argument {list} this is used as a |List|
2076 with two, three or four item:
2077 [{lnum}, {col}]
2078 [{lnum}, {col}, {off}]
2079 [{lnum}, {col}, {off}, {curswant}]
2080 This is like the return value of |getpos()| or |getcurpos()|,
2081 but without the first item.
2082
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01002083 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002084 |setcursorcharpos()|.
2085
2086 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01002087 {lnum} is used like with |getline()|, except that if {lnum} is
2088 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002089 If {lnum} is greater than the number of lines in the buffer,
2090 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002091 If {col} is greater than the number of bytes in the line,
2092 the cursor will be positioned at the last character in the
2093 line.
2094 If {col} is zero, the cursor will stay in the current column.
2095 If {curswant} is given it is used to set the preferred column
2096 for vertical movement. Otherwise {col} is used.
2097
2098 When 'virtualedit' is used {off} specifies the offset in
2099 screen columns from the start of the character. E.g., a
2100 position within a <Tab> or after the last character.
2101 Returns 0 when the position could be set, -1 otherwise.
2102
2103 Can also be used as a |method|: >
2104 GetCursorPos()->cursor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002105<
2106 Return type: |Number|
2107
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002108
2109debugbreak({pid}) *debugbreak()*
2110 Specifically used to interrupt a program being debugged. It
2111 will cause process {pid} to get a SIGTRAP. Behavior for other
2112 processes is undefined. See |terminal-debugger|.
2113 {only available on MS-Windows}
2114
Bram Moolenaar016188f2022-06-06 20:52:59 +01002115 Returns |TRUE| if successfully interrupted the program.
2116 Otherwise returns |FALSE|.
2117
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002118 Can also be used as a |method|: >
2119 GetPid()->debugbreak()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002120<
2121 Return type: |Number|
2122
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002123
2124deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
2125 Make a copy of {expr}. For Numbers and Strings this isn't
2126 different from using {expr} directly.
2127 When {expr} is a |List| a full copy is created. This means
2128 that the original |List| can be changed without changing the
2129 copy, and vice versa. When an item is a |List| or
2130 |Dictionary|, a copy for it is made, recursively. Thus
2131 changing an item in the copy does not change the contents of
2132 the original |List|.
2133 A |Dictionary| is copied in a similar way as a |List|.
2134
2135 When {noref} is omitted or zero a contained |List| or
2136 |Dictionary| is only copied once. All references point to
2137 this single copy. With {noref} set to 1 every occurrence of a
2138 |List| or |Dictionary| results in a new copy. This also means
2139 that a cyclic reference causes deepcopy() to fail.
2140 *E724*
2141 Nesting is possible up to 100 levels. When there is an item
2142 that refers back to a higher level making a deep copy with
2143 {noref} set to 1 will fail.
2144 Also see |copy()|.
2145
2146 Can also be used as a |method|: >
2147 GetObject()->deepcopy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002148<
2149 Return type: any, depending on {expr}
2150
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002151
2152delete({fname} [, {flags}]) *delete()*
2153 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002154 name {fname}.
2155
2156 This also works when {fname} is a symbolic link. The symbolic
2157 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002158
2159 When {flags} is "d": Deletes the directory by the name
2160 {fname}. This fails when directory {fname} is not empty.
2161
2162 When {flags} is "rf": Deletes the directory by the name
2163 {fname} and everything in it, recursively. BE CAREFUL!
2164 Note: on MS-Windows it is not possible to delete a directory
2165 that is being used.
2166
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002167 The result is a Number, which is 0/false if the delete
2168 operation was successful and -1/true when the deletion failed
2169 or partly failed.
2170
2171 Use |remove()| to delete an item from a |List|.
2172 To delete a line from the buffer use |:delete| or
2173 |deletebufline()|.
2174
2175 Can also be used as a |method|: >
2176 GetName()->delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002177<
2178 Return type: |Number|
2179
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002180
2181deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2182 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2183 If {last} is omitted then delete line {first} only.
2184 On success 0 is returned, on failure 1 is returned.
2185
2186 This function works only for loaded buffers. First call
2187 |bufload()| if needed.
2188
2189 For the use of {buf}, see |bufname()| above.
2190
2191 {first} and {last} are used like with |getline()|. Note that
2192 when using |line()| this refers to the current buffer. Use "$"
2193 to refer to the last line in buffer {buf}.
2194
2195 Can also be used as a |method|: >
2196 GetBuffer()->deletebufline(1)
2197<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002198 Return type: |Number|
2199
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002200 *did_filetype()*
2201did_filetype() Returns |TRUE| when autocommands are being executed and the
2202 FileType event has been triggered at least once. Can be used
2203 to avoid triggering the FileType event again in the scripts
2204 that detect the file type. |FileType|
2205 Returns |FALSE| when `:setf FALLBACK` was used.
2206 When editing another file, the counter is reset, thus this
2207 really checks if the FileType event has been triggered for the
2208 current buffer. This allows an autocommand that starts
2209 editing another buffer to set 'filetype' and load a syntax
2210 file.
2211
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002212 Return type: |Number|
2213
2214
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002215diff({fromlist}, {tolist} [, {options}]) *diff()*
2216 Returns a String or a List containing the diff between the
2217 strings in {fromlist} and {tolist}. Uses the Vim internal
2218 diff library to compute the diff.
2219
2220 *E106*
2221 The optional "output" item in {options} specifies the returned
2222 diff format. The following values are supported:
2223 indices Return a List of the starting and ending
2224 indices and a count of the strings in each
2225 diff hunk.
2226 unified Return the unified diff output as a String.
2227 This is the default.
2228
2229 If the "output" item in {options} is "indices", then a List is
2230 returned. Each List item contains a Dict with the following
2231 items for each diff hunk:
2232 from_idx start index in {fromlist} for this diff hunk.
2233 from_count number of strings in {fromlist} that are
2234 added/removed/modified in this diff hunk.
2235 to_idx start index in {tolist} for this diff hunk.
2236 to_count number of strings in {tolist} that are
2237 added/removed/modified in this diff hunk.
2238
2239 The {options} Dict argument also specifies diff options
2240 (similar to 'diffopt') and supports the following items:
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002241 algorithm Dict specifying the diff algorithm to
2242 use. Supported boolean items are
2243 "myers", "minimal", "patience" and
2244 "histogram".
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002245 context diff context length. Default is 0.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002246 iblank ignore changes where lines are all
2247 blank.
2248 icase ignore changes in case of text.
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002249 indent-heuristic use the indent heuristic for the
2250 internal diff library.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002251 iwhite ignore changes in amount of white
2252 space.
2253 iwhiteall ignore all white space changes.
2254 iwhiteeol ignore white space changes at end of
2255 line.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002256 For more information about these options, refer to 'diffopt'.
2257
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002258 To compute the unified diff, all the items in {fromlist} are
2259 concatenated into a string using a newline separator and the
2260 same for {tolist}. The unified diff output uses line numbers.
2261
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002262 Returns an empty List or String if {fromlist} and {tolist} are
2263 identical.
2264
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002265 Examples: >
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002266 :echo diff(['abc'], ['xxx'])
2267 @@ -1 +1 @@
2268 -abc
2269 +xxx
2270
2271 :echo diff(['abc'], ['xxx'], {'output': 'indices'})
2272 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}]
2273 :echo diff(readfile('oldfile'), readfile('newfile'))
2274 :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$'))
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002275<
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002276 For more examples, refer to |diff-func-examples|
2277
2278 Can also be used as a |method|: >
2279 GetFromList->diff(to_list)
2280<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002281 Return type: |String| or list<dict<number>> or list<any>
2282 depending on {options}
2283
2284
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002285diff_filler({lnum}) *diff_filler()*
2286 Returns the number of filler lines above line {lnum}.
2287 These are the lines that were inserted at this point in
2288 another diff'ed window. These filler lines are shown in the
2289 display but don't exist in the buffer.
2290 {lnum} is used like with |getline()|. Thus "." is the current
2291 line, "'m" mark m, etc.
2292 Returns 0 if the current window is not in diff mode.
2293
2294 Can also be used as a |method|: >
2295 GetLnum()->diff_filler()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002296<
2297 Return type: |Number|
2298
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002299
2300diff_hlID({lnum}, {col}) *diff_hlID()*
2301 Returns the highlight ID for diff mode at line {lnum} column
2302 {col} (byte index). When the current line does not have a
2303 diff change zero is returned.
2304 {lnum} is used like with |getline()|. Thus "." is the current
2305 line, "'m" mark m, etc.
2306 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2307 line.
2308 The highlight ID can be used with |synIDattr()| to obtain
2309 syntax information about the highlighting.
2310
2311 Can also be used as a |method|: >
2312 GetLnum()->diff_hlID(col)
2313<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002314 Return type: |Number|
2315
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002316
2317digraph_get({chars}) *digraph_get()* *E1214*
2318 Return the digraph of {chars}. This should be a string with
2319 exactly two characters. If {chars} are not just two
2320 characters, or the digraph of {chars} does not exist, an error
2321 is given and an empty string is returned.
2322
2323 The character will be converted from Unicode to 'encoding'
2324 when needed. This does require the conversion to be
2325 available, it might fail.
2326
2327 Also see |digraph_getlist()|.
2328
2329 Examples: >
2330 " Get a built-in digraph
2331 :echo digraph_get('00') " Returns '∞'
2332
2333 " Get a user-defined digraph
2334 :call digraph_set('aa', 'あ')
2335 :echo digraph_get('aa') " Returns 'あ'
2336<
2337 Can also be used as a |method|: >
2338 GetChars()->digraph_get()
2339<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002340 Return type: |String|
2341
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002342 This function works only when compiled with the |+digraphs|
2343 feature. If this feature is disabled, this function will
2344 display an error message.
2345
2346
2347digraph_getlist([{listall}]) *digraph_getlist()*
2348 Return a list of digraphs. If the {listall} argument is given
2349 and it is TRUE, return all digraphs, including the default
2350 digraphs. Otherwise, return only user-defined digraphs.
2351
2352 The characters will be converted from Unicode to 'encoding'
2353 when needed. This does require the conservation to be
2354 available, it might fail.
2355
2356 Also see |digraph_get()|.
2357
2358 Examples: >
2359 " Get user-defined digraphs
2360 :echo digraph_getlist()
2361
2362 " Get all the digraphs, including default digraphs
2363 :echo digraph_getlist(1)
2364<
2365 Can also be used as a |method|: >
2366 GetNumber()->digraph_getlist()
2367<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002368 Return type: list<list<string>>
2369
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002370 This function works only when compiled with the |+digraphs|
2371 feature. If this feature is disabled, this function will
2372 display an error message.
2373
2374
Bram Moolenaara2baa732022-02-04 16:09:54 +00002375digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002376 Add digraph {chars} to the list. {chars} must be a string
2377 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002378 encoded character. *E1215*
2379 Be careful, composing characters are NOT ignored. This
2380 function is similar to |:digraphs| command, but useful to add
2381 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002382
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002383 The function returns v:true if |digraph| is registered. If
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002384 this fails an error message is given and v:false is returned.
2385
2386 If you want to define multiple digraphs at once, you can use
2387 |digraph_setlist()|.
2388
2389 Example: >
2390 call digraph_set(' ', 'あ')
2391<
2392 Can be used as a |method|: >
2393 GetString()->digraph_set('あ')
2394<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002395 Return type: |vim9-boolean|
2396
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002397 This function works only when compiled with the |+digraphs|
2398 feature. If this feature is disabled, this function will
2399 display an error message.
2400
2401
2402digraph_setlist({digraphlist}) *digraph_setlist()*
2403 Similar to |digraph_set()| but this function can add multiple
2404 digraphs at once. {digraphlist} is a list composed of lists,
2405 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002406 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002407 Example: >
2408 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2409<
2410 It is similar to the following: >
2411 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2412 call digraph_set(chars, digraph)
2413 endfor
2414< Except that the function returns after the first error,
2415 following digraphs will not be added.
2416
2417 Can be used as a |method|: >
2418 GetList()->digraph_setlist()
2419<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002420 Return type: |vim9-boolean|
2421
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002422 This function works only when compiled with the |+digraphs|
2423 feature. If this feature is disabled, this function will
2424 display an error message.
2425
2426
2427echoraw({string}) *echoraw()*
2428 Output {string} as-is, including unprintable characters.
2429 This can be used to output a terminal code. For example, to
2430 disable modifyOtherKeys: >
2431 call echoraw(&t_TE)
2432< and to enable it again: >
2433 call echoraw(&t_TI)
2434< Use with care, you can mess up the terminal this way.
2435
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002436 Return type: |Number|
2437
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002438
2439empty({expr}) *empty()*
2440 Return the Number 1 if {expr} is empty, zero otherwise.
2441 - A |List| or |Dictionary| is empty when it does not have any
2442 items.
2443 - A |String| is empty when its length is zero.
2444 - A |Number| and |Float| are empty when their value is zero.
2445 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2446 - A |Job| is empty when it failed to start.
2447 - A |Channel| is empty when it is closed.
2448 - A |Blob| is empty when its length is zero.
mityu7f0bba22024-03-29 10:14:41 +01002449 - An |Object| is empty, when the empty() method in the object
2450 (if present) returns true. |object-empty()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002451
2452 For a long |List| this is much faster than comparing the
2453 length with zero.
2454
2455 Can also be used as a |method|: >
2456 mylist->empty()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002457<
2458 Return type: |Number|
2459
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002460
2461environ() *environ()*
2462 Return all of environment variables as dictionary. You can
2463 check if an environment variable exists like this: >
2464 :echo has_key(environ(), 'HOME')
2465< Note that the variable name may be CamelCase; to ignore case
2466 use this: >
2467 :echo index(keys(environ()), 'HOME', 0, 1) != -1
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002468<
2469 Return type: dict<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002470
Bram Moolenaar416bd912023-07-07 23:19:18 +01002471
2472err_teapot([{expr}]) *err_teapot()*
2473 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002474 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002475 If {expr} is present and it is TRUE error 503 is given,
2476 indicating that coffee is temporarily not available.
2477 If {expr} is present it must be a String.
2478
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002479 Return type: |Number|
2480
Bram Moolenaar416bd912023-07-07 23:19:18 +01002481
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002482escape({string}, {chars}) *escape()*
2483 Escape the characters in {chars} that occur in {string} with a
2484 backslash. Example: >
2485 :echo escape('c:\program files\vim', ' \')
2486< results in: >
2487 c:\\program\ files\\vim
2488< Also see |shellescape()| and |fnameescape()|.
2489
2490 Can also be used as a |method|: >
2491 GetText()->escape(' \')
2492<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002493 Return type: |String|
2494
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002495 *eval()*
2496eval({string}) Evaluate {string} and return the result. Especially useful to
2497 turn the result of |string()| back into the original value.
2498 This works for Numbers, Floats, Strings, Blobs and composites
2499 of them. Also works for |Funcref|s that refer to existing
Aliaksei Budavei95740222024-04-04 23:05:33 +03002500 functions. In |Vim9| script, it can be used to obtain |enum|
2501 values from their fully qualified names.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002502
2503 Can also be used as a |method|: >
2504 argv->join()->eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002505<
2506 Return type: any, depending on {string}
2507
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002508
2509eventhandler() *eventhandler()*
2510 Returns 1 when inside an event handler. That is that Vim got
2511 interrupted while waiting for the user to type a character,
2512 e.g., when dropping a file on Vim. This means interactive
2513 commands cannot be used. Otherwise zero is returned.
2514
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002515 Return type: |Number|
2516
2517
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002518executable({expr}) *executable()*
2519 This function checks if an executable with the name {expr}
2520 exists. {expr} must be the name of the program without any
2521 arguments.
2522 executable() uses the value of $PATH and/or the normal
2523 searchpath for programs. *PATHEXT*
2524 On MS-Windows the ".exe", ".bat", etc. can optionally be
2525 included. Then the extensions in $PATHEXT are tried. Thus if
2526 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2527 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2528 by itself can be used in $PATHEXT to try using the name
2529 without an extension. When 'shell' looks like a Unix shell,
2530 then the name is also tried without adding an extension.
2531 On MS-Windows it only checks if the file exists and is not a
2532 directory, not if it's really executable.
2533 On MS-Windows an executable in the same directory as Vim is
Yasuhiro Matsumoto05cf63e2022-05-03 11:02:28 +01002534 normally found. Since this directory is added to $PATH it
2535 should also work to execute it |win32-PATH|. This can be
2536 disabled by setting the $NoDefaultCurrentDirectoryInExePath
2537 environment variable. *NoDefaultCurrentDirectoryInExePath*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002538 The result is a Number:
2539 1 exists
2540 0 does not exist
2541 -1 not implemented on this system
2542 |exepath()| can be used to get the full path of an executable.
2543
2544 Can also be used as a |method|: >
2545 GetCommand()->executable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002546<
2547 Return type: |Number|
2548
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002549
2550execute({command} [, {silent}]) *execute()*
2551 Execute an Ex command or commands and return the output as a
2552 string.
2553 {command} can be a string or a List. In case of a List the
2554 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002555 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002556 redir => var
2557 {command}
2558 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002559< Except that line continuation in {command} is not recognized.
2560
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002561 The optional {silent} argument can have these values:
2562 "" no `:silent` used
2563 "silent" `:silent` used
2564 "silent!" `:silent!` used
2565 The default is "silent". Note that with "silent!", unlike
2566 `:redir`, error messages are dropped. When using an external
2567 command the screen may be messed up, use `system()` instead.
2568 *E930*
2569 It is not possible to use `:redir` anywhere in {command}.
2570
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002571 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002572 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002573
2574< To execute a command in another window than the current one
2575 use `win_execute()`.
2576
2577 When used recursively the output of the recursive call is not
2578 included in the output of the higher level call.
2579
2580 Can also be used as a |method|: >
2581 GetCommand()->execute()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002582<
2583 Return type: |Number|
2584
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002585
2586exepath({expr}) *exepath()*
2587 If {expr} is an executable and is either an absolute path, a
2588 relative path or found in $PATH, return the full path.
2589 Note that the current directory is used when {expr} starts
2590 with "./", which may be a problem for Vim: >
2591 echo exepath(v:progpath)
2592< If {expr} cannot be found in $PATH or is not executable then
2593 an empty string is returned.
2594
2595 Can also be used as a |method|: >
2596 GetCommand()->exepath()
2597<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002598 Return type: |String|
2599
2600
2601exists({expr}) *exists()*
2602 The result is a Number, which is |TRUE| if {expr} is defined,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002603 zero otherwise.
2604
2605 Note: In a compiled |:def| function the evaluation is done at
2606 runtime. Use `exists_compiled()` to evaluate the expression
2607 at compile time.
2608
2609 For checking for a supported feature use |has()|.
2610 For checking if a file exists use |filereadable()|.
2611
2612 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002613 varname internal variable (see
2614 dict.key |internal-variables|). Also works
2615 list[i] for |curly-braces-names|, |Dictionary|
Yegappan Lakshmanana2ebb6e2024-02-25 08:40:10 +01002616 import.Func entries, |List| items, class and
2617 class.Func object methods, imported items, etc.
2618 object.Func Does not work for local variables in a
2619 class.varname compiled `:def` function.
2620 object.varname Also works for a function in |Vim9|
Bram Moolenaar944697a2022-02-20 19:48:20 +00002621 script, since it can be used as a
2622 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002623 Beware that evaluating an index may
2624 cause an error message for an invalid
2625 expression. E.g.: >
2626 :let l = [1, 2, 3]
2627 :echo exists("l[5]")
2628< 0 >
2629 :echo exists("l[xx]")
2630< E121: Undefined variable: xx
2631 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002632 &option-name Vim option (only checks if it exists,
2633 not if it really works)
2634 +option-name Vim option that works.
2635 $ENVNAME environment variable (could also be
2636 done by comparing with an empty
2637 string)
2638 *funcname built-in function (see |functions|)
2639 or user defined function (see
2640 |user-functions|) that is implemented.
2641 Also works for a variable that is a
2642 Funcref.
2643 ?funcname built-in function that could be
2644 implemented; to be used to check if
2645 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002646 :cmdname Ex command: built-in command, user
2647 command or command modifier |:command|.
2648 Returns:
2649 1 for match with start of a command
2650 2 full match with a command
2651 3 matches several user commands
2652 To check for a supported command
2653 always check the return value to be 2.
2654 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002655 :3match The |:3match| command (but you
2656 probably should not use it, it is
2657 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002658 #event autocommand defined for this event
2659 #event#pattern autocommand defined for this event and
2660 pattern (the pattern is taken
2661 literally and compared to the
2662 autocommand patterns character by
2663 character)
2664 #group autocommand group exists
2665 #group#event autocommand defined for this group and
2666 event.
2667 #group#event#pattern
2668 autocommand defined for this group,
2669 event and pattern.
2670 ##event autocommand for this event is
2671 supported.
2672
2673 Examples: >
2674 exists("&shortname")
2675 exists("$HOSTNAME")
2676 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002677 exists("*s:MyFunc") " only for legacy script
2678 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002679 exists("bufcount")
2680 exists(":Make")
2681 exists("#CursorHold")
2682 exists("#BufReadPre#*.gz")
2683 exists("#filetypeindent")
2684 exists("#filetypeindent#FileType")
2685 exists("#filetypeindent#FileType#*")
2686 exists("##ColorScheme")
2687< There must be no space between the symbol (&/$/*/#) and the
2688 name.
2689 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002690 a few cases this is ignored. That may become stricter in the
2691 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002692 Working example: >
2693 exists(":make")
2694< NOT working example: >
2695 exists(":make install")
2696
2697< Note that the argument must be a string, not the name of the
2698 variable itself. For example: >
2699 exists(bufcount)
2700< This doesn't check for existence of the "bufcount" variable,
2701 but gets the value of "bufcount", and checks if that exists.
2702
2703 Can also be used as a |method|: >
2704 Varname()->exists()
2705<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002706 Return type: |String|
2707
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002708
2709exists_compiled({expr}) *exists_compiled()*
2710 Like `exists()` but evaluated at compile time. This is useful
2711 to skip a block where a function is used that would otherwise
2712 give an error: >
2713 if exists_compiled('*ThatFunction')
2714 ThatFunction('works')
2715 endif
2716< If `exists()` were used then a compilation error would be
2717 given if ThatFunction() is not defined.
2718
2719 {expr} must be a literal string. *E1232*
2720 Can only be used in a |:def| function. *E1233*
2721 This does not work to check for arguments or local variables.
2722
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002723 Return type: |String|
2724
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002725
2726exp({expr}) *exp()*
2727 Return the exponential of {expr} as a |Float| in the range
2728 [0, inf].
2729 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002730 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002731 Examples: >
2732 :echo exp(2)
2733< 7.389056 >
2734 :echo exp(-1)
2735< 0.367879
2736
2737 Can also be used as a |method|: >
2738 Compute()->exp()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002739<
2740 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002741
2742
2743expand({string} [, {nosuf} [, {list}]]) *expand()*
2744 Expand wildcards and the following special keywords in
2745 {string}. 'wildignorecase' applies.
2746
2747 If {list} is given and it is |TRUE|, a List will be returned.
2748 Otherwise the result is a String and when there are several
2749 matches, they are separated by <NL> characters. [Note: in
2750 version 5.0 a space was used, which caused problems when a
2751 file name contains a space]
2752
2753 If the expansion fails, the result is an empty string. A name
2754 for a non-existing file is not included, unless {string} does
2755 not start with '%', '#' or '<', see below.
2756
Christian Brabandtec9c3262024-02-21 20:40:05 +01002757 For a |:terminal| window '%' expands to a '!' followed by
h-east53753f62024-05-05 18:42:31 +02002758 the command or shell that is run. |terminal-bufname|
Christian Brabandtec9c3262024-02-21 20:40:05 +01002759
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002760 When {string} starts with '%', '#' or '<', the expansion is
2761 done like for the |cmdline-special| variables with their
2762 associated modifiers. Here is a short overview:
2763
2764 % current file name
2765 # alternate file name
2766 #n alternate file name n
2767 <cfile> file name under the cursor
2768 <afile> autocmd file name
2769 <abuf> autocmd buffer number (as a String!)
2770 <amatch> autocmd matched name
2771 <cexpr> C expression under the cursor
2772 <sfile> sourced script file or function name
2773 <slnum> sourced script line number or function
2774 line number
2775 <sflnum> script file line number, also when in
2776 a function
2777 <SID> "<SNR>123_" where "123" is the
2778 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002779 <script> sourced script file, or script file
2780 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002781 <stack> call stack
2782 <cword> word under the cursor
2783 <cWORD> WORD under the cursor
2784 <client> the {clientid} of the last received
2785 message |server2client()|
2786 Modifiers:
2787 :p expand to full path
2788 :h head (last path component removed)
2789 :t tail (last path component only)
2790 :r root (one extension removed)
2791 :e extension only
2792
2793 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002794 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002795< Note that when expanding a string that starts with '%', '#' or
2796 '<', any following text is ignored. This does NOT work: >
2797 :let doesntwork = expand("%:h.bak")
2798< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002799 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002800< Also note that expanding "<cfile>" and others only returns the
2801 referenced file name without further expansion. If "<cfile>"
2802 is "~/.cshrc", you need to do another expand() to have the
2803 "~/" expanded into the path of the home directory: >
2804 :echo expand(expand("<cfile>"))
2805<
2806 There cannot be white space between the variables and the
2807 following modifier. The |fnamemodify()| function can be used
2808 to modify normal file names.
2809
2810 When using '%' or '#', and the current or alternate file name
2811 is not defined, an empty string is used. Using "%:p" in a
2812 buffer with no name, results in the current directory, with a
2813 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002814 When 'verbose' is set then expanding '%', '#' and <> items
2815 will result in an error message if the argument cannot be
2816 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002817
2818 When {string} does not start with '%', '#' or '<', it is
2819 expanded like a file name is expanded on the command line.
2820 'suffixes' and 'wildignore' are used, unless the optional
2821 {nosuf} argument is given and it is |TRUE|.
2822 Names for non-existing files are included. The "**" item can
2823 be used to search in a directory tree. For example, to find
2824 all "README" files in the current directory and below: >
2825 :echo expand("**/README")
2826<
2827 expand() can also be used to expand variables and environment
2828 variables that are only known in a shell. But this can be
2829 slow, because a shell may be used to do the expansion. See
2830 |expr-env-expand|.
2831 The expanded variable is still handled like a list of file
2832 names. When an environment variable cannot be expanded, it is
2833 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2834 "$FOOBAR".
2835
2836 See |glob()| for finding existing files. See |system()| for
2837 getting the raw output of an external command.
2838
2839 Can also be used as a |method|: >
2840 Getpattern()->expand()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002841<
2842 Return type: |String| or list<string> depending on {list}
2843
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002844
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002845expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002846 Expand special items in String {string} like what is done for
2847 an Ex command such as `:edit`. This expands special keywords,
2848 like with |expand()|, and environment variables, anywhere in
2849 {string}. "~user" and "~/path" are only expanded at the
2850 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002851
2852 The following items are supported in the {options} Dict
2853 argument:
2854 errmsg If set to TRUE, error messages are displayed
2855 if an error is encountered during expansion.
2856 By default, error messages are not displayed.
2857
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002858 Returns the expanded string. If an error is encountered
2859 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002860
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002861 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002862 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002863 make /path/runtime/doc/builtin.o
2864 :echo expandcmd('make %<.o', {'errmsg': v:true})
2865<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002866 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002867 GetCommand()->expandcmd()
2868<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002869 Return type: |String| or list<string> depending on {list}
2870
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002871extend({expr1}, {expr2} [, {expr3}]) *extend()*
2872 {expr1} and {expr2} must be both |Lists| or both
2873 |Dictionaries|.
2874
2875 If they are |Lists|: Append {expr2} to {expr1}.
2876 If {expr3} is given insert the items of {expr2} before the
2877 item with index {expr3} in {expr1}. When {expr3} is zero
2878 insert before the first item. When {expr3} is equal to
2879 len({expr1}) then {expr2} is appended.
2880 Examples: >
2881 :echo sort(extend(mylist, [7, 5]))
2882 :call extend(mylist, [2, 3], 1)
2883< When {expr1} is the same List as {expr2} then the number of
2884 items copied is equal to the original length of the List.
2885 E.g., when {expr3} is 1 you get N new copies of the first item
2886 (where N is the original length of the List).
2887 Use |add()| to concatenate one item to a list. To concatenate
2888 two lists into a new list use the + operator: >
2889 :let newlist = [1, 2, 3] + [4, 5]
2890<
2891 If they are |Dictionaries|:
2892 Add all entries from {expr2} to {expr1}.
2893 If a key exists in both {expr1} and {expr2} then {expr3} is
2894 used to decide what to do:
2895 {expr3} = "keep": keep the value of {expr1}
2896 {expr3} = "force": use the value of {expr2}
2897 {expr3} = "error": give an error message *E737*
2898 When {expr3} is omitted then "force" is assumed.
2899
2900 {expr1} is changed when {expr2} is not empty. If necessary
2901 make a copy of {expr1} first.
2902 {expr2} remains unchanged.
2903 When {expr1} is locked and {expr2} is not empty the operation
2904 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002905 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002906
2907 Can also be used as a |method|: >
2908 mylist->extend(otherlist)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002909<
2910 Return type: list<{type}> or dict<{type}> depending on {expr1}
2911 and {expr2}, in case of error: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002912
2913
2914extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
2915 Like |extend()| but instead of adding items to {expr1} a new
2916 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00002917 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002918
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002919 Return type: list<{type}> or dict<{type}> depending on {expr1}
2920 and {expr2}, in case of error: |Number|
2921
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002922
2923feedkeys({string} [, {mode}]) *feedkeys()*
2924 Characters in {string} are queued for processing as if they
2925 come from a mapping or were typed by the user.
2926
2927 By default the string is added to the end of the typeahead
2928 buffer, thus if a mapping is still being executed the
2929 characters come after them. Use the 'i' flag to insert before
2930 other characters, they will be executed next, before any
2931 characters from a mapping.
2932
2933 The function does not wait for processing of keys contained in
2934 {string}.
2935
2936 To include special keys into {string}, use double-quotes
2937 and "\..." notation |expr-quote|. For example,
2938 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
2939 feedkeys('\<CR>') pushes 5 characters.
2940 A special code that might be useful is <Ignore>, it exits the
2941 wait for a character without doing anything. *<Ignore>*
2942
2943 {mode} is a String, which can contain these character flags:
2944 'm' Remap keys. This is default. If {mode} is absent,
2945 keys are remapped.
2946 'n' Do not remap keys.
2947 't' Handle keys as if typed; otherwise they are handled as
2948 if coming from a mapping. This matters for undo,
2949 opening folds, etc.
2950 'L' Lowlevel input. Only works for Unix or when using the
2951 GUI. Keys are used as if they were coming from the
2952 terminal. Other flags are not used. *E980*
2953 When a CTRL-C interrupts and 't' is included it sets
2954 the internal "got_int" flag.
2955 'i' Insert the string instead of appending (see above).
2956 'x' Execute commands until typeahead is empty. This is
2957 similar to using ":normal!". You can call feedkeys()
2958 several times without 'x' and then one time with 'x'
2959 (possibly with an empty {string}) to execute all the
2960 typeahead. Note that when Vim ends in Insert mode it
2961 will behave as if <Esc> is typed, to avoid getting
2962 stuck, waiting for a character to be typed before the
2963 script continues.
2964 Note that if you manage to call feedkeys() while
2965 executing commands, thus calling it recursively, then
2966 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00002967 'c' Remove any script context when executing, so that
2968 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01002969 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01002970 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002971 '!' When used with 'x' will not end Insert mode. Can be
2972 used in a test when a timer is set to exit Insert mode
2973 a little later. Useful for testing CursorHoldI.
2974
2975 Return value is always 0.
2976
2977 Can also be used as a |method|: >
2978 GetInput()->feedkeys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002979<
2980 Return type: |String| or list<string> depending on {list}
2981
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002982
Shougo Matsushita60c87432024-06-03 22:59:27 +02002983filecopy({from}, {to}) *filecopy()*
2984 Copy the file pointed to by the name {from} to {to}. The
2985 result is a Number, which is |TRUE| if the file was copied
2986 successfully, and |FALSE| when it failed.
2987 If a file with name {to} already exists, it will fail.
2988 Note that it does not handle directories (yet).
2989
2990 This function is not available in the |sandbox|.
2991
2992 Can also be used as a |method|: >
2993 GetOldName()->filecopy(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002994<
2995 Return type: |Number|
2996
Shougo Matsushita60c87432024-06-03 22:59:27 +02002997
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002998filereadable({file}) *filereadable()*
2999 The result is a Number, which is |TRUE| when a file with the
3000 name {file} exists, and can be read. If {file} doesn't exist,
3001 or is a directory, the result is |FALSE|. {file} is any
3002 expression, which is used as a String.
3003 If you don't care about the file being readable you can use
3004 |glob()|.
3005 {file} is used as-is, you may want to expand wildcards first: >
3006 echo filereadable('~/.vimrc')
3007 0
3008 echo filereadable(expand('~/.vimrc'))
3009 1
3010
3011< Can also be used as a |method|: >
3012 GetName()->filereadable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003013<
3014 Return type: |Number|
3015
3016 *file_readable()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003017 Obsolete name: file_readable().
3018
3019
3020filewritable({file}) *filewritable()*
3021 The result is a Number, which is 1 when a file with the
3022 name {file} exists, and can be written. If {file} doesn't
3023 exist, or is not writable, the result is 0. If {file} is a
3024 directory, and we can write to it, the result is 2.
3025
3026 Can also be used as a |method|: >
3027 GetName()->filewritable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003028<
3029 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003030
3031
3032filter({expr1}, {expr2}) *filter()*
3033 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3034 For each item in {expr1} evaluate {expr2} and when the result
3035 is zero or false remove the item from the |List| or
3036 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003037 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003038
3039 {expr2} must be a |string| or |Funcref|.
3040
3041 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3042 of the current item. For a |Dictionary| |v:key| has the key
3043 of the current item and for a |List| |v:key| has the index of
3044 the current item. For a |Blob| |v:key| has the index of the
3045 current byte. For a |String| |v:key| has the index of the
3046 current character.
3047 Examples: >
3048 call filter(mylist, 'v:val !~ "OLD"')
3049< Removes the items where "OLD" appears. >
3050 call filter(mydict, 'v:key >= 8')
3051< Removes the items with a key below 8. >
3052 call filter(var, 0)
3053< Removes all the items, thus clears the |List| or |Dictionary|.
3054
3055 Note that {expr2} is the result of expression and is then
3056 used as an expression again. Often it is good to use a
3057 |literal-string| to avoid having to double backslashes.
3058
3059 If {expr2} is a |Funcref| it must take two arguments:
3060 1. the key or the index of the current item.
3061 2. the value of the current item.
3062 The function must return |TRUE| if the item should be kept.
3063 Example that keeps the odd items of a list: >
3064 func Odd(idx, val)
3065 return a:idx % 2 == 1
3066 endfunc
3067 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003068< It is shorter when using a |lambda|. In |Vim9| syntax: >
3069 call filter(myList, (idx, val) => idx * val <= 42)
3070< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003071 call filter(myList, {idx, val -> idx * val <= 42})
3072< If you do not use "val" you can leave it out: >
3073 call filter(myList, {idx -> idx % 2 == 1})
3074<
3075 In |Vim9| script the result must be true, false, zero or one.
3076 Other values will result in a type error.
3077
3078 For a |List| and a |Dictionary| the operation is done
3079 in-place. If you want it to remain unmodified make a copy
3080 first: >
3081 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
3082
3083< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00003084 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003085 When an error is encountered while evaluating {expr2} no
3086 further items in {expr1} are processed.
3087 When {expr2} is a Funcref errors inside a function are ignored,
3088 unless it was defined with the "abort" flag.
3089
3090 Can also be used as a |method|: >
3091 mylist->filter(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003092<
3093 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
3094 depending on {expr1}
3095
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003096
3097finddir({name} [, {path} [, {count}]]) *finddir()*
3098 Find directory {name} in {path}. Supports both downwards and
3099 upwards recursive directory searches. See |file-searching|
3100 for the syntax of {path}.
3101
3102 Returns the path of the first found match. When the found
3103 directory is below the current directory a relative path is
3104 returned. Otherwise a full path is returned.
3105 If {path} is omitted or empty then 'path' is used.
3106
3107 If the optional {count} is given, find {count}'s occurrence of
3108 {name} in {path} instead of the first one.
3109 When {count} is negative return all the matches in a |List|.
3110
Bram Moolenaar016188f2022-06-06 20:52:59 +01003111 Returns an empty string if the directory is not found.
3112
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003113 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003114
3115 Can also be used as a |method|: >
3116 GetName()->finddir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003117<
3118 Return type: |String|
3119
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003120
3121findfile({name} [, {path} [, {count}]]) *findfile()*
3122 Just like |finddir()|, but find a file instead of a directory.
3123 Uses 'suffixesadd'.
3124 Example: >
3125 :echo findfile("tags.vim", ".;")
3126< Searches from the directory of the current file upwards until
3127 it finds the file "tags.vim".
3128
3129 Can also be used as a |method|: >
3130 GetName()->findfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003131<
3132 Return type: |String|
3133
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003134
3135flatten({list} [, {maxdepth}]) *flatten()*
3136 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
3137 the result is a |List| without nesting, as if {maxdepth} is
3138 a very large number.
3139 The {list} is changed in place, use |flattennew()| if you do
3140 not want that.
3141 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00003142 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003143 *E900*
3144 {maxdepth} means how deep in nested lists changes are made.
3145 {list} is not modified when {maxdepth} is 0.
3146 {maxdepth} must be positive number.
3147
3148 If there is an error the number zero is returned.
3149
3150 Example: >
3151 :echo flatten([1, [2, [3, 4]], 5])
3152< [1, 2, 3, 4, 5] >
3153 :echo flatten([1, [2, [3, 4]], 5], 1)
3154< [1, 2, [3, 4], 5]
3155
3156 Can also be used as a |method|: >
3157 mylist->flatten()
3158<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003159 Return type: list<{type}>
3160
3161
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003162flattennew({list} [, {maxdepth}]) *flattennew()*
3163 Like |flatten()| but first make a copy of {list}.
3164
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003165 Return type: list<{type}>
3166
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003167
3168float2nr({expr}) *float2nr()*
3169 Convert {expr} to a Number by omitting the part after the
3170 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00003171 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003172 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003173 When the value of {expr} is out of range for a |Number| the
3174 result is truncated to 0x7fffffff or -0x7fffffff (or when
3175 64-bit Number support is enabled, 0x7fffffffffffffff or
3176 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
3177 64-bit Number support is enabled, -0x8000000000000000).
3178 Examples: >
3179 echo float2nr(3.95)
3180< 3 >
3181 echo float2nr(-23.45)
3182< -23 >
3183 echo float2nr(1.0e100)
3184< 2147483647 (or 9223372036854775807) >
3185 echo float2nr(-1.0e150)
3186< -2147483647 (or -9223372036854775807) >
3187 echo float2nr(1.0e-100)
3188< 0
3189
3190 Can also be used as a |method|: >
3191 Compute()->float2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003192<
3193 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003194
3195
3196floor({expr}) *floor()*
3197 Return the largest integral value less than or equal to
3198 {expr} as a |Float| (round down).
3199 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003200 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003201 Examples: >
3202 echo floor(1.856)
3203< 1.0 >
3204 echo floor(-5.456)
3205< -6.0 >
3206 echo floor(4.0)
3207< 4.0
3208
3209 Can also be used as a |method|: >
3210 Compute()->floor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003211<
3212 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003213
3214
3215fmod({expr1}, {expr2}) *fmod()*
3216 Return the remainder of {expr1} / {expr2}, even if the
3217 division is not representable. Returns {expr1} - i * {expr2}
3218 for some integer i such that if {expr2} is non-zero, the
3219 result has the same sign as {expr1} and magnitude less than
3220 the magnitude of {expr2}. If {expr2} is zero, the value
3221 returned is zero. The value returned is a |Float|.
3222 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003223 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
3224 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003225 Examples: >
3226 :echo fmod(12.33, 1.22)
3227< 0.13 >
3228 :echo fmod(-12.33, 1.22)
3229< -0.13
3230
3231 Can also be used as a |method|: >
3232 Compute()->fmod(1.22)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003233<
3234 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003235
3236
3237fnameescape({string}) *fnameescape()*
3238 Escape {string} for use as file name command argument. All
3239 characters that have a special meaning, such as '%' and '|'
3240 are escaped with a backslash.
3241 For most systems the characters escaped are
3242 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3243 appears in a filename, it depends on the value of 'isfname'.
3244 A leading '+' and '>' is also escaped (special after |:edit|
3245 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01003246 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003247 Example: >
3248 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003249 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003250< results in executing: >
3251 edit \+some\ str\%nge\|name
3252<
3253 Can also be used as a |method|: >
3254 GetName()->fnameescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003255<
3256 Return type: |String|
3257
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003258
3259fnamemodify({fname}, {mods}) *fnamemodify()*
3260 Modify file name {fname} according to {mods}. {mods} is a
3261 string of characters like it is used for file names on the
3262 command line. See |filename-modifiers|.
3263 Example: >
3264 :echo fnamemodify("main.c", ":p:h")
3265< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01003266 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01003267< If {mods} is empty or an unsupported modifier is used then
3268 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01003269 When {fname} is empty then with {mods} ":h" returns ".", so
3270 that `:cd` can be used with it. This is different from
3271 expand('%:h') without a buffer name, which returns an empty
3272 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003273 Note: Environment variables don't work in {fname}, use
3274 |expand()| first then.
3275
3276 Can also be used as a |method|: >
3277 GetName()->fnamemodify(':p:h')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003278<
3279 Return type: |String|
3280
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003281
3282foldclosed({lnum}) *foldclosed()*
3283 The result is a Number. If the line {lnum} is in a closed
3284 fold, the result is the number of the first line in that fold.
3285 If the line {lnum} is not in a closed fold, -1 is returned.
3286 {lnum} is used like with |getline()|. Thus "." is the current
3287 line, "'m" mark m, etc.
3288
3289 Can also be used as a |method|: >
3290 GetLnum()->foldclosed()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003291<
3292 Return type: |Number|
3293
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003294
3295foldclosedend({lnum}) *foldclosedend()*
3296 The result is a Number. If the line {lnum} is in a closed
3297 fold, the result is the number of the last line in that fold.
3298 If the line {lnum} is not in a closed fold, -1 is returned.
3299 {lnum} is used like with |getline()|. Thus "." is the current
3300 line, "'m" mark m, etc.
3301
3302 Can also be used as a |method|: >
3303 GetLnum()->foldclosedend()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003304<
3305 Return type: |Number|
3306
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003307
3308foldlevel({lnum}) *foldlevel()*
3309 The result is a Number, which is the foldlevel of line {lnum}
3310 in the current buffer. For nested folds the deepest level is
3311 returned. If there is no fold at line {lnum}, zero is
3312 returned. It doesn't matter if the folds are open or closed.
3313 When used while updating folds (from 'foldexpr') -1 is
3314 returned for lines where folds are still to be updated and the
3315 foldlevel is unknown. As a special case the level of the
3316 previous line is usually available.
3317 {lnum} is used like with |getline()|. Thus "." is the current
3318 line, "'m" mark m, etc.
3319
3320 Can also be used as a |method|: >
3321 GetLnum()->foldlevel()
3322<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003323 Return type: |Number|
3324
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003325 *foldtext()*
3326foldtext() Returns a String, to be displayed for a closed fold. This is
3327 the default function used for the 'foldtext' option and should
3328 only be called from evaluating 'foldtext'. It uses the
3329 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3330 The returned string looks like this: >
3331 +-- 45 lines: abcdef
3332< The number of leading dashes depends on the foldlevel. The
3333 "45" is the number of lines in the fold. "abcdef" is the text
3334 in the first non-blank line of the fold. Leading white space,
3335 "//" or "/*" and the text from the 'foldmarker' and
3336 'commentstring' options is removed.
3337 When used to draw the actual foldtext, the rest of the line
3338 will be filled with the fold char from the 'fillchars'
3339 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003340 Returns an empty string when there is no fold.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003341
3342 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003343 {not available when compiled without the |+folding| feature}
3344
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003345
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003346foldtextresult({lnum}) *foldtextresult()*
3347 Returns the text that is displayed for the closed fold at line
3348 {lnum}. Evaluates 'foldtext' in the appropriate context.
3349 When there is no closed fold at {lnum} an empty string is
3350 returned.
3351 {lnum} is used like with |getline()|. Thus "." is the current
3352 line, "'m" mark m, etc.
3353 Useful when exporting folded text, e.g., to HTML.
3354 {not available when compiled without the |+folding| feature}
3355
3356
3357 Can also be used as a |method|: >
3358 GetLnum()->foldtextresult()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003359<
3360 Return type: |String|
3361
Ernie Raele79e2072024-01-13 11:47:33 +01003362
3363foreach({expr1}, {expr2}) *foreach()*
3364 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3365 For each item in {expr1} execute {expr2}. {expr1} is not
erraelc92b8be2024-01-14 10:11:07 -08003366 modified; its values may be, as with |:lockvar| 1. |E741|
Ernie Raele79e2072024-01-13 11:47:33 +01003367 See |map()| and |filter()| to modify {expr1}.
3368
3369 {expr2} must be a |string| or |Funcref|.
3370
3371 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3372 of the current item. For a |Dictionary| |v:key| has the key
3373 of the current item and for a |List| |v:key| has the index of
3374 the current item. For a |Blob| |v:key| has the index of the
3375 current byte. For a |String| |v:key| has the index of the
3376 current character.
3377 Examples: >
3378 call foreach(mylist, 'used[v:val] = true')
3379< This records the items that are in the {expr1} list.
3380
3381 Note that {expr2} is the result of expression and is then used
3382 as a command. Often it is good to use a |literal-string| to
3383 avoid having to double backslashes.
3384
3385 If {expr2} is a |Funcref| it must take two arguments:
3386 1. the key or the index of the current item.
3387 2. the value of the current item.
3388 With a legacy script lambda you don't get an error if it only
3389 accepts one argument, but with a Vim9 lambda you get "E1106:
3390 One argument too many", the number of arguments must match.
3391 If the function returns a value, it is ignored.
3392
3393 Returns {expr1} in all cases.
3394 When an error is encountered while executing {expr2} no
3395 further items in {expr1} are processed.
3396 When {expr2} is a Funcref errors inside a function are ignored,
3397 unless it was defined with the "abort" flag.
3398
3399 Can also be used as a |method|: >
3400 mylist->foreach(expr2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003401<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003402 Return type: |String|, |Blob| list<{type}> or dict<{type}>
3403 depending on {expr1}
3404
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003405 *foreground()*
3406foreground() Move the Vim window to the foreground. Useful when sent from
3407 a client to a Vim server. |remote_send()|
3408 On Win32 systems this might not work, the OS does not always
3409 allow a window to bring itself to the foreground. Use
3410 |remote_foreground()| instead.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003411
3412 Return type: |Number|
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003413 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003414 Win32 console version}
3415
Bram Moolenaaraa534142022-09-15 21:46:02 +01003416fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003417 Get the full command name from a short abbreviated command
3418 name; see |20.2| for details on command abbreviations.
3419
3420 The string argument {name} may start with a `:` and can
3421 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003422 Returns an empty string if a command doesn't exist, if it's
3423 ambiguous (for user-defined commands) or cannot be shortened
3424 this way. |vim9-no-shorten|
3425
3426 Without the {vim9} argument uses the current script version.
3427 If {vim9} is present and FALSE then legacy script rules are
3428 used. When {vim9} is present and TRUE then Vim9 rules are
3429 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003430
3431 For example `fullcommand('s')`, `fullcommand('sub')`,
3432 `fullcommand(':%substitute')` all return "substitute".
3433
3434 Can also be used as a |method|: >
3435 GetName()->fullcommand()
3436<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003437 Return type: |String|
3438
3439
3440funcref({name} [, {arglist}] [, {dict}]) *funcref()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003441 Just like |function()|, but the returned Funcref will lookup
3442 the function by reference, not by name. This matters when the
3443 function {name} is redefined later.
3444
3445 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003446 It only works for an autoloaded function if it has already
3447 been loaded (to avoid mistakenly loading the autoload script
3448 when only intending to use the function name, use |function()|
3449 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003450 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003451
3452 Can also be used as a |method|: >
3453 GetFuncname()->funcref([arg])
3454<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003455 Return type: func(...): any or |Number| on error
3456
Dominique Pellee764d1b2023-03-12 21:20:59 +00003457 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003458function({name} [, {arglist}] [, {dict}])
3459 Return a |Funcref| variable that refers to function {name}.
3460 {name} can be the name of a user defined function or an
3461 internal function.
3462
3463 {name} can also be a Funcref or a partial. When it is a
3464 partial the dict stored in it will be used and the {dict}
3465 argument is not allowed. E.g.: >
3466 let FuncWithArg = function(dict.Func, [arg])
3467 let Broken = function(dict.Func, [arg], dict)
3468<
3469 When using the Funcref the function will be found by {name},
3470 also when it was redefined later. Use |funcref()| to keep the
3471 same function.
3472
3473 When {arglist} or {dict} is present this creates a partial.
3474 That means the argument list and/or the dictionary is stored in
3475 the Funcref and will be used when the Funcref is called.
3476
3477 The arguments are passed to the function in front of other
3478 arguments, but after any argument from |method|. Example: >
3479 func Callback(arg1, arg2, name)
3480 ...
3481 let Partial = function('Callback', ['one', 'two'])
3482 ...
3483 call Partial('name')
3484< Invokes the function as with: >
3485 call Callback('one', 'two', 'name')
3486
3487< With a |method|: >
3488 func Callback(one, two, three)
3489 ...
3490 let Partial = function('Callback', ['two'])
3491 ...
3492 eval 'one'->Partial('three')
3493< Invokes the function as with: >
3494 call Callback('one', 'two', 'three')
3495
3496< The function() call can be nested to add more arguments to the
3497 Funcref. The extra arguments are appended to the list of
3498 arguments. Example: >
3499 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003500 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003501 let Func = function('Callback', ['one'])
3502 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003503 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003504 call Func2('name')
3505< Invokes the function as with: >
3506 call Callback('one', 'two', 'name')
3507
3508< The Dictionary is only useful when calling a "dict" function.
3509 In that case the {dict} is passed in as "self". Example: >
3510 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003511 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003512 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003513 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003514 let context = {"name": "example"}
3515 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003516 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003517 call Func() " will echo: called for example
3518< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003519 arguments, these two are equivalent, if Callback() is defined
3520 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003521 let Func = function('Callback', context)
3522 let Func = context.Callback
3523
3524< The argument list and the Dictionary can be combined: >
3525 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003526 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003527 let context = {"name": "example"}
3528 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003529 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003530 call Func(500)
3531< Invokes the function as with: >
3532 call context.Callback('one', 500)
3533<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003534 Returns 0 on error.
3535
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003536 Can also be used as a |method|: >
3537 GetFuncname()->function([arg])
3538
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003539<
3540 Return type: func(...): any or |Number| on error
3541
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003542
3543garbagecollect([{atexit}]) *garbagecollect()*
3544 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3545 that have circular references.
3546
3547 There is hardly ever a need to invoke this function, as it is
3548 automatically done when Vim runs out of memory or is waiting
3549 for the user to press a key after 'updatetime'. Items without
3550 circular references are always freed when they become unused.
3551 This is useful if you have deleted a very big |List| and/or
3552 |Dictionary| with circular references in a script that runs
3553 for a long time.
3554
3555 When the optional {atexit} argument is one, garbage
3556 collection will also be done when exiting Vim, if it wasn't
3557 done before. This is useful when checking for memory leaks.
3558
3559 The garbage collection is not done immediately but only when
3560 it's safe to perform. This is when waiting for the user to
3561 type a character. To force garbage collection immediately use
3562 |test_garbagecollect_now()|.
3563
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003564 Return type: |String|
3565
3566
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003567get({list}, {idx} [, {default}]) *get()*
3568 Get item {idx} from |List| {list}. When this item is not
3569 available return {default}. Return zero when {default} is
3570 omitted.
3571 Preferably used as a |method|: >
3572 mylist->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003573<
3574 Return type: any, depending on {list}
3575
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003576get({blob}, {idx} [, {default}])
3577 Get byte {idx} from |Blob| {blob}. When this byte is not
3578 available return {default}. Return -1 when {default} is
3579 omitted.
3580 Preferably used as a |method|: >
3581 myblob->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003582<
3583 Return type: |Number|
3584
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003585get({dict}, {key} [, {default}])
3586 Get item with key {key} from |Dictionary| {dict}. When this
3587 item is not available return {default}. Return zero when
3588 {default} is omitted. Useful example: >
3589 let val = get(g:, 'var_name', 'default')
3590< This gets the value of g:var_name if it exists, and uses
3591 'default' when it does not exist.
3592 Preferably used as a |method|: >
3593 mydict->get(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003594<
h-east84ac2122024-06-17 18:12:30 +02003595 Return type: any, depending on {dict}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003596
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003597get({func}, {what})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00003598 Get item {what} from Funcref {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003599 {what} are:
3600 "name" The function name
3601 "func" The function
3602 "dict" The dictionary
3603 "args" The list with arguments
Bram Moolenaar016188f2022-06-06 20:52:59 +01003604 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003605 Preferably used as a |method|: >
3606 myfunc->get(what)
3607<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003608 Return type: any, depending on {func}
3609
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003610 *getbufinfo()*
3611getbufinfo([{buf}])
3612getbufinfo([{dict}])
3613 Get information about buffers as a List of Dictionaries.
3614
3615 Without an argument information about all the buffers is
3616 returned.
3617
3618 When the argument is a |Dictionary| only the buffers matching
3619 the specified criteria are returned. The following keys can
3620 be specified in {dict}:
3621 buflisted include only listed buffers.
3622 bufloaded include only loaded buffers.
3623 bufmodified include only modified buffers.
3624
3625 Otherwise, {buf} specifies a particular buffer to return
3626 information for. For the use of {buf}, see |bufname()|
3627 above. If the buffer is found the returned List has one item.
3628 Otherwise the result is an empty list.
3629
3630 Each returned List item is a dictionary with the following
3631 entries:
3632 bufnr Buffer number.
3633 changed TRUE if the buffer is modified.
3634 changedtick Number of changes made to the buffer.
Sean Dewar1fb41032023-08-16 17:15:05 +01003635 command TRUE if the buffer belongs to the
3636 command-line window |cmdwin|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003637 hidden TRUE if the buffer is hidden.
3638 lastused Timestamp in seconds, like
3639 |localtime()|, when the buffer was
3640 last used.
3641 {only with the |+viminfo| feature}
3642 listed TRUE if the buffer is listed.
3643 lnum Line number used for the buffer when
3644 opened in the current window.
3645 Only valid if the buffer has been
3646 displayed in the window in the past.
3647 If you want the line number of the
3648 last known cursor position in a given
3649 window, use |line()|: >
3650 :echo line('.', {winid})
3651<
3652 linecount Number of lines in the buffer (only
3653 valid when loaded)
3654 loaded TRUE if the buffer is loaded.
3655 name Full path to the file in the buffer.
3656 signs List of signs placed in the buffer.
3657 Each list item is a dictionary with
3658 the following fields:
3659 id sign identifier
3660 lnum line number
3661 name sign name
3662 variables A reference to the dictionary with
3663 buffer-local variables.
3664 windows List of |window-ID|s that display this
3665 buffer
3666 popups List of popup |window-ID|s that
3667 display this buffer
3668
3669 Examples: >
3670 for buf in getbufinfo()
3671 echo buf.name
3672 endfor
3673 for buf in getbufinfo({'buflisted':1})
3674 if buf.changed
3675 ....
3676 endif
3677 endfor
3678<
3679 To get buffer-local options use: >
3680 getbufvar({bufnr}, '&option_name')
3681<
3682 Can also be used as a |method|: >
3683 GetBufnr()->getbufinfo()
3684<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003685 Return type: list<dict<any>>
3686
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003687
3688 *getbufline()*
3689getbufline({buf}, {lnum} [, {end}])
3690 Return a |List| with the lines starting from {lnum} to {end}
3691 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003692 |List| with only the line {lnum} is returned. See
3693 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003694
3695 For the use of {buf}, see |bufname()| above.
3696
3697 For {lnum} and {end} "$" can be used for the last line of the
3698 buffer. Otherwise a number must be used.
3699
3700 When {lnum} is smaller than 1 or bigger than the number of
3701 lines in the buffer, an empty |List| is returned.
3702
3703 When {end} is greater than the number of lines in the buffer,
3704 it is treated as {end} is set to the number of lines in the
3705 buffer. When {end} is before {lnum} an empty |List| is
3706 returned.
3707
3708 This function works only for loaded buffers. For unloaded and
3709 non-existing buffers, an empty |List| is returned.
3710
3711 Example: >
3712 :let lines = getbufline(bufnr("myfile"), 1, "$")
3713
3714< Can also be used as a |method|: >
3715 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003716<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003717 Return type: list<string>
3718
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003719 *getbufoneline()*
3720getbufoneline({buf}, {lnum})
3721 Just like `getbufline()` but only get one line and return it
3722 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003723
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003724 Return type: |String|
3725
3726
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003727getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3728 The result is the value of option or local buffer variable
3729 {varname} in buffer {buf}. Note that the name without "b:"
3730 must be used.
3731 The {varname} argument is a string.
3732 When {varname} is empty returns a |Dictionary| with all the
3733 buffer-local variables.
3734 When {varname} is equal to "&" returns a |Dictionary| with all
3735 the buffer-local options.
3736 Otherwise, when {varname} starts with "&" returns the value of
3737 a buffer-local option.
3738 This also works for a global or buffer-local option, but it
3739 doesn't work for a global variable, window-local variable or
3740 window-local option.
3741 For the use of {buf}, see |bufname()| above.
3742 When the buffer or variable doesn't exist {def} or an empty
3743 string is returned, there is no error message.
3744 Examples: >
3745 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003746 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003747
3748< Can also be used as a |method|: >
3749 GetBufnr()->getbufvar(varname)
3750<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003751 Return type: any, depending on {varname}
3752
3753
Kota Kato66bb9ae2023-01-17 18:31:56 +00003754getcellwidths() *getcellwidths()*
3755 Returns a |List| of cell widths of character ranges overridden
3756 by |setcellwidths()|. The format is equal to the argument of
3757 |setcellwidths()|. If no character ranges have their cell
3758 widths overridden, an empty List is returned.
h-east84ac2122024-06-17 18:12:30 +02003759
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003760 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003761
3762
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003763getchangelist([{buf}]) *getchangelist()*
3764 Returns the |changelist| for the buffer {buf}. For the use
3765 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3766 exist, an empty list is returned.
3767
3768 The returned list contains two entries: a list with the change
3769 locations and the current position in the list. Each
3770 entry in the change list is a dictionary with the following
3771 entries:
3772 col column number
3773 coladd column offset for 'virtualedit'
3774 lnum line number
3775 If buffer {buf} is the current buffer, then the current
3776 position refers to the position in the list. For other
3777 buffers, it is set to the length of the list.
3778
3779 Can also be used as a |method|: >
3780 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003781<
3782 Return type: list<any>
3783
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003784
Doug Kearns9cd9e752024-04-07 17:42:17 +02003785getchar([{expr}]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003786 Get a single character from the user or input stream.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003787 If {expr} is omitted, wait until a character is available.
3788 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003789 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003790 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003791 not consumed. Return zero if no character available.
3792 If you prefer always getting a string use |getcharstr()|.
3793
Doug Kearns9cd9e752024-04-07 17:42:17 +02003794 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003795 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003796 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003797 Otherwise a String is returned with the encoded character.
3798 For a special key it's a String with a sequence of bytes
3799 starting with 0x80 (decimal: 128). This is the same value as
3800 the String "\<Key>", e.g., "\<Left>". The returned value is
3801 also a String when a modifier (shift, control, alt) was used
3802 that is not included in the character.
3803
Doug Kearns9cd9e752024-04-07 17:42:17 +02003804 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003805 while Vim waits to see if this is the start of an escape
3806 sequence.
3807
Doug Kearns9cd9e752024-04-07 17:42:17 +02003808 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003809 one-byte character it is the character itself as a number.
3810 Use nr2char() to convert it to a String.
3811
3812 Use getcharmod() to obtain any additional modifiers.
3813
3814 When the user clicks a mouse button, the mouse event will be
3815 returned. The position can then be found in |v:mouse_col|,
3816 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3817 |getmousepos()| can also be used. Mouse move events will be
3818 ignored.
3819 This example positions the mouse as it would normally happen: >
3820 let c = getchar()
3821 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003822 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003823 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003824 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003825 endif
3826<
3827 When using bracketed paste only the first character is
3828 returned, the rest of the pasted text is dropped.
3829 |xterm-bracketed-paste|.
3830
3831 There is no prompt, you will somehow have to make clear to the
3832 user that a character has to be typed. The screen is not
3833 redrawn, e.g. when resizing the window. When using a popup
3834 window it should work better with a |popup-filter|.
3835
3836 There is no mapping for the character.
3837 Key codes are replaced, thus when the user presses the <Del>
3838 key you get the code for the <Del> key, not the raw character
3839 sequence. Examples: >
3840 getchar() == "\<Del>"
3841 getchar() == "\<S-Left>"
3842< This example redefines "f" to ignore case: >
3843 :nmap f :call FindChar()<CR>
3844 :function FindChar()
3845 : let c = nr2char(getchar())
3846 : while col('.') < col('$') - 1
3847 : normal l
3848 : if getline('.')[col('.') - 1] ==? c
3849 : break
3850 : endif
3851 : endwhile
3852 :endfunction
3853<
3854 You may also receive synthetic characters, such as
3855 |<CursorHold>|. Often you will want to ignore this and get
3856 another character: >
3857 :function GetKey()
3858 : let c = getchar()
3859 : while c == "\<CursorHold>"
3860 : let c = getchar()
3861 : endwhile
3862 : return c
3863 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003864<
3865 Return type: |Number| or |String|
3866
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003867
3868getcharmod() *getcharmod()*
3869 The result is a Number which is the state of the modifiers for
3870 the last obtained character with getchar() or in another way.
3871 These values are added together:
3872 2 shift
3873 4 control
3874 8 alt (meta)
3875 16 meta (when it's different from ALT)
3876 32 mouse double click
3877 64 mouse triple click
3878 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01003879 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003880 Only the modifiers that have not been included in the
3881 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01003882 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003883
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003884 Return type: |Number|
3885
3886
3887getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003888 Get the position for String {expr}. Same as |getpos()| but the
3889 column number in the returned List is a character index
3890 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00003891 If |getpos()| returns a very large column number, equal to
3892 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003893 of the last character.
3894
3895 Example:
3896 With the cursor on '세' in line 5 with text "여보세요": >
3897 getcharpos('.') returns [0, 5, 3, 0]
3898 getpos('.') returns [0, 5, 7, 0]
3899<
3900 Can also be used as a |method|: >
3901 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003902<
3903 Return type: list<number>
3904
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003905
3906getcharsearch() *getcharsearch()*
3907 Return the current character search information as a {dict}
3908 with the following entries:
3909
3910 char character previously used for a character
3911 search (|t|, |f|, |T|, or |F|); empty string
3912 if no character search has been performed
3913 forward direction of character search; 1 for forward,
3914 0 for backward
3915 until type of character search; 1 for a |t| or |T|
3916 character search, 0 for an |f| or |F|
3917 character search
3918
3919 This can be useful to always have |;| and |,| search
3920 forward/backward regardless of the direction of the previous
3921 character search: >
3922 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
3923 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
3924< Also see |setcharsearch()|.
3925
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003926 Return type: dict<any>
3927
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003928
Doug Kearns9cd9e752024-04-07 17:42:17 +02003929getcharstr([{expr}]) *getcharstr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003930 Get a single character from the user or input stream as a
3931 string.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003932 If {expr} is omitted, wait until a character is available.
3933 If {expr} is 0 or false, only get a character when one is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003934 available. Return an empty string otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003935 If {expr} is 1 or true, only check if a character is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003936 available, it is not consumed. Return an empty string
3937 if no character is available.
3938 Otherwise this works like |getchar()|, except that a number
3939 result is converted to a string.
3940
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003941 Return type: |String|
3942
3943
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003944getcmdcompltype() *getcmdcompltype()*
3945 Return the type of the current command-line completion.
3946 Only works when the command line is being edited, thus
3947 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01003948 See |:command-completion| for the return string.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003949 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
3950 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003951 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003952
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003953 Return type: |String|
3954
3955
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003956getcmdline() *getcmdline()*
3957 Return the current command-line. Only works when the command
3958 line is being edited, thus requires use of |c_CTRL-\_e| or
3959 |c_CTRL-R_=|.
3960 Example: >
3961 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003962< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()| and
3963 |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003964 Returns an empty string when entering a password or using
3965 |inputsecret()|.
3966
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003967 Return type: |String|
3968
3969
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003970getcmdpos() *getcmdpos()*
3971 Return the position of the cursor in the command line as a
3972 byte count. The first column is 1.
3973 Only works when editing the command line, thus requires use of
3974 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3975 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003976 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
3977 |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003978
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003979 Return type: |Number|
3980
3981
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003982getcmdscreenpos() *getcmdscreenpos()*
3983 Return the screen position of the cursor in the command line
3984 as a byte count. The first column is 1.
3985 Instead of |getcmdpos()|, it adds the prompt position.
3986 Only works when editing the command line, thus requires use of
3987 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3988 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003989 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
3990 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003991
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003992 Return type: |Number|
3993
3994
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003995getcmdtype() *getcmdtype()*
3996 Return the current command-line type. Possible return values
3997 are:
3998 : normal Ex command
3999 > debug mode command |debug-mode|
4000 / forward search command
4001 ? backward search command
4002 @ |input()| command
4003 - |:insert| or |:append| command
4004 = |i_CTRL-R_=|
4005 Only works when editing the command line, thus requires use of
4006 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4007 Returns an empty string otherwise.
4008 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4009
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004010 Return type: |String|
4011
4012
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004013getcmdwintype() *getcmdwintype()*
4014 Return the current |command-line-window| type. Possible return
4015 values are the same as |getcmdtype()|. Returns an empty string
4016 when not in the command-line window.
4017
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004018 Return type: |String|
4019
4020
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004021getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4022 Return a list of command-line completion matches. The String
4023 {type} argument specifies what for. The following completion
4024 types are supported:
4025
4026 arglist file names in argument list
4027 augroup autocmd groups
4028 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004029 behave |:behave| suboptions
4030 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004031 color color schemes
4032 command Ex command
4033 cmdline |cmdline-completion| result
4034 compiler compilers
4035 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004036 custom,{func} custom completion, defined via {func}
4037 customlist,{func} custom completion, defined via {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004038 diff_buffer |:diffget| and |:diffput| completion
4039 dir directory names
4040 environment environment variable names
4041 event autocommand events
4042 expression Vim expression
4043 file file and directory names
4044 file_in_path file and directory names in |'path'|
4045 filetype filetype names |'filetype'|
4046 function function name
4047 help help subjects
4048 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004049 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004050 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004051 locale locale names (as output of locale -a)
4052 mapclear buffer argument
4053 mapping mapping name
4054 menu menus
4055 messages |:messages| suboptions
4056 option options
4057 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004058 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004059 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004060 shellcmd Shell command
4061 sign |:sign| suboptions
4062 syntax syntax file names |'syntax'|
4063 syntime |:syntime| suboptions
4064 tag tags
4065 tag_listfiles tags, file names
4066 user user names
4067 var user variables
4068
4069 If {pat} is an empty string, then all the matches are
4070 returned. Otherwise only items matching {pat} are returned.
4071 See |wildcards| for the use of special characters in {pat}.
4072
4073 If the optional {filtered} flag is set to 1, then 'wildignore'
4074 is applied to filter the results. Otherwise all the matches
4075 are returned. The 'wildignorecase' option always applies.
4076
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004077 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4078 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004079 regular expression matching is used. Thus this function
4080 follows the user preference, what happens on the command line.
4081 If you do not want this you can make 'wildoptions' empty
4082 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004083
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004084 If {type} is "cmdline", then the |cmdline-completion| result is
4085 returned. For example, to complete the possible values after
4086 a ":call" command: >
4087 echo getcompletion('call ', 'cmdline')
4088<
4089 If there are no matches, an empty list is returned. An
4090 invalid value for {type} produces an error.
4091
4092 Can also be used as a |method|: >
4093 GetPattern()->getcompletion('color')
4094<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004095 Return type: list<string>
4096
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004097 *getcurpos()*
4098getcurpos([{winid}])
4099 Get the position of the cursor. This is like getpos('.'), but
4100 includes an extra "curswant" item in the list:
4101 [0, lnum, col, off, curswant] ~
4102 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004103 cursor vertically. After |$| command it will be a very large
4104 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004105 |getpos()|.
4106 The first "bufnum" item is always zero. The byte position of
4107 the cursor is returned in 'col'. To get the character
4108 position, use |getcursorcharpos()|.
4109
4110 The optional {winid} argument can specify the window. It can
4111 be the window number or the |window-ID|. The last known
4112 cursor position is returned, this may be invalid for the
4113 current value of the buffer if it is not the current window.
4114 If {winid} is invalid a list with zeroes is returned.
4115
4116 This can be used to save and restore the cursor position: >
4117 let save_cursor = getcurpos()
4118 MoveTheCursorAround
4119 call setpos('.', save_cursor)
4120< Note that this only works within the window. See
4121 |winrestview()| for restoring more state.
4122
4123 Can also be used as a |method|: >
4124 GetWinid()->getcurpos()
4125<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004126 Return type: list<number>
4127
4128
4129getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004130 Same as |getcurpos()| but the column number in the returned
4131 List is a character index instead of a byte index.
4132
4133 Example:
4134 With the cursor on '보' in line 3 with text "여보세요": >
4135 getcursorcharpos() returns [0, 3, 2, 0, 3]
4136 getcurpos() returns [0, 3, 4, 0, 3]
4137<
4138 Can also be used as a |method|: >
4139 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004140<
4141 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004142
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004143
4144getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004145 The result is a String, which is the name of the current
4146 working directory. 'autochdir' is ignored.
4147
4148 With {winnr} return the local current directory of this window
4149 in the current tab page. {winnr} can be the window number or
4150 the |window-ID|.
4151 If {winnr} is -1 return the name of the global working
4152 directory. See also |haslocaldir()|.
4153
4154 With {winnr} and {tabnr} return the local current directory of
4155 the window in the specified tab page. If {winnr} is -1 return
4156 the working directory of the tabpage.
4157 If {winnr} is zero use the current window, if {tabnr} is zero
4158 use the current tabpage.
4159 Without any arguments, return the actual working directory of
4160 the current window.
4161 Return an empty string if the arguments are invalid.
4162
4163 Examples: >
4164 " Get the working directory of the current window
4165 :echo getcwd()
4166 :echo getcwd(0)
4167 :echo getcwd(0, 0)
4168 " Get the working directory of window 3 in tabpage 2
4169 :echo getcwd(3, 2)
4170 " Get the global working directory
4171 :echo getcwd(-1)
4172 " Get the working directory of tabpage 3
4173 :echo getcwd(-1, 3)
4174 " Get the working directory of current tabpage
4175 :echo getcwd(-1, 0)
4176
4177< Can also be used as a |method|: >
4178 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004179<
4180 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004181
4182getenv({name}) *getenv()*
4183 Return the value of environment variable {name}. The {name}
4184 argument is a string, without a leading '$'. Example: >
4185 myHome = getenv('HOME')
4186
4187< When the variable does not exist |v:null| is returned. That
4188 is different from a variable set to an empty string, although
4189 some systems interpret the empty value as the variable being
4190 deleted. See also |expr-env|.
4191
4192 Can also be used as a |method|: >
4193 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004194<
4195 Return type: |String| or |Number|
4196
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004197
4198getfontname([{name}]) *getfontname()*
4199 Without an argument returns the name of the normal font being
4200 used. Like what is used for the Normal highlight group
4201 |hl-Normal|.
4202 With an argument a check is done whether String {name} is a
4203 valid font name. If not then an empty string is returned.
4204 Otherwise the actual font name is returned, or {name} if the
4205 GUI does not support obtaining the real name.
4206 Only works when the GUI is running, thus not in your vimrc or
4207 gvimrc file. Use the |GUIEnter| autocommand to use this
4208 function just after the GUI has started.
4209 Note that the GTK GUI accepts any font name, thus checking for
4210 a valid name does not work.
4211
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004212 Return type: |String|
4213
4214
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004215getfperm({fname}) *getfperm()*
4216 The result is a String, which is the read, write, and execute
4217 permissions of the given file {fname}.
4218 If {fname} does not exist or its directory cannot be read, an
4219 empty string is returned.
4220 The result is of the form "rwxrwxrwx", where each group of
4221 "rwx" flags represent, in turn, the permissions of the owner
4222 of the file, the group the file belongs to, and other users.
4223 If a user does not have a given permission the flag for this
4224 is replaced with the string "-". Examples: >
4225 :echo getfperm("/etc/passwd")
4226 :echo getfperm(expand("~/.vimrc"))
4227< This will hopefully (from a security point of view) display
4228 the string "rw-r--r--" or even "rw-------".
4229
4230 Can also be used as a |method|: >
4231 GetFilename()->getfperm()
4232<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004233 Return type: |String|
4234
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004235 For setting permissions use |setfperm()|.
4236
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004237
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004238getfsize({fname}) *getfsize()*
4239 The result is a Number, which is the size in bytes of the
4240 given file {fname}.
4241 If {fname} is a directory, 0 is returned.
4242 If the file {fname} can't be found, -1 is returned.
4243 If the size of {fname} is too big to fit in a Number then -2
4244 is returned.
4245
4246 Can also be used as a |method|: >
4247 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004248<
4249 Return type: |Number|
4250
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004251
4252getftime({fname}) *getftime()*
4253 The result is a Number, which is the last modification time of
4254 the given file {fname}. The value is measured as seconds
4255 since 1st Jan 1970, and may be passed to strftime(). See also
4256 |localtime()| and |strftime()|.
4257 If the file {fname} can't be found -1 is returned.
4258
4259 Can also be used as a |method|: >
4260 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004261<
4262 Return type: |Number|
4263
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004264
4265getftype({fname}) *getftype()*
4266 The result is a String, which is a description of the kind of
4267 file of the given file {fname}.
4268 If {fname} does not exist an empty string is returned.
4269 Here is a table over different kinds of files and their
4270 results:
4271 Normal file "file"
4272 Directory "dir"
4273 Symbolic link "link"
4274 Block device "bdev"
4275 Character device "cdev"
4276 Socket "socket"
4277 FIFO "fifo"
4278 All other "other"
4279 Example: >
4280 getftype("/home")
4281< Note that a type such as "link" will only be returned on
4282 systems that support it. On some systems only "dir" and
4283 "file" are returned. On MS-Windows a symbolic link to a
4284 directory returns "dir" instead of "link".
4285
4286 Can also be used as a |method|: >
4287 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004288<
4289 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004290
4291getimstatus() *getimstatus()*
4292 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004293 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004294 See 'imstatusfunc'.
4295
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004296 Return type: |Number|
4297
4298
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004299getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4300 Returns the |jumplist| for the specified window.
4301
4302 Without arguments use the current window.
4303 With {winnr} only use this window in the current tab page.
4304 {winnr} can also be a |window-ID|.
4305 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004306 page. If {winnr} or {tabnr} is invalid, an empty list is
4307 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004308
4309 The returned list contains two entries: a list with the jump
4310 locations and the last used jump position number in the list.
4311 Each entry in the jump location list is a dictionary with
4312 the following entries:
4313 bufnr buffer number
4314 col column number
4315 coladd column offset for 'virtualedit'
4316 filename filename if available
4317 lnum line number
4318
4319 Can also be used as a |method|: >
4320 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004321<
4322 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004323
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004324 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004325getline({lnum} [, {end}])
4326 Without {end} the result is a String, which is line {lnum}
4327 from the current buffer. Example: >
4328 getline(1)
4329< When {lnum} is a String that doesn't start with a
4330 digit, |line()| is called to translate the String into a Number.
4331 To get the line under the cursor: >
4332 getline(".")
4333< When {lnum} is a number smaller than 1 or bigger than the
4334 number of lines in the buffer, an empty string is returned.
4335
4336 When {end} is given the result is a |List| where each item is
4337 a line from the current buffer in the range {lnum} to {end},
4338 including line {end}.
4339 {end} is used in the same way as {lnum}.
4340 Non-existing lines are silently omitted.
4341 When {end} is before {lnum} an empty |List| is returned.
4342 Example: >
4343 :let start = line('.')
4344 :let end = search("^$") - 1
4345 :let lines = getline(start, end)
4346
4347< Can also be used as a |method|: >
4348 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004349<
4350 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004351
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004352 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004353 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004354
4355getloclist({nr} [, {what}]) *getloclist()*
4356 Returns a |List| with all the entries in the location list for
4357 window {nr}. {nr} can be the window number or the |window-ID|.
4358 When {nr} is zero the current window is used.
4359
4360 For a location list window, the displayed location list is
4361 returned. For an invalid window number {nr}, an empty list is
4362 returned. Otherwise, same as |getqflist()|.
4363
4364 If the optional {what} dictionary argument is supplied, then
4365 returns the items listed in {what} as a dictionary. Refer to
4366 |getqflist()| for the supported items in {what}.
4367
4368 In addition to the items supported by |getqflist()| in {what},
4369 the following item is supported by |getloclist()|:
4370
4371 filewinid id of the window used to display files
4372 from the location list. This field is
4373 applicable only when called from a
4374 location list window. See
4375 |location-list-file-window| for more
4376 details.
4377
4378 Returns a |Dictionary| with default values if there is no
4379 location list for the window {nr}.
4380 Returns an empty Dictionary if window {nr} does not exist.
4381
4382 Examples (See also |getqflist-examples|): >
4383 :echo getloclist(3, {'all': 0})
4384 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004385<
4386 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004387
4388
4389getmarklist([{buf}]) *getmarklist()*
4390 Without the {buf} argument returns a |List| with information
4391 about all the global marks. |mark|
4392
4393 If the optional {buf} argument is specified, returns the
4394 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004395 see |bufname()|. If {buf} is invalid, an empty list is
4396 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004397
4398 Each item in the returned List is a |Dict| with the following:
4399 mark name of the mark prefixed by "'"
4400 pos a |List| with the position of the mark:
4401 [bufnum, lnum, col, off]
4402 Refer to |getpos()| for more information.
4403 file file name
4404
4405 Refer to |getpos()| for getting information about a specific
4406 mark.
4407
4408 Can also be used as a |method|: >
4409 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004410<
4411 Return type: list<dict<any>> or list<any>
4412
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004413
4414getmatches([{win}]) *getmatches()*
4415 Returns a |List| with all matches previously defined for the
4416 current window by |matchadd()| and the |:match| commands.
4417 |getmatches()| is useful in combination with |setmatches()|,
4418 as |setmatches()| can restore a list of matches saved by
4419 |getmatches()|.
4420 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004421 window ID instead of the current window. If {win} is invalid,
4422 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004423 Example: >
4424 :echo getmatches()
4425< [{'group': 'MyGroup1', 'pattern': 'TODO',
4426 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4427 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4428 :let m = getmatches()
4429 :call clearmatches()
4430 :echo getmatches()
4431< [] >
4432 :call setmatches(m)
4433 :echo getmatches()
4434< [{'group': 'MyGroup1', 'pattern': 'TODO',
4435 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4436 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4437 :unlet m
4438<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004439 Return type: list<dict<any>> or list<any>
4440
4441
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004442getmousepos() *getmousepos()*
4443 Returns a |Dictionary| with the last known position of the
4444 mouse. This can be used in a mapping for a mouse click or in
4445 a filter of a popup window. The items are:
4446 screenrow screen row
4447 screencol screen column
4448 winid Window ID of the click
4449 winrow row inside "winid"
4450 wincol column inside "winid"
4451 line text line inside "winid"
4452 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004453 coladd offset (in screen columns) from the
4454 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004455 All numbers are 1-based.
4456
4457 If not over a window, e.g. when in the command line, then only
4458 "screenrow" and "screencol" are valid, the others are zero.
4459
4460 When on the status line below a window or the vertical
4461 separator right of a window, the "line" and "column" values
4462 are zero.
4463
4464 When the position is after the text then "column" is the
4465 length of the text in bytes plus one.
4466
4467 If the mouse is over a popup window then that window is used.
4468
4469 When using |getchar()| the Vim variables |v:mouse_lnum|,
4470 |v:mouse_col| and |v:mouse_winid| also provide these values.
4471
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004472 Return type: dict<number>
4473
4474
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004475getmouseshape() *getmouseshape()*
4476 Returns the name of the currently showing mouse pointer.
4477 When the |+mouseshape| feature is not supported or the shape
4478 is unknown an empty string is returned.
4479 This function is mainly intended for testing.
4480
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004481 Return type: |String|
4482
4483
4484getpid() *getpid()*
4485 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004486 On Unix and MS-Windows this is a unique number, until Vim
4487 exits.
4488
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004489 Return type: |Number|
4490
4491
4492getpos({expr}) *getpos()*
zeertzjq02f3eba2024-06-12 20:45:24 +02004493 Get the position for String {expr}.
4494 The accepted values for {expr} are: *E1209*
4495 . The cursor position.
4496 $ The last line in the current buffer.
4497 'x Position of mark x (if the mark is not set, 0 is
zeertzjqd353d272024-06-13 23:00:25 +08004498 returned for all values).
zeertzjq02f3eba2024-06-12 20:45:24 +02004499 w0 First line visible in current window (one if the
4500 display isn't updated, e.g. in silent Ex mode).
4501 w$ Last line visible in current window (this is one
4502 less than "w0" if no lines are visible).
4503 v When not in Visual mode, returns the cursor
4504 position. In Visual mode, returns the other end
4505 of the Visual area. A good way to think about
4506 this is that in Visual mode "v" and "." complement
4507 each other. While "." refers to the cursor
4508 position, "v" refers to where |v_o| would move the
4509 cursor. As a result, you can use "v" and "."
4510 together to work on all of a selection in
4511 characterwise Visual mode. If the cursor is at
4512 the end of a characterwise Visual area, "v" refers
4513 to the start of the same Visual area. And if the
4514 cursor is at the start of a characterwise Visual
4515 area, "v" refers to the end of the same Visual
4516 area. "v" differs from |'<| and |'>| in that it's
4517 updated right away.
4518 Note that a mark in another file can be used. The line number
4519 then applies to another buffer.
4520
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004521 The result is a |List| with four numbers:
4522 [bufnum, lnum, col, off]
4523 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4524 is the buffer number of the mark.
4525 "lnum" and "col" are the position in the buffer. The first
4526 column is 1.
4527 The "off" number is zero, unless 'virtualedit' is used. Then
4528 it is the offset in screen columns from the start of the
4529 character. E.g., a position within a <Tab> or after the last
4530 character.
zeertzjq02f3eba2024-06-12 20:45:24 +02004531
4532 For getting the cursor position see |getcurpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004533 The column number in the returned List is the byte position
4534 within the line. To get the character position in the line,
4535 use |getcharpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02004536
4537 Note that for '< and '> Visual mode matters: when it is "V"
4538 (visual line mode) the column of '< is zero and the column of
4539 '> is a large number equal to |v:maxcol|.
naohiro ono56200ee2022-01-01 14:59:44 +00004540 A very large column number equal to |v:maxcol| can be returned,
4541 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004542 If {expr} is invalid, returns a list with all zeros.
zeertzjq02f3eba2024-06-12 20:45:24 +02004543
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004544 This can be used to save and restore the position of a mark: >
4545 let save_a_mark = getpos("'a")
4546 ...
4547 call setpos("'a", save_a_mark)
zeertzjqd353d272024-06-13 23:00:25 +08004548<
4549 Also see |getcharpos()|, |getcurpos()| and |setpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004550
4551 Can also be used as a |method|: >
4552 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004553<
4554 Return type: list<number>
4555
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004556
4557getqflist([{what}]) *getqflist()*
4558 Returns a |List| with all the current quickfix errors. Each
4559 list item is a dictionary with these entries:
4560 bufnr number of buffer that has the file name, use
4561 bufname() to get the name
4562 module module name
4563 lnum line number in the buffer (first line is 1)
4564 end_lnum
4565 end of line number if the item is multiline
4566 col column number (first column is 1)
4567 end_col end of column number if the item has range
4568 vcol |TRUE|: "col" is visual column
4569 |FALSE|: "col" is byte index
4570 nr error number
h-east84ac2122024-06-17 18:12:30 +02004571 pattern search pattern used to locate the error
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004572 text description of the error
4573 type type of the error, 'E', '1', etc.
4574 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004575 user_data
4576 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004577 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004578
4579 When there is no error list or it's empty, an empty list is
4580 returned. Quickfix list entries with a non-existing buffer
4581 number are returned with "bufnr" set to zero (Note: some
4582 functions accept buffer number zero for the alternate buffer,
4583 you may need to explicitly check for zero).
4584
4585 Useful application: Find pattern matches in multiple files and
4586 do something with them: >
4587 :vimgrep /theword/jg *.c
4588 :for d in getqflist()
4589 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4590 :endfor
4591<
4592 If the optional {what} dictionary argument is supplied, then
4593 returns only the items listed in {what} as a dictionary. The
4594 following string items are supported in {what}:
4595 changedtick get the total number of changes made
4596 to the list |quickfix-changedtick|
4597 context get the |quickfix-context|
4598 efm errorformat to use when parsing "lines". If
4599 not present, then the 'errorformat' option
4600 value is used.
4601 id get information for the quickfix list with
4602 |quickfix-ID|; zero means the id for the
4603 current list or the list specified by "nr"
4604 idx get information for the quickfix entry at this
4605 index in the list specified by 'id' or 'nr'.
4606 If set to zero, then uses the current entry.
4607 See |quickfix-index|
4608 items quickfix list entries
4609 lines parse a list of lines using 'efm' and return
4610 the resulting entries. Only a |List| type is
4611 accepted. The current quickfix list is not
4612 modified. See |quickfix-parse|.
4613 nr get information for this quickfix list; zero
4614 means the current quickfix list and "$" means
4615 the last quickfix list
4616 qfbufnr number of the buffer displayed in the quickfix
4617 window. Returns 0 if the quickfix buffer is
4618 not present. See |quickfix-buffer|.
4619 size number of entries in the quickfix list
4620 title get the list title |quickfix-title|
4621 winid get the quickfix |window-ID|
4622 all all of the above quickfix properties
4623 Non-string items in {what} are ignored. To get the value of a
4624 particular item, set it to zero.
4625 If "nr" is not present then the current quickfix list is used.
4626 If both "nr" and a non-zero "id" are specified, then the list
4627 specified by "id" is used.
4628 To get the number of lists in the quickfix stack, set "nr" to
4629 "$" in {what}. The "nr" value in the returned dictionary
4630 contains the quickfix stack size.
4631 When "lines" is specified, all the other items except "efm"
4632 are ignored. The returned dictionary contains the entry
4633 "items" with the list of entries.
4634
4635 The returned dictionary contains the following entries:
4636 changedtick total number of changes made to the
4637 list |quickfix-changedtick|
4638 context quickfix list context. See |quickfix-context|
4639 If not present, set to "".
4640 id quickfix list ID |quickfix-ID|. If not
4641 present, set to 0.
4642 idx index of the quickfix entry in the list. If not
4643 present, set to 0.
4644 items quickfix list entries. If not present, set to
4645 an empty list.
4646 nr quickfix list number. If not present, set to 0
4647 qfbufnr number of the buffer displayed in the quickfix
4648 window. If not present, set to 0.
4649 size number of entries in the quickfix list. If not
4650 present, set to 0.
4651 title quickfix list title text. If not present, set
4652 to "".
4653 winid quickfix |window-ID|. If not present, set to 0
4654
4655 Examples (See also |getqflist-examples|): >
4656 :echo getqflist({'all': 1})
4657 :echo getqflist({'nr': 2, 'title': 1})
4658 :echo getqflist({'lines' : ["F1:10:L10"]})
4659<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004660 Return type: list<dict<any>> or list<any>
4661
4662
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004663getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4664 The result is a String, which is the contents of register
4665 {regname}. Example: >
4666 :let cliptext = getreg('*')
4667< When register {regname} was not set the result is an empty
4668 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004669 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004670
4671 getreg('=') returns the last evaluated value of the expression
4672 register. (For use in maps.)
4673 getreg('=', 1) returns the expression itself, so that it can
4674 be restored with |setreg()|. For other registers the extra
4675 argument is ignored, thus you can always give it.
4676
4677 If {list} is present and |TRUE|, the result type is changed
4678 to |List|. Each list item is one text line. Use it if you care
4679 about zero bytes possibly present inside register: without
4680 third argument both NLs and zero bytes are represented as NLs
4681 (see |NL-used-for-Nul|).
4682 When the register was not set an empty list is returned.
4683
4684 If {regname} is "", the unnamed register '"' is used.
4685 If {regname} is not specified, |v:register| is used.
4686 In |Vim9-script| {regname} must be one character.
4687
4688 Can also be used as a |method|: >
4689 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004690<
4691 Return type: |String|
4692
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004693
4694getreginfo([{regname}]) *getreginfo()*
4695 Returns detailed information about register {regname} as a
4696 Dictionary with the following entries:
4697 regcontents List of lines contained in register
4698 {regname}, like
4699 |getreg|({regname}, 1, 1).
4700 regtype the type of register {regname}, as in
4701 |getregtype()|.
4702 isunnamed Boolean flag, v:true if this register
4703 is currently pointed to by the unnamed
4704 register.
4705 points_to for the unnamed register, gives the
4706 single letter name of the register
4707 currently pointed to (see |quotequote|).
4708 For example, after deleting a line
4709 with `dd`, this field will be "1",
4710 which is the register that got the
4711 deleted text.
4712
4713 The {regname} argument is a string. If {regname} is invalid
4714 or not set, an empty Dictionary will be returned.
4715 If {regname} is "" or "@", the unnamed register '"' is used.
4716 If {regname} is not specified, |v:register| is used.
4717 The returned Dictionary can be passed to |setreg()|.
4718 In |Vim9-script| {regname} must be one character.
4719
4720 Can also be used as a |method|: >
4721 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004722<
4723 Return type: dict<any>
4724
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004725
Shougo Matsushita19b71882024-02-28 22:48:12 +01004726getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004727 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01004728 buffer.
4729
4730 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004731 See |getpos()| for the format of the list. It's possible
4732 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01004733 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01004734
4735 The optional argument {opts} is a Dict and supports the
4736 following items:
4737
zeertzjqafc22952024-05-24 19:07:12 +02004738 type Specify the region's selection type.
4739 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02004740 except that the width can be omitted
4741 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02004742 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01004743
zeertzjq87410ab2024-03-02 06:00:23 +08004744 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02004745 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08004746 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01004747
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004748 You can get the last selection type by |visualmode()|.
4749 If Visual mode is active, use |mode()| to get the Visual mode
4750 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08004751 This function is useful to get text starting and ending in
4752 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004753
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004754 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004755 Note that:
4756 - Order of {pos1} and {pos2} doesn't matter, it will always
4757 return content from the upper left position to the lower
4758 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08004759 - If 'virtualedit' is enabled and the region is past the end
4760 of the lines, resulting lines are padded with spaces.
4761 - If the region is blockwise and it starts or ends in the
4762 middle of a multi-cell character, it is not included but
4763 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004764 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01004765 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004766 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01004767 - It is evaluated in current window context, which makes a
4768 difference if the buffer is displayed in a window with
4769 different 'virtualedit' or 'list' values.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004770
4771 Examples: >
4772 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01004773 \ <Cmd>echow getregion(
4774 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004775<
4776 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01004777 getpos('.')->getregion(getpos("'a"))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004778
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004779<
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004780getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
4781 Same as |getregion()|, but returns a list of positions
4782 describing the buffer text segments bound by {pos1} and
4783 {pos2}.
4784 The segments are a pair of positions for every line: >
4785 [[{start_pos}, {end_pos}], ...]
4786<
4787 The position is a |List| with four numbers:
4788 [bufnum, lnum, col, off]
4789 "bufnum" is the buffer number.
4790 "lnum" and "col" are the position in the buffer. The first
4791 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02004792 If the "off" number of a starting position is non-zero, it is
4793 the offset in screen columns from the start of the character.
4794 E.g., a position within a <Tab> or after the last character.
4795 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02004796 the offset of the character's first cell not included in the
4797 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004798
zeertzjq2b09de92024-05-24 07:48:51 +02004799 Apart from the options supported by |getregion()|, {opts} also
4800 supports the following:
4801
4802 eol If |TRUE|, indicate positions beyond
4803 the end of a line with "col" values
4804 one more than the length of the line.
4805 If |FALSE|, positions are limited
4806 within their lines, and if a line is
4807 empty or the selection is entirely
4808 beyond the end of a line, a "col"
4809 value of 0 is used for both positions.
4810 (default: |FALSE|)
4811
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004812 Can also be used as a |method|: >
4813 getpos('.')->getregionpos(getpos("'a"))
4814<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004815 Return type: list<string>
4816
4817
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004818getregtype([{regname}]) *getregtype()*
4819 The result is a String, which is type of register {regname}.
4820 The value will be one of:
4821 "v" for |characterwise| text
4822 "V" for |linewise| text
4823 "<CTRL-V>{width}" for |blockwise-visual| text
4824 "" for an empty or unknown register
4825 <CTRL-V> is one character with value 0x16.
4826 The {regname} argument is a string. If {regname} is "", the
4827 unnamed register '"' is used. If {regname} is not specified,
4828 |v:register| is used.
4829 In |Vim9-script| {regname} must be one character.
4830
4831 Can also be used as a |method|: >
4832 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004833<
4834 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004835
Bram Moolenaar71badf92023-04-22 22:40:14 +01004836getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004837 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01004838 scripts in the order they were sourced, like what
4839 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004840
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004841 The optional Dict argument {opts} supports the following
4842 optional items:
4843 name Script name match pattern. If specified,
4844 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01004845 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004846 "name" are returned.
4847 sid Script ID |<SID>|. If specified, only
4848 information about the script with ID "sid" is
4849 returned and "name" is ignored.
4850
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004851 Each item in the returned List is a |Dict| with the following
4852 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004853 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01004854 `import autoload` but was not actually sourced
4855 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004856 functions List of script-local function names defined in
4857 the script. Present only when a particular
4858 script is specified using the "sid" item in
4859 {opts}.
4860 name Vim script file name.
4861 sid Script ID |<SID>|.
4862 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01004863 this script name links to, if any, otherwise
4864 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004865 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00004866 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004867 specified using the "sid" item in {opts}.
4868 Note that this is a copy, the value of
4869 script-local variables cannot be changed using
4870 this dictionary.
h_east59858792023-10-25 22:47:05 +09004871 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01004872
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004873 Examples: >
4874 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08004875 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004876<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004877 Return type: list<dict<any>>
4878
4879
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004880gettabinfo([{tabnr}]) *gettabinfo()*
4881 If {tabnr} is not specified, then information about all the
4882 tab pages is returned as a |List|. Each List item is a
4883 |Dictionary|. Otherwise, {tabnr} specifies the tab page
4884 number and information about that one is returned. If the tab
4885 page does not exist an empty List is returned.
4886
4887 Each List item is a |Dictionary| with the following entries:
4888 tabnr tab page number.
4889 variables a reference to the dictionary with
4890 tabpage-local variables
4891 windows List of |window-ID|s in the tab page.
4892
4893 Can also be used as a |method|: >
4894 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004895<
4896 Return type: list<dict<any>>
4897
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004898
4899gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
4900 Get the value of a tab-local variable {varname} in tab page
4901 {tabnr}. |t:var|
4902 Tabs are numbered starting with one.
4903 The {varname} argument is a string. When {varname} is empty a
4904 dictionary with all tab-local variables is returned.
4905 Note that the name without "t:" must be used.
4906 When the tab or variable doesn't exist {def} or an empty
4907 string is returned, there is no error message.
4908
4909 Can also be used as a |method|: >
4910 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004911<
4912 Return type: any, depending on {varname}
4913
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004914
4915gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
4916 Get the value of window-local variable {varname} in window
4917 {winnr} in tab page {tabnr}.
4918 The {varname} argument is a string. When {varname} is empty a
4919 dictionary with all window-local variables is returned.
4920 When {varname} is equal to "&" get the values of all
4921 window-local options in a |Dictionary|.
4922 Otherwise, when {varname} starts with "&" get the value of a
4923 window-local option.
4924 Note that {varname} must be the name without "w:".
4925 Tabs are numbered starting with one. For the current tabpage
4926 use |getwinvar()|.
4927 {winnr} can be the window number or the |window-ID|.
4928 When {winnr} is zero the current window is used.
4929 This also works for a global option, buffer-local option and
4930 window-local option, but it doesn't work for a global variable
4931 or buffer-local variable.
4932 When the tab, window or variable doesn't exist {def} or an
4933 empty string is returned, there is no error message.
4934 Examples: >
4935 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004936 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004937<
4938 To obtain all window-local variables use: >
4939 gettabwinvar({tabnr}, {winnr}, '&')
4940
4941< Can also be used as a |method|: >
4942 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004943<
4944 Return type: any, depending on {varname}
4945
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004946
4947gettagstack([{winnr}]) *gettagstack()*
4948 The result is a Dict, which is the tag stack of window {winnr}.
4949 {winnr} can be the window number or the |window-ID|.
4950 When {winnr} is not specified, the current window is used.
4951 When window {winnr} doesn't exist, an empty Dict is returned.
4952
4953 The returned dictionary contains the following entries:
4954 curidx Current index in the stack. When at
4955 top of the stack, set to (length + 1).
4956 Index of bottom of the stack is 1.
4957 items List of items in the stack. Each item
4958 is a dictionary containing the
4959 entries described below.
4960 length Number of entries in the stack.
4961
4962 Each item in the stack is a dictionary with the following
4963 entries:
4964 bufnr buffer number of the current jump
4965 from cursor position before the tag jump.
4966 See |getpos()| for the format of the
4967 returned list.
4968 matchnr current matching tag number. Used when
4969 multiple matching tags are found for a
4970 name.
4971 tagname name of the tag
4972
4973 See |tagstack| for more information about the tag stack.
4974
4975 Can also be used as a |method|: >
4976 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004977<
4978 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004979
4980
4981gettext({text}) *gettext()*
4982 Translate String {text} if possible.
4983 This is mainly for use in the distributed Vim scripts. When
4984 generating message translations the {text} is extracted by
4985 xgettext, the translator can add the translated message in the
4986 .po file and Vim will lookup the translation when gettext() is
4987 called.
4988 For {text} double quoted strings are preferred, because
4989 xgettext does not understand escaping in single quoted
4990 strings.
4991
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004992 Return type: |String|
4993
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004994
4995getwininfo([{winid}]) *getwininfo()*
4996 Returns information about windows as a |List| with Dictionaries.
4997
4998 If {winid} is given Information about the window with that ID
4999 is returned, as a |List| with one item. If the window does not
5000 exist the result is an empty list.
5001
5002 Without {winid} information about all the windows in all the
5003 tab pages is returned.
5004
5005 Each List item is a |Dictionary| with the following entries:
5006 botline last complete displayed buffer line
5007 bufnr number of buffer in the window
5008 height window height (excluding winbar)
5009 loclist 1 if showing a location list
5010 {only with the +quickfix feature}
5011 quickfix 1 if quickfix or location list window
5012 {only with the +quickfix feature}
5013 terminal 1 if a terminal window
5014 {only with the +terminal feature}
5015 tabnr tab page number
5016 topline first displayed buffer line
5017 variables a reference to the dictionary with
5018 window-local variables
5019 width window width
5020 winbar 1 if the window has a toolbar, 0
5021 otherwise
5022 wincol leftmost screen column of the window;
5023 "col" from |win_screenpos()|
5024 textoff number of columns occupied by any
5025 'foldcolumn', 'signcolumn' and line
5026 number in front of the text
5027 winid |window-ID|
5028 winnr window number
5029 winrow topmost screen line of the window;
5030 "row" from |win_screenpos()|
5031
5032 Can also be used as a |method|: >
5033 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005034<
5035 Return type: list<dict<any>>
5036
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005037
5038getwinpos([{timeout}]) *getwinpos()*
5039 The result is a |List| with two numbers, the result of
5040 |getwinposx()| and |getwinposy()| combined:
5041 [x-pos, y-pos]
5042 {timeout} can be used to specify how long to wait in msec for
5043 a response from the terminal. When omitted 100 msec is used.
5044 Use a longer time for a remote terminal.
5045 When using a value less than 10 and no response is received
5046 within that time, a previously reported position is returned,
5047 if available. This can be used to poll for the position and
5048 do some work in the meantime: >
5049 while 1
5050 let res = getwinpos(1)
5051 if res[0] >= 0
5052 break
5053 endif
5054 " Do some work here
5055 endwhile
5056<
5057
5058 Can also be used as a |method|: >
5059 GetTimeout()->getwinpos()
5060<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005061 Return type: list<number>
5062
5063
5064getwinposx() *getwinposx()*
5065 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005066 the left hand side of the GUI Vim window. Also works for an
5067 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005068 The result will be -1 if the information is not available
5069 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005070 The value can be used with `:winpos`.
5071
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005072 Return type: |Number|
5073
5074
5075getwinposy() *getwinposy()*
5076 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005077 the top of the GUI Vim window. Also works for an xterm (uses
5078 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005079 The result will be -1 if the information is not available
5080 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005081 The value can be used with `:winpos`.
5082
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005083 Return type: |Number|
5084
5085
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005086getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5087 Like |gettabwinvar()| for the current tabpage.
5088 Examples: >
5089 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005090 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005091
5092< Can also be used as a |method|: >
5093 GetWinnr()->getwinvar(varname)
5094<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005095 Return type: any, depending on {varname}
5096
5097
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005098glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5099 Expand the file wildcards in {expr}. See |wildcards| for the
5100 use of special characters.
5101
5102 Unless the optional {nosuf} argument is given and is |TRUE|,
5103 the 'suffixes' and 'wildignore' options apply: Names matching
5104 one of the patterns in 'wildignore' will be skipped and
5105 'suffixes' affect the ordering of matches.
5106 'wildignorecase' always applies.
5107
5108 When {list} is present and it is |TRUE| the result is a |List|
5109 with all matching files. The advantage of using a List is,
5110 you also get filenames containing newlines correctly.
5111 Otherwise the result is a String and when there are several
5112 matches, they are separated by <NL> characters.
5113
5114 If the expansion fails, the result is an empty String or List.
5115
5116 You can also use |readdir()| if you need to do complicated
5117 things, such as limiting the number of matches.
5118
5119 A name for a non-existing file is not included. A symbolic
5120 link is only included if it points to an existing file.
5121 However, when the {alllinks} argument is present and it is
5122 |TRUE| then all symbolic links are included.
5123
5124 For most systems backticks can be used to get files names from
5125 any external command. Example: >
5126 :let tagfiles = glob("`find . -name tags -print`")
5127 :let &tags = substitute(tagfiles, "\n", ",", "g")
5128< The result of the program inside the backticks should be one
5129 item per line. Spaces inside an item are allowed.
5130
5131 See |expand()| for expanding special Vim variables. See
5132 |system()| for getting the raw output of an external command.
5133
5134 Can also be used as a |method|: >
5135 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005136<
5137 Return type: |String| or list<string> or list<any> depending
5138 on {list}
5139
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005140
5141glob2regpat({string}) *glob2regpat()*
5142 Convert a file pattern, as used by glob(), into a search
5143 pattern. The result can be used to match with a string that
5144 is a file name. E.g. >
5145 if filename =~ glob2regpat('Make*.mak')
5146< This is equivalent to: >
5147 if filename =~ '^Make.*\.mak$'
5148< When {string} is an empty string the result is "^$", match an
5149 empty string.
5150 Note that the result depends on the system. On MS-Windows
5151 a backslash usually means a path separator.
5152
5153 Can also be used as a |method|: >
5154 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005155<
5156 Return type: |String|
5157
5158 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005159globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5160 Perform glob() for String {expr} on all directories in {path}
5161 and concatenate the results. Example: >
5162 :echo globpath(&rtp, "syntax/c.vim")
5163<
5164 {path} is a comma-separated list of directory names. Each
5165 directory name is prepended to {expr} and expanded like with
5166 |glob()|. A path separator is inserted when needed.
5167 To add a comma inside a directory name escape it with a
5168 backslash. Note that on MS-Windows a directory may have a
5169 trailing backslash, remove it if you put a comma after it.
5170 If the expansion fails for one of the directories, there is no
5171 error message.
5172
5173 Unless the optional {nosuf} argument is given and is |TRUE|,
5174 the 'suffixes' and 'wildignore' options apply: Names matching
5175 one of the patterns in 'wildignore' will be skipped and
5176 'suffixes' affect the ordering of matches.
5177
5178 When {list} is present and it is |TRUE| the result is a |List|
5179 with all matching files. The advantage of using a List is, you
5180 also get filenames containing newlines correctly. Otherwise
5181 the result is a String and when there are several matches,
5182 they are separated by <NL> characters. Example: >
5183 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5184<
5185 {alllinks} is used as with |glob()|.
5186
5187 The "**" item can be used to search in a directory tree.
5188 For example, to find all "README.txt" files in the directories
5189 in 'runtimepath' and below: >
5190 :echo globpath(&rtp, "**/README.txt")
5191< Upwards search and limiting the depth of "**" is not
5192 supported, thus using 'path' will not always work properly.
5193
5194 Can also be used as a |method|, the base is passed as the
5195 second argument: >
5196 GetExpr()->globpath(&rtp)
5197<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005198 Return type: |String| or list<string> or list<any> depending
5199 on {list}
5200
5201
5202has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005203 When {check} is omitted or is zero: The result is a Number,
5204 which is 1 if the feature {feature} is supported, zero
5205 otherwise. The {feature} argument is a string, case is
5206 ignored. See |feature-list| below.
5207
5208 When {check} is present and not zero: The result is a Number,
5209 which is 1 if the feature {feature} could ever be supported,
5210 zero otherwise. This is useful to check for a typo in
5211 {feature} and to detect dead code. Keep in mind that an older
5212 Vim version will not know about a feature added later and
5213 features that have been abandoned will not be known by the
5214 current Vim version.
5215
5216 Also see |exists()| and |exists_compiled()|.
5217
5218 Note that to skip code that has a syntax error when the
5219 feature is not available, Vim may skip the rest of the line
5220 and miss a following `endif`. Therefore put the `endif` on a
5221 separate line: >
5222 if has('feature')
5223 let x = this->breaks->without->the->feature
5224 endif
5225< If the `endif` would be moved to the second line as "| endif" it
5226 would not be found.
5227
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005228 Return type: |Number|
5229
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005230
5231has_key({dict}, {key}) *has_key()*
5232 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005233 has an entry with key {key}. FALSE otherwise.
5234 The {key} argument is a string. In |Vim9| script a number is
5235 also accepted (and converted to a string) but no other types.
5236 In legacy script the usual automatic conversion to string is
5237 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005238
5239 Can also be used as a |method|: >
5240 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005241<
5242 Return type: |Number|
5243
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005244
5245haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5246 The result is a Number:
5247 1 when the window has set a local directory via |:lcd|
5248 2 when the tab-page has set a local directory via |:tcd|
5249 0 otherwise.
5250
5251 Without arguments use the current window.
5252 With {winnr} use this window in the current tab page.
5253 With {winnr} and {tabnr} use the window in the specified tab
5254 page.
5255 {winnr} can be the window number or the |window-ID|.
5256 If {winnr} is -1 it is ignored and only the tabpage is used.
5257 Return 0 if the arguments are invalid.
5258 Examples: >
5259 if haslocaldir() == 1
5260 " window local directory case
5261 elseif haslocaldir() == 2
5262 " tab-local directory case
5263 else
5264 " global directory case
5265 endif
5266
5267 " current window
5268 :echo haslocaldir()
5269 :echo haslocaldir(0)
5270 :echo haslocaldir(0, 0)
5271 " window n in current tab page
5272 :echo haslocaldir(n)
5273 :echo haslocaldir(n, 0)
5274 " window n in tab page m
5275 :echo haslocaldir(n, m)
5276 " tab page m
5277 :echo haslocaldir(-1, m)
5278<
5279 Can also be used as a |method|: >
5280 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005281<
5282 Return type: |Number|
5283
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005284
5285hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5286 The result is a Number, which is TRUE if there is a mapping
5287 that contains {what} in somewhere in the rhs (what it is
5288 mapped to) and this mapping exists in one of the modes
5289 indicated by {mode}.
5290 The arguments {what} and {mode} are strings.
5291 When {abbr} is there and it is |TRUE| use abbreviations
5292 instead of mappings. Don't forget to specify Insert and/or
5293 Command-line mode.
5294 Both the global mappings and the mappings local to the current
5295 buffer are checked for a match.
5296 If no matching mapping is found FALSE is returned.
5297 The following characters are recognized in {mode}:
5298 n Normal mode
5299 v Visual and Select mode
5300 x Visual mode
5301 s Select mode
5302 o Operator-pending mode
5303 i Insert mode
5304 l Language-Argument ("r", "f", "t", etc.)
5305 c Command-line mode
5306 When {mode} is omitted, "nvo" is used.
5307
5308 This function is useful to check if a mapping already exists
5309 to a function in a Vim script. Example: >
5310 :if !hasmapto('\ABCdoit')
5311 : map <Leader>d \ABCdoit
5312 :endif
5313< This installs the mapping to "\ABCdoit" only if there isn't
5314 already a mapping to "\ABCdoit".
5315
5316 Can also be used as a |method|: >
5317 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005318<
5319 Return type: |Number|
5320
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005321
5322histadd({history}, {item}) *histadd()*
5323 Add the String {item} to the history {history} which can be
5324 one of: *hist-names*
5325 "cmd" or ":" command line history
5326 "search" or "/" search pattern history
5327 "expr" or "=" typed expression history
5328 "input" or "@" input line history
5329 "debug" or ">" debug command history
5330 empty the current or last used history
5331 The {history} string does not need to be the whole name, one
5332 character is sufficient.
5333 If {item} does already exist in the history, it will be
5334 shifted to become the newest entry.
5335 The result is a Number: TRUE if the operation was successful,
5336 otherwise FALSE is returned.
5337
5338 Example: >
5339 :call histadd("input", strftime("%Y %b %d"))
5340 :let date=input("Enter date: ")
5341< This function is not available in the |sandbox|.
5342
5343 Can also be used as a |method|, the base is passed as the
5344 second argument: >
5345 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005346<
5347 Return type: |Number|
5348
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005349
5350histdel({history} [, {item}]) *histdel()*
5351 Clear {history}, i.e. delete all its entries. See |hist-names|
5352 for the possible values of {history}.
5353
5354 If the parameter {item} evaluates to a String, it is used as a
5355 regular expression. All entries matching that expression will
5356 be removed from the history (if there are any).
5357 Upper/lowercase must match, unless "\c" is used |/\c|.
5358 If {item} evaluates to a Number, it will be interpreted as
5359 an index, see |:history-indexing|. The respective entry will
5360 be removed if it exists.
5361
5362 The result is TRUE for a successful operation, otherwise FALSE
5363 is returned.
5364
5365 Examples:
5366 Clear expression register history: >
5367 :call histdel("expr")
5368<
5369 Remove all entries starting with "*" from the search history: >
5370 :call histdel("/", '^\*')
5371<
5372 The following three are equivalent: >
5373 :call histdel("search", histnr("search"))
5374 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005375 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005376<
5377 To delete the last search pattern and use the last-but-one for
5378 the "n" command and 'hlsearch': >
5379 :call histdel("search", -1)
5380 :let @/ = histget("search", -1)
5381<
5382 Can also be used as a |method|: >
5383 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005384<
5385 Return type: |Number|
5386
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005387
5388histget({history} [, {index}]) *histget()*
5389 The result is a String, the entry with Number {index} from
5390 {history}. See |hist-names| for the possible values of
5391 {history}, and |:history-indexing| for {index}. If there is
5392 no such entry, an empty String is returned. When {index} is
5393 omitted, the most recent item from the history is used.
5394
5395 Examples:
5396 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005397 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005398
5399< Define an Ex command ":H {num}" that supports re-execution of
5400 the {num}th entry from the output of |:history|. >
5401 :command -nargs=1 H execute histget("cmd", 0+<args>)
5402<
5403 Can also be used as a |method|: >
5404 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005405<
5406 Return type: |String|
5407
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005408
5409histnr({history}) *histnr()*
5410 The result is the Number of the current entry in {history}.
5411 See |hist-names| for the possible values of {history}.
5412 If an error occurred, -1 is returned.
5413
5414 Example: >
5415 :let inp_index = histnr("expr")
5416
5417< Can also be used as a |method|: >
5418 GetHistory()->histnr()
5419<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005420 Return type: |Number|
5421
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005422hlexists({name}) *hlexists()*
5423 The result is a Number, which is TRUE if a highlight group
5424 called {name} exists. This is when the group has been
5425 defined in some way. Not necessarily when highlighting has
5426 been defined for it, it may also have been used for a syntax
5427 item.
5428 *highlight_exists()*
5429 Obsolete name: highlight_exists().
5430
5431 Can also be used as a |method|: >
5432 GetName()->hlexists()
5433<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005434 Return type: |Number|
5435
5436
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005437hlget([{name} [, {resolve}]]) *hlget()*
5438 Returns a List of all the highlight group attributes. If the
5439 optional {name} is specified, then returns a List with only
5440 the attributes of the specified highlight group. Returns an
5441 empty List if the highlight group {name} is not present.
5442
5443 If the optional {resolve} argument is set to v:true and the
5444 highlight group {name} is linked to another group, then the
5445 link is resolved recursively and the attributes of the
5446 resolved highlight group are returned.
5447
5448 Each entry in the returned List is a Dictionary with the
5449 following items:
5450 cleared boolean flag, set to v:true if the highlight
5451 group attributes are cleared or not yet
5452 specified. See |highlight-clear|.
5453 cterm cterm attributes. See |highlight-cterm|.
5454 ctermbg cterm background color.
5455 See |highlight-ctermbg|.
5456 ctermfg cterm foreground color.
5457 See |highlight-ctermfg|.
5458 ctermul cterm underline color. See |highlight-ctermul|.
5459 default boolean flag, set to v:true if the highlight
5460 group link is a default link. See
5461 |highlight-default|.
5462 font highlight group font. See |highlight-font|.
5463 gui gui attributes. See |highlight-gui|.
5464 guibg gui background color. See |highlight-guibg|.
5465 guifg gui foreground color. See |highlight-guifg|.
5466 guisp gui special color. See |highlight-guisp|.
5467 id highlight group ID.
5468 linksto linked highlight group name.
5469 See |:highlight-link|.
5470 name highlight group name. See |group-name|.
5471 start start terminal keycode. See |highlight-start|.
5472 stop stop terminal keycode. See |highlight-stop|.
5473 term term attributes. See |highlight-term|.
5474
5475 The 'term', 'cterm' and 'gui' items in the above Dictionary
5476 have a dictionary value with the following optional boolean
5477 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5478 'reverse', 'inverse' and 'strikethrough'.
5479
5480 Example(s): >
5481 :echo hlget()
5482 :echo hlget('ModeMsg')
5483 :echo hlget('Number', v:true)
5484<
5485 Can also be used as a |method|: >
5486 GetName()->hlget()
5487<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005488 Return type: list<dict<any>>
5489
5490
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005491hlset({list}) *hlset()*
5492 Creates or modifies the attributes of a List of highlight
5493 groups. Each item in {list} is a dictionary containing the
5494 attributes of a highlight group. See |hlget()| for the list of
5495 supported items in this dictionary.
5496
5497 In addition to the items described in |hlget()|, the following
5498 additional items are supported in the dictionary:
5499
5500 force boolean flag to force the creation of
5501 a link for an existing highlight group
5502 with attributes.
5503
5504 The highlight group is identified using the 'name' item and
5505 the 'id' item (if supplied) is ignored. If a highlight group
5506 with a specified name doesn't exist, then it is created.
5507 Otherwise the attributes of an existing highlight group are
5508 modified.
5509
5510 If an empty dictionary value is used for the 'term' or 'cterm'
5511 or 'gui' entries, then the corresponding attributes are
5512 cleared. If the 'cleared' item is set to v:true, then all the
5513 attributes of the highlight group are cleared.
5514
5515 The 'linksto' item can be used to link a highlight group to
5516 another highlight group. See |:highlight-link|.
5517
5518 Returns zero for success, -1 for failure.
5519
5520 Example(s): >
5521 " add bold attribute to the Visual highlight group
5522 :call hlset([#{name: 'Visual',
5523 \ term: #{reverse: 1 , bold: 1}}])
5524 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5525 :let l = hlget()
5526 :call hlset(l)
5527 " clear the Search highlight group
5528 :call hlset([#{name: 'Search', cleared: v:true}])
5529 " clear the 'term' attributes for a highlight group
5530 :call hlset([#{name: 'Title', term: {}}])
5531 " create the MyHlg group linking it to DiffAdd
5532 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5533 " remove the MyHlg group link
5534 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5535 " clear the attributes and a link
5536 :call hlset([#{name: 'MyHlg', cleared: v:true,
5537 \ linksto: 'NONE'}])
5538<
5539 Can also be used as a |method|: >
5540 GetAttrList()->hlset()
5541<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005542 Return type: |Number|
5543
5544hlID({name}) *hlID()*
5545 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005546 with name {name}. When the highlight group doesn't exist,
5547 zero is returned.
5548 This can be used to retrieve information about the highlight
5549 group. For example, to get the background color of the
5550 "Comment" group: >
5551 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5552< *highlightID()*
5553 Obsolete name: highlightID().
5554
5555 Can also be used as a |method|: >
5556 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005557<
5558 Return type: |Number|
5559
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005560
5561hostname() *hostname()*
5562 The result is a String, which is the name of the machine on
5563 which Vim is currently running. Machine names greater than
5564 256 characters long are truncated.
5565
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005566 Return type: |String|
5567
5568
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005569iconv({string}, {from}, {to}) *iconv()*
5570 The result is a String, which is the text {string} converted
5571 from encoding {from} to encoding {to}.
5572 When the conversion completely fails an empty string is
5573 returned. When some characters could not be converted they
5574 are replaced with "?".
5575 The encoding names are whatever the iconv() library function
5576 can accept, see ":!man 3 iconv".
5577 Most conversions require Vim to be compiled with the |+iconv|
5578 feature. Otherwise only UTF-8 to latin1 conversion and back
5579 can be done.
5580 This can be used to display messages with special characters,
5581 no matter what 'encoding' is set to. Write the message in
5582 UTF-8 and use: >
5583 echo iconv(utf8_str, "utf-8", &enc)
5584< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5585 from/to UCS-2 is automatically changed to use UTF-8. You
5586 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5587
5588 Can also be used as a |method|: >
5589 GetText()->iconv('latin1', 'utf-8')
5590<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005591 Return type: |String|
5592
5593
5594indent({lnum}) *indent()*
5595 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005596 current buffer. The indent is counted in spaces, the value
5597 of 'tabstop' is relevant. {lnum} is used just like in
5598 |getline()|.
5599 When {lnum} is invalid -1 is returned. In |Vim9| script an
5600 error is given.
5601
5602 Can also be used as a |method|: >
5603 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005604<
5605 Return type: |Number|
5606
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005607
5608index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005609 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005610 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005611
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005612 If {object} is a |List| return the lowest index where the item
5613 has a value equal to {expr}. There is no automatic
5614 conversion, so the String "4" is different from the Number 4.
5615 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005616 of 'ignorecase' is not used here, case matters as indicated by
5617 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005618
5619 If {object} is |Blob| return the lowest index where the byte
5620 value is equal to {expr}.
5621
5622 If {start} is given then start looking at the item with index
5623 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005624
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005625 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5626 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005627
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005628 -1 is returned when {expr} is not found in {object}.
5629 Example: >
5630 :let idx = index(words, "the")
5631 :if index(numbers, 123) >= 0
5632
5633< Can also be used as a |method|: >
5634 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005635<
5636 Return type: |Number|
5637
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005638
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005639indexof({object}, {expr} [, {opts}]) *indexof()*
5640 Returns the index of an item in {object} where {expr} is
5641 v:true. {object} must be a |List| or a |Blob|.
5642
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005643 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005644 List until the expression is v:true and return the index of
5645 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005646
5647 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005648 Blob until the expression is v:true and return the index of
5649 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005650
5651 {expr} must be a |string| or |Funcref|.
5652
5653 If {expr} is a |string|: If {object} is a |List|, inside
5654 {expr} |v:key| has the index of the current List item and
5655 |v:val| has the value of the item. If {object} is a |Blob|,
5656 inside {expr} |v:key| has the index of the current byte and
5657 |v:val| has the byte value.
5658
5659 If {expr} is a |Funcref| it must take two arguments:
5660 1. the key or the index of the current item.
5661 2. the value of the current item.
5662 The function must return |TRUE| if the item is found and the
5663 search should stop.
5664
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005665 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005666 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005667 startidx start evaluating {expr} at the item with this
5668 index; may be negative for an item relative to
5669 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005670 Returns -1 when {expr} evaluates to v:false for all the items.
5671 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005672 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
5673 :echo indexof(l, "v:val.n == 20")
5674 :echo indexof(l, {i, v -> v.n == 30})
5675 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005676
5677< Can also be used as a |method|: >
5678 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005679<
5680 Return type: |Number|
5681
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005682
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005683input({prompt} [, {text} [, {completion}]]) *input()*
5684 The result is a String, which is whatever the user typed on
5685 the command-line. The {prompt} argument is either a prompt
5686 string, or a blank string (for no prompt). A '\n' can be used
5687 in the prompt to start a new line.
5688 The highlighting set with |:echohl| is used for the prompt.
5689 The input is entered just like a command-line, with the same
5690 editing commands and mappings. There is a separate history
5691 for lines typed for input().
5692 Example: >
5693 :if input("Coffee or beer? ") == "beer"
5694 : echo "Cheers!"
5695 :endif
5696<
5697 If the optional {text} argument is present and not empty, this
5698 is used for the default reply, as if the user typed this.
5699 Example: >
5700 :let color = input("Color? ", "white")
5701
5702< The optional {completion} argument specifies the type of
5703 completion supported for the input. Without it completion is
5704 not performed. The supported completion types are the same as
5705 that can be supplied to a user-defined command using the
5706 "-complete=" argument. Refer to |:command-completion| for
5707 more information. Example: >
5708 let fname = input("File: ", "", "file")
5709<
5710 NOTE: This function must not be used in a startup file, for
5711 the versions that only run in GUI mode (e.g., the Win32 GUI).
5712 Note: When input() is called from within a mapping it will
5713 consume remaining characters from that mapping, because a
5714 mapping is handled like the characters were typed.
5715 Use |inputsave()| before input() and |inputrestore()|
5716 after input() to avoid that. Another solution is to avoid
5717 that further characters follow in the mapping, e.g., by using
5718 |:execute| or |:normal|.
5719
5720 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005721 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005722 :function GetFoo()
5723 : call inputsave()
5724 : let g:Foo = input("enter search pattern: ")
5725 : call inputrestore()
5726 :endfunction
5727
5728< Can also be used as a |method|: >
5729 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005730<
5731 Return type: |String|
5732
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005733
5734inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
5735 Like |input()|, but when the GUI is running and text dialogs
5736 are supported, a dialog window pops up to input the text.
5737 Example: >
5738 :let n = inputdialog("value for shiftwidth", shiftwidth())
5739 :if n != ""
5740 : let &sw = n
5741 :endif
5742< When the dialog is cancelled {cancelreturn} is returned. When
5743 omitted an empty string is returned.
5744 Hitting <Enter> works like pressing the OK button. Hitting
5745 <Esc> works like pressing the Cancel button.
5746 NOTE: Command-line completion is not supported.
5747
5748 Can also be used as a |method|: >
5749 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005750<
5751 Return type: |String|
5752
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005753
5754inputlist({textlist}) *inputlist()*
5755 {textlist} must be a |List| of strings. This |List| is
5756 displayed, one string per line. The user will be prompted to
5757 enter a number, which is returned.
5758 The user can also select an item by clicking on it with the
5759 mouse, if the mouse is enabled in the command line ('mouse' is
5760 "a" or includes "c"). For the first string 0 is returned.
5761 When clicking above the first item a negative number is
5762 returned. When clicking on the prompt one more than the
5763 length of {textlist} is returned.
5764 Make sure {textlist} has less than 'lines' entries, otherwise
5765 it won't work. It's a good idea to put the entry number at
5766 the start of the string. And put a prompt in the first item.
5767 Example: >
5768 let color = inputlist(['Select color:', '1. red',
5769 \ '2. green', '3. blue'])
5770
5771< Can also be used as a |method|: >
5772 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005773<
5774 Return type: |Number|
5775
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005776
5777inputrestore() *inputrestore()*
5778 Restore typeahead that was saved with a previous |inputsave()|.
5779 Should be called the same number of times inputsave() is
5780 called. Calling it more often is harmless though.
5781 Returns TRUE when there is nothing to restore, FALSE otherwise.
5782
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005783 Return type: |Number|
5784
5785
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005786inputsave() *inputsave()*
5787 Preserve typeahead (also from mappings) and clear it, so that
5788 a following prompt gets input from the user. Should be
5789 followed by a matching inputrestore() after the prompt. Can
5790 be used several times, in which case there must be just as
5791 many inputrestore() calls.
5792 Returns TRUE when out of memory, FALSE otherwise.
5793
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005794 Return type: |Number|
5795
5796
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005797inputsecret({prompt} [, {text}]) *inputsecret()*
5798 This function acts much like the |input()| function with but
5799 two exceptions:
5800 a) the user's response will be displayed as a sequence of
5801 asterisks ("*") thereby keeping the entry secret, and
5802 b) the user's response will not be recorded on the input
5803 |history| stack.
5804 The result is a String, which is whatever the user actually
5805 typed on the command-line in response to the issued prompt.
5806 NOTE: Command-line completion is not supported.
5807
5808 Can also be used as a |method|: >
5809 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005810<
5811 Return type: |String|
5812
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005813
5814insert({object}, {item} [, {idx}]) *insert()*
5815 When {object} is a |List| or a |Blob| insert {item} at the start
5816 of it.
5817
5818 If {idx} is specified insert {item} before the item with index
5819 {idx}. If {idx} is zero it goes before the first item, just
5820 like omitting {idx}. A negative {idx} is also possible, see
5821 |list-index|. -1 inserts just before the last item.
5822
5823 Returns the resulting |List| or |Blob|. Examples: >
5824 :let mylist = insert([2, 3, 5], 1)
5825 :call insert(mylist, 4, -1)
5826 :call insert(mylist, 6, len(mylist))
5827< The last example can be done simpler with |add()|.
5828 Note that when {item} is a |List| it is inserted as a single
5829 item. Use |extend()| to concatenate |Lists|.
5830
5831 Can also be used as a |method|: >
5832 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005833<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005834 Return type: |Number|
5835
5836
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005837 *instanceof()* *E614* *E616* *E693*
5838instanceof({object}, {class})
5839 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01005840 argument is a direct or indirect instance of a |Class|,
5841 |Interface|, or class |:type| alias specified by {class}.
5842 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005843 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02005844 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01005845 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02005846
5847< Can also be used as a |method|: >
5848 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005849<
5850 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02005851
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005852interrupt() *interrupt()*
5853 Interrupt script execution. It works more or less like the
5854 user typing CTRL-C, most commands won't execute and control
5855 returns to the user. This is useful to abort execution
5856 from lower down, e.g. in an autocommand. Example: >
5857 :function s:check_typoname(file)
5858 : if fnamemodify(a:file, ':t') == '['
5859 : echomsg 'Maybe typo'
5860 : call interrupt()
5861 : endif
5862 :endfunction
5863 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005864<
5865 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005866
5867invert({expr}) *invert()*
5868 Bitwise invert. The argument is converted to a number. A
5869 List, Dict or Float argument causes an error. Example: >
5870 :let bits = invert(bits)
5871< Can also be used as a |method|: >
5872 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005873<
5874 Return type: |Number|
5875
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005876
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005877isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01005878 The result is a Number, which is |TRUE| when {path} is an
5879 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005880 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01005881 On MS-Windows, it is considered absolute when it starts with an
5882 optional drive prefix and is followed by a '\' or '/'. UNC paths
5883 are always absolute.
5884 Example: >
5885 echo isabsolutepath('/usr/share/') " 1
5886 echo isabsolutepath('./foobar') " 0
5887 echo isabsolutepath('C:\Windows') " 1
5888 echo isabsolutepath('foobar') " 0
5889 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005890<
LemonBoydca1d402022-04-28 15:26:33 +01005891 Can also be used as a |method|: >
5892 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005893<
5894 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01005895
5896
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005897isdirectory({directory}) *isdirectory()*
5898 The result is a Number, which is |TRUE| when a directory
5899 with the name {directory} exists. If {directory} doesn't
5900 exist, or isn't a directory, the result is |FALSE|. {directory}
5901 is any expression, which is used as a String.
5902
5903 Can also be used as a |method|: >
5904 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005905<
5906 Return type: |Number|
5907
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005908
5909isinf({expr}) *isinf()*
5910 Return 1 if {expr} is a positive infinity, or -1 a negative
5911 infinity, otherwise 0. >
5912 :echo isinf(1.0 / 0.0)
5913< 1 >
5914 :echo isinf(-1.0 / 0.0)
5915< -1
5916
5917 Can also be used as a |method|: >
5918 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005919<
5920 Return type: |Number|
5921
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005922
5923islocked({expr}) *islocked()* *E786*
5924 The result is a Number, which is |TRUE| when {expr} is the
5925 name of a locked variable.
5926 The string argument {expr} must be the name of a variable,
5927 |List| item or |Dictionary| entry, not the variable itself!
5928 Example: >
5929 :let alist = [0, ['a', 'b'], 2, 3]
5930 :lockvar 1 alist
5931 :echo islocked('alist') " 1
5932 :echo islocked('alist[1]') " 0
5933
Bram Moolenaar9da17d72022-02-09 21:50:44 +00005934< When {expr} is a variable that does not exist -1 is returned.
5935 If {expr} uses a range, list or dict index that is out of
5936 range or does not exist you get an error message. Use
5937 |exists()| to check for existence.
5938 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005939
5940 Can also be used as a |method|: >
5941 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005942<
5943 Return type: |Number|
5944
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005945
5946isnan({expr}) *isnan()*
5947 Return |TRUE| if {expr} is a float with value NaN. >
5948 echo isnan(0.0 / 0.0)
5949< 1
5950
5951 Can also be used as a |method|: >
5952 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005953<
5954 Return type: |Number|
5955
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005956
5957items({dict}) *items()*
5958 Return a |List| with all the key-value pairs of {dict}. Each
5959 |List| item is a list with two items: the key of a {dict}
5960 entry and the value of this entry. The |List| is in arbitrary
5961 order. Also see |keys()| and |values()|.
5962 Example: >
5963 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005964 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005965 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01005966<
5967 A List or a String argument is also supported. In these
5968 cases, items() returns a List with the index and the value at
5969 the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005970
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01005971 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005972 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005973<
5974 Return type: list<list<any>> or list<any>
5975
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005976
5977job_ functions are documented here: |job-functions-details|
5978
5979
5980join({list} [, {sep}]) *join()*
5981 Join the items in {list} together into one String.
5982 When {sep} is specified it is put in between the items. If
5983 {sep} is omitted a single space is used.
5984 Note that {sep} is not added at the end. You might want to
5985 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005986 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005987< String items are used as-is. |Lists| and |Dictionaries| are
5988 converted into a string like with |string()|.
5989 The opposite function is |split()|.
5990
5991 Can also be used as a |method|: >
5992 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005993<
5994 Return type: |String|
5995
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005996
5997js_decode({string}) *js_decode()*
5998 This is similar to |json_decode()| with these differences:
5999 - Object key names do not have to be in quotes.
6000 - Strings can be in single quotes.
6001 - Empty items in an array (between two commas) are allowed and
6002 result in v:none items.
6003
6004 Can also be used as a |method|: >
6005 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006006<
6007 Return type: any, depending on {varname}
6008
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006009
6010js_encode({expr}) *js_encode()*
6011 This is similar to |json_encode()| with these differences:
6012 - Object key names are not in quotes.
6013 - v:none items in an array result in an empty item between
6014 commas.
6015 For example, the Vim object:
6016 [1,v:none,{"one":1},v:none] ~
6017 Will be encoded as:
6018 [1,,{one:1},,] ~
6019 While json_encode() would produce:
6020 [1,null,{"one":1},null] ~
6021 This encoding is valid for JavaScript. It is more efficient
6022 than JSON, especially when using an array with optional items.
6023
6024 Can also be used as a |method|: >
6025 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006026<
6027 Return type: |String|
6028
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006029
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006030json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006031 This parses a JSON formatted string and returns the equivalent
6032 in Vim values. See |json_encode()| for the relation between
6033 JSON and Vim values.
6034 The decoding is permissive:
6035 - A trailing comma in an array and object is ignored, e.g.
6036 "[1, 2, ]" is the same as "[1, 2]".
6037 - Integer keys are accepted in objects, e.g. {1:2} is the
6038 same as {"1":2}.
6039 - More floating point numbers are recognized, e.g. "1." for
6040 "1.0", or "001.2" for "1.2". Special floating point values
6041 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6042 are accepted.
6043 - Leading zeroes in integer numbers are ignored, e.g. "012"
6044 for "12" or "-012" for "-12".
6045 - Capitalization is ignored in literal names null, true or
6046 false, e.g. "NULL" for "null", "True" for "true".
6047 - Control characters U+0000 through U+001F which are not
6048 escaped in strings are accepted, e.g. " " (tab
6049 character in string) for "\t".
6050 - An empty JSON expression or made of only spaces is accepted
6051 and results in v:none.
6052 - Backslash in an invalid 2-character sequence escape is
6053 ignored, e.g. "\a" is decoded as "a".
6054 - A correct surrogate pair in JSON strings should normally be
6055 a 12 character sequence such as "\uD834\uDD1E", but
6056 json_decode() silently accepts truncated surrogate pairs
6057 such as "\uD834" or "\uD834\u"
6058 *E938*
6059 A duplicate key in an object, valid in rfc7159, is not
6060 accepted by json_decode() as the result must be a valid Vim
6061 type, e.g. this fails: {"a":"b", "a":"c"}
6062
6063 Can also be used as a |method|: >
6064 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006065<
6066 Return type: any, depending on {varname}
6067
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006068
6069json_encode({expr}) *json_encode()*
6070 Encode {expr} as JSON and return this as a string.
6071 The encoding is specified in:
6072 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006073 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006074 |Number| decimal number
6075 |Float| floating point number
6076 Float nan "NaN"
6077 Float inf "Infinity"
6078 Float -inf "-Infinity"
6079 |String| in double quotes (possibly null)
6080 |Funcref| not possible, error
6081 |List| as an array (possibly null); when
6082 used recursively: []
6083 |Dict| as an object (possibly null); when
6084 used recursively: {}
6085 |Blob| as an array of the individual bytes
6086 v:false "false"
6087 v:true "true"
6088 v:none "null"
6089 v:null "null"
6090 Note that NaN and Infinity are passed on as values. This is
6091 missing in the JSON standard, but several implementations do
6092 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006093 If a string contains an illegal character then the replacement
6094 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006095
6096 Can also be used as a |method|: >
6097 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006098<
6099 Return type: |String|
6100
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006101
6102keys({dict}) *keys()*
6103 Return a |List| with all the keys of {dict}. The |List| is in
6104 arbitrary order. Also see |items()| and |values()|.
6105
6106 Can also be used as a |method|: >
6107 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006108<
6109 Return type: list<string>
6110
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006111
zeertzjqcdc83932022-09-12 13:38:41 +01006112keytrans({string}) *keytrans()*
6113 Turn the internal byte representation of keys into a form that
6114 can be used for |:map|. E.g. >
6115 :let xx = "\<C-Home>"
6116 :echo keytrans(xx)
6117< <C-Home>
6118
6119 Can also be used as a |method|: >
6120 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006121<
6122 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006123
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006124
6125len({expr}) *len()* *E701*
6126 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006127 When {expr} is a String or a Number the length in bytes is
6128 used, as with |strlen()|.
6129 When {expr} is a |List| the number of items in the |List| is
6130 returned.
6131 When {expr} is a |Blob| the number of bytes is returned.
6132 When {expr} is a |Dictionary| the number of entries in the
6133 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006134 When {expr} is an |Object|, invokes the len() method in the
6135 object (if present) to get the length (|object-len()|).
6136 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006137
6138 Can also be used as a |method|: >
6139 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006140<
6141 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006142
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006143
6144 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006145libcall({libname}, {funcname}, {argument})
6146 Call function {funcname} in the run-time library {libname}
6147 with single argument {argument}.
6148 This is useful to call functions in a library that you
6149 especially made to be used with Vim. Since only one argument
6150 is possible, calling standard library functions is rather
6151 limited.
6152 The result is the String returned by the function. If the
6153 function returns NULL, this will appear as an empty string ""
6154 to Vim.
6155 If the function returns a number, use libcallnr()!
6156 If {argument} is a number, it is passed to the function as an
6157 int; if {argument} is a string, it is passed as a
6158 null-terminated string.
6159 This function will fail in |restricted-mode|.
6160
6161 libcall() allows you to write your own 'plug-in' extensions to
6162 Vim without having to recompile the program. It is NOT a
6163 means to call system functions! If you try to do so Vim will
6164 very probably crash.
6165
6166 For Win32, the functions you write must be placed in a DLL
6167 and use the normal C calling convention (NOT Pascal which is
6168 used in Windows System DLLs). The function must take exactly
6169 one parameter, either a character pointer or a long integer,
6170 and must return a character pointer or NULL. The character
6171 pointer returned must point to memory that will remain valid
6172 after the function has returned (e.g. in static data in the
6173 DLL). If it points to allocated memory, that memory will
6174 leak away. Using a static buffer in the function should work,
6175 it's then freed when the DLL is unloaded.
6176
6177 WARNING: If the function returns a non-valid pointer, Vim may
6178 crash! This also happens if the function returns a number,
6179 because Vim thinks it's a pointer.
6180 For Win32 systems, {libname} should be the filename of the DLL
6181 without the ".DLL" suffix. A full path is only required if
6182 the DLL is not in the usual places.
6183 For Unix: When compiling your own plugins, remember that the
6184 object code must be compiled as position-independent ('PIC').
6185 {only in Win32 and some Unix versions, when the |+libcall|
6186 feature is present}
6187 Examples: >
6188 :echo libcall("libc.so", "getenv", "HOME")
6189
6190< Can also be used as a |method|, the base is passed as the
6191 third argument: >
6192 GetValue()->libcall("libc.so", "getenv")
6193<
6194 *libcallnr()*
6195libcallnr({libname}, {funcname}, {argument})
6196 Just like |libcall()|, but used for a function that returns an
6197 int instead of a string.
6198 {only in Win32 on some Unix versions, when the |+libcall|
6199 feature is present}
6200 Examples: >
6201 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6202 :call libcallnr("libc.so", "printf", "Hello World!\n")
6203 :call libcallnr("libc.so", "sleep", 10)
6204<
6205 Can also be used as a |method|, the base is passed as the
6206 third argument: >
6207 GetValue()->libcallnr("libc.so", "printf")
6208<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006209 Return type: |String|
6210
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006211
6212line({expr} [, {winid}]) *line()*
6213 The result is a Number, which is the line number of the file
6214 position given with {expr}. The {expr} argument is a string.
zeertzjq02f3eba2024-06-12 20:45:24 +02006215 See |getpos()| for accepted positions.
6216
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006217 To get the column number use |col()|. To get both use
6218 |getpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02006219
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006220 With the optional {winid} argument the values are obtained for
6221 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02006222
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006223 Returns 0 for invalid values of {expr} and {winid}.
zeertzjq02f3eba2024-06-12 20:45:24 +02006224
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006225 Examples: >
6226 line(".") line number of the cursor
6227 line(".", winid) idem, in window "winid"
6228 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006229 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006230<
6231 To jump to the last known position when opening a file see
6232 |last-position-jump|.
6233
6234 Can also be used as a |method|: >
6235 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006236<
6237 Return type: |Number|
6238
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006239
6240line2byte({lnum}) *line2byte()*
6241 Return the byte count from the start of the buffer for line
6242 {lnum}. This includes the end-of-line character, depending on
6243 the 'fileformat' option for the current buffer. The first
6244 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6245 This can also be used to get the byte count for the line just
6246 below the last line: >
6247 line2byte(line("$") + 1)
6248< This is the buffer size plus one. If 'fileencoding' is empty
6249 it is the file size plus one. {lnum} is used like with
6250 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6251 feature has been disabled at compile time, -1 is returned.
6252 Also see |byte2line()|, |go| and |:goto|.
6253
6254 Can also be used as a |method|: >
6255 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006256<
6257 Return type: |Number|
6258
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006259
6260lispindent({lnum}) *lispindent()*
6261 Get the amount of indent for line {lnum} according the lisp
6262 indenting rules, as with 'lisp'.
6263 The indent is counted in spaces, the value of 'tabstop' is
6264 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006265 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006266 error is given.
6267
6268 Can also be used as a |method|: >
6269 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006270<
6271 Return type: |Number|
6272
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006273
6274list2blob({list}) *list2blob()*
6275 Return a Blob concatenating all the number values in {list}.
6276 Examples: >
6277 list2blob([1, 2, 3, 4]) returns 0z01020304
6278 list2blob([]) returns 0z
6279< Returns an empty Blob on error. If one of the numbers is
6280 negative or more than 255 error *E1239* is given.
6281
6282 |blob2list()| does the opposite.
6283
6284 Can also be used as a |method|: >
6285 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006286<
6287 Return type: |Blob|
6288
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006289
6290list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006291 Convert each number in {list} to a character string and
6292 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006293 list2str([32]) returns " "
6294 list2str([65, 66, 67]) returns "ABC"
6295< The same can be done (slowly) with: >
6296 join(map(list, {nr, val -> nr2char(val)}), '')
6297< |str2list()| does the opposite.
6298
6299 When {utf8} is omitted or zero, the current 'encoding' is used.
6300 When {utf8} is TRUE, always return UTF-8 characters.
6301 With UTF-8 composing characters work as expected: >
6302 list2str([97, 769]) returns "á"
6303<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006304 Returns an empty string on error.
6305
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006306 Can also be used as a |method|: >
6307 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006308<
6309 Return type: |String|
6310
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006311
6312listener_add({callback} [, {buf}]) *listener_add()*
6313 Add a callback function that will be invoked when changes have
6314 been made to buffer {buf}.
6315 {buf} refers to a buffer name or number. For the accepted
6316 values, see |bufname()|. When {buf} is omitted the current
6317 buffer is used.
6318 Returns a unique ID that can be passed to |listener_remove()|.
6319
6320 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006321 bufnr the buffer that was changed
6322 start first changed line number
6323 end first line number below the change
6324 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006325 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006326 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006327
6328 Example: >
6329 func Listener(bufnr, start, end, added, changes)
6330 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6331 endfunc
6332 call listener_add('Listener', bufnr)
6333
Bram Moolenaar944697a2022-02-20 19:48:20 +00006334< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006335 dictionary with these entries:
6336 lnum the first line number of the change
6337 end the first line below the change
6338 added number of lines added; negative if lines were
6339 deleted
6340 col first column in "lnum" that was affected by
6341 the change; one if unknown or the whole line
6342 was affected; this is a byte index, first
6343 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006344 When lines are inserted (not when a line is split, e.g. by
6345 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006346 lnum line above which the new line is added
6347 end equal to "lnum"
6348 added number of lines inserted
6349 col 1
6350 When lines are deleted the values are:
6351 lnum the first deleted line
6352 end the line below the first deleted line, before
6353 the deletion was done
6354 added negative, number of lines deleted
6355 col 1
6356 When lines are changed:
6357 lnum the first changed line
6358 end the line below the last changed line
6359 added 0
6360 col first column with a change or 1
6361
6362 The entries are in the order the changes were made, thus the
6363 most recent change is at the end. The line numbers are valid
6364 when the callback is invoked, but later changes may make them
6365 invalid, thus keeping a copy for later might not work.
6366
6367 The {callback} is invoked just before the screen is updated,
6368 when |listener_flush()| is called or when a change is being
6369 made that changes the line count in a way it causes a line
6370 number in the list of changes to become invalid.
6371
6372 The {callback} is invoked with the text locked, see
6373 |textlock|. If you do need to make changes to the buffer, use
6374 a timer to do this later |timer_start()|.
6375
6376 The {callback} is not invoked when the buffer is first loaded.
6377 Use the |BufReadPost| autocmd event to handle the initial text
6378 of a buffer.
6379 The {callback} is also not invoked when the buffer is
6380 unloaded, use the |BufUnload| autocmd event for that.
6381
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006382 Returns zero if {callback} or {buf} is invalid.
6383
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006384 Can also be used as a |method|, the base is passed as the
6385 second argument: >
6386 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006387<
6388 Return type: |Number|
6389
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006390
6391listener_flush([{buf}]) *listener_flush()*
6392 Invoke listener callbacks for buffer {buf}. If there are no
6393 pending changes then no callbacks are invoked.
6394
6395 {buf} refers to a buffer name or number. For the accepted
6396 values, see |bufname()|. When {buf} is omitted the current
6397 buffer is used.
6398
6399 Can also be used as a |method|: >
6400 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006401<
6402 Return type: |Number|
6403
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006404
6405listener_remove({id}) *listener_remove()*
6406 Remove a listener previously added with listener_add().
6407 Returns FALSE when {id} could not be found, TRUE when {id} was
6408 removed.
6409
6410 Can also be used as a |method|: >
6411 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006412<
6413 Return type: |Number|
6414
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006415
6416localtime() *localtime()*
6417 Return the current time, measured as seconds since 1st Jan
6418 1970. See also |strftime()|, |strptime()| and |getftime()|.
6419
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006420 Return type: |Number|
6421
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006422
6423log({expr}) *log()*
6424 Return the natural logarithm (base e) of {expr} as a |Float|.
6425 {expr} must evaluate to a |Float| or a |Number| in the range
6426 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006427 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006428 Examples: >
6429 :echo log(10)
6430< 2.302585 >
6431 :echo log(exp(5))
6432< 5.0
6433
6434 Can also be used as a |method|: >
6435 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006436<
6437 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006438
6439
6440log10({expr}) *log10()*
6441 Return the logarithm of Float {expr} to base 10 as a |Float|.
6442 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006443 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006444 Examples: >
6445 :echo log10(1000)
6446< 3.0 >
6447 :echo log10(0.01)
6448< -2.0
6449
6450 Can also be used as a |method|: >
6451 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006452<
6453 Return type: |Float|
6454
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006455
6456luaeval({expr} [, {expr}]) *luaeval()*
6457 Evaluate Lua expression {expr} and return its result converted
6458 to Vim data structures. Second {expr} may hold additional
6459 argument accessible as _A inside first {expr}.
6460 Strings are returned as they are.
6461 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006462 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006463 Dictionaries and lists obtained by vim.eval() are returned
6464 as-is.
6465 Other objects are returned as zero without any errors.
6466 See |lua-luaeval| for more details.
6467 Note that in a `:def` function local variables are not visible
6468 to {expr}.
6469
6470 Can also be used as a |method|: >
6471 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006472<
6473 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006474
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006475 {only available when compiled with the |+lua| feature}
6476
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006477
6478map({expr1}, {expr2}) *map()*
6479 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006480 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006481 item in {expr1} with the result of evaluating {expr2}.
6482 For a |Blob| each byte is replaced.
6483 For a |String|, each character, including composing
6484 characters, is replaced.
6485 If the item type changes you may want to use |mapnew()| to
6486 create a new List or Dictionary. This is required when using
6487 Vim9 script.
6488
6489 {expr2} must be a |String| or |Funcref|.
6490
6491 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6492 of the current item. For a |Dictionary| |v:key| has the key
6493 of the current item and for a |List| |v:key| has the index of
6494 the current item. For a |Blob| |v:key| has the index of the
6495 current byte. For a |String| |v:key| has the index of the
6496 current character.
6497 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006498 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006499< This puts "> " before and " <" after each item in "mylist".
6500
6501 Note that {expr2} is the result of an expression and is then
6502 used as an expression again. Often it is good to use a
6503 |literal-string| to avoid having to double backslashes. You
6504 still have to double ' quotes
6505
6506 If {expr2} is a |Funcref| it is called with two arguments:
6507 1. The key or the index of the current item.
6508 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006509 With a legacy script lambda you don't get an error if it only
6510 accepts one argument, but with a Vim9 lambda you get "E1106:
6511 One argument too many", the number of arguments must match.
6512
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006513 The function must return the new value of the item. Example
6514 that changes each value by "key-value": >
6515 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006516 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006517 endfunc
6518 call map(myDict, function('KeyValue'))
6519< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006520 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006521< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006522 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006523< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006524 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006525<
6526 The operation is done in-place for a |List| and |Dictionary|.
6527 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006528 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006529
6530< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6531 or a new |Blob| or |String|.
6532 When an error is encountered while evaluating {expr2} no
6533 further items in {expr1} are processed.
6534 When {expr2} is a Funcref errors inside a function are ignored,
6535 unless it was defined with the "abort" flag.
6536
6537 Can also be used as a |method|: >
6538 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006539<
6540 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6541 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006542
6543
6544maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6545 When {dict} is omitted or zero: Return the rhs of mapping
6546 {name} in mode {mode}. The returned String has special
6547 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006548 listing. When {dict} is TRUE a dictionary is returned, see
6549 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006550
6551 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006552 returned if {dict} is FALSE, otherwise returns an empty Dict.
6553 When the mapping for {name} is empty, then "<Nop>" is
6554 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006555
6556 The {name} can have special key names, like in the ":map"
6557 command.
6558
6559 {mode} can be one of these strings:
6560 "n" Normal
6561 "v" Visual (including Select)
6562 "o" Operator-pending
6563 "i" Insert
6564 "c" Cmd-line
6565 "s" Select
6566 "x" Visual
6567 "l" langmap |language-mapping|
6568 "t" Terminal-Job
6569 "" Normal, Visual and Operator-pending
6570 When {mode} is omitted, the modes for "" are used.
6571
6572 When {abbr} is there and it is |TRUE| use abbreviations
6573 instead of mappings.
6574
6575 When {dict} is there and it is |TRUE| return a dictionary
6576 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006577 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006578 "lhs" The {lhs} of the mapping as it would be typed
6579 "lhsraw" The {lhs} of the mapping as raw bytes
6580 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6581 form, only present when it differs from "lhsraw"
6582 "rhs" The {rhs} of the mapping as typed.
6583 "silent" 1 for a |:map-silent| mapping, else 0.
6584 "noremap" 1 if the {rhs} of the mapping is not remappable.
6585 "script" 1 if mapping was defined with <script>.
6586 "expr" 1 for an expression mapping (|:map-<expr>|).
6587 "buffer" 1 for a buffer local mapping (|:map-local|).
6588 "mode" Modes for which the mapping is defined. In
6589 addition to the modes mentioned above, these
6590 characters will be used:
6591 " " Normal, Visual and Operator-pending
6592 "!" Insert and Commandline mode
6593 (|mapmode-ic|)
6594 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006595 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006596 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006597 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006598 "lnum" The line number in "sid", zero if unknown.
6599 "nowait" Do not wait for other, longer mappings.
6600 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006601 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006602 "mode_bits" Vim's internal binary representation of "mode".
6603 |mapset()| ignores this; only "mode" is used.
6604 See |maplist()| for usage examples. The values
6605 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006606
6607 The dictionary can be used to restore a mapping with
6608 |mapset()|.
6609
6610 The mappings local to the current buffer are checked first,
6611 then the global mappings.
6612 This function can be used to map a key even when it's already
6613 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006614 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006615
6616< Can also be used as a |method|: >
6617 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006618<
6619 Return type: |String| or dict<any> depending on {dict}
6620
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006621
6622mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6623 Check if there is a mapping that matches with {name} in mode
6624 {mode}. See |maparg()| for {mode} and special names in
6625 {name}.
6626 When {abbr} is there and it is |TRUE| use abbreviations
6627 instead of mappings.
6628 A match happens with a mapping that starts with {name} and
6629 with a mapping which is equal to the start of {name}.
6630
6631 matches mapping "a" "ab" "abc" ~
6632 mapcheck("a") yes yes yes
6633 mapcheck("abc") yes yes yes
6634 mapcheck("ax") yes no no
6635 mapcheck("b") no no no
6636
6637 The difference with maparg() is that mapcheck() finds a
6638 mapping that matches with {name}, while maparg() only finds a
6639 mapping for {name} exactly.
6640 When there is no mapping that starts with {name}, an empty
6641 String is returned. If there is one, the RHS of that mapping
6642 is returned. If there are several mappings that start with
6643 {name}, the RHS of one of them is returned. This will be
6644 "<Nop>" if the RHS is empty.
6645 The mappings local to the current buffer are checked first,
6646 then the global mappings.
6647 This function can be used to check if a mapping can be added
6648 without being ambiguous. Example: >
6649 :if mapcheck("_vv") == ""
6650 : map _vv :set guifont=7x13<CR>
6651 :endif
6652< This avoids adding the "_vv" mapping when there already is a
6653 mapping for "_v" or for "_vvv".
6654
6655 Can also be used as a |method|: >
6656 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006657<
6658 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006659
6660
Ernie Rael09661202022-04-25 14:40:44 +01006661maplist([{abbr}]) *maplist()*
6662 Returns a |List| of all mappings. Each List item is a |Dict|,
6663 the same as what is returned by |maparg()|, see
6664 |mapping-dict|. When {abbr} is there and it is |TRUE| use
6665 abbreviations instead of mappings.
6666
6667 Example to show all mappings with 'MultiMatch' in rhs: >
6668 vim9script
6669 echo maplist()->filter(
6670 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01006671< It can be tricky to find mappings for particular |:map-modes|.
6672 |mapping-dict|'s "mode_bits" can simplify this. For example,
6673 the mode_bits for Normal, Insert or Command-line modes are
6674 0x19. To find all the mappings available in those modes you
6675 can do: >
6676 vim9script
6677 var saved_maps = []
6678 for m in maplist()
6679 if and(m.mode_bits, 0x19) != 0
6680 saved_maps->add(m)
6681 endif
6682 endfor
6683 echo saved_maps->mapnew((_, m) => m.lhs)
6684< The values of the mode_bits are defined in Vim's src/vim.h
6685 file and they can be discovered at runtime using
6686 |:map-commands| and "maplist()". Example: >
6687 vim9script
6688 omap xyzzy <Nop>
6689 var op_bit = maplist()->filter(
6690 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
6691 ounmap xyzzy
6692 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006693<
6694 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01006695
6696
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006697mapnew({expr1}, {expr2}) *mapnew()*
6698 Like |map()| but instead of replacing items in {expr1} a new
6699 List or Dictionary is created and returned. {expr1} remains
6700 unchanged. Items can still be changed by {expr2}, if you
6701 don't want that use |deepcopy()| first.
6702
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006703 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6704 depending on {expr1}
6705
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006706
6707mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01006708mapset({dict})
6709 Restore a mapping from a dictionary, possibly returned by
6710 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
6711 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006712 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01006713 feature allows copying mappings from one buffer to another.
6714 The dict.mode value may restore a single mapping that covers
6715 more than one mode, like with mode values of '!', ' ', 'nox',
6716 or 'v'. *E1276*
6717
6718 In the first form, {mode} and {abbr} should be the same as
6719 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006720 {mode} is used to define the mode in which the mapping is set,
6721 not the "mode" entry in {dict}.
6722 Example for saving and restoring a mapping: >
6723 let save_map = maparg('K', 'n', 0, 1)
6724 nnoremap K somethingelse
6725 ...
6726 call mapset('n', 0, save_map)
6727< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01006728 e.g. with `:map!`, you need to save/restore the mapping for
6729 all of them, when they might differ.
6730
6731 In the second form, with {dict} as the only argument, mode
6732 and abbr are taken from the dict.
6733 Example: >
6734 vim9script
6735 var save_maps = maplist()->filter(
6736 (_, m) => m.lhs == 'K')
6737 nnoremap K somethingelse
6738 cnoremap K somethingelse2
6739 # ...
6740 unmap K
6741 for d in save_maps
6742 mapset(d)
6743 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006744<
6745 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006746
6747
6748match({expr}, {pat} [, {start} [, {count}]]) *match()*
6749 When {expr} is a |List| then this returns the index of the
6750 first item where {pat} matches. Each item is used as a
6751 String, |Lists| and |Dictionaries| are used as echoed.
6752
6753 Otherwise, {expr} is used as a String. The result is a
6754 Number, which gives the index (byte offset) in {expr} where
6755 {pat} matches.
6756
6757 A match at the first character or |List| item returns zero.
6758 If there is no match -1 is returned.
6759
6760 For getting submatches see |matchlist()|.
6761 Example: >
6762 :echo match("testing", "ing") " results in 4
6763 :echo match([1, 'x'], '\a') " results in 1
6764< See |string-match| for how {pat} is used.
6765 *strpbrk()*
6766 Vim doesn't have a strpbrk() function. But you can do: >
6767 :let sepidx = match(line, '[.,;: \t]')
6768< *strcasestr()*
6769 Vim doesn't have a strcasestr() function. But you can add
6770 "\c" to the pattern to ignore case: >
6771 :let idx = match(haystack, '\cneedle')
6772<
6773 If {start} is given, the search starts from byte index
6774 {start} in a String or item {start} in a |List|.
6775 The result, however, is still the index counted from the
6776 first character/item. Example: >
6777 :echo match("testing", "ing", 2)
6778< result is again "4". >
6779 :echo match("testing", "ing", 4)
6780< result is again "4". >
6781 :echo match("testing", "t", 2)
6782< result is "3".
6783 For a String, if {start} > 0 then it is like the string starts
6784 {start} bytes later, thus "^" will match at {start}. Except
6785 when {count} is given, then it's like matches before the
6786 {start} byte are ignored (this is a bit complicated to keep it
6787 backwards compatible).
6788 For a String, if {start} < 0, it will be set to 0. For a list
6789 the index is counted from the end.
6790 If {start} is out of range ({start} > strlen({expr}) for a
6791 String or {start} > len({expr}) for a |List|) -1 is returned.
6792
6793 When {count} is given use the {count}'th match. When a match
6794 is found in a String the search for the next one starts one
6795 character further. Thus this example results in 1: >
6796 echo match("testing", "..", 0, 2)
6797< In a |List| the search continues in the next item.
6798 Note that when {count} is added the way {start} works changes,
6799 see above.
6800
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01006801 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006802 See |pattern| for the patterns that are accepted.
6803 The 'ignorecase' option is used to set the ignore-caseness of
6804 the pattern. 'smartcase' is NOT used. The matching is always
6805 done like 'magic' is set and 'cpoptions' is empty.
6806 Note that a match at the start is preferred, thus when the
6807 pattern is using "*" (any number of matches) it tends to find
6808 zero matches at the start instead of a number of matches
6809 further down in the text.
6810
6811 Can also be used as a |method|: >
6812 GetText()->match('word')
6813 GetList()->match('word')
6814<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006815 Return type: |Number|
6816
6817
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006818 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006819matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
6820 Defines a pattern to be highlighted in the current window (a
6821 "match"). It will be highlighted with {group}. Returns an
6822 identification number (ID), which can be used to delete the
6823 match using |matchdelete()|. The ID is bound to the window.
6824 Matching is case sensitive and magic, unless case sensitivity
6825 or magicness are explicitly overridden in {pattern}. The
6826 'magic', 'smartcase' and 'ignorecase' options are not used.
6827 The "Conceal" value is special, it causes the match to be
6828 concealed.
6829
6830 The optional {priority} argument assigns a priority to the
6831 match. A match with a high priority will have its
6832 highlighting overrule that of a match with a lower priority.
6833 A priority is specified as an integer (negative numbers are no
6834 exception). If the {priority} argument is not specified, the
6835 default priority is 10. The priority of 'hlsearch' is zero,
6836 hence all matches with a priority greater than zero will
6837 overrule it. Syntax highlighting (see 'syntax') is a separate
6838 mechanism, and regardless of the chosen priority a match will
6839 always overrule syntax highlighting.
6840
6841 The optional {id} argument allows the request for a specific
6842 match ID. If a specified ID is already taken, an error
6843 message will appear and the match will not be added. An ID
6844 is specified as a positive integer (zero excluded). IDs 1, 2
6845 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01006846 respectively. 3 is reserved for use by the |matchparen|
6847 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01006848 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01006849 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006850
6851 The optional {dict} argument allows for further custom
6852 values. Currently this is used to specify a match specific
6853 conceal character that will be shown for |hl-Conceal|
6854 highlighted matches. The dict can have the following members:
6855
6856 conceal Special character to show instead of the
6857 match (only for |hl-Conceal| highlighted
6858 matches, see |:syn-cchar|)
6859 window Instead of the current window use the
6860 window with this number or window ID.
6861
6862 The number of matches is not limited, as it is the case with
6863 the |:match| commands.
6864
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006865 Returns -1 on error.
6866
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006867 Example: >
6868 :highlight MyGroup ctermbg=green guibg=green
6869 :let m = matchadd("MyGroup", "TODO")
6870< Deletion of the pattern: >
6871 :call matchdelete(m)
6872
6873< A list of matches defined by |matchadd()| and |:match| are
6874 available from |getmatches()|. All matches can be deleted in
6875 one operation by |clearmatches()|.
6876
6877 Can also be used as a |method|: >
6878 GetGroup()->matchadd('TODO')
6879<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006880 Return type: |Number|
6881
6882
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006883 *matchaddpos()*
6884matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
6885 Same as |matchadd()|, but requires a list of positions {pos}
6886 instead of a pattern. This command is faster than |matchadd()|
6887 because it does not require to handle regular expressions and
6888 sets buffer line boundaries to redraw screen. It is supposed
6889 to be used when fast match additions and deletions are
6890 required, for example to highlight matching parentheses.
6891
6892 {pos} is a list of positions. Each position can be one of
6893 these:
6894 - A number. This whole line will be highlighted. The first
6895 line has number 1.
6896 - A list with one number, e.g., [23]. The whole line with this
6897 number will be highlighted.
6898 - A list with two numbers, e.g., [23, 11]. The first number is
6899 the line number, the second one is the column number (first
6900 column is 1, the value must correspond to the byte index as
6901 |col()| would return). The character at this position will
6902 be highlighted.
6903 - A list with three numbers, e.g., [23, 11, 3]. As above, but
6904 the third number gives the length of the highlight in bytes.
6905
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006906 Returns -1 on error.
6907
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006908 Example: >
6909 :highlight MyGroup ctermbg=green guibg=green
6910 :let m = matchaddpos("MyGroup", [[23, 24], 34])
6911< Deletion of the pattern: >
6912 :call matchdelete(m)
6913
6914< Matches added by |matchaddpos()| are returned by
6915 |getmatches()|.
6916
6917 Can also be used as a |method|: >
6918 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006919<
6920 Return type: |Number|
6921
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006922
6923matcharg({nr}) *matcharg()*
6924 Selects the {nr} match item, as set with a |:match|,
6925 |:2match| or |:3match| command.
6926 Return a |List| with two elements:
6927 The name of the highlight group used
6928 The pattern used.
6929 When {nr} is not 1, 2 or 3 returns an empty |List|.
6930 When there is no match item set returns ['', ''].
6931 This is useful to save and restore a |:match|.
6932 Highlighting matches using the |:match| commands are limited
6933 to three matches. |matchadd()| does not have this limitation.
6934
6935 Can also be used as a |method|: >
6936 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006937<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006938 Return type: list<string>
6939
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006940 *matchbufline()*
6941matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
6942 Returns the |List| of matches in lines from {lnum} to {end} in
6943 buffer {buf} where {pat} matches.
6944
6945 {lnum} and {end} can either be a line number or the string "$"
6946 to refer to the last line in {buf}.
6947
6948 The {dict} argument supports following items:
6949 submatches include submatch information (|/\(|)
6950
6951 For each match, a |Dict| with the following items is returned:
6952 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08006953 lnum line number where there is a match
6954 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006955 Note that there can be multiple matches in a single line.
6956
6957 This function works only for loaded buffers. First call
6958 |bufload()| if needed.
6959
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01006960 See |match-pattern| for information about the effect of some
6961 option settings on the pattern.
6962
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006963 When {buf} is not a valid buffer, the buffer is not loaded or
6964 {lnum} or {end} is not valid then an error is given and an
6965 empty |List| is returned.
6966
6967 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08006968 " Assuming line 3 in buffer 5 contains "a"
6969 :echo matchbufline(5, '\<\k\+\>', 3, 3)
6970 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
6971 " Assuming line 4 in buffer 10 contains "tik tok"
6972 :echo matchbufline(10, '\<\k\+\>', 1, 4)
6973 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006974<
6975 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08006976 "\1", "\2", etc. are also returned. Example: >
6977 " Assuming line 2 in buffer 2 contains "acd"
6978 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006979 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08006980 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006981< The "submatches" List always contains 9 items. If a submatch
6982 is not found, then an empty string is returned for that
6983 submatch.
6984
6985 Can also be used as a |method|: >
6986 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006987<
6988 Return type: list<dict<any>> or list<any>
6989
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006990
6991matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
6992 Deletes a match with ID {id} previously defined by |matchadd()|
6993 or one of the |:match| commands. Returns 0 if successful,
6994 otherwise -1. See example for |matchadd()|. All matches can
6995 be deleted in one operation by |clearmatches()|.
6996 If {win} is specified, use the window with this number or
6997 window ID instead of the current window.
6998
6999 Can also be used as a |method|: >
7000 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007001<
7002 Return type: |Number|
7003
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007004
7005matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
7006 Same as |match()|, but return the index of first character
7007 after the match. Example: >
7008 :echo matchend("testing", "ing")
7009< results in "7".
7010 *strspn()* *strcspn()*
7011 Vim doesn't have a strspn() or strcspn() function, but you can
7012 do it with matchend(): >
7013 :let span = matchend(line, '[a-zA-Z]')
7014 :let span = matchend(line, '[^a-zA-Z]')
7015< Except that -1 is returned when there are no matches.
7016
7017 The {start}, if given, has the same meaning as for |match()|. >
7018 :echo matchend("testing", "ing", 2)
7019< results in "7". >
7020 :echo matchend("testing", "ing", 5)
7021< result is "-1".
7022 When {expr} is a |List| the result is equal to |match()|.
7023
7024 Can also be used as a |method|: >
7025 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007026<
7027 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007028
7029
7030matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7031 If {list} is a list of strings, then returns a |List| with all
7032 the strings in {list} that fuzzy match {str}. The strings in
7033 the returned list are sorted based on the matching score.
7034
7035 The optional {dict} argument always supports the following
7036 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007037 matchseq When this item is present return only matches
7038 that contain the characters in {str} in the
7039 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007040 limit Maximum number of matches in {list} to be
7041 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007042
7043 If {list} is a list of dictionaries, then the optional {dict}
7044 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007045 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007046 {str}. The value of this item should be a
7047 string.
7048 text_cb |Funcref| that will be called for every item
7049 in {list} to get the text for fuzzy matching.
7050 This should accept a dictionary item as the
7051 argument and return the text for that item to
7052 use for fuzzy matching.
7053
7054 {str} is treated as a literal string and regular expression
7055 matching is NOT supported. The maximum supported {str} length
7056 is 256.
7057
7058 When {str} has multiple words each separated by white space,
7059 then the list of strings that have all the words is returned.
7060
7061 If there are no matching strings or there is an error, then an
7062 empty list is returned. If length of {str} is greater than
7063 256, then returns an empty list.
7064
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007065 When {limit} is given, matchfuzzy() will find up to this
7066 number of matches in {list} and return them in sorted order.
7067
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007068 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007069 matching strings.
7070
7071 Example: >
7072 :echo matchfuzzy(["clay", "crow"], "cay")
7073< results in ["clay"]. >
7074 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7075< results in a list of buffer names fuzzy matching "ndl". >
7076 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7077< results in a list of buffer information dicts with buffer
7078 names fuzzy matching "ndl". >
7079 :echo getbufinfo()->matchfuzzy("spl",
7080 \ {'text_cb' : {v -> v.name}})
7081< results in a list of buffer information dicts with buffer
7082 names fuzzy matching "spl". >
7083 :echo v:oldfiles->matchfuzzy("test")
7084< results in a list of file names fuzzy matching "test". >
7085 :let l = readfile("buffer.c")->matchfuzzy("str")
7086< results in a list of lines in "buffer.c" fuzzy matching "str". >
7087 :echo ['one two', 'two one']->matchfuzzy('two one')
7088< results in ['two one', 'one two']. >
7089 :echo ['one two', 'two one']->matchfuzzy('two one',
7090 \ {'matchseq': 1})
7091< results in ['two one'].
7092
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007093 Return type: list<string> or list<any>
7094
7095
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007096matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7097 Same as |matchfuzzy()|, but returns the list of matched
7098 strings, the list of character positions where characters
7099 in {str} matches and a list of matching scores. You can
7100 use |byteidx()| to convert a character position to a byte
7101 position.
7102
7103 If {str} matches multiple times in a string, then only the
7104 positions for the best match is returned.
7105
7106 If there are no matching strings or there is an error, then a
7107 list with three empty list items is returned.
7108
7109 Example: >
7110 :echo matchfuzzypos(['testing'], 'tsg')
7111< results in [['testing'], [[0, 2, 6]], [99]] >
7112 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7113< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7114 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7115< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7116
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007117 Return type: list<list<any>>
7118
7119
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007120matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7121 Same as |match()|, but return a |List|. The first item in the
7122 list is the matched string, same as what matchstr() would
7123 return. Following items are submatches, like "\1", "\2", etc.
7124 in |:substitute|. When an optional submatch didn't match an
7125 empty string is used. Example: >
7126 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7127< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7128 When there is no match an empty list is returned.
7129
7130 You can pass in a List, but that is not very useful.
7131
7132 Can also be used as a |method|: >
7133 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007134<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007135 Return type: list<string> or list<any>
7136
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007137 *matchstrlist()*
7138matchstrlist({list}, {pat} [, {dict}])
7139 Returns the |List| of matches in {list} where {pat} matches.
7140 {list} is a |List| of strings. {pat} is matched against each
7141 string in {list}.
7142
7143 The {dict} argument supports following items:
7144 submatches include submatch information (|/\(|)
7145
7146 For each match, a |Dict| with the following items is returned:
7147 byteidx starting byte index of the match.
7148 idx index in {list} of the match.
7149 text matched string
7150 submatches a List of submatches. Present only if
7151 "submatches" is set to v:true in {dict}.
7152
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007153 See |match-pattern| for information about the effect of some
7154 option settings on the pattern.
7155
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007156 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007157 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7158 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7159 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7160 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007161<
7162 If "submatches" is present and is v:true, then submatches like
7163 "\1", "\2", etc. are also returned. Example: >
7164 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7165 \ #{submatches: v:true})
7166 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7167< The "submatches" List always contains 9 items. If a submatch
7168 is not found, then an empty string is returned for that
7169 submatch.
7170
7171 Can also be used as a |method|: >
7172 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007173<
7174 Return type: list<dict<any>> or list<any>
7175
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007176
7177matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7178 Same as |match()|, but return the matched string. Example: >
7179 :echo matchstr("testing", "ing")
7180< results in "ing".
7181 When there is no match "" is returned.
7182 The {start}, if given, has the same meaning as for |match()|. >
7183 :echo matchstr("testing", "ing", 2)
7184< results in "ing". >
7185 :echo matchstr("testing", "ing", 5)
7186< result is "".
7187 When {expr} is a |List| then the matching item is returned.
7188 The type isn't changed, it's not necessarily a String.
7189
7190 Can also be used as a |method|: >
7191 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007192<
7193 Return type: |String|
7194
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007195
7196matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7197 Same as |matchstr()|, but return the matched string, the start
7198 position and the end position of the match. Example: >
7199 :echo matchstrpos("testing", "ing")
7200< results in ["ing", 4, 7].
7201 When there is no match ["", -1, -1] is returned.
7202 The {start}, if given, has the same meaning as for |match()|. >
7203 :echo matchstrpos("testing", "ing", 2)
7204< results in ["ing", 4, 7]. >
7205 :echo matchstrpos("testing", "ing", 5)
7206< result is ["", -1, -1].
7207 When {expr} is a |List| then the matching item, the index
7208 of first item where {pat} matches, the start position and the
7209 end position of the match are returned. >
7210 :echo matchstrpos([1, '__x'], '\a')
7211< result is ["x", 1, 2, 3].
7212 The type isn't changed, it's not necessarily a String.
7213
7214 Can also be used as a |method|: >
7215 GetText()->matchstrpos('word')
7216<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007217 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007218
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007219
7220max({expr}) *max()*
7221 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007222 echo max([apples, pears, oranges])
7223
7224< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7225 it returns the maximum of all values in the Dictionary.
7226 If {expr} is neither a List nor a Dictionary, or one of the
7227 items in {expr} cannot be used as a Number this results in
7228 an error. An empty |List| or |Dictionary| results in zero.
7229
7230 Can also be used as a |method|: >
7231 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007232<
7233 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007234
7235
7236menu_info({name} [, {mode}]) *menu_info()*
7237 Return information about the specified menu {name} in
7238 mode {mode}. The menu name should be specified without the
7239 shortcut character ('&'). If {name} is "", then the top-level
7240 menu names are returned.
7241
7242 {mode} can be one of these strings:
7243 "n" Normal
7244 "v" Visual (including Select)
7245 "o" Operator-pending
7246 "i" Insert
7247 "c" Cmd-line
7248 "s" Select
7249 "x" Visual
7250 "t" Terminal-Job
7251 "" Normal, Visual and Operator-pending
7252 "!" Insert and Cmd-line
7253 When {mode} is omitted, the modes for "" are used.
7254
7255 Returns a |Dictionary| containing the following items:
7256 accel menu item accelerator text |menu-text|
7257 display display name (name without '&')
7258 enabled v:true if this menu item is enabled
7259 Refer to |:menu-enable|
7260 icon name of the icon file (for toolbar)
7261 |toolbar-icon|
7262 iconidx index of a built-in icon
7263 modes modes for which the menu is defined. In
7264 addition to the modes mentioned above, these
7265 characters will be used:
7266 " " Normal, Visual and Operator-pending
7267 name menu item name.
7268 noremenu v:true if the {rhs} of the menu item is not
7269 remappable else v:false.
7270 priority menu order priority |menu-priority|
7271 rhs right-hand-side of the menu item. The returned
7272 string has special characters translated like
7273 in the output of the ":menu" command listing.
7274 When the {rhs} of a menu item is empty, then
7275 "<Nop>" is returned.
7276 script v:true if script-local remapping of {rhs} is
7277 allowed else v:false. See |:menu-script|.
7278 shortcut shortcut key (character after '&' in
7279 the menu name) |menu-shortcut|
7280 silent v:true if the menu item is created
7281 with <silent> argument |:menu-silent|
7282 submenus |List| containing the names of
7283 all the submenus. Present only if the menu
7284 item has submenus.
7285
7286 Returns an empty dictionary if the menu item is not found.
7287
7288 Examples: >
7289 :echo menu_info('Edit.Cut')
7290 :echo menu_info('File.Save', 'n')
7291
7292 " Display the entire menu hierarchy in a buffer
7293 func ShowMenu(name, pfx)
7294 let m = menu_info(a:name)
7295 call append(line('$'), a:pfx .. m.display)
7296 for child in m->get('submenus', [])
7297 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7298 \ a:pfx .. ' ')
7299 endfor
7300 endfunc
7301 new
7302 for topmenu in menu_info('').submenus
7303 call ShowMenu(topmenu, '')
7304 endfor
7305<
7306 Can also be used as a |method|: >
7307 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007308<
7309 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007310
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007311min({expr}) *min()*
7312 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007313 echo min([apples, pears, oranges])
7314
7315< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7316 it returns the minimum of all values in the Dictionary.
7317 If {expr} is neither a List nor a Dictionary, or one of the
7318 items in {expr} cannot be used as a Number this results in
7319 an error. An empty |List| or |Dictionary| results in zero.
7320
7321 Can also be used as a |method|: >
7322 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007323<
7324 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007325
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007326
7327mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007328 Create directory {name}.
7329
Bram Moolenaar938ae282023-02-20 20:44:55 +00007330 When {flags} is present it must be a string. An empty string
7331 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007332
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007333 {flags} can contain these character flags:
7334 "p" intermediate directories will be created as necessary
7335 "D" {name} will be deleted at the end of the current
Christian Brabandtc509c002024-06-14 20:22:05 +02007336 function, but not recursively |:defer|
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007337 "R" {name} will be deleted recursively at the end of the
Christian Brabandtc509c002024-06-14 20:22:05 +02007338 current function |:defer|
Bram Moolenaar938ae282023-02-20 20:44:55 +00007339
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007340 Note that when {name} has more than one part and "p" is used
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007341 some directories may already exist. Only the first one that
7342 is created and what it contains is scheduled to be deleted.
7343 E.g. when using: >
7344 call mkdir('subdir/tmp/autoload', 'pR')
7345< and "subdir" already exists then "subdir/tmp" will be
7346 scheduled for deletion, like with: >
7347 defer delete('subdir/tmp', 'rf')
7348< Note that if scheduling the defer fails the directory is not
7349 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007350
7351 If {prot} is given it is used to set the protection bits of
7352 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7353 the user, readable for others). Use 0o700 to make it
7354 unreadable for others. This is only used for the last part of
7355 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
7356 created with 0o755.
7357 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007358 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007359
7360< This function is not available in the |sandbox|.
7361
7362 There is no error if the directory already exists and the "p"
7363 flag is passed (since patch 8.0.1708). However, without the
7364 "p" option the call will fail.
7365
7366 The function result is a Number, which is TRUE if the call was
7367 successful or FALSE if the directory creation failed or partly
7368 failed.
7369
7370 Not available on all systems. To check use: >
7371 :if exists("*mkdir")
7372
7373< Can also be used as a |method|: >
7374 GetName()->mkdir()
7375<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007376 Return type: |Number|
7377
7378
7379mode([{expr}]) *mode()*
7380 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007381 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007382 a non-empty String (|non-zero-arg|), then the full mode is
7383 returned, otherwise only the first letter is returned.
7384 Also see |state()|.
7385
7386 n Normal
7387 no Operator-pending
7388 nov Operator-pending (forced characterwise |o_v|)
7389 noV Operator-pending (forced linewise |o_V|)
7390 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7391 CTRL-V is one character
7392 niI Normal using |i_CTRL-O| in |Insert-mode|
7393 niR Normal using |i_CTRL-O| in |Replace-mode|
7394 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7395 nt Terminal-Normal (insert goes to Terminal-Job mode)
7396 v Visual by character
7397 vs Visual by character using |v_CTRL-O| in Select mode
7398 V Visual by line
7399 Vs Visual by line using |v_CTRL-O| in Select mode
7400 CTRL-V Visual blockwise
7401 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7402 s Select by character
7403 S Select by line
7404 CTRL-S Select blockwise
7405 i Insert
7406 ic Insert mode completion |compl-generic|
7407 ix Insert mode |i_CTRL-X| completion
7408 R Replace |R|
7409 Rc Replace mode completion |compl-generic|
7410 Rx Replace mode |i_CTRL-X| completion
7411 Rv Virtual Replace |gR|
7412 Rvc Virtual Replace mode completion |compl-generic|
7413 Rvx Virtual Replace mode |i_CTRL-X| completion
7414 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007415 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007416 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007417 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007418 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007419 ce Normal Ex mode |Q|
7420 r Hit-enter prompt
7421 rm The -- more -- prompt
7422 r? A |:confirm| query of some sort
7423 ! Shell or external command is executing
7424 t Terminal-Job mode: keys go to the job
7425
7426 This is useful in the 'statusline' option or when used
7427 with |remote_expr()| In most other places it always returns
7428 "c" or "n".
7429 Note that in the future more modes and more specific modes may
7430 be added. It's better not to compare the whole string but only
7431 the leading character(s).
7432 Also see |visualmode()|.
7433
7434 Can also be used as a |method|: >
7435 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007436<
7437 Return type: |String|
7438
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007439
7440mzeval({expr}) *mzeval()*
7441 Evaluate MzScheme expression {expr} and return its result
7442 converted to Vim data structures.
7443 Numbers and strings are returned as they are.
7444 Pairs (including lists and improper lists) and vectors are
7445 returned as Vim |Lists|.
7446 Hash tables are represented as Vim |Dictionary| type with keys
7447 converted to strings.
7448 All other types are converted to string with display function.
7449 Examples: >
7450 :mz (define l (list 1 2 3))
7451 :mz (define h (make-hash)) (hash-set! h "list" l)
7452 :echo mzeval("l")
7453 :echo mzeval("h")
7454<
7455 Note that in a `:def` function local variables are not visible
7456 to {expr}.
7457
7458 Can also be used as a |method|: >
7459 GetExpr()->mzeval()
7460<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007461 Return type: any, depending on {expr}
7462
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007463 {only available when compiled with the |+mzscheme| feature}
7464
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007465
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007466nextnonblank({lnum}) *nextnonblank()*
7467 Return the line number of the first line at or below {lnum}
7468 that is not blank. Example: >
7469 if getline(nextnonblank(1)) =~ "Java"
7470< When {lnum} is invalid or there is no non-blank line at or
7471 below it, zero is returned.
7472 {lnum} is used like with |getline()|.
7473 See also |prevnonblank()|.
7474
7475 Can also be used as a |method|: >
7476 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007477<
7478 Return type: |Number|
7479
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007480
7481nr2char({expr} [, {utf8}]) *nr2char()*
7482 Return a string with a single character, which has the number
7483 value {expr}. Examples: >
7484 nr2char(64) returns "@"
7485 nr2char(32) returns " "
7486< When {utf8} is omitted or zero, the current 'encoding' is used.
7487 Example for "utf-8": >
7488 nr2char(300) returns I with bow character
7489< When {utf8} is TRUE, always return UTF-8 characters.
7490 Note that a NUL character in the file is specified with
7491 nr2char(10), because NULs are represented with newline
7492 characters. nr2char(0) is a real NUL and terminates the
7493 string, thus results in an empty string.
7494 To turn a list of character numbers into a string: >
7495 let list = [65, 66, 67]
7496 let str = join(map(list, {_, val -> nr2char(val)}), '')
7497< Result: "ABC"
7498
7499 Can also be used as a |method|: >
7500 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007501<
7502 Return type: |String|
7503
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007504
7505or({expr}, {expr}) *or()*
7506 Bitwise OR on the two arguments. The arguments are converted
7507 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007508 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007509 Example: >
7510 :let bits = or(bits, 0x80)
7511< Can also be used as a |method|: >
7512 :let bits = bits->or(0x80)
7513
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007514< Rationale: The reason this is a function and not using the "|"
7515 character like many languages, is that Vi has always used "|"
7516 to separate commands. In many places it would not be clear if
7517 "|" is an operator or a command separator.
7518
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007519 Return type: |Number|
7520
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007521
7522pathshorten({path} [, {len}]) *pathshorten()*
7523 Shorten directory names in the path {path} and return the
7524 result. The tail, the file name, is kept as-is. The other
7525 components in the path are reduced to {len} letters in length.
7526 If {len} is omitted or smaller than 1 then 1 is used (single
7527 letters). Leading '~' and '.' characters are kept. Examples: >
7528 :echo pathshorten('~/.vim/autoload/myfile.vim')
7529< ~/.v/a/myfile.vim ~
7530>
7531 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7532< ~/.vi/au/myfile.vim ~
7533 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007534 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007535
7536 Can also be used as a |method|: >
7537 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007538<
7539 Return type: |String|
7540
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007541
7542perleval({expr}) *perleval()*
7543 Evaluate Perl expression {expr} in scalar context and return
7544 its result converted to Vim data structures. If value can't be
7545 converted, it is returned as a string Perl representation.
7546 Note: If you want an array or hash, {expr} must return a
7547 reference to it.
7548 Example: >
7549 :echo perleval('[1 .. 4]')
7550< [1, 2, 3, 4]
7551
7552 Note that in a `:def` function local variables are not visible
7553 to {expr}.
7554
7555 Can also be used as a |method|: >
7556 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007557<
7558 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007559
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007560 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007561
7562
7563popup_ functions are documented here: |popup-functions|
7564
7565
7566pow({x}, {y}) *pow()*
7567 Return the power of {x} to the exponent {y} as a |Float|.
7568 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007569 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007570 Examples: >
7571 :echo pow(3, 3)
7572< 27.0 >
7573 :echo pow(2, 16)
7574< 65536.0 >
7575 :echo pow(32, 0.20)
7576< 2.0
7577
7578 Can also be used as a |method|: >
7579 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007580<
7581 Return type: |Number|
7582
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007583
7584prevnonblank({lnum}) *prevnonblank()*
7585 Return the line number of the first line at or above {lnum}
7586 that is not blank. Example: >
7587 let ind = indent(prevnonblank(v:lnum - 1))
7588< When {lnum} is invalid or there is no non-blank line at or
7589 above it, zero is returned.
7590 {lnum} is used like with |getline()|.
7591 Also see |nextnonblank()|.
7592
7593 Can also be used as a |method|: >
7594 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007595<
7596 Return type: |Number|
7597
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007598
7599printf({fmt}, {expr1} ...) *printf()*
7600 Return a String with {fmt}, where "%" items are replaced by
7601 the formatted form of their respective arguments. Example: >
7602 printf("%4d: E%d %.30s", lnum, errno, msg)
7603< May result in:
7604 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7605
7606 When used as a |method| the base is passed as the second
7607 argument: >
7608 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007609<
7610 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007611
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007612 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007613 %s string
7614 %6S string right-aligned in 6 display cells
7615 %6s string right-aligned in 6 bytes
7616 %.9s string truncated to 9 bytes
7617 %c single byte
7618 %d decimal number
7619 %5d decimal number padded with spaces to 5 characters
7620 %x hex number
7621 %04x hex number padded with zeros to at least 4 characters
7622 %X hex number using upper case letters
7623 %o octal number
7624 %08b binary number padded with zeros to at least 8 chars
7625 %f floating point number as 12.23, inf, -inf or nan
7626 %F floating point number as 12.23, INF, -INF or NAN
7627 %e floating point number as 1.23e3, inf, -inf or nan
7628 %E floating point number as 1.23E3, INF, -INF or NAN
7629 %g floating point number, as %f or %e depending on value
7630 %G floating point number, as %F or %E depending on value
7631 %% the % character itself
7632
7633 Conversion specifications start with '%' and end with the
7634 conversion type. All other characters are copied unchanged to
7635 the result.
7636
7637 The "%" starts a conversion specification. The following
7638 arguments appear in sequence:
7639
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007640 % [pos-argument] [flags] [field-width] [.precision] type
7641
7642 pos-argument
7643 At most one positional argument specifier. These
7644 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007645
7646 flags
7647 Zero or more of the following flags:
7648
7649 # The value should be converted to an "alternate
7650 form". For c, d, and s conversions, this option
7651 has no effect. For o conversions, the precision
7652 of the number is increased to force the first
7653 character of the output string to a zero (except
7654 if a zero value is printed with an explicit
7655 precision of zero).
7656 For b and B conversions, a non-zero result has
7657 the string "0b" (or "0B" for B conversions)
7658 prepended to it.
7659 For x and X conversions, a non-zero result has
7660 the string "0x" (or "0X" for X conversions)
7661 prepended to it.
7662
7663 0 (zero) Zero padding. For all conversions the converted
7664 value is padded on the left with zeros rather
7665 than blanks. If a precision is given with a
7666 numeric conversion (d, b, B, o, x, and X), the 0
7667 flag is ignored.
7668
7669 - A negative field width flag; the converted value
7670 is to be left adjusted on the field boundary.
7671 The converted value is padded on the right with
7672 blanks, rather than on the left with blanks or
7673 zeros. A - overrides a 0 if both are given.
7674
7675 ' ' (space) A blank should be left before a positive
7676 number produced by a signed conversion (d).
7677
7678 + A sign must always be placed before a number
7679 produced by a signed conversion. A + overrides
7680 a space if both are used.
7681
7682 field-width
7683 An optional decimal digit string specifying a minimum
7684 field width. If the converted value has fewer bytes
7685 than the field width, it will be padded with spaces on
7686 the left (or right, if the left-adjustment flag has
7687 been given) to fill out the field width. For the S
7688 conversion the count is in cells.
7689
7690 .precision
7691 An optional precision, in the form of a period '.'
7692 followed by an optional digit string. If the digit
7693 string is omitted, the precision is taken as zero.
7694 This gives the minimum number of digits to appear for
7695 d, o, x, and X conversions, the maximum number of
7696 bytes to be printed from a string for s conversions,
7697 or the maximum number of cells to be printed from a
7698 string for S conversions.
7699 For floating point it is the number of digits after
7700 the decimal point.
7701
7702 type
7703 A character that specifies the type of conversion to
7704 be applied, see below.
7705
7706 A field width or precision, or both, may be indicated by an
7707 asterisk '*' instead of a digit string. In this case, a
7708 Number argument supplies the field width or precision. A
7709 negative field width is treated as a left adjustment flag
7710 followed by a positive field width; a negative precision is
7711 treated as though it were missing. Example: >
7712 :echo printf("%d: %.*s", nr, width, line)
7713< This limits the length of the text used from "line" to
7714 "width" bytes.
7715
Dominique Pellé17dca3c2023-12-14 20:36:32 +01007716 If the argument to be formatted is specified using a
7717 positional argument specifier, and a '*' is used to indicate
7718 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007719 precision, the argument(s) to be used must also be specified
7720 using a {n$} positional argument specifier. See |printf-$|.
7721
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007722 The conversion specifiers and their meanings are:
7723
7724 *printf-d* *printf-b* *printf-B* *printf-o*
7725 *printf-x* *printf-X*
7726 dbBoxX The Number argument is converted to signed decimal
7727 (d), unsigned binary (b and B), unsigned octal (o), or
7728 unsigned hexadecimal (x and X) notation. The letters
7729 "abcdef" are used for x conversions; the letters
7730 "ABCDEF" are used for X conversions.
7731 The precision, if any, gives the minimum number of
7732 digits that must appear; if the converted value
7733 requires fewer digits, it is padded on the left with
7734 zeros.
7735 In no case does a non-existent or small field width
7736 cause truncation of a numeric field; if the result of
7737 a conversion is wider than the field width, the field
7738 is expanded to contain the conversion result.
7739 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02007740 The 'l' modifier indicates the argument is a long
7741 integer. The size will be 32 bits or 64 bits
7742 depending on your platform.
7743 The "ll" modifier indicates the argument is 64 bits.
7744 The b and B conversion specifiers never take a width
7745 modifier and always assume their argument is a 64 bit
7746 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007747 Generally, these modifiers are not useful. They are
7748 ignored when type is known from the argument.
7749
7750 i alias for d
7751 D alias for ld
7752 U alias for lu
7753 O alias for lo
7754
7755 *printf-c*
7756 c The Number argument is converted to a byte, and the
7757 resulting character is written.
7758
7759 *printf-s*
7760 s The text of the String argument is used. If a
7761 precision is specified, no more bytes than the number
7762 specified are used.
7763 If the argument is not a String type, it is
7764 automatically converted to text with the same format
7765 as ":echo".
7766 *printf-S*
7767 S The text of the String argument is used. If a
7768 precision is specified, no more display cells than the
7769 number specified are used.
7770
7771 *printf-f* *E807*
7772 f F The Float argument is converted into a string of the
7773 form 123.456. The precision specifies the number of
7774 digits after the decimal point. When the precision is
7775 zero the decimal point is omitted. When the precision
7776 is not specified 6 is used. A really big number
7777 (out of range or dividing by zero) results in "inf"
7778 or "-inf" with %f (INF or -INF with %F).
7779 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
7780 Example: >
7781 echo printf("%.2f", 12.115)
7782< 12.12
7783 Note that roundoff depends on the system libraries.
7784 Use |round()| when in doubt.
7785
7786 *printf-e* *printf-E*
7787 e E The Float argument is converted into a string of the
7788 form 1.234e+03 or 1.234E+03 when using 'E'. The
7789 precision specifies the number of digits after the
7790 decimal point, like with 'f'.
7791
7792 *printf-g* *printf-G*
7793 g G The Float argument is converted like with 'f' if the
7794 value is between 0.001 (inclusive) and 10000000.0
7795 (exclusive). Otherwise 'e' is used for 'g' and 'E'
7796 for 'G'. When no precision is specified superfluous
7797 zeroes and '+' signs are removed, except for the zero
7798 immediately after the decimal point. Thus 10000000.0
7799 results in 1.0e7.
7800
7801 *printf-%*
7802 % A '%' is written. No argument is converted. The
7803 complete conversion specification is "%%".
7804
7805 When a Number argument is expected a String argument is also
7806 accepted and automatically converted.
7807 When a Float or String argument is expected a Number argument
7808 is also accepted and automatically converted.
7809 Any other argument type results in an error message.
7810
7811 *E766* *E767*
7812 The number of {exprN} arguments must exactly match the number
7813 of "%" items. If there are not sufficient or too many
7814 arguments an error is given. Up to 18 arguments can be used.
7815
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007816 *printf-$*
7817 In certain languages, error and informative messages are
7818 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02007819 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007820 having a different word order, positional arguments may be
7821 used to indicate this. For instance: >
7822
h_east596a9f22023-11-21 21:24:23 +09007823 #, c-format
7824 msgid "%s returning %s"
7825 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007826<
h_east596a9f22023-11-21 21:24:23 +09007827 In this example, the sentence has its 2 string arguments
7828 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007829
h_east596a9f22023-11-21 21:24:23 +09007830 echo printf(
7831 "In The Netherlands, vim's creator's name is: %1$s %2$s",
7832 "Bram", "Moolenaar")
7833< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007834
h_east596a9f22023-11-21 21:24:23 +09007835 echo printf(
7836 "In Belgium, vim's creator's name is: %2$s %1$s",
7837 "Bram", "Moolenaar")
7838< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007839
7840 Width (and precision) can be specified using the '*' specifier.
7841 In this case, you must specify the field width position in the
7842 argument list. >
7843
h_east596a9f22023-11-21 21:24:23 +09007844 echo printf("%1$*2$.*3$d", 1, 2, 3)
7845< 001 >
7846 echo printf("%2$*3$.*1$d", 1, 2, 3)
7847< 2 >
7848 echo printf("%3$*1$.*2$d", 1, 2, 3)
7849< 03 >
7850 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
7851< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007852
7853 You can mix specifying the width and/or precision directly
7854 and via positional arguments: >
7855
h_east596a9f22023-11-21 21:24:23 +09007856 echo printf("%1$4.*2$f", 1.4142135, 6)
7857< 1.414214 >
7858 echo printf("%1$*2$.4f", 1.4142135, 6)
7859< 1.4142 >
7860 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
7861< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007862
Christ van Willegenc35fc032024-03-14 18:30:41 +01007863 You will get an overflow error |E1510|, when the field-width
7864 or precision will result in a string longer than 6400 chars.
7865
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007866 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007867 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09007868 echo printf("%s%1$s", "One", "Two")
7869< E1500: Cannot mix positional and non-positional arguments:
7870 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007871
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007872 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007873 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09007874 echo printf("%3$s%1$s", "One", "Two", "Three")
7875< E1501: format argument 2 unused in $-style format:
7876 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007877
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007878 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007879 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09007880 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
7881< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007882
7883 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09007884 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
7885< E1502: Positional argument 2 used as field width reused as
7886 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007887
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007888 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007889 When a positional argument is used, but not the correct number
7890 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09007891 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
7892< E1503: Positional argument 3 out of bounds: %1$d at width
7893 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007894
7895 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09007896 echo printf("%01$*2$.*3$d %4$d", 1, 2)
7897< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
7898 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007899
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007900 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007901 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09007902 echo printf("%1$s %2$s %1$s", "One", "Two")
7903< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007904
7905 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09007906 echo printf("%1$s %2$s %1$d", "One", "Two")
7907< E1504: Positional argument 1 type used inconsistently:
7908 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007909
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007910 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007911 Various other errors that lead to a format string being
7912 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09007913 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
7914< E1505: Invalid format specifier: %1$d at width %2$d is:
7915 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007916
Christ van Willegenea746f92023-10-05 20:48:36 +02007917 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08007918 This internal error indicates that the logic to parse a
7919 positional format argument ran into a problem that couldn't be
7920 otherwise reported. Please file a bug against Vim if you run
7921 into this, copying the exact format string and parameters that
7922 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02007923
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007924 Return type: |String|
7925
Christ van Willegenea746f92023-10-05 20:48:36 +02007926
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007927prompt_getprompt({buf}) *prompt_getprompt()*
7928 Returns the effective prompt text for buffer {buf}. {buf} can
7929 be a buffer name or number. See |prompt-buffer|.
7930
7931 If the buffer doesn't exist or isn't a prompt buffer, an empty
7932 string is returned.
7933
7934 Can also be used as a |method|: >
7935 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007936<
7937 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007938
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007939 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007940
7941
7942prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
7943 Set prompt callback for buffer {buf} to {expr}. When {expr}
7944 is an empty string the callback is removed. This has only
7945 effect if {buf} has 'buftype' set to "prompt".
7946
7947 The callback is invoked when pressing Enter. The current
7948 buffer will always be the prompt buffer. A new line for a
7949 prompt is added before invoking the callback, thus the prompt
7950 for which the callback was invoked will be in the last but one
7951 line.
7952 If the callback wants to add text to the buffer, it must
7953 insert it above the last line, since that is where the current
7954 prompt is. This can also be done asynchronously.
7955 The callback is invoked with one argument, which is the text
7956 that was entered at the prompt. This can be an empty string
7957 if the user only typed Enter.
7958 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007959 func s:TextEntered(text)
7960 if a:text == 'exit' || a:text == 'quit'
7961 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01007962 " Reset 'modified' to allow the buffer to be closed.
7963 " We assume there is nothing useful to be saved.
7964 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007965 close
7966 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01007967 " Do something useful with "a:text". In this example
7968 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007969 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007970 endif
7971 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01007972 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007973
7974< Can also be used as a |method|: >
7975 GetBuffer()->prompt_setcallback(callback)
7976
7977< {only available when compiled with the |+channel| feature}
7978
7979prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
7980 Set a callback for buffer {buf} to {expr}. When {expr} is an
7981 empty string the callback is removed. This has only effect if
7982 {buf} has 'buftype' set to "prompt".
7983
7984 This callback will be invoked when pressing CTRL-C in Insert
7985 mode. Without setting a callback Vim will exit Insert mode,
7986 as in any buffer.
7987
7988 Can also be used as a |method|: >
7989 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007990<
7991 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007992
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007993 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007994
7995prompt_setprompt({buf}, {text}) *prompt_setprompt()*
7996 Set prompt for buffer {buf} to {text}. You most likely want
7997 {text} to end in a space.
7998 The result is only visible if {buf} has 'buftype' set to
7999 "prompt". Example: >
8000 call prompt_setprompt(bufnr(), 'command: ')
8001<
8002 Can also be used as a |method|: >
8003 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008004<
8005 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008006
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008007 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008008
8009prop_ functions are documented here: |text-prop-functions|
8010
8011pum_getpos() *pum_getpos()*
8012 If the popup menu (see |ins-completion-menu|) is not visible,
8013 returns an empty |Dictionary|, otherwise, returns a
8014 |Dictionary| with the following keys:
8015 height nr of items visible
8016 width screen cells
8017 row top screen row (0 first row)
8018 col leftmost screen column (0 first col)
8019 size total nr of items
8020 scrollbar |TRUE| if scrollbar is visible
8021
8022 The values are the same as in |v:event| during
8023 |CompleteChanged|.
8024
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008025 Return type: dict<any>
8026
8027
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008028pumvisible() *pumvisible()*
8029 Returns non-zero when the popup menu is visible, zero
8030 otherwise. See |ins-completion-menu|.
8031 This can be used to avoid some things that would remove the
8032 popup menu.
8033
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008034 Return type: |Number|
8035
8036
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008037py3eval({expr}) *py3eval()*
8038 Evaluate Python expression {expr} and return its result
8039 converted to Vim data structures.
8040 Numbers and strings are returned as they are (strings are
8041 copied though, Unicode strings are additionally converted to
8042 'encoding').
8043 Lists are represented as Vim |List| type.
8044 Dictionaries are represented as Vim |Dictionary| type with
8045 keys converted to strings.
8046 Note that in a `:def` function local variables are not visible
8047 to {expr}.
8048
8049 Can also be used as a |method|: >
8050 GetExpr()->py3eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008051<
8052 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008053
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008054 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008055
8056 *E858* *E859*
8057pyeval({expr}) *pyeval()*
8058 Evaluate Python expression {expr} and return its result
8059 converted to Vim data structures.
8060 Numbers and strings are returned as they are (strings are
8061 copied though).
8062 Lists are represented as Vim |List| type.
8063 Dictionaries are represented as Vim |Dictionary| type,
8064 non-string keys result in error.
8065 Note that in a `:def` function local variables are not visible
8066 to {expr}.
8067
8068 Can also be used as a |method|: >
8069 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008070<
8071 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008072
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008073 {only available when compiled with the |+python| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008074
8075pyxeval({expr}) *pyxeval()*
8076 Evaluate Python expression {expr} and return its result
8077 converted to Vim data structures.
8078 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8079 See also: |pyeval()|, |py3eval()|
8080
8081 Can also be used as a |method|: >
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008082 < GetExpr()->pyxeval()
8083<
8084 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008085
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008086 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008087 |+python3| feature}
8088
8089rand([{expr}]) *rand()* *random*
8090 Return a pseudo-random Number generated with an xoshiro128**
8091 algorithm using seed {expr}. The returned number is 32 bits,
8092 also on 64 bits systems, for consistency.
8093 {expr} can be initialized by |srand()| and will be updated by
8094 rand(). If {expr} is omitted, an internal seed value is used
8095 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008096 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008097
8098 Examples: >
8099 :echo rand()
8100 :let seed = srand()
8101 :echo rand(seed)
8102 :echo rand(seed) % 16 " random number 0 - 15
8103<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008104 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008105
8106 *E726* *E727*
8107range({expr} [, {max} [, {stride}]]) *range()*
8108 Returns a |List| with Numbers:
8109 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8110 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8111 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8112 {max}] (increasing {expr} with {stride} each time, not
8113 producing a value past {max}).
8114 When the maximum is one before the start the result is an
8115 empty list. When the maximum is more than one before the
8116 start this is an error.
8117 Examples: >
8118 range(4) " [0, 1, 2, 3]
8119 range(2, 4) " [2, 3, 4]
8120 range(2, 9, 3) " [2, 5, 8]
8121 range(2, -2, -1) " [2, 1, 0, -1, -2]
8122 range(0) " []
8123 range(2, 0) " error!
8124<
8125 Can also be used as a |method|: >
8126 GetExpr()->range()
8127<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008128 Return type: list<number>
8129
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008130
K.Takata11df3ae2022-10-19 14:02:40 +01008131readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008132 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008133 If {offset} is specified, read the file from the specified
8134 offset. If it is a negative value, it is used as an offset
8135 from the end of the file. E.g., to read the last 12 bytes: >
8136 readblob('file.bin', -12)
8137< If {size} is specified, only the specified size will be read.
8138 E.g. to read the first 100 bytes of a file: >
8139 readblob('file.bin', 0, 100)
8140< If {size} is -1 or omitted, the whole data starting from
8141 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008142 This can be also used to read the data from a character device
8143 on Unix when {size} is explicitly set. Only if the device
8144 supports seeking {offset} can be used. Otherwise it should be
8145 zero. E.g. to read 10 bytes from a serial console: >
8146 readblob('/dev/ttyS0', 0, 10)
8147< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008148 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008149 When the offset is beyond the end of the file the result is an
8150 empty blob.
8151 When trying to read more bytes than are available the result
8152 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008153 Also see |readfile()| and |writefile()|.
8154
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008155 Return type: |Blob|
8156
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008157
8158readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8159 Return a list with file and directory names in {directory}.
8160 You can also use |glob()| if you don't need to do complicated
8161 things, such as limiting the number of matches.
8162 The list will be sorted (case sensitive), see the {dict}
8163 argument below for changing the sort order.
8164
8165 When {expr} is omitted all entries are included.
8166 When {expr} is given, it is evaluated to check what to do:
8167 If {expr} results in -1 then no further entries will
8168 be handled.
8169 If {expr} results in 0 then this entry will not be
8170 added to the list.
8171 If {expr} results in 1 then this entry will be added
8172 to the list.
8173 The entries "." and ".." are always excluded.
8174 Each time {expr} is evaluated |v:val| is set to the entry name.
8175 When {expr} is a function the name is passed as the argument.
8176 For example, to get a list of files ending in ".txt": >
8177 readdir(dirname, {n -> n =~ '.txt$'})
8178< To skip hidden and backup files: >
8179 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008180< *E857*
8181 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008182 values. Currently this is used to specify if and how sorting
8183 should be performed. The dict can have the following members:
8184
8185 sort How to sort the result returned from the system.
8186 Valid values are:
8187 "none" do not sort (fastest method)
8188 "case" sort case sensitive (byte value of
8189 each character, technically, using
8190 strcmp()) (default)
8191 "icase" sort case insensitive (technically
8192 using strcasecmp())
8193 "collate" sort using the collation order
8194 of the "POSIX" or "C" |locale|
8195 (technically using strcoll())
8196 Other values are silently ignored.
8197
8198 For example, to get a list of all files in the current
8199 directory without sorting the individual entries: >
8200 readdir('.', '1', #{sort: 'none'})
8201< If you want to get a directory tree: >
8202 function! s:tree(dir)
8203 return {a:dir : map(readdir(a:dir),
8204 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008205 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008206 endfunction
8207 echo s:tree(".")
8208<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008209 Returns an empty List on error.
8210
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008211 Can also be used as a |method|: >
8212 GetDirName()->readdir()
8213<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008214 Return type: list<string> or list<any>
8215
8216
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008217readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8218 Extended version of |readdir()|.
8219 Return a list of Dictionaries with file and directory
8220 information in {directory}.
8221 This is useful if you want to get the attributes of file and
8222 directory at the same time as getting a list of a directory.
8223 This is much faster than calling |readdir()| then calling
8224 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8225 each file and directory especially on MS-Windows.
8226 The list will by default be sorted by name (case sensitive),
8227 the sorting can be changed by using the optional {dict}
8228 argument, see |readdir()|.
8229
8230 The Dictionary for file and directory information has the
8231 following items:
8232 group Group name of the entry. (Only on Unix)
8233 name Name of the entry.
8234 perm Permissions of the entry. See |getfperm()|.
8235 size Size of the entry. See |getfsize()|.
8236 time Timestamp of the entry. See |getftime()|.
8237 type Type of the entry.
8238 On Unix, almost same as |getftype()| except:
8239 Symlink to a dir "linkd"
8240 Other symlink "link"
8241 On MS-Windows:
8242 Normal file "file"
8243 Directory "dir"
8244 Junction "junction"
8245 Symlink to a dir "linkd"
8246 Other symlink "link"
8247 Other reparse point "reparse"
8248 user User name of the entry's owner. (Only on Unix)
8249 On Unix, if the entry is a symlink, the Dictionary includes
8250 the information of the target (except the "type" item).
8251 On MS-Windows, it includes the information of the symlink
8252 itself because of performance reasons.
8253
8254 When {expr} is omitted all entries are included.
8255 When {expr} is given, it is evaluated to check what to do:
8256 If {expr} results in -1 then no further entries will
8257 be handled.
8258 If {expr} results in 0 then this entry will not be
8259 added to the list.
8260 If {expr} results in 1 then this entry will be added
8261 to the list.
8262 The entries "." and ".." are always excluded.
8263 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8264 of the entry.
8265 When {expr} is a function the entry is passed as the argument.
8266 For example, to get a list of files ending in ".txt": >
8267 readdirex(dirname, {e -> e.name =~ '.txt$'})
8268<
8269 For example, to get a list of all files in the current
8270 directory without sorting the individual entries: >
8271 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008272<
8273 Can also be used as a |method|: >
8274 GetDirName()->readdirex()
8275<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008276 Return type: list<dict<any>> or list<any>
8277
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008278
8279 *readfile()*
8280readfile({fname} [, {type} [, {max}]])
8281 Read file {fname} and return a |List|, each line of the file
8282 as an item. Lines are broken at NL characters. Macintosh
8283 files separated with CR will result in a single long line
8284 (unless a NL appears somewhere).
8285 All NUL characters are replaced with a NL character.
8286 When {type} contains "b" binary mode is used:
8287 - When the last line ends in a NL an extra empty list item is
8288 added.
8289 - No CR characters are removed.
8290 Otherwise:
8291 - CR characters that appear before a NL are removed.
8292 - Whether the last line ends in a NL or not does not matter.
8293 - When 'encoding' is Unicode any UTF-8 byte order mark is
8294 removed from the text.
8295 When {max} is given this specifies the maximum number of lines
8296 to be read. Useful if you only want to check the first ten
8297 lines of a file: >
8298 :for line in readfile(fname, '', 10)
8299 : if line =~ 'Date' | echo line | endif
8300 :endfor
8301< When {max} is negative -{max} lines from the end of the file
8302 are returned, or as many as there are.
8303 When {max} is zero the result is an empty list.
8304 Note that without {max} the whole file is read into memory.
8305 Also note that there is no recognition of encoding. Read a
8306 file into a buffer if you need to.
8307 Deprecated (use |readblob()| instead): When {type} contains
8308 "B" a |Blob| is returned with the binary data of the file
8309 unmodified.
8310 When the file can't be opened an error message is given and
8311 the result is an empty list.
8312 Also see |writefile()|.
8313
8314 Can also be used as a |method|: >
8315 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008316<
8317 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008318
8319reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8320 {func} is called for every item in {object}, which can be a
8321 |String|, |List| or a |Blob|. {func} is called with two
8322 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008323 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008324
8325 {initial} is the initial result. When omitted, the first item
8326 in {object} is used and {func} is first called for the second
8327 item. If {initial} is not given and {object} is empty no
8328 result can be computed, an E998 error is given.
8329
8330 Examples: >
8331 echo reduce([1, 3, 5], { acc, val -> acc + val })
8332 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8333 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8334 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8335<
8336 Can also be used as a |method|: >
8337 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008338<
8339 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8340 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008341
8342
8343reg_executing() *reg_executing()*
8344 Returns the single letter name of the register being executed.
8345 Returns an empty string when no register is being executed.
8346 See |@|.
8347
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008348 Return type: |String|
8349
8350
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008351reg_recording() *reg_recording()*
8352 Returns the single letter name of the register being recorded.
8353 Returns an empty string when not recording. See |q|.
8354
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008355 Return type: |String|
8356
8357
8358reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008359reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008360reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008361 Return an item that represents a time value. The item is a
8362 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008363 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008364 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008365 string or |reltimefloat()| to convert to a Float. For
8366 example, to see the time spent in function Work(): >
8367 var startTime = reltime()
8368 Work()
8369 echo startTime->reltime()->reltimestr()
8370<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008371 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008372 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008373 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008374 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008375 specified in the argument.
8376 With two arguments it returns the time passed between {start}
8377 and {end}.
8378
8379 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008380 reltime(). If there is an error an empty List is returned in
8381 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008382
8383 Can also be used as a |method|: >
8384 GetStart()->reltime()
8385<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008386 Return type: list<number>
8387
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008388 {only available when compiled with the |+reltime| feature}
8389
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008390
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008391reltimefloat({time}) *reltimefloat()*
8392 Return a Float that represents the time value of {time}.
8393 Example: >
8394 let start = reltime()
8395 call MyFunction()
8396 let seconds = reltimefloat(reltime(start))
8397< See the note of reltimestr() about overhead.
8398 Also see |profiling|.
8399 If there is an error 0.0 is returned in legacy script, in Vim9
8400 script an error is given.
8401
8402 Can also be used as a |method|: >
8403 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008404<
8405 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008406
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008407 {only available when compiled with the |+reltime| feature}
8408
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008409
8410reltimestr({time}) *reltimestr()*
8411 Return a String that represents the time value of {time}.
8412 This is the number of seconds, a dot and the number of
8413 microseconds. Example: >
8414 let start = reltime()
8415 call MyFunction()
8416 echo reltimestr(reltime(start))
8417< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008418 The accuracy depends on the system. Use reltimefloat() for the
8419 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008420 Leading spaces are used to make the string align nicely. You
8421 can use split() to remove it. >
8422 echo split(reltimestr(reltime(start)))[0]
8423< Also see |profiling|.
8424 If there is an error an empty string is returned in legacy
8425 script, in Vim9 script an error is given.
8426
8427 Can also be used as a |method|: >
8428 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008429<
8430 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008431
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008432 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008433
8434 *remote_expr()* *E449*
8435remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008436 Send the {string} to {server}. The {server} argument is a
8437 string, also see |{server}|.
8438
8439 The string is sent as an expression and the result is returned
8440 after evaluation. The result must be a String or a |List|. A
8441 |List| is turned into a String by joining the items with a
8442 line break in between (not at the end), like with join(expr,
8443 "\n").
8444
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008445 If {idvar} is present and not empty, it is taken as the name
8446 of a variable and a {serverid} for later use with
8447 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008448
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008449 If {timeout} is given the read times out after this many
8450 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008451
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008452 See also |clientserver| |RemoteReply|.
8453 This function is not available in the |sandbox|.
8454 {only available when compiled with the |+clientserver| feature}
8455 Note: Any errors will cause a local error message to be issued
8456 and the result will be the empty string.
8457
8458 Variables will be evaluated in the global namespace,
8459 independent of a function currently being active. Except
8460 when in debug mode, then local function variables and
8461 arguments can be evaluated.
8462
8463 Examples: >
8464 :echo remote_expr("gvim", "2+2")
8465 :echo remote_expr("gvim1", "b:current_syntax")
8466<
8467 Can also be used as a |method|: >
8468 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008469<
8470 Return type: |String| or list<{type}>
8471
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008472
8473remote_foreground({server}) *remote_foreground()*
8474 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008475 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008476 This works like: >
8477 remote_expr({server}, "foreground()")
8478< Except that on Win32 systems the client does the work, to work
8479 around the problem that the OS doesn't always allow the server
8480 to bring itself to the foreground.
8481 Note: This does not restore the window if it was minimized,
8482 like foreground() does.
8483 This function is not available in the |sandbox|.
8484
8485 Can also be used as a |method|: >
8486 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008487<
8488 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008489
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008490 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008491 Win32 console version}
8492
8493
8494remote_peek({serverid} [, {retvar}]) *remote_peek()*
8495 Returns a positive number if there are available strings
8496 from {serverid}. Copies any reply string into the variable
8497 {retvar} if specified. {retvar} must be a string with the
8498 name of a variable.
8499 Returns zero if none are available.
8500 Returns -1 if something is wrong.
8501 See also |clientserver|.
8502 This function is not available in the |sandbox|.
8503 {only available when compiled with the |+clientserver| feature}
8504 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008505 :let repl = ""
8506 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008507
8508< Can also be used as a |method|: >
8509 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008510<
8511 Return type: |Number|
8512
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008513
8514remote_read({serverid}, [{timeout}]) *remote_read()*
8515 Return the oldest available reply from {serverid} and consume
8516 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008517 reply is available. Returns an empty string, if a reply is
8518 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008519 See also |clientserver|.
8520 This function is not available in the |sandbox|.
8521 {only available when compiled with the |+clientserver| feature}
8522 Example: >
8523 :echo remote_read(id)
8524
8525< Can also be used as a |method|: >
8526 ServerId()->remote_read()
8527<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008528 Return type: |String|
8529
8530
8531remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008532 Send the {string} to {server}. The {server} argument is a
8533 string, also see |{server}|.
8534
8535 The string is sent as input keys and the function returns
8536 immediately. At the Vim server the keys are not mapped
8537 |:map|.
8538
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008539 If {idvar} is present, it is taken as the name of a variable
8540 and a {serverid} for later use with remote_read() is stored
8541 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008542
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008543 See also |clientserver| |RemoteReply|.
8544 This function is not available in the |sandbox|.
8545 {only available when compiled with the |+clientserver| feature}
8546
8547 Note: Any errors will be reported in the server and may mess
8548 up the display.
8549 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008550 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008551 \ remote_read(serverid)
8552
8553 :autocmd NONE RemoteReply *
8554 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008555 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008556 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8557<
8558 Can also be used as a |method|: >
8559 ServerName()->remote_send(keys)
8560<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008561 Return type: |String|
8562
8563
8564remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008565 Become the server {name}. {name} must be a non-empty string.
8566 This fails if already running as a server, when |v:servername|
8567 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008568
8569 Can also be used as a |method|: >
8570 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008571<
8572 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008573
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008574 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008575
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008576
8577remove({list}, {idx}) *remove()*
8578remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008579 Without {end}: Remove the item at {idx} from |List| {list} and
8580 return the item.
8581 With {end}: Remove items from {idx} to {end} (inclusive) and
8582 return a |List| with these items. When {idx} points to the same
8583 item as {end} a list with one item is returned. When {end}
8584 points to an item before {idx} this is an error.
8585 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008586 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008587 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008588 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008589 :call remove(mylist, 0, 9)
8590<
8591 Use |delete()| to remove a file.
8592
8593 Can also be used as a |method|: >
8594 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008595<
8596 Return type: any, depending on {list}
8597
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008598
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008599remove({blob}, {idx})
8600remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008601 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8602 return the byte.
8603 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8604 return a |Blob| with these bytes. When {idx} points to the same
8605 byte as {end} a |Blob| with one byte is returned. When {end}
8606 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008607 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008608 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008609 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008610 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008611<
8612 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008613
8614remove({dict}, {key})
8615 Remove the entry from {dict} with key {key} and return it.
8616 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008617 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008618< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008619 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008620
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008621 Return type: any, depending on {dict}
8622
8623
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008624rename({from}, {to}) *rename()*
8625 Rename the file by the name {from} to the name {to}. This
8626 should also work to move files across file systems. The
8627 result is a Number, which is 0 if the file was renamed
8628 successfully, and non-zero when the renaming failed.
8629 NOTE: If {to} exists it is overwritten without warning.
8630 This function is not available in the |sandbox|.
8631
8632 Can also be used as a |method|: >
8633 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008634<
8635 Return type: |Number|
8636
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008637
8638repeat({expr}, {count}) *repeat()*
8639 Repeat {expr} {count} times and return the concatenated
8640 result. Example: >
8641 :let separator = repeat('-', 80)
8642< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01008643 When {expr} is a |List| or a |Blob| the result is {expr}
8644 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008645 :let longlist = repeat(['a', 'b'], 3)
8646< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
8647
8648 Can also be used as a |method|: >
8649 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008650<
8651 Return type: |String|, |Blob| or list<{type}> depending on
8652 {expr}
8653
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008654
8655resolve({filename}) *resolve()* *E655*
8656 On MS-Windows, when {filename} is a shortcut (a .lnk file),
8657 returns the path the shortcut points to in a simplified form.
8658 When {filename} is a symbolic link or junction point, return
8659 the full path to the target. If the target of junction is
8660 removed, return {filename}.
8661 On Unix, repeat resolving symbolic links in all path
8662 components of {filename} and return the simplified result.
8663 To cope with link cycles, resolving of symbolic links is
8664 stopped after 100 iterations.
8665 On other systems, return the simplified {filename}.
8666 The simplification step is done as by |simplify()|.
8667 resolve() keeps a leading path component specifying the
8668 current directory (provided the result is still a relative
8669 path name) and also keeps a trailing path separator.
8670
8671 Can also be used as a |method|: >
8672 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008673<
8674 Return type: |String|
8675
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008676
8677reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01008678 Reverse the order of items in {object}. {object} can be a
8679 |List|, a |Blob| or a |String|. For a List and a Blob the
8680 items are reversed in-place and {object} is returned.
8681 For a String a new String is returned.
8682 Returns zero if {object} is not a List, Blob or a String.
8683 If you want a List or Blob to remain unmodified make a copy
8684 first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008685 :let revlist = reverse(copy(mylist))
8686< Can also be used as a |method|: >
8687 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008688<
8689 Return type: |String|, |Blob| or list<{type}> depending on
8690 {object}
8691
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008692
8693round({expr}) *round()*
8694 Round off {expr} to the nearest integral value and return it
8695 as a |Float|. If {expr} lies halfway between two integral
8696 values, then use the larger one (away from zero).
8697 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008698 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008699 Examples: >
8700 echo round(0.456)
8701< 0.0 >
8702 echo round(4.5)
8703< 5.0 >
8704 echo round(-4.5)
8705< -5.0
8706
8707 Can also be used as a |method|: >
8708 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008709<
8710 Return type: |Float|
8711
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008712
8713rubyeval({expr}) *rubyeval()*
8714 Evaluate Ruby expression {expr} and return its result
8715 converted to Vim data structures.
8716 Numbers, floats and strings are returned as they are (strings
8717 are copied though).
8718 Arrays are represented as Vim |List| type.
8719 Hashes are represented as Vim |Dictionary| type.
8720 Other objects are represented as strings resulted from their
8721 "Object#to_s" method.
8722 Note that in a `:def` function local variables are not visible
8723 to {expr}.
8724
8725 Can also be used as a |method|: >
8726 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008727<
8728 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008729
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008730 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008731
8732screenattr({row}, {col}) *screenattr()*
8733 Like |screenchar()|, but return the attribute. This is a rather
8734 arbitrary number that can only be used to compare to the
8735 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008736 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008737
8738 Can also be used as a |method|: >
8739 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008740<
8741 Return type: |Number|
8742
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008743
8744screenchar({row}, {col}) *screenchar()*
8745 The result is a Number, which is the character at position
8746 [row, col] on the screen. This works for every possible
8747 screen position, also status lines, window separators and the
8748 command line. The top left position is row one, column one
8749 The character excludes composing characters. For double-byte
8750 encodings it may only be the first byte.
8751 This is mainly to be used for testing.
8752 Returns -1 when row or col is out of range.
8753
8754 Can also be used as a |method|: >
8755 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008756<
8757 Return type: |Number|
8758
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008759
8760screenchars({row}, {col}) *screenchars()*
8761 The result is a |List| of Numbers. The first number is the same
8762 as what |screenchar()| returns. Further numbers are
8763 composing characters on top of the base character.
8764 This is mainly to be used for testing.
8765 Returns an empty List when row or col is out of range.
8766
8767 Can also be used as a |method|: >
8768 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008769<
8770 Return type: list<number> or list<any>
8771
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008772
8773screencol() *screencol()*
8774 The result is a Number, which is the current screen column of
8775 the cursor. The leftmost column has number 1.
8776 This function is mainly used for testing.
8777
8778 Note: Always returns the current screen column, thus if used
8779 in a command (e.g. ":echo screencol()") it will return the
8780 column inside the command line, which is 1 when the command is
8781 executed. To get the cursor position in the file use one of
8782 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008783 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008784 nnoremap <silent> GG :echom screencol()<CR>
8785 nnoremap GG <Cmd>echom screencol()<CR>
8786<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008787 Return type: |Number|
8788
8789
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008790screenpos({winid}, {lnum}, {col}) *screenpos()*
8791 The result is a Dict with the screen position of the text
8792 character in window {winid} at buffer line {lnum} and column
8793 {col}. {col} is a one-based byte index.
8794 The Dict has these members:
8795 row screen row
8796 col first screen column
8797 endcol last screen column
8798 curscol cursor screen column
8799 If the specified position is not visible, all values are zero.
8800 The "endcol" value differs from "col" when the character
8801 occupies more than one screen cell. E.g. for a Tab "col" can
8802 be 1 and "endcol" can be 8.
8803 The "curscol" value is where the cursor would be placed. For
8804 a Tab it would be the same as "endcol", while for a double
8805 width character it would be the same as "col".
8806 The |conceal| feature is ignored here, the column numbers are
8807 as if 'conceallevel' is zero. You can set the cursor to the
8808 right position and use |screencol()| to get the value with
8809 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008810 If the position is in a closed fold the screen position of the
8811 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008812 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008813
8814 Can also be used as a |method|: >
8815 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008816<
8817 Return type: dict<number> or dict<any>
8818
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008819
8820screenrow() *screenrow()*
8821 The result is a Number, which is the current screen row of the
8822 cursor. The top line has number one.
8823 This function is mainly used for testing.
8824 Alternatively you can use |winline()|.
8825
8826 Note: Same restrictions as with |screencol()|.
8827
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008828 Return type: |Number|
8829
8830
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008831screenstring({row}, {col}) *screenstring()*
8832 The result is a String that contains the base character and
8833 any composing characters at position [row, col] on the screen.
8834 This is like |screenchars()| but returning a String with the
8835 characters.
8836 This is mainly to be used for testing.
8837 Returns an empty String when row or col is out of range.
8838
8839 Can also be used as a |method|: >
8840 GetRow()->screenstring(col)
8841<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008842 Return type: |String|
8843
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008844 *search()*
8845search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
8846 Search for regexp pattern {pattern}. The search starts at the
8847 cursor position (you can use |cursor()| to set it).
8848
8849 When a match has been found its line number is returned.
8850 If there is no match a 0 is returned and the cursor doesn't
8851 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01008852 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008853
8854 {flags} is a String, which can contain these character flags:
8855 'b' search Backward instead of forward
8856 'c' accept a match at the Cursor position
8857 'e' move to the End of the match
8858 'n' do Not move the cursor
8859 'p' return number of matching sub-Pattern (see below)
8860 's' Set the ' mark at the previous location of the cursor
8861 'w' Wrap around the end of the file
8862 'W' don't Wrap around the end of the file
8863 'z' start searching at the cursor column instead of zero
8864 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
8865
8866 If the 's' flag is supplied, the ' mark is set, only if the
8867 cursor is moved. The 's' flag cannot be combined with the 'n'
8868 flag.
8869
8870 'ignorecase', 'smartcase' and 'magic' are used.
8871
8872 When the 'z' flag is not given, forward searching always
8873 starts in column zero and then matches before the cursor are
8874 skipped. When the 'c' flag is present in 'cpo' the next
8875 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01008876 search starts one column after the start of the match. This
8877 matters for overlapping matches. See |cpo-c|. You can also
8878 insert "\ze" to change where the match ends, see |/\ze|.
8879
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008880 When searching backwards and the 'z' flag is given then the
8881 search starts in column zero, thus no match in the current
8882 line will be found (unless wrapping around the end of the
8883 file).
8884
8885 When the {stopline} argument is given then the search stops
8886 after searching this line. This is useful to restrict the
8887 search to a range of lines. Examples: >
8888 let match = search('(', 'b', line("w0"))
8889 let end = search('END', '', line("w$"))
8890< When {stopline} is used and it is not zero this also implies
8891 that the search does not wrap around the end of the file.
8892 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01008893 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008894 When the {timeout} argument is given the search stops when
8895 more than this many milliseconds have passed. Thus when
8896 {timeout} is 500 the search stops after half a second.
8897 The value must not be negative. A zero value is like not
8898 giving the argument.
8899 {only available when compiled with the |+reltime| feature}
8900
8901 If the {skip} expression is given it is evaluated with the
8902 cursor positioned on the start of a match. If it evaluates to
8903 non-zero this match is skipped. This can be used, for
8904 example, to skip a match in a comment or a string.
8905 {skip} can be a string, which is evaluated as an expression, a
8906 function reference or a lambda.
8907 When {skip} is omitted or empty, every match is accepted.
8908 When evaluating {skip} causes an error the search is aborted
8909 and -1 returned.
8910 *search()-sub-match*
8911 With the 'p' flag the returned value is one more than the
8912 first sub-match in \(\). One if none of them matched but the
8913 whole pattern did match.
8914 To get the column number too use |searchpos()|.
8915
8916 The cursor will be positioned at the match, unless the 'n'
8917 flag is used.
8918
8919 Example (goes over all files in the argument list): >
8920 :let n = 1
8921 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008922 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008923 : " start at the last char in the file and wrap for the
8924 : " first search to find match at start of file
8925 : normal G$
8926 : let flags = "w"
8927 : while search("foo", flags) > 0
8928 : s/foo/bar/g
8929 : let flags = "W"
8930 : endwhile
8931 : update " write the file if modified
8932 : let n = n + 1
8933 :endwhile
8934<
8935 Example for using some flags: >
8936 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
8937< This will search for the keywords "if", "else", and "endif"
8938 under or after the cursor. Because of the 'p' flag, it
8939 returns 1, 2, or 3 depending on which keyword is found, or 0
8940 if the search fails. With the cursor on the first word of the
8941 line:
8942 if (foo == 0) | let foo = foo + 1 | endif ~
8943 the function returns 1. Without the 'c' flag, the function
8944 finds the "endif" and returns 3. The same thing happens
8945 without the 'e' flag if the cursor is on the "f" of "if".
8946 The 'n' flag tells the function not to move the cursor.
8947
8948 Can also be used as a |method|: >
8949 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008950<
8951 Return type: |Number|
8952
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008953
8954searchcount([{options}]) *searchcount()*
8955 Get or update the last search count, like what is displayed
8956 without the "S" flag in 'shortmess'. This works even if
8957 'shortmess' does contain the "S" flag.
8958
8959 This returns a |Dictionary|. The dictionary is empty if the
8960 previous pattern was not set and "pattern" was not specified.
8961
8962 key type meaning ~
8963 current |Number| current position of match;
8964 0 if the cursor position is
8965 before the first match
8966 exact_match |Boolean| 1 if "current" is matched on
8967 "pos", otherwise 0
8968 total |Number| total count of matches found
8969 incomplete |Number| 0: search was fully completed
8970 1: recomputing was timed out
8971 2: max count exceeded
8972
8973 For {options} see further down.
8974
8975 To get the last search count when |n| or |N| was pressed, call
8976 this function with `recompute: 0` . This sometimes returns
8977 wrong information because |n| and |N|'s maximum count is 99.
8978 If it exceeded 99 the result must be max count + 1 (100). If
8979 you want to get correct information, specify `recompute: 1`: >
8980
8981 " result == maxcount + 1 (100) when many matches
8982 let result = searchcount(#{recompute: 0})
8983
8984 " Below returns correct result (recompute defaults
8985 " to 1)
8986 let result = searchcount()
8987<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01008988 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008989 function! LastSearchCount() abort
8990 let result = searchcount(#{recompute: 0})
8991 if empty(result)
8992 return ''
8993 endif
8994 if result.incomplete ==# 1 " timed out
8995 return printf(' /%s [?/??]', @/)
8996 elseif result.incomplete ==# 2 " max count exceeded
8997 if result.total > result.maxcount &&
8998 \ result.current > result.maxcount
8999 return printf(' /%s [>%d/>%d]', @/,
9000 \ result.current, result.total)
9001 elseif result.total > result.maxcount
9002 return printf(' /%s [%d/>%d]', @/,
9003 \ result.current, result.total)
9004 endif
9005 endif
9006 return printf(' /%s [%d/%d]', @/,
9007 \ result.current, result.total)
9008 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009009 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009010
9011 " Or if you want to show the count only when
9012 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009013 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009014 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9015<
9016 You can also update the search count, which can be useful in a
9017 |CursorMoved| or |CursorMovedI| autocommand: >
9018
9019 autocmd CursorMoved,CursorMovedI *
9020 \ let s:searchcount_timer = timer_start(
9021 \ 200, function('s:update_searchcount'))
9022 function! s:update_searchcount(timer) abort
9023 if a:timer ==# s:searchcount_timer
9024 call searchcount(#{
9025 \ recompute: 1, maxcount: 0, timeout: 100})
9026 redrawstatus
9027 endif
9028 endfunction
9029<
9030 This can also be used to count matched texts with specified
9031 pattern in the current buffer using "pattern": >
9032
9033 " Count '\<foo\>' in this buffer
9034 " (Note that it also updates search count)
9035 let result = searchcount(#{pattern: '\<foo\>'})
9036
9037 " To restore old search count by old pattern,
9038 " search again
9039 call searchcount()
9040<
9041 {options} must be a |Dictionary|. It can contain:
9042 key type meaning ~
9043 recompute |Boolean| if |TRUE|, recompute the count
9044 like |n| or |N| was executed.
9045 otherwise returns the last
9046 computed result (when |n| or
9047 |N| was used when "S" is not
9048 in 'shortmess', or this
9049 function was called).
9050 (default: |TRUE|)
9051 pattern |String| recompute if this was given
9052 and different with |@/|.
9053 this works as same as the
9054 below command is executed
9055 before calling this function >
9056 let @/ = pattern
9057< (default: |@/|)
9058 timeout |Number| 0 or negative number is no
9059 timeout. timeout milliseconds
9060 for recomputing the result
9061 (default: 0)
9062 maxcount |Number| 0 or negative number is no
9063 limit. max count of matched
9064 text while recomputing the
9065 result. if search exceeded
9066 total count, "total" value
9067 becomes `maxcount + 1`
9068 (default: 99)
9069 pos |List| `[lnum, col, off]` value
9070 when recomputing the result.
9071 this changes "current" result
9072 value. see |cursor()|,
9073 |getpos()|
9074 (default: cursor's position)
9075
9076 Can also be used as a |method|: >
9077 GetSearchOpts()->searchcount()
9078<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009079 Return type: dict<number>
9080
9081
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009082searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9083 Search for the declaration of {name}.
9084
9085 With a non-zero {global} argument it works like |gD|, find
9086 first match in the file. Otherwise it works like |gd|, find
9087 first match in the function.
9088
9089 With a non-zero {thisblock} argument matches in a {} block
9090 that ends before the cursor position are ignored. Avoids
9091 finding variable declarations only valid in another scope.
9092
9093 Moves the cursor to the found match.
9094 Returns zero for success, non-zero for failure.
9095 Example: >
9096 if searchdecl('myvar') == 0
9097 echo getline('.')
9098 endif
9099<
9100 Can also be used as a |method|: >
9101 GetName()->searchdecl()
9102<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009103 Return type: |Number|
9104
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009105 *searchpair()*
9106searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9107 [, {stopline} [, {timeout}]]]])
9108 Search for the match of a nested start-end pair. This can be
9109 used to find the "endif" that matches an "if", while other
9110 if/endif pairs in between are ignored.
9111 The search starts at the cursor. The default is to search
9112 forward, include 'b' in {flags} to search backward.
9113 If a match is found, the cursor is positioned at it and the
9114 line number is returned. If no match is found 0 or -1 is
9115 returned and the cursor doesn't move. No error message is
9116 given.
9117
9118 {start}, {middle} and {end} are patterns, see |pattern|. They
9119 must not contain \( \) pairs. Use of \%( \) is allowed. When
9120 {middle} is not empty, it is found when searching from either
9121 direction, but only when not in a nested start-end pair. A
9122 typical use is: >
9123 searchpair('\<if\>', '\<else\>', '\<endif\>')
9124< By leaving {middle} empty the "else" is skipped.
9125
9126 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9127 |search()|. Additionally:
9128 'r' Repeat until no more matches found; will find the
9129 outer pair. Implies the 'W' flag.
9130 'm' Return number of matches instead of line number with
9131 the match; will be > 1 when 'r' is used.
9132 Note: it's nearly always a good idea to use the 'W' flag, to
9133 avoid wrapping around the end of the file.
9134
9135 When a match for {start}, {middle} or {end} is found, the
9136 {skip} expression is evaluated with the cursor positioned on
9137 the start of the match. It should return non-zero if this
9138 match is to be skipped. E.g., because it is inside a comment
9139 or a string.
9140 When {skip} is omitted or empty, every match is accepted.
9141 When evaluating {skip} causes an error the search is aborted
9142 and -1 returned.
9143 {skip} can be a string, a lambda, a funcref or a partial.
9144 Anything else makes the function fail.
9145 In a `:def` function when the {skip} argument is a string
9146 constant it is compiled into instructions.
9147
9148 For {stopline} and {timeout} see |search()|.
9149
9150 The value of 'ignorecase' is used. 'magic' is ignored, the
9151 patterns are used like it's on.
9152
9153 The search starts exactly at the cursor. A match with
9154 {start}, {middle} or {end} at the next character, in the
9155 direction of searching, is the first one found. Example: >
9156 if 1
9157 if 2
9158 endif 2
9159 endif 1
9160< When starting at the "if 2", with the cursor on the "i", and
9161 searching forwards, the "endif 2" is found. When starting on
9162 the character just before the "if 2", the "endif 1" will be
9163 found. That's because the "if 2" will be found first, and
9164 then this is considered to be a nested if/endif from "if 2" to
9165 "endif 2".
9166 When searching backwards and {end} is more than one character,
9167 it may be useful to put "\zs" at the end of the pattern, so
9168 that when the cursor is inside a match with the end it finds
9169 the matching start.
9170
9171 Example, to find the "endif" command in a Vim script: >
9172
9173 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9174 \ 'getline(".") =~ "^\\s*\""')
9175
9176< The cursor must be at or after the "if" for which a match is
9177 to be found. Note that single-quote strings are used to avoid
9178 having to double the backslashes. The skip expression only
9179 catches comments at the start of a line, not after a command.
9180 Also, a word "en" or "if" halfway a line is considered a
9181 match.
9182 Another example, to search for the matching "{" of a "}": >
9183
9184 :echo searchpair('{', '', '}', 'bW')
9185
9186< This works when the cursor is at or before the "}" for which a
9187 match is to be found. To reject matches that syntax
9188 highlighting recognized as strings: >
9189
9190 :echo searchpair('{', '', '}', 'bW',
9191 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9192<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009193 Return type: |Number|
9194
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009195 *searchpairpos()*
9196searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9197 [, {stopline} [, {timeout}]]]])
9198 Same as |searchpair()|, but returns a |List| with the line and
9199 column position of the match. The first element of the |List|
9200 is the line number and the second element is the byte index of
9201 the column position of the match. If no match is found,
9202 returns [0, 0]. >
9203
9204 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9205<
9206 See |match-parens| for a bigger and more useful example.
9207
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009208 Return type: list<number>
9209
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009210 *searchpos()*
9211searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9212 Same as |search()|, but returns a |List| with the line and
9213 column position of the match. The first element of the |List|
9214 is the line number and the second element is the byte index of
9215 the column position of the match. If no match is found,
9216 returns [0, 0].
9217 Example: >
9218 :let [lnum, col] = searchpos('mypattern', 'n')
9219
9220< When the 'p' flag is given then there is an extra item with
9221 the sub-pattern match number |search()-sub-match|. Example: >
9222 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9223< In this example "submatch" is 2 when a lowercase letter is
9224 found |/\l|, 3 when an uppercase letter is found |/\u|.
9225
9226 Can also be used as a |method|: >
9227 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009228<
9229 Return type: list<number>
9230
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009231
9232server2client({clientid}, {string}) *server2client()*
9233 Send a reply string to {clientid}. The most recent {clientid}
9234 that sent a string can be retrieved with expand("<client>").
9235 {only available when compiled with the |+clientserver| feature}
9236 Returns zero for success, -1 for failure.
9237 Note:
9238 This id has to be stored before the next command can be
9239 received. I.e. before returning from the received command and
9240 before calling any commands that waits for input.
9241 See also |clientserver|.
9242 Example: >
9243 :echo server2client(expand("<client>"), "HELLO")
9244
9245< Can also be used as a |method|: >
9246 GetClientId()->server2client(string)
9247<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009248 Return type: |Number|
9249
9250
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009251serverlist() *serverlist()*
9252 Return a list of available server names, one per line.
9253 When there are no servers or the information is not available
9254 an empty string is returned. See also |clientserver|.
9255 {only available when compiled with the |+clientserver| feature}
9256 Example: >
9257 :echo serverlist()
9258<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009259 Return type: |String|
9260
9261
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009262setbufline({buf}, {lnum}, {text}) *setbufline()*
9263 Set line {lnum} to {text} in buffer {buf}. This works like
9264 |setline()| for the specified buffer.
9265
9266 This function works only for loaded buffers. First call
9267 |bufload()| if needed.
9268
9269 To insert lines use |appendbufline()|.
9270 Any text properties in {lnum} are cleared.
9271
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009272 {text} can be a string to set one line, or a List of strings
9273 to set multiple lines. If the List extends below the last
9274 line then those lines are added. If the List is empty then
9275 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009276
9277 For the use of {buf}, see |bufname()| above.
9278
9279 {lnum} is used like with |setline()|.
9280 Use "$" to refer to the last line in buffer {buf}.
9281 When {lnum} is just below the last line the {text} will be
9282 added below the last line.
9283
9284 When {buf} is not a valid buffer, the buffer is not loaded or
9285 {lnum} is not valid then 1 is returned. In |Vim9| script an
9286 error is given.
9287 On success 0 is returned.
9288
9289 Can also be used as a |method|, the base is passed as the
9290 third argument: >
9291 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009292<
9293 Return type: |Number|
9294
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009295
9296setbufvar({buf}, {varname}, {val}) *setbufvar()*
9297 Set option or local variable {varname} in buffer {buf} to
9298 {val}.
9299 This also works for a global or local window option, but it
9300 doesn't work for a global or local window variable.
9301 For a local window option the global value is unchanged.
9302 For the use of {buf}, see |bufname()| above.
9303 The {varname} argument is a string.
9304 Note that the variable name without "b:" must be used.
9305 Examples: >
9306 :call setbufvar(1, "&mod", 1)
9307 :call setbufvar("todo", "myvar", "foobar")
9308< This function is not available in the |sandbox|.
9309
9310 Can also be used as a |method|, the base is passed as the
9311 third argument: >
9312 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009313<
9314 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009315
9316
9317setcellwidths({list}) *setcellwidths()*
9318 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009319 tells Vim how wide characters are when displayed in the
9320 terminal, counted in screen cells. The values override
9321 'ambiwidth'. Example: >
9322 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009323 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009324 \ [0x2194, 0x2199, 2],
9325 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009326
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009327< The {list} argument is a List of Lists with each three
9328 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9329 {low} and {high} can be the same, in which case this refers to
9330 one character. Otherwise it is the range of characters from
9331 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009332 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009333
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009334 {width} must be either 1 or 2, indicating the character width
9335 in screen cells. *E1112*
9336 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009337 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009338
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009339 If the new value causes 'fillchars' or 'listchars' to become
9340 invalid it is rejected and an error is given.
9341
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009342 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009343 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009344
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009345< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009346 the effect for known emoji characters. Move the cursor
9347 through the text to check if the cell widths of your terminal
9348 match with what Vim knows about each emoji. If it doesn't
9349 look right you need to adjust the {list} argument.
9350
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009351 Return type: |Number|
9352
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009353
9354setcharpos({expr}, {list}) *setcharpos()*
9355 Same as |setpos()| but uses the specified column number as the
9356 character index instead of the byte index in the line.
9357
9358 Example:
9359 With the text "여보세요" in line 8: >
9360 call setcharpos('.', [0, 8, 4, 0])
9361< positions the cursor on the fourth character '요'. >
9362 call setpos('.', [0, 8, 4, 0])
9363< positions the cursor on the second character '보'.
9364
9365 Can also be used as a |method|: >
9366 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009367<
9368 Return type: |Number|
9369
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009370
9371setcharsearch({dict}) *setcharsearch()*
9372 Set the current character search information to {dict},
9373 which contains one or more of the following entries:
9374
9375 char character which will be used for a subsequent
9376 |,| or |;| command; an empty string clears the
9377 character search
9378 forward direction of character search; 1 for forward,
9379 0 for backward
9380 until type of character search; 1 for a |t| or |T|
9381 character search, 0 for an |f| or |F|
9382 character search
9383
9384 This can be useful to save/restore a user's character search
9385 from a script: >
9386 :let prevsearch = getcharsearch()
9387 :" Perform a command which clobbers user's search
9388 :call setcharsearch(prevsearch)
9389< Also see |getcharsearch()|.
9390
9391 Can also be used as a |method|: >
9392 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009393<
9394 Return type: dict<any>
9395
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009396
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009397setcmdline({str} [, {pos}]) *setcmdline()*
9398 Set the command line to {str} and set the cursor position to
9399 {pos}.
9400 If {pos} is omitted, the cursor is positioned after the text.
9401 Returns 0 when successful, 1 when not editing the command
9402 line.
9403
9404 Can also be used as a |method|: >
9405 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009406<
9407 Return type: |Number|
9408
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009409
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009410setcmdpos({pos}) *setcmdpos()*
9411 Set the cursor position in the command line to byte position
9412 {pos}. The first position is 1.
9413 Use |getcmdpos()| to obtain the current position.
9414 Only works while editing the command line, thus you must use
9415 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9416 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9417 set after the command line is set to the expression. For
9418 |c_CTRL-R_=| it is set after evaluating the expression but
9419 before inserting the resulting text.
9420 When the number is too big the cursor is put at the end of the
9421 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009422 Returns 0 when successful, 1 when not editing the command
9423 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009424
9425 Can also be used as a |method|: >
9426 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009427<
9428 Return type: |Number|
9429
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009430
9431setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9432setcursorcharpos({list})
9433 Same as |cursor()| but uses the specified column number as the
9434 character index instead of the byte index in the line.
9435
9436 Example:
9437 With the text "여보세요" in line 4: >
9438 call setcursorcharpos(4, 3)
9439< positions the cursor on the third character '세'. >
9440 call cursor(4, 3)
9441< positions the cursor on the first character '여'.
9442
9443 Can also be used as a |method|: >
9444 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009445<
9446 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009447
9448
9449setenv({name}, {val}) *setenv()*
9450 Set environment variable {name} to {val}. Example: >
9451 call setenv('HOME', '/home/myhome')
9452
9453< When {val} is |v:null| the environment variable is deleted.
9454 See also |expr-env|.
9455
9456 Can also be used as a |method|, the base is passed as the
9457 second argument: >
9458 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009459<
9460 Return type: |Number|
9461
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009462
9463setfperm({fname}, {mode}) *setfperm()* *chmod*
9464 Set the file permissions for {fname} to {mode}.
9465 {mode} must be a string with 9 characters. It is of the form
9466 "rwxrwxrwx", where each group of "rwx" flags represent, in
9467 turn, the permissions of the owner of the file, the group the
9468 file belongs to, and other users. A '-' character means the
9469 permission is off, any other character means on. Multi-byte
9470 characters are not supported.
9471
9472 For example "rw-r-----" means read-write for the user,
9473 readable by the group, not accessible by others. "xx-x-----"
9474 would do the same thing.
9475
9476 Returns non-zero for success, zero for failure.
9477
9478 Can also be used as a |method|: >
9479 GetFilename()->setfperm(mode)
9480<
9481 To read permissions see |getfperm()|.
9482
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009483 Return type: |Number|
9484
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009485
9486setline({lnum}, {text}) *setline()*
9487 Set line {lnum} of the current buffer to {text}. To insert
9488 lines use |append()|. To set lines in another buffer use
Christian Brabandt946f61c2024-06-17 13:17:58 +02009489 |setbufline()|.
9490 Any text properties in {lnum} are cleared |text-prop-cleared|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009491
9492 {lnum} is used like with |getline()|.
9493 When {lnum} is just below the last line the {text} will be
9494 added below the last line.
9495 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009496 converted to a String. When {text} is an empty List then
9497 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009498
9499 If this succeeds, FALSE is returned. If this fails (most likely
9500 because {lnum} is invalid) TRUE is returned.
9501 In |Vim9| script an error is given if {lnum} is invalid.
9502
9503 Example: >
9504 :call setline(5, strftime("%c"))
9505
9506< When {text} is a |List| then line {lnum} and following lines
9507 will be set to the items in the list. Example: >
9508 :call setline(5, ['aaa', 'bbb', 'ccc'])
9509< This is equivalent to: >
9510 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9511 : call setline(n, l)
9512 :endfor
9513
9514< Note: The '[ and '] marks are not set.
9515
9516 Can also be used as a |method|, the base is passed as the
9517 second argument: >
9518 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009519<
9520 Return type: |Number|
9521
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009522
9523setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9524 Create or replace or add to the location list for window {nr}.
9525 {nr} can be the window number or the |window-ID|.
9526 When {nr} is zero the current window is used.
9527
9528 For a location list window, the displayed location list is
9529 modified. For an invalid window number {nr}, -1 is returned.
9530 Otherwise, same as |setqflist()|.
9531 Also see |location-list|.
9532
9533 For {action} see |setqflist-action|.
9534
9535 If the optional {what} dictionary argument is supplied, then
9536 only the items listed in {what} are set. Refer to |setqflist()|
9537 for the list of supported keys in {what}.
9538
9539 Can also be used as a |method|, the base is passed as the
9540 second argument: >
9541 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009542<
9543 Return type: |Number|
9544
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009545
9546setmatches({list} [, {win}]) *setmatches()*
9547 Restores a list of matches saved by |getmatches()| for the
9548 current window. Returns 0 if successful, otherwise -1. All
9549 current matches are cleared before the list is restored. See
9550 example for |getmatches()|.
9551 If {win} is specified, use the window with this number or
9552 window ID instead of the current window.
9553
9554 Can also be used as a |method|: >
9555 GetMatches()->setmatches()
9556<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009557 Return type: |Number|
9558
9559
9560setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009561 Set the position for String {expr}. Possible values:
9562 . the cursor
9563 'x mark x
9564
9565 {list} must be a |List| with four or five numbers:
9566 [bufnum, lnum, col, off]
9567 [bufnum, lnum, col, off, curswant]
9568
9569 "bufnum" is the buffer number. Zero can be used for the
9570 current buffer. When setting an uppercase mark "bufnum" is
9571 used for the mark position. For other marks it specifies the
9572 buffer to set the mark in. You can use the |bufnr()| function
9573 to turn a file name into a buffer number.
9574 For setting the cursor and the ' mark "bufnum" is ignored,
9575 since these are associated with a window, not a buffer.
9576 Does not change the jumplist.
9577
9578 "lnum" and "col" are the position in the buffer. The first
9579 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9580 smaller than 1 then 1 is used. To use the character count
9581 instead of the byte count, use |setcharpos()|.
9582
9583 The "off" number is only used when 'virtualedit' is set. Then
9584 it is the offset in screen columns from the start of the
9585 character. E.g., a position within a <Tab> or after the last
9586 character.
9587
9588 The "curswant" number is only used when setting the cursor
9589 position. It sets the preferred column for when moving the
9590 cursor vertically. When the "curswant" number is missing the
9591 preferred column is not set. When it is present and setting a
9592 mark position it is not used.
9593
9594 Note that for '< and '> changing the line number may result in
9595 the marks to be effectively be swapped, so that '< is always
9596 before '>.
9597
9598 Returns 0 when the position could be set, -1 otherwise.
9599 An error message is given if {expr} is invalid.
9600
9601 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9602
9603 This does not restore the preferred column for moving
9604 vertically; if you set the cursor position with this, |j| and
9605 |k| motions will jump to previous columns! Use |cursor()| to
9606 also set the preferred column. Also see the "curswant" key in
9607 |winrestview()|.
9608
9609 Can also be used as a |method|: >
9610 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009611<
9612 Return type: |Number|
9613
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009614
9615setqflist({list} [, {action} [, {what}]]) *setqflist()*
9616 Create or replace or add to the quickfix list.
9617
9618 If the optional {what} dictionary argument is supplied, then
9619 only the items listed in {what} are set. The first {list}
9620 argument is ignored. See below for the supported items in
9621 {what}.
9622 *setqflist-what*
9623 When {what} is not present, the items in {list} are used. Each
9624 item must be a dictionary. Non-dictionary items in {list} are
9625 ignored. Each dictionary item can contain the following
9626 entries:
9627
9628 bufnr buffer number; must be the number of a valid
9629 buffer
9630 filename name of a file; only used when "bufnr" is not
9631 present or it is invalid.
9632 module name of a module; if given it will be used in
9633 quickfix error window instead of the filename.
9634 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00009635 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009636 pattern search pattern used to locate the error
9637 col column number
9638 vcol when non-zero: "col" is visual column
9639 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00009640 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009641 nr error number
9642 text description of the error
9643 type single-character error type, 'E', 'W', etc.
9644 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +02009645 user_data custom data associated with the item, can be
9646 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009647
9648 The "col", "vcol", "nr", "type" and "text" entries are
9649 optional. Either "lnum" or "pattern" entry can be used to
9650 locate a matching error line.
9651 If the "filename" and "bufnr" entries are not present or
9652 neither the "lnum" or "pattern" entries are present, then the
9653 item will not be handled as an error line.
9654 If both "pattern" and "lnum" are present then "pattern" will
9655 be used.
9656 If the "valid" entry is not supplied, then the valid flag is
9657 set when "bufnr" is a valid buffer or "filename" exists.
9658 If you supply an empty {list}, the quickfix list will be
9659 cleared.
9660 Note that the list is not exactly the same as what
9661 |getqflist()| returns.
9662
9663 {action} values: *setqflist-action* *E927*
9664 'a' The items from {list} are added to the existing
9665 quickfix list. If there is no existing list, then a
9666 new list is created.
9667
9668 'r' The items from the current quickfix list are replaced
9669 with the items from {list}. This can also be used to
9670 clear the list: >
9671 :call setqflist([], 'r')
9672<
9673 'f' All the quickfix lists in the quickfix stack are
9674 freed.
9675
9676 If {action} is not present or is set to ' ', then a new list
9677 is created. The new quickfix list is added after the current
9678 quickfix list in the stack and all the following lists are
9679 freed. To add a new quickfix list at the end of the stack,
9680 set "nr" in {what} to "$".
9681
9682 The following items can be specified in dictionary {what}:
9683 context quickfix list context. See |quickfix-context|
9684 efm errorformat to use when parsing text from
9685 "lines". If this is not present, then the
9686 'errorformat' option value is used.
9687 See |quickfix-parse|
9688 id quickfix list identifier |quickfix-ID|
9689 idx index of the current entry in the quickfix
9690 list specified by 'id' or 'nr'. If set to '$',
9691 then the last entry in the list is set as the
9692 current entry. See |quickfix-index|
9693 items list of quickfix entries. Same as the {list}
9694 argument.
9695 lines use 'errorformat' to parse a list of lines and
9696 add the resulting entries to the quickfix list
9697 {nr} or {id}. Only a |List| value is supported.
9698 See |quickfix-parse|
9699 nr list number in the quickfix stack; zero
9700 means the current quickfix list and "$" means
9701 the last quickfix list.
9702 quickfixtextfunc
9703 function to get the text to display in the
9704 quickfix window. The value can be the name of
9705 a function or a funcref or a lambda. Refer to
9706 |quickfix-window-function| for an explanation
9707 of how to write the function and an example.
9708 title quickfix list title text. See |quickfix-title|
9709 Unsupported keys in {what} are ignored.
9710 If the "nr" item is not present, then the current quickfix list
9711 is modified. When creating a new quickfix list, "nr" can be
9712 set to a value one greater than the quickfix stack size.
9713 When modifying a quickfix list, to guarantee that the correct
9714 list is modified, "id" should be used instead of "nr" to
9715 specify the list.
9716
9717 Examples (See also |setqflist-examples|): >
9718 :call setqflist([], 'r', {'title': 'My search'})
9719 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
9720 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
9721<
9722 Returns zero for success, -1 for failure.
9723
9724 This function can be used to create a quickfix list
9725 independent of the 'errorformat' setting. Use a command like
9726 `:cc 1` to jump to the first position.
9727
9728 Can also be used as a |method|, the base is passed as the
9729 second argument: >
9730 GetErrorlist()->setqflist()
9731<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009732 Return type: |Number|
9733
9734
9735setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009736 Set the register {regname} to {value}.
9737 If {regname} is "" or "@", the unnamed register '"' is used.
9738 The {regname} argument is a string. In |Vim9-script|
9739 {regname} must be one character.
9740
9741 {value} may be any value returned by |getreg()| or
9742 |getreginfo()|, including a |List| or |Dict|.
9743 If {options} contains "a" or {regname} is upper case,
9744 then the value is appended.
9745
9746 {options} can also contain a register type specification:
9747 "c" or "v" |characterwise| mode
9748 "l" or "V" |linewise| mode
9749 "b" or "<CTRL-V>" |blockwise-visual| mode
9750 If a number immediately follows "b" or "<CTRL-V>" then this is
9751 used as the width of the selection - if it is not specified
9752 then the width of the block is set to the number of characters
9753 in the longest line (counting a <Tab> as 1 character).
9754
9755 If {options} contains no register settings, then the default
9756 is to use character mode unless {value} ends in a <NL> for
9757 string {value} and linewise mode for list {value}. Blockwise
9758 mode is never selected automatically.
9759 Returns zero for success, non-zero for failure.
9760
9761 *E883*
9762 Note: you may not use |List| containing more than one item to
9763 set search and expression registers. Lists containing no
9764 items act like empty strings.
9765
9766 Examples: >
9767 :call setreg(v:register, @*)
9768 :call setreg('*', @%, 'ac')
9769 :call setreg('a', "1\n2\n3", 'b5')
9770 :call setreg('"', { 'points_to': 'a'})
9771
9772< This example shows using the functions to save and restore a
9773 register: >
9774 :let var_a = getreginfo()
9775 :call setreg('a', var_a)
9776< or: >
9777 :let var_a = getreg('a', 1, 1)
9778 :let var_amode = getregtype('a')
9779 ....
9780 :call setreg('a', var_a, var_amode)
9781< Note: you may not reliably restore register value
9782 without using the third argument to |getreg()| as without it
9783 newlines are represented as newlines AND Nul bytes are
9784 represented as newlines as well, see |NL-used-for-Nul|.
9785
9786 You can also change the type of a register by appending
9787 nothing: >
9788 :call setreg('a', '', 'al')
9789
9790< Can also be used as a |method|, the base is passed as the
9791 second argument: >
9792 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009793<
9794 Return type: |Number|
9795
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009796
9797settabvar({tabnr}, {varname}, {val}) *settabvar()*
9798 Set tab-local variable {varname} to {val} in tab page {tabnr}.
9799 |t:var|
9800 The {varname} argument is a string.
9801 Note that autocommands are blocked, side effects may not be
9802 triggered, e.g. when setting 'filetype'.
9803 Note that the variable name without "t:" must be used.
9804 Tabs are numbered starting with one.
9805 This function is not available in the |sandbox|.
9806
9807 Can also be used as a |method|, the base is passed as the
9808 third argument: >
9809 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009810<
9811 Return type: |Number|
9812
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009813
9814settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
9815 Set option or local variable {varname} in window {winnr} to
9816 {val}.
9817 Tabs are numbered starting with one. For the current tabpage
9818 use |setwinvar()|.
9819 {winnr} can be the window number or the |window-ID|.
9820 When {winnr} is zero the current window is used.
9821 Note that autocommands are blocked, side effects may not be
9822 triggered, e.g. when setting 'filetype' or 'syntax'.
9823 This also works for a global or local buffer option, but it
9824 doesn't work for a global or local buffer variable.
9825 For a local buffer option the global value is unchanged.
9826 Note that the variable name without "w:" must be used.
9827 Examples: >
9828 :call settabwinvar(1, 1, "&list", 0)
9829 :call settabwinvar(3, 2, "myvar", "foobar")
9830< This function is not available in the |sandbox|.
9831
9832 Can also be used as a |method|, the base is passed as the
9833 fourth argument: >
9834 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009835<
9836 Return type: |Number|
9837
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009838
9839settagstack({nr}, {dict} [, {action}]) *settagstack()*
9840 Modify the tag stack of the window {nr} using {dict}.
9841 {nr} can be the window number or the |window-ID|.
9842
9843 For a list of supported items in {dict}, refer to
9844 |gettagstack()|. "curidx" takes effect before changing the tag
9845 stack.
9846 *E962*
9847 How the tag stack is modified depends on the {action}
9848 argument:
9849 - If {action} is not present or is set to 'r', then the tag
9850 stack is replaced.
9851 - If {action} is set to 'a', then new entries from {dict} are
9852 pushed (added) onto the tag stack.
9853 - If {action} is set to 't', then all the entries from the
9854 current entry in the tag stack or "curidx" in {dict} are
9855 removed and then new entries are pushed to the stack.
9856
9857 The current index is set to one after the length of the tag
9858 stack after the modification.
9859
9860 Returns zero for success, -1 for failure.
9861
9862 Examples (for more examples see |tagstack-examples|):
9863 Empty the tag stack of window 3: >
9864 call settagstack(3, {'items' : []})
9865
9866< Save and restore the tag stack: >
9867 let stack = gettagstack(1003)
9868 " do something else
9869 call settagstack(1003, stack)
9870 unlet stack
9871<
9872 Can also be used as a |method|, the base is passed as the
9873 second argument: >
9874 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009875<
9876 Return type: |Number|
9877
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009878
9879setwinvar({winnr}, {varname}, {val}) *setwinvar()*
9880 Like |settabwinvar()| for the current tab page.
9881 Examples: >
9882 :call setwinvar(1, "&list", 0)
9883 :call setwinvar(2, "myvar", "foobar")
9884
9885< Can also be used as a |method|, the base is passed as the
9886 third argument: >
9887 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009888<
9889 Return type: |Number|
9890
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009891
9892sha256({string}) *sha256()*
9893 Returns a String with 64 hex characters, which is the SHA256
9894 checksum of {string}.
9895
9896 Can also be used as a |method|: >
9897 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009898<
9899 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009900
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009901 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009902
9903shellescape({string} [, {special}]) *shellescape()*
9904 Escape {string} for use as a shell command argument.
9905 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +00009906 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009907 in single quotes and will double up all internal single
9908 quotes.
9909 On MS-Windows, when 'shellslash' is not set, it will enclose
9910 {string} in double quotes and double all double quotes within
9911 {string}.
9912 Otherwise it will enclose {string} in single quotes and
9913 replace all "'" with "'\''".
9914
Enno5faeb602024-05-15 21:54:19 +02009915 The {special} argument adds additional escaping of keywords
9916 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +09009917 number or a non-empty String (|non-zero-arg|), then special
9918 items such as "!", "%", "#" and "<cword>" (as listed in
9919 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +02009920 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009921
9922 The "!" character will be escaped (again with a |non-zero-arg|
9923 {special}) when 'shell' contains "csh" in the tail. That is
9924 because for csh and tcsh "!" is used for history replacement
9925 even when inside single quotes.
9926
9927 With a |non-zero-arg| {special} the <NL> character is also
9928 escaped. When 'shell' containing "csh" in the tail it's
9929 escaped a second time.
9930
9931 The "\" character will be escaped when 'shell' contains "fish"
9932 in the tail. That is because for fish "\" is used as an escape
9933 character inside single quotes.
9934
9935 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009936 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009937< This results in a directory listing for the file under the
9938 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009939 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009940< See also |::S|.
9941
9942 Can also be used as a |method|: >
9943 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009944<
9945 Return type: |String|
9946
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009947
9948shiftwidth([{col}]) *shiftwidth()*
9949 Returns the effective value of 'shiftwidth'. This is the
9950 'shiftwidth' value unless it is zero, in which case it is the
9951 'tabstop' value. This function was introduced with patch
9952 7.3.694 in 2012, everybody should have it by now (however it
9953 did not allow for the optional {col} argument until 8.1.542).
9954
9955 When there is one argument {col} this is used as column number
9956 for which to return the 'shiftwidth' value. This matters for the
9957 'vartabstop' feature. If the 'vartabstop' setting is enabled and
9958 no {col} argument is given, column 1 will be assumed.
9959
9960 Can also be used as a |method|: >
9961 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009962<
9963 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009964
9965sign_ functions are documented here: |sign-functions-details|
9966
9967
9968simplify({filename}) *simplify()*
9969 Simplify the file name as much as possible without changing
9970 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
9971 Unix) are not resolved. If the first path component in
9972 {filename} designates the current directory, this will be
9973 valid for the result as well. A trailing path separator is
9974 not removed either. On Unix "//path" is unchanged, but
9975 "///path" is simplified to "/path" (this follows the Posix
9976 standard).
9977 Example: >
9978 simplify("./dir/.././/file/") == "./file/"
9979< Note: The combination "dir/.." is only removed if "dir" is
9980 a searchable directory or does not exist. On Unix, it is also
9981 removed when "dir" is a symbolic link within the same
9982 directory. In order to resolve all the involved symbolic
9983 links before simplifying the path name, use |resolve()|.
9984
9985 Can also be used as a |method|: >
9986 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009987<
9988 Return type: |String|
9989
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009990
9991sin({expr}) *sin()*
9992 Return the sine of {expr}, measured in radians, as a |Float|.
9993 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009994 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009995 Examples: >
9996 :echo sin(100)
9997< -0.506366 >
9998 :echo sin(-4.01)
9999< 0.763301
10000
10001 Can also be used as a |method|: >
10002 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010003<
10004 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010005
10006
10007sinh({expr}) *sinh()*
10008 Return the hyperbolic sine of {expr} as a |Float| in the range
10009 [-inf, inf].
10010 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010011 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010012 Examples: >
10013 :echo sinh(0.5)
10014< 0.521095 >
10015 :echo sinh(-0.9)
10016< -1.026517
10017
10018 Can also be used as a |method|: >
10019 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010020<
10021 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010022
10023
10024slice({expr}, {start} [, {end}]) *slice()*
10025 Similar to using a |slice| "expr[start : end]", but "end" is
10026 used exclusive. And for a string the indexes are used as
10027 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010028 |vim9script|. Also, composing characters are treated as a
10029 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010030 When {end} is omitted the slice continues to the last item.
10031 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010032 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010033
10034 Can also be used as a |method|: >
10035 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010036<
10037 Return type: list<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010038
10039
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010040sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010041 Sort the items in {list} in-place. Returns {list}.
10042
10043 If you want a list to remain unmodified make a copy first: >
10044 :let sortedlist = sort(copy(mylist))
10045
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010046< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010047 string representation of each item to sort on. Numbers sort
10048 after Strings, |Lists| after Numbers. For sorting text in the
10049 current buffer use |:sort|.
10050
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010051 When {how} is given and it is 'i' then case is ignored.
10052 In legacy script, for backwards compatibility, the value one
10053 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010054
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010055 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010056 locale is used for ordering. Implementation details: strcoll()
10057 is used to compare strings. See |:language| check or set the
10058 collation locale. |v:collate| can also be used to check the
10059 current locale. Sorting using the locale typically ignores
10060 case. Example: >
10061 " ö is sorted similarly to o with English locale.
10062 :language collate en_US.UTF8
10063 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10064< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10065>
10066 " ö is sorted after z with Swedish locale.
10067 :language collate sv_SE.UTF8
10068 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10069< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10070 This does not work properly on Mac.
10071
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010072 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010073 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010074 strtod() function to parse numbers. Strings, Lists, Dicts and
10075 Funcrefs will be considered as being 0). Note that this won't
10076 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010077
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010078 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010079 sorted numerical. This is like 'n' but a string containing
10080 digits will be used as the number they represent.
10081
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010082 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010083 sorted numerical. All values must be a Number or a Float.
10084
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010085 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010086 is called to compare items. The function is invoked with two
10087 items as argument and must return zero if they are equal, 1 or
10088 bigger if the first one sorts after the second one, -1 or
10089 smaller if the first one sorts before the second one.
10090
10091 {dict} is for functions with the "dict" attribute. It will be
10092 used to set the local variable "self". |Dictionary-function|
10093
10094 The sort is stable, items which compare equal (as number or as
10095 string) will keep their relative position. E.g., when sorting
10096 on numbers, text strings will sort next to each other, in the
10097 same order as they were originally.
10098
10099 Can also be used as a |method|: >
10100 mylist->sort()
10101
10102< Also see |uniq()|.
10103
10104 Example: >
10105 func MyCompare(i1, i2)
10106 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10107 endfunc
10108 eval mylist->sort("MyCompare")
10109< A shorter compare version for this specific simple case, which
10110 ignores overflow: >
10111 func MyCompare(i1, i2)
10112 return a:i1 - a:i2
10113 endfunc
10114< For a simple expression you can use a lambda: >
10115 eval mylist->sort({i1, i2 -> i1 - i2})
10116<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010117 Return type: list<{type}>
10118
10119
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010120sound_clear() *sound_clear()*
10121 Stop playing all sounds.
10122
10123 On some Linux systems you may need the libcanberra-pulse
10124 package, otherwise sound may not stop.
10125
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010126 Return type: |Number|
10127
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010128 {only available when compiled with the |+sound| feature}
10129
10130 *sound_playevent()*
10131sound_playevent({name} [, {callback}])
10132 Play a sound identified by {name}. Which event names are
10133 supported depends on the system. Often the XDG sound names
10134 are used. On Ubuntu they may be found in
10135 /usr/share/sounds/freedesktop/stereo. Example: >
10136 call sound_playevent('bell')
10137< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10138 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10139 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010140 On macOS, {name} refers to files located in
10141 /System/Library/Sounds (e.g. "Tink"). It will also work for
10142 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010143
10144 When {callback} is specified it is invoked when the sound is
10145 finished. The first argument is the sound ID, the second
10146 argument is the status:
10147 0 sound was played to the end
10148 1 sound was interrupted
10149 2 error occurred after sound started
10150 Example: >
10151 func Callback(id, status)
10152 echomsg "sound " .. a:id .. " finished with " .. a:status
10153 endfunc
10154 call sound_playevent('bell', 'Callback')
10155
10156< MS-Windows: {callback} doesn't work for this function.
10157
10158 Returns the sound ID, which can be passed to `sound_stop()`.
10159 Returns zero if the sound could not be played.
10160
10161 Can also be used as a |method|: >
10162 GetSoundName()->sound_playevent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010163<
10164 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010165
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010166 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010167
10168 *sound_playfile()*
10169sound_playfile({path} [, {callback}])
10170 Like `sound_playevent()` but play sound file {path}. {path}
10171 must be a full path. On Ubuntu you may find files to play
10172 with this command: >
10173 :!find /usr/share/sounds -type f | grep -v index.theme
10174
10175< Can also be used as a |method|: >
10176 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010177<
10178 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010179
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010180 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010181
10182
10183sound_stop({id}) *sound_stop()*
10184 Stop playing sound {id}. {id} must be previously returned by
10185 `sound_playevent()` or `sound_playfile()`.
10186
10187 On some Linux systems you may need the libcanberra-pulse
10188 package, otherwise sound may not stop.
10189
10190 On MS-Windows, this does not work for event sound started by
10191 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10192
10193 Can also be used as a |method|: >
10194 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010195<
10196 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010197
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010198 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010199
10200 *soundfold()*
10201soundfold({word})
10202 Return the sound-folded equivalent of {word}. Uses the first
10203 language in 'spelllang' for the current window that supports
10204 soundfolding. 'spell' must be set. When no sound folding is
10205 possible the {word} is returned unmodified.
10206 This can be used for making spelling suggestions. Note that
10207 the method can be quite slow.
10208
10209 Can also be used as a |method|: >
10210 GetWord()->soundfold()
10211<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010212 Return type: |String|
10213
10214
10215spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010216 Without argument: The result is the badly spelled word under
10217 or after the cursor. The cursor is moved to the start of the
10218 bad word. When no bad word is found in the cursor line the
10219 result is an empty string and the cursor doesn't move.
10220
10221 With argument: The result is the first word in {sentence} that
10222 is badly spelled. If there are no spelling mistakes the
10223 result is an empty string.
10224
10225 The return value is a list with two items:
10226 - The badly spelled word or an empty string.
10227 - The type of the spelling error:
10228 "bad" spelling mistake
10229 "rare" rare word
10230 "local" word only valid in another region
10231 "caps" word should start with Capital
10232 Example: >
10233 echo spellbadword("the quik brown fox")
10234< ['quik', 'bad'] ~
10235
10236 The spelling information for the current window and the value
10237 of 'spelllang' are used.
10238
10239 Can also be used as a |method|: >
10240 GetText()->spellbadword()
10241<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010242 Return type: list<string>
10243
10244
10245spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010246 Return a |List| with spelling suggestions to replace {word}.
10247 When {max} is given up to this number of suggestions are
10248 returned. Otherwise up to 25 suggestions are returned.
10249
10250 When the {capital} argument is given and it's non-zero only
10251 suggestions with a leading capital will be given. Use this
10252 after a match with 'spellcapcheck'.
10253
10254 {word} can be a badly spelled word followed by other text.
10255 This allows for joining two words that were split. The
10256 suggestions also include the following text, thus you can
10257 replace a line.
10258
10259 {word} may also be a good word. Similar words will then be
10260 returned. {word} itself is not included in the suggestions,
10261 although it may appear capitalized.
10262
10263 The spelling information for the current window is used. The
10264 values of 'spelllang' and 'spellsuggest' are used.
10265
10266 Can also be used as a |method|: >
10267 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010268<
10269 Return type: list<string> or list<any>
10270
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010271
10272split({string} [, {pattern} [, {keepempty}]]) *split()*
10273 Make a |List| out of {string}. When {pattern} is omitted or
10274 empty each white-separated sequence of characters becomes an
10275 item.
10276 Otherwise the string is split where {pattern} matches,
10277 removing the matched characters. 'ignorecase' is not used
10278 here, add \c to ignore case. |/\c|
10279 When the first or last item is empty it is omitted, unless the
10280 {keepempty} argument is given and it's non-zero.
10281 Other empty items are kept when {pattern} matches at least one
10282 character or when {keepempty} is non-zero.
10283 Example: >
10284 :let words = split(getline('.'), '\W\+')
10285< To split a string in individual characters: >
10286 :for c in split(mystring, '\zs')
10287< If you want to keep the separator you can also use '\zs' at
10288 the end of the pattern: >
10289 :echo split('abc:def:ghi', ':\zs')
10290< ['abc:', 'def:', 'ghi'] ~
10291 Splitting a table where the first element can be empty: >
10292 :let items = split(line, ':', 1)
10293< The opposite function is |join()|.
10294
10295 Can also be used as a |method|: >
10296 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010297<
10298 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010299
10300sqrt({expr}) *sqrt()*
10301 Return the non-negative square root of Float {expr} as a
10302 |Float|.
10303 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010304 is negative the result is NaN (Not a Number). Returns 0.0 if
10305 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010306 Examples: >
10307 :echo sqrt(100)
10308< 10.0 >
10309 :echo sqrt(-4.01)
10310< nan
10311 "nan" may be different, it depends on system libraries.
10312
10313 Can also be used as a |method|: >
10314 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010315<
10316 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010317
10318
10319srand([{expr}]) *srand()*
10320 Initialize seed used by |rand()|:
10321 - If {expr} is not given, seed values are initialized by
10322 reading from /dev/urandom, if possible, or using time(NULL)
10323 a.k.a. epoch time otherwise; this only has second accuracy.
10324 - If {expr} is given it must be a Number. It is used to
10325 initialize the seed values. This is useful for testing or
10326 when a predictable sequence is intended.
10327
10328 Examples: >
10329 :let seed = srand()
10330 :let seed = srand(userinput)
10331 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010332<
10333 Return type: list<number>
10334
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010335
10336state([{what}]) *state()*
10337 Return a string which contains characters indicating the
10338 current state. Mostly useful in callbacks that want to do
10339 work that may not always be safe. Roughly this works like:
10340 - callback uses state() to check if work is safe to do.
10341 Yes: then do it right away.
10342 No: add to work queue and add a |SafeState| and/or
10343 |SafeStateAgain| autocommand (|SafeState| triggers at
10344 toplevel, |SafeStateAgain| triggers after handling
10345 messages and callbacks).
10346 - When SafeState or SafeStateAgain is triggered and executes
10347 your autocommand, check with `state()` if the work can be
10348 done now, and if yes remove it from the queue and execute.
10349 Remove the autocommand if the queue is now empty.
10350 Also see |mode()|.
10351
10352 When {what} is given only characters in this string will be
10353 added. E.g, this checks if the screen has scrolled: >
10354 if state('s') == ''
10355 " screen has not scrolled
10356<
10357 These characters indicate the state, generally indicating that
10358 something is busy:
10359 m halfway a mapping, :normal command, feedkeys() or
10360 stuffed command
10361 o operator pending, e.g. after |d|
10362 a Insert mode autocomplete active
10363 x executing an autocommand
10364 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10365 ch_readraw() when reading json
10366 S not triggering SafeState or SafeStateAgain, e.g. after
10367 |f| or a count
10368 c callback invoked, including timer (repeats for
10369 recursiveness up to "ccc")
10370 s screen has scrolled for messages
10371
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010372 Return type: |String|
10373
10374
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010375str2float({string} [, {quoted}]) *str2float()*
10376 Convert String {string} to a Float. This mostly works the
10377 same as when using a floating point number in an expression,
10378 see |floating-point-format|. But it's a bit more permissive.
10379 E.g., "1e40" is accepted, while in an expression you need to
10380 write "1.0e40". The hexadecimal form "0x123" is also
10381 accepted, but not others, like binary or octal.
10382 When {quoted} is present and non-zero then embedded single
10383 quotes before the dot are ignored, thus "1'000.0" is a
10384 thousand.
10385 Text after the number is silently ignored.
10386 The decimal point is always '.', no matter what the locale is
10387 set to. A comma ends the number: "12,345.67" is converted to
10388 12.0. You can strip out thousands separators with
10389 |substitute()|: >
10390 let f = str2float(substitute(text, ',', '', 'g'))
10391<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010392 Returns 0.0 if the conversion fails.
10393
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010394 Can also be used as a |method|: >
10395 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010396<
10397 Return type: |Float|
10398
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010399
10400str2list({string} [, {utf8}]) *str2list()*
10401 Return a list containing the number values which represent
10402 each character in String {string}. Examples: >
10403 str2list(" ") returns [32]
10404 str2list("ABC") returns [65, 66, 67]
10405< |list2str()| does the opposite.
10406
10407 When {utf8} is omitted or zero, the current 'encoding' is used.
10408 When {utf8} is TRUE, always treat the String as UTF-8
10409 characters. With UTF-8 composing characters are handled
10410 properly: >
10411 str2list("á") returns [97, 769]
10412
10413< Can also be used as a |method|: >
10414 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010415<
10416 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010417
10418
10419str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10420 Convert string {string} to a number.
10421 {base} is the conversion base, it can be 2, 8, 10 or 16.
10422 When {quoted} is present and non-zero then embedded single
10423 quotes are ignored, thus "1'000'000" is a million.
10424
10425 When {base} is omitted base 10 is used. This also means that
10426 a leading zero doesn't cause octal conversion to be used, as
10427 with the default String to Number conversion. Example: >
10428 let nr = str2nr('0123')
10429<
10430 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10431 different base the result will be zero. Similarly, when
10432 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10433 {base} is 2 a leading "0b" or "0B" is ignored.
10434 Text after the number is silently ignored.
10435
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010436 Returns 0 if {string} is empty or on error.
10437
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010438 Can also be used as a |method|: >
10439 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010440<
10441 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010442
10443
10444strcharlen({string}) *strcharlen()*
10445 The result is a Number, which is the number of characters
10446 in String {string}. Composing characters are ignored.
10447 |strchars()| can count the number of characters, counting
10448 composing characters separately.
10449
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010450 Returns 0 if {string} is empty or on error.
10451
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010452 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10453
10454 Can also be used as a |method|: >
10455 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010456<
10457 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010458
10459
10460strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10461 Like |strpart()| but using character index and length instead
10462 of byte index and length.
10463 When {skipcc} is omitted or zero, composing characters are
10464 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010465 When {skipcc} set to 1, composing characters are treated as a
10466 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010467 When a character index is used where a character does not
10468 exist it is omitted and counted as one character. For
10469 example: >
10470 strcharpart('abc', -1, 2)
10471< results in 'a'.
10472
Bram Moolenaard592deb2022-06-17 15:42:40 +010010473 Returns an empty string on error.
10474
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010475 Can also be used as a |method|: >
10476 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010477<
10478 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010479
10480
10481strchars({string} [, {skipcc}]) *strchars()*
10482 The result is a Number, which is the number of characters
10483 in String {string}.
10484 When {skipcc} is omitted or zero, composing characters are
10485 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010486 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010487 |strcharlen()| always does this.
10488
Bram Moolenaard592deb2022-06-17 15:42:40 +010010489 Returns zero on error.
10490
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010491 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10492
10493 {skipcc} is only available after 7.4.755. For backward
10494 compatibility, you can define a wrapper function: >
10495 if has("patch-7.4.755")
10496 function s:strchars(str, skipcc)
10497 return strchars(a:str, a:skipcc)
10498 endfunction
10499 else
10500 function s:strchars(str, skipcc)
10501 if a:skipcc
10502 return strlen(substitute(a:str, ".", "x", "g"))
10503 else
10504 return strchars(a:str)
10505 endif
10506 endfunction
10507 endif
10508<
10509 Can also be used as a |method|: >
10510 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010511<
10512 Return type: |Number|
10513
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010514
10515strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10516 The result is a Number, which is the number of display cells
10517 String {string} occupies on the screen when it starts at {col}
10518 (first column is zero). When {col} is omitted zero is used.
10519 Otherwise it is the screen column where to start. This
10520 matters for Tab characters.
10521 The option settings of the current window are used. This
10522 matters for anything that's displayed differently, such as
10523 'tabstop' and 'display'.
10524 When {string} contains characters with East Asian Width Class
10525 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010526 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010527 Also see |strlen()|, |strwidth()| and |strchars()|.
10528
10529 Can also be used as a |method|: >
10530 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010531<
10532 Return type: |Number|
10533
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010534
10535strftime({format} [, {time}]) *strftime()*
10536 The result is a String, which is a formatted date and time, as
10537 specified by the {format} string. The given {time} is used,
10538 or the current time if no time is given. The accepted
10539 {format} depends on your system, thus this is not portable!
10540 See the manual page of the C function strftime() for the
10541 format. The maximum length of the result is 80 characters.
10542 See also |localtime()|, |getftime()| and |strptime()|.
10543 The language can be changed with the |:language| command.
10544 Examples: >
10545 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10546 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10547 :echo strftime("%y%m%d %T") 970427 11:53:55
10548 :echo strftime("%H:%M") 11:55
10549 :echo strftime("%c", getftime("file.c"))
10550 Show mod time of file.c.
10551< Not available on all systems. To check use: >
10552 :if exists("*strftime")
10553
10554< Can also be used as a |method|: >
10555 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010556<
10557 Return type: |String|
10558
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010559
10560strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010561 Get a Number corresponding to the character at {index} in
10562 {str}. This uses a zero-based character index, not a byte
10563 index. Composing characters are considered separate
10564 characters here. Use |nr2char()| to convert the Number to a
10565 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010566 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010567 Also see |strcharpart()| and |strchars()|.
10568
10569 Can also be used as a |method|: >
10570 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010571<
10572 Return type: |Number|
10573
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010574
10575stridx({haystack}, {needle} [, {start}]) *stridx()*
10576 The result is a Number, which gives the byte index in
10577 {haystack} of the first occurrence of the String {needle}.
10578 If {start} is specified, the search starts at index {start}.
10579 This can be used to find a second match: >
10580 :let colon1 = stridx(line, ":")
10581 :let colon2 = stridx(line, ":", colon1 + 1)
10582< The search is done case-sensitive.
10583 For pattern searches use |match()|.
10584 -1 is returned if the {needle} does not occur in {haystack}.
10585 See also |strridx()|.
10586 Examples: >
10587 :echo stridx("An Example", "Example") 3
10588 :echo stridx("Starting point", "Start") 0
10589 :echo stridx("Starting point", "start") -1
10590< *strstr()* *strchr()*
10591 stridx() works similar to the C function strstr(). When used
10592 with a single character it works similar to strchr().
10593
10594 Can also be used as a |method|: >
10595 GetHaystack()->stridx(needle)
10596<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010597 Return type: |Number|
10598
10599
10600string({expr}) *string()*
10601 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010602 Float, String, Blob or a composition of them, then the result
10603 can be parsed back with |eval()|.
10604 {expr} type result ~
10605 String 'string' (single quotes are doubled)
10606 Number 123
10607 Float 123.123456 or 1.123456e8
10608 Funcref function('name')
10609 Blob 0z00112233.44556677.8899
10610 List [item, item]
10611 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000010612 Class class SomeName
10613 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010010614 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020010615 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010616
10617 When a |List| or |Dictionary| has a recursive reference it is
10618 replaced by "[...]" or "{...}". Using eval() on the result
10619 will then fail.
10620
mityu7f0bba22024-03-29 10:14:41 +010010621 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010622 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010010623 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010624
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010625 Can also be used as a |method|: >
10626 mylist->string()
10627
10628< Also see |strtrans()|.
10629
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010630 Return type: |String|
10631
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010632
10633strlen({string}) *strlen()*
10634 The result is a Number, which is the length of the String
10635 {string} in bytes.
10636 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010637 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010638 If you want to count the number of multibyte characters use
10639 |strchars()|.
10640 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
10641
10642 Can also be used as a |method|: >
10643 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010644<
10645 Return type: |Number|
10646
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010647
10648strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
10649 The result is a String, which is part of {src}, starting from
10650 byte {start}, with the byte length {len}.
10651 When {chars} is present and TRUE then {len} is the number of
10652 characters positions (composing characters are not counted
10653 separately, thus "1" means one base character and any
10654 following composing characters).
10655 To count {start} as characters instead of bytes use
10656 |strcharpart()|.
10657
10658 When bytes are selected which do not exist, this doesn't
10659 result in an error, the bytes are simply omitted.
10660 If {len} is missing, the copy continues from {start} till the
10661 end of the {src}. >
10662 strpart("abcdefg", 3, 2) == "de"
10663 strpart("abcdefg", -2, 4) == "ab"
10664 strpart("abcdefg", 5, 4) == "fg"
10665 strpart("abcdefg", 3) == "defg"
10666
10667< Note: To get the first character, {start} must be 0. For
10668 example, to get the character under the cursor: >
10669 strpart(getline("."), col(".") - 1, 1, v:true)
10670<
Bram Moolenaard592deb2022-06-17 15:42:40 +010010671 Returns an empty string on error.
10672
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010673 Can also be used as a |method|: >
10674 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010675<
10676 Return type: |String|
10677
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010678
10679strptime({format}, {timestring}) *strptime()*
10680 The result is a Number, which is a unix timestamp representing
10681 the date and time in {timestring}, which is expected to match
10682 the format specified in {format}.
10683
10684 The accepted {format} depends on your system, thus this is not
10685 portable! See the manual page of the C function strptime()
10686 for the format. Especially avoid "%c". The value of $TZ also
10687 matters.
10688
10689 If the {timestring} cannot be parsed with {format} zero is
10690 returned. If you do not know the format of {timestring} you
10691 can try different {format} values until you get a non-zero
10692 result.
10693
10694 See also |strftime()|.
10695 Examples: >
10696 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
10697< 862156163 >
10698 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
10699< Sun Apr 27 11:53:55 1997 >
10700 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
10701< Sun Apr 27 12:53:55 1997
10702
10703 Can also be used as a |method|: >
10704 GetFormat()->strptime(timestring)
10705<
10706 Not available on all systems. To check use: >
10707 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010708<
10709 Return type: |Number|
10710
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010711
10712strridx({haystack}, {needle} [, {start}]) *strridx()*
10713 The result is a Number, which gives the byte index in
10714 {haystack} of the last occurrence of the String {needle}.
10715 When {start} is specified, matches beyond this index are
10716 ignored. This can be used to find a match before a previous
10717 match: >
10718 :let lastcomma = strridx(line, ",")
10719 :let comma2 = strridx(line, ",", lastcomma - 1)
10720< The search is done case-sensitive.
10721 For pattern searches use |match()|.
10722 -1 is returned if the {needle} does not occur in {haystack}.
10723 If the {needle} is empty the length of {haystack} is returned.
10724 See also |stridx()|. Examples: >
10725 :echo strridx("an angry armadillo", "an") 3
10726< *strrchr()*
10727 When used with a single character it works similar to the C
10728 function strrchr().
10729
10730 Can also be used as a |method|: >
10731 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010732<
10733 Return type: |Number|
10734
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010735
10736strtrans({string}) *strtrans()*
10737 The result is a String, which is {string} with all unprintable
10738 characters translated into printable characters |'isprint'|.
10739 Like they are shown in a window. Example: >
10740 echo strtrans(@a)
10741< This displays a newline in register a as "^@" instead of
10742 starting a new line.
10743
Bram Moolenaard592deb2022-06-17 15:42:40 +010010744 Returns an empty string on error.
10745
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010746 Can also be used as a |method|: >
10747 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010748<
10749 Return type: |String|
10750
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010751
Christian Brabandt67672ef2023-04-24 21:09:54 +010010752strutf16len({string} [, {countcc}]) *strutf16len()*
10753 The result is a Number, which is the number of UTF-16 code
10754 units in String {string} (after converting it to UTF-16).
10755
10756 When {countcc} is TRUE, composing characters are counted
10757 separately.
10758 When {countcc} is omitted or FALSE, composing characters are
10759 ignored.
10760
10761 Returns zero on error.
10762
10763 Also see |strlen()| and |strcharlen()|.
10764 Examples: >
10765 echo strutf16len('a') returns 1
10766 echo strutf16len('©') returns 1
10767 echo strutf16len('😊') returns 2
10768 echo strutf16len('ą́') returns 1
10769 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090010770<
Christian Brabandt67672ef2023-04-24 21:09:54 +010010771 Can also be used as a |method|: >
10772 GetText()->strutf16len()
10773<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010774 Return type: |Number|
10775
10776
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010777strwidth({string}) *strwidth()*
10778 The result is a Number, which is the number of display cells
10779 String {string} occupies. A Tab character is counted as one
10780 cell, alternatively use |strdisplaywidth()|.
10781 When {string} contains characters with East Asian Width Class
10782 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010783 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010784 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
10785
10786 Can also be used as a |method|: >
10787 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010788<
10789 Return type: |Number|
10790
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010791
10792submatch({nr} [, {list}]) *submatch()* *E935*
10793 Only for an expression in a |:substitute| command or
10794 substitute() function.
10795 Returns the {nr}'th submatch of the matched text. When {nr}
10796 is 0 the whole matched text is returned.
10797 Note that a NL in the string can stand for a line break of a
10798 multi-line match or a NUL character in the text.
10799 Also see |sub-replace-expression|.
10800
10801 If {list} is present and non-zero then submatch() returns
10802 a list of strings, similar to |getline()| with two arguments.
10803 NL characters in the text represent NUL characters in the
10804 text.
10805 Only returns more than one item for |:substitute|, inside
10806 |substitute()| this list will always contain one or zero
10807 items, since there are no real line breaks.
10808
10809 When substitute() is used recursively only the submatches in
10810 the current (deepest) call can be obtained.
10811
Bram Moolenaard592deb2022-06-17 15:42:40 +010010812 Returns an empty string or list on error.
10813
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010814 Examples: >
10815 :s/\d\+/\=submatch(0) + 1/
10816 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
10817< This finds the first number in the line and adds one to it.
10818 A line break is included as a newline character.
10819
10820 Can also be used as a |method|: >
10821 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010822<
10823 Return type: |String| or list<string> depending on {list}
10824
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010825
10826substitute({string}, {pat}, {sub}, {flags}) *substitute()*
10827 The result is a String, which is a copy of {string}, in which
10828 the first match of {pat} is replaced with {sub}.
10829 When {flags} is "g", all matches of {pat} in {string} are
10830 replaced. Otherwise {flags} should be "".
10831
10832 This works like the ":substitute" command (without any flags).
10833 But the matching with {pat} is always done like the 'magic'
10834 option is set and 'cpoptions' is empty (to make scripts
10835 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
10836 if you want to ignore or match case and ignore 'ignorecase'.
10837 'smartcase' is not used. See |string-match| for how {pat} is
10838 used.
10839
10840 A "~" in {sub} is not replaced with the previous {sub}.
10841 Note that some codes in {sub} have a special meaning
10842 |sub-replace-special|. For example, to replace something with
10843 "\n" (two characters), use "\\\\n" or '\\n'.
10844
10845 When {pat} does not match in {string}, {string} is returned
10846 unmodified.
10847
10848 Example: >
10849 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
10850< This removes the last component of the 'path' option. >
10851 :echo substitute("testing", ".*", "\\U\\0", "")
10852< results in "TESTING".
10853
10854 When {sub} starts with "\=", the remainder is interpreted as
10855 an expression. See |sub-replace-expression|. Example: >
10856 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010857 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010858
10859< When {sub} is a Funcref that function is called, with one
10860 optional argument. Example: >
10861 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
10862< The optional argument is a list which contains the whole
10863 matched string and up to nine submatches, like what
10864 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010865 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010866
Bram Moolenaard592deb2022-06-17 15:42:40 +010010867< Returns an empty string on error.
10868
10869 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010870 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010871<
10872 Return type: |String|
10873
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010874
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000010875swapfilelist() *swapfilelist()*
10876 Returns a list of swap file names, like what "vim -r" shows.
10877 See the |-r| command argument. The 'directory' option is used
10878 for the directories to inspect. If you only want to get a
10879 list of swap files in the current directory then temporarily
10880 set 'directory' to a dot: >
10881 let save_dir = &directory
10882 let &directory = '.'
10883 let swapfiles = swapfilelist()
10884 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010885<
10886 Return type: list<string>
10887
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000010888
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010889swapinfo({fname}) *swapinfo()*
10890 The result is a dictionary, which holds information about the
10891 swapfile {fname}. The available fields are:
10892 version Vim version
10893 user user name
10894 host host name
10895 fname original file name
10896 pid PID of the Vim process that created the swap
10897 file
10898 mtime last modification time in seconds
10899 inode Optional: INODE number of the file
10900 dirty 1 if file was modified, 0 if not
10901 Note that "user" and "host" are truncated to at most 39 bytes.
10902 In case of failure an "error" item is added with the reason:
10903 Cannot open file: file not found or in accessible
10904 Cannot read file: cannot read first block
10905 Not a swap file: does not contain correct block ID
10906 Magic number mismatch: Info in first block is invalid
10907
10908 Can also be used as a |method|: >
10909 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010910<
10911 Return type: dict<any> or dict<string>
10912
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010913
10914swapname({buf}) *swapname()*
10915 The result is the swap file path of the buffer {expr}.
10916 For the use of {buf}, see |bufname()| above.
10917 If buffer {buf} is the current buffer, the result is equal to
10918 |:swapname| (unless there is no swap file).
10919 If buffer {buf} has no swap file, returns an empty string.
10920
10921 Can also be used as a |method|: >
10922 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010923<
10924 Return type: |String|
10925
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010926
10927synID({lnum}, {col}, {trans}) *synID()*
10928 The result is a Number, which is the syntax ID at the position
10929 {lnum} and {col} in the current window.
10930 The syntax ID can be used with |synIDattr()| and
10931 |synIDtrans()| to obtain syntax information about text.
10932
10933 {col} is 1 for the leftmost column, {lnum} is 1 for the first
10934 line. 'synmaxcol' applies, in a longer line zero is returned.
10935 Note that when the position is after the last character,
10936 that's where the cursor can be in Insert mode, synID() returns
10937 zero. {lnum} is used like with |getline()|.
10938
10939 When {trans} is |TRUE|, transparent items are reduced to the
10940 item that they reveal. This is useful when wanting to know
10941 the effective color. When {trans} is |FALSE|, the transparent
10942 item is returned. This is useful when wanting to know which
10943 syntax item is effective (e.g. inside parens).
10944 Warning: This function can be very slow. Best speed is
10945 obtained by going through the file in forward direction.
10946
Bram Moolenaard592deb2022-06-17 15:42:40 +010010947 Returns zero on error.
10948
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010949 Example (echoes the name of the syntax item under the cursor): >
10950 :echo synIDattr(synID(line("."), col("."), 1), "name")
10951<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010952 Return type: |Number|
10953
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010954
10955synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
10956 The result is a String, which is the {what} attribute of
10957 syntax ID {synID}. This can be used to obtain information
10958 about a syntax item.
10959 {mode} can be "gui", "cterm" or "term", to get the attributes
10960 for that mode. When {mode} is omitted, or an invalid value is
10961 used, the attributes for the currently active highlighting are
10962 used (GUI, cterm or term).
10963 Use synIDtrans() to follow linked highlight groups.
10964 {what} result
10965 "name" the name of the syntax item
10966 "fg" foreground color (GUI: color name used to set
10967 the color, cterm: color number as a string,
10968 term: empty string)
10969 "bg" background color (as with "fg")
10970 "font" font name (only available in the GUI)
10971 |highlight-font|
10972 "sp" special color for the GUI (as with "fg")
10973 |highlight-guisp|
10974 "ul" underline color for cterm: number as a string
10975 "fg#" like "fg", but for the GUI and the GUI is
10976 running the name in "#RRGGBB" form
10977 "bg#" like "fg#" for "bg"
10978 "sp#" like "fg#" for "sp"
10979 "bold" "1" if bold
10980 "italic" "1" if italic
10981 "reverse" "1" if reverse
10982 "inverse" "1" if inverse (= reverse)
10983 "standout" "1" if standout
10984 "underline" "1" if underlined
10985 "undercurl" "1" if undercurled
10986 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010010987 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010988
Bram Moolenaard592deb2022-06-17 15:42:40 +010010989 Returns an empty string on error.
10990
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010991 Example (echoes the color of the syntax item under the
10992 cursor): >
10993 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
10994<
10995 Can also be used as a |method|: >
10996 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010997<
10998 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010999
11000
11001synIDtrans({synID}) *synIDtrans()*
11002 The result is a Number, which is the translated syntax ID of
11003 {synID}. This is the syntax group ID of what is being used to
11004 highlight the character. Highlight links given with
11005 ":highlight link" are followed.
11006
Bram Moolenaard592deb2022-06-17 15:42:40 +010011007 Returns zero on error.
11008
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011009 Can also be used as a |method|: >
11010 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011011<
11012 Return type: |Number|
11013
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011014
11015synconcealed({lnum}, {col}) *synconcealed()*
11016 The result is a |List| with currently three items:
11017 1. The first item in the list is 0 if the character at the
11018 position {lnum} and {col} is not part of a concealable
11019 region, 1 if it is. {lnum} is used like with |getline()|.
11020 2. The second item in the list is a string. If the first item
11021 is 1, the second item contains the text which will be
11022 displayed in place of the concealed text, depending on the
11023 current setting of 'conceallevel' and 'listchars'.
11024 3. The third and final item in the list is a number
11025 representing the specific syntax region matched in the
11026 line. When the character is not concealed the value is
11027 zero. This allows detection of the beginning of a new
11028 concealable region if there are two consecutive regions
11029 with the same replacement character. For an example, if
11030 the text is "123456" and both "23" and "45" are concealed
11031 and replaced by the character "X", then:
11032 call returns ~
11033 synconcealed(lnum, 1) [0, '', 0]
11034 synconcealed(lnum, 2) [1, 'X', 1]
11035 synconcealed(lnum, 3) [1, 'X', 1]
11036 synconcealed(lnum, 4) [1, 'X', 2]
11037 synconcealed(lnum, 5) [1, 'X', 2]
11038 synconcealed(lnum, 6) [0, '', 0]
11039
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011040 Note: Doesn't consider |matchadd()| highlighting items,
11041 since syntax and matching highlighting are two different
11042 mechanisms |syntax-vs-match|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011043<
11044 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011045
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011046
11047synstack({lnum}, {col}) *synstack()*
11048 Return a |List|, which is the stack of syntax items at the
11049 position {lnum} and {col} in the current window. {lnum} is
11050 used like with |getline()|. Each item in the List is an ID
11051 like what |synID()| returns.
11052 The first item in the List is the outer region, following are
11053 items contained in that one. The last one is what |synID()|
11054 returns, unless not the whole item is highlighted or it is a
11055 transparent item.
11056 This function is useful for debugging a syntax file.
11057 Example that shows the syntax stack under the cursor: >
11058 for id in synstack(line("."), col("."))
11059 echo synIDattr(id, "name")
11060 endfor
11061< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011062 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011063 character in a line and the first column in an empty line are
11064 valid positions.
11065
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011066 Return type: list<number> or list<any>
11067
11068
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011069system({expr} [, {input}]) *system()* *E677*
11070 Get the output of the shell command {expr} as a |String|. See
11071 |systemlist()| to get the output as a |List|.
11072
11073 When {input} is given and is a |String| this string is written
11074 to a file and passed as stdin to the command. The string is
11075 written as-is, you need to take care of using the correct line
11076 separators yourself.
11077 If {input} is given and is a |List| it is written to the file
11078 in a way |writefile()| does with {binary} set to "b" (i.e.
11079 with a newline between each list item with newlines inside
11080 list items converted to NULs).
11081 When {input} is given and is a number that is a valid id for
11082 an existing buffer then the content of the buffer is written
11083 to the file line by line, each line terminated by a NL and
11084 NULs characters where the text has a NL.
11085
11086 Pipes are not used, the 'shelltemp' option is not used.
11087
11088 When prepended by |:silent| the terminal will not be set to
11089 cooked mode. This is meant to be used for commands that do
11090 not need the user to type. It avoids stray characters showing
11091 up on the screen which require |CTRL-L| to remove. >
11092 :silent let f = system('ls *.vim')
11093<
11094 Note: Use |shellescape()| or |::S| with |expand()| or
11095 |fnamemodify()| to escape special characters in a command
11096 argument. Newlines in {expr} may cause the command to fail.
11097 The characters in 'shellquote' and 'shellxquote' may also
11098 cause trouble.
11099 This is not to be used for interactive commands.
11100
11101 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011102 :let files = system('ls ' .. shellescape(expand('%:h')))
11103 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011104
11105< To make the result more system-independent, the shell output
11106 is filtered to replace <CR> with <NL> for Macintosh, and
11107 <CR><NL> with <NL> for DOS-like systems.
11108 To avoid the string being truncated at a NUL, all NUL
11109 characters are replaced with SOH (0x01).
11110
11111 The command executed is constructed using several options:
11112 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11113 ({tmp} is an automatically generated file name).
11114 For Unix, braces are put around {expr} to allow for
11115 concatenated commands.
11116
11117 The command will be executed in "cooked" mode, so that a
11118 CTRL-C will interrupt the command (on Unix at least).
11119
11120 The resulting error code can be found in |v:shell_error|.
11121 This function will fail in |restricted-mode|.
11122
11123 Note that any wrong value in the options mentioned above may
11124 make the function fail. It has also been reported to fail
11125 when using a security agent application.
11126 Unlike ":!cmd" there is no automatic check for changed files.
11127 Use |:checktime| to force a check.
11128
11129 Can also be used as a |method|: >
11130 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011131<
11132 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011133
11134
11135systemlist({expr} [, {input}]) *systemlist()*
11136 Same as |system()|, but returns a |List| with lines (parts of
11137 output separated by NL) with NULs transformed into NLs. Output
11138 is the same as |readfile()| will output with {binary} argument
11139 set to "b", except that there is no extra empty item when the
11140 result ends in a NL.
11141 Note that on MS-Windows you may get trailing CR characters.
11142
11143 To see the difference between "echo hello" and "echo -n hello"
11144 use |system()| and |split()|: >
11145 echo system('echo hello')->split('\n', 1)
11146<
11147 Returns an empty string on error.
11148
11149 Can also be used as a |method|: >
11150 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011151<
11152 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011153
11154
11155tabpagebuflist([{arg}]) *tabpagebuflist()*
11156 The result is a |List|, where each item is the number of the
11157 buffer associated with each window in the current tab page.
11158 {arg} specifies the number of the tab page to be used. When
11159 omitted the current tab page is used.
11160 When {arg} is invalid the number zero is returned.
11161 To get a list of all buffers in all tabs use this: >
11162 let buflist = []
11163 for i in range(tabpagenr('$'))
11164 call extend(buflist, tabpagebuflist(i + 1))
11165 endfor
11166< Note that a buffer may appear in more than one window.
11167
11168 Can also be used as a |method|: >
11169 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011170<
11171 Return type: list<number>
11172
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011173
11174tabpagenr([{arg}]) *tabpagenr()*
11175 The result is a Number, which is the number of the current
11176 tab page. The first tab page has number 1.
11177
11178 The optional argument {arg} supports the following values:
11179 $ the number of the last tab page (the tab page
11180 count).
11181 # the number of the last accessed tab page
11182 (where |g<Tab>| goes to). if there is no
11183 previous tab page 0 is returned.
11184 The number can be used with the |:tab| command.
11185
Bram Moolenaard592deb2022-06-17 15:42:40 +010011186 Returns zero on error.
11187
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011188 Return type: |Number|
11189
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011190
11191tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11192 Like |winnr()| but for tab page {tabarg}.
11193 {tabarg} specifies the number of tab page to be used.
11194 {arg} is used like with |winnr()|:
11195 - When omitted the current window number is returned. This is
11196 the window which will be used when going to this tab page.
11197 - When "$" the number of windows is returned.
11198 - When "#" the previous window nr is returned.
11199 Useful examples: >
11200 tabpagewinnr(1) " current window of tab page 1
11201 tabpagewinnr(4, '$') " number of windows in tab page 4
11202< When {tabarg} is invalid zero is returned.
11203
11204 Can also be used as a |method|: >
11205 GetTabpage()->tabpagewinnr()
11206<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011207 Return type: |Number|
11208
11209
11210tagfiles() *tagfiles()*
11211 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011212 for the current buffer. This is the 'tags' option expanded.
11213
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011214 Return type: list<string> or list<any>
11215
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011216
11217taglist({expr} [, {filename}]) *taglist()*
11218 Returns a |List| of tags matching the regular expression {expr}.
11219
11220 If {filename} is passed it is used to prioritize the results
11221 in the same way that |:tselect| does. See |tag-priority|.
11222 {filename} should be the full path of the file.
11223
11224 Each list item is a dictionary with at least the following
11225 entries:
11226 name Name of the tag.
11227 filename Name of the file where the tag is
11228 defined. It is either relative to the
11229 current directory or a full path.
11230 cmd Ex command used to locate the tag in
11231 the file.
11232 kind Type of the tag. The value for this
11233 entry depends on the language specific
11234 kind values. Only available when
11235 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011236 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011237 static A file specific tag. Refer to
11238 |static-tag| for more information.
11239 More entries may be present, depending on the content of the
11240 tags file: access, implementation, inherits and signature.
11241 Refer to the ctags documentation for information about these
11242 fields. For C code the fields "struct", "class" and "enum"
11243 may appear, they give the name of the entity the tag is
11244 contained in.
11245
11246 The ex-command "cmd" can be either an ex search pattern, a
11247 line number or a line number followed by a byte number.
11248
11249 If there are no matching tags, then an empty list is returned.
11250
11251 To get an exact tag match, the anchors '^' and '$' should be
11252 used in {expr}. This also make the function work faster.
11253 Refer to |tag-regexp| for more information about the tag
11254 search regular expression pattern.
11255
11256 Refer to |'tags'| for information about how the tags file is
11257 located by Vim. Refer to |tags-file-format| for the format of
11258 the tags file generated by the different ctags tools.
11259
11260 Can also be used as a |method|: >
11261 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011262<
11263 Return type: list<dict<any>> or list<any>
11264
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011265
11266tan({expr}) *tan()*
11267 Return the tangent of {expr}, measured in radians, as a |Float|
11268 in the range [-inf, inf].
11269 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011270 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011271 Examples: >
11272 :echo tan(10)
11273< 0.648361 >
11274 :echo tan(-4.01)
11275< -1.181502
11276
11277 Can also be used as a |method|: >
11278 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011279<
11280 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011281
11282
11283tanh({expr}) *tanh()*
11284 Return the hyperbolic tangent of {expr} as a |Float| in the
11285 range [-1, 1].
11286 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011287 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011288 Examples: >
11289 :echo tanh(0.5)
11290< 0.462117 >
11291 :echo tanh(-1)
11292< -0.761594
11293
11294 Can also be used as a |method|: >
11295 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011296<
11297 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011298
11299
11300tempname() *tempname()* *temp-file-name*
11301 The result is a String, which is the name of a file that
11302 doesn't exist. It can be used for a temporary file. The name
11303 is different for at least 26 consecutive calls. Example: >
11304 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011305 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011306< For Unix, the file will be in a private directory |tempfile|
11307 that is recursively deleted when Vim exits, on other systems
11308 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011309 For MS-Windows forward slashes are used when the 'shellslash'
11310 option is set, or when 'shellcmdflag' starts with '-' and
11311 'shell' does not contain powershell or pwsh.
11312
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011313 Return type: |String|
11314
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011315
11316term_ functions are documented here: |terminal-function-details|
11317
11318
11319terminalprops() *terminalprops()*
11320 Returns a |Dictionary| with properties of the terminal that Vim
11321 detected from the response to |t_RV| request. See
11322 |v:termresponse| for the response itself. If |v:termresponse|
11323 is empty most values here will be 'u' for unknown.
11324 cursor_style whether sending |t_RS| works **
11325 cursor_blink_mode whether sending |t_RC| works **
11326 underline_rgb whether |t_8u| works **
11327 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011328 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011329
11330 ** value 'u' for unknown, 'y' for yes, 'n' for no
11331
11332 If the |+termresponse| feature is missing then the result is
11333 an empty dictionary.
11334
11335 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11336 current cursor style.
11337 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11338 request the cursor blink status.
11339 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11340 is not empty, Vim will detect the working of sending |t_RS|
11341 and |t_RC| on startup.
11342
11343 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11344 This avoids sending it to xterm, which would clear the colors.
11345
11346 For "mouse" the value 'u' is unknown
11347
11348 Also see:
11349 - 'ambiwidth' - detected by using |t_u7|.
11350 - |v:termstyleresp| and |v:termblinkresp| for the response to
11351 |t_RS| and |t_RC|.
11352
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011353 Return type: dict<string>
11354
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011355
11356test_ functions are documented here: |test-functions-details|
11357
11358
11359 *timer_info()*
11360timer_info([{id}])
11361 Return a list with information about timers.
11362 When {id} is given only information about this timer is
11363 returned. When timer {id} does not exist an empty list is
11364 returned.
11365 When {id} is omitted information about all timers is returned.
11366
11367 For each timer the information is stored in a |Dictionary| with
11368 these items:
11369 "id" the timer ID
11370 "time" time the timer was started with
11371 "remaining" time until the timer fires
11372 "repeat" number of times the timer will still fire;
11373 -1 means forever
11374 "callback" the callback
11375 "paused" 1 if the timer is paused, 0 otherwise
11376
11377 Can also be used as a |method|: >
11378 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011379<
11380 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011381
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011382 {only available when compiled with the |+timers| feature}
11383
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011384
11385timer_pause({timer}, {paused}) *timer_pause()*
11386 Pause or unpause a timer. A paused timer does not invoke its
11387 callback when its time expires. Unpausing a timer may cause
11388 the callback to be invoked almost immediately if enough time
11389 has passed.
11390
11391 Pausing a timer is useful to avoid the callback to be called
11392 for a short time.
11393
11394 If {paused} evaluates to a non-zero Number or a non-empty
11395 String, then the timer is paused, otherwise it is unpaused.
11396 See |non-zero-arg|.
11397
11398 Can also be used as a |method|: >
11399 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011400<
11401 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011402
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011403 {only available when compiled with the |+timers| feature}
11404
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011405
11406 *timer_start()* *timer* *timers*
11407timer_start({time}, {callback} [, {options}])
11408 Create a timer and return the timer ID.
11409
11410 {time} is the waiting time in milliseconds. This is the
11411 minimum time before invoking the callback. When the system is
11412 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011413 Zero can be used to execute the callback when Vim is back in
11414 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011415
11416 {callback} is the function to call. It can be the name of a
11417 function or a |Funcref|. It is called with one argument, which
11418 is the timer ID. The callback is only invoked when Vim is
11419 waiting for input.
11420 If you want to show a message look at |popup_notification()|
11421 to avoid interfering with what the user is doing.
11422
11423 {options} is a dictionary. Supported entries:
11424 "repeat" Number of times to repeat calling the
11425 callback. -1 means forever. When not present
11426 the callback will be called once.
11427 If the timer causes an error three times in a
11428 row the repeat is cancelled. This avoids that
11429 Vim becomes unusable because of all the error
11430 messages.
11431
Bram Moolenaard592deb2022-06-17 15:42:40 +010011432 Returns -1 on error.
11433
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011434 Example: >
11435 func MyHandler(timer)
11436 echo 'Handler called'
11437 endfunc
11438 let timer = timer_start(500, 'MyHandler',
11439 \ {'repeat': 3})
11440< This will invoke MyHandler() three times at 500 msec
11441 intervals.
11442
11443 Can also be used as a |method|: >
11444 GetMsec()->timer_start(callback)
11445
11446< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011447
11448 Return type: |Number|
11449
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011450 {only available when compiled with the |+timers| feature}
11451
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011452
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011453timer_stop({timer}) *timer_stop()*
11454 Stop a timer. The timer callback will no longer be invoked.
11455 {timer} is an ID returned by timer_start(), thus it must be a
11456 Number. If {timer} does not exist there is no error.
11457
11458 Can also be used as a |method|: >
11459 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011460<
11461 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011462
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011463 {only available when compiled with the |+timers| feature}
11464
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011465
11466timer_stopall() *timer_stopall()*
11467 Stop all timers. The timer callbacks will no longer be
11468 invoked. Useful if a timer is misbehaving. If there are no
11469 timers there is no error.
11470
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011471 Return type: |Number|
11472
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011473 {only available when compiled with the |+timers| feature}
11474
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011475
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011476tolower({expr}) *tolower()*
11477 The result is a copy of the String given, with all uppercase
11478 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011479 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011480
11481 Can also be used as a |method|: >
11482 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011483<
11484 Return type: |String|
11485
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011486
11487toupper({expr}) *toupper()*
11488 The result is a copy of the String given, with all lowercase
11489 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011490 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011491
11492 Can also be used as a |method|: >
11493 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011494<
11495 Return type: |String|
11496
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011497
11498tr({src}, {fromstr}, {tostr}) *tr()*
11499 The result is a copy of the {src} string with all characters
11500 which appear in {fromstr} replaced by the character in that
11501 position in the {tostr} string. Thus the first character in
11502 {fromstr} is translated into the first character in {tostr}
11503 and so on. Exactly like the unix "tr" command.
11504 This code also deals with multibyte characters properly.
11505
Bram Moolenaard592deb2022-06-17 15:42:40 +010011506 Returns an empty string on error.
11507
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011508 Examples: >
11509 echo tr("hello there", "ht", "HT")
11510< returns "Hello THere" >
11511 echo tr("<blob>", "<>", "{}")
11512< returns "{blob}"
11513
11514 Can also be used as a |method|: >
11515 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011516<
11517 Return type: |String|
11518
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011519
11520trim({text} [, {mask} [, {dir}]]) *trim()*
11521 Return {text} as a String where any character in {mask} is
11522 removed from the beginning and/or end of {text}.
11523
Illia Bobyr80799172023-10-17 18:00:50 +020011524 If {mask} is not given, or is an empty string, {mask} is all
11525 characters up to 0x20, which includes Tab, space, NL and CR,
11526 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011527
11528 The optional {dir} argument specifies where to remove the
11529 characters:
11530 0 remove from the beginning and end of {text}
11531 1 remove only at the beginning of {text}
11532 2 remove only at the end of {text}
11533 When omitted both ends are trimmed.
11534
11535 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011536 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011537
11538 Examples: >
11539 echo trim(" some text ")
11540< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011541 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011542< returns "RESERVE_TAIL" >
11543 echo trim("rm<Xrm<>X>rrm", "rm<>")
11544< returns "Xrm<>X" (characters in the middle are not removed) >
11545 echo trim(" vim ", " ", 2)
11546< returns " vim"
11547
11548 Can also be used as a |method|: >
11549 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011550<
11551 Return type: |String|
11552
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011553
11554trunc({expr}) *trunc()*
11555 Return the largest integral value with magnitude less than or
11556 equal to {expr} as a |Float| (truncate towards zero).
11557 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011558 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011559 Examples: >
11560 echo trunc(1.456)
11561< 1.0 >
11562 echo trunc(-5.456)
11563< -5.0 >
11564 echo trunc(4.0)
11565< 4.0
11566
11567 Can also be used as a |method|: >
11568 Compute()->trunc()
11569<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011570 Return type: |Float|
11571
11572
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011573 *type()*
11574type({expr}) The result is a Number representing the type of {expr}.
11575 Instead of using the number directly, it is better to use the
11576 v:t_ variable that has the value:
11577 Number: 0 |v:t_number|
11578 String: 1 |v:t_string|
11579 Funcref: 2 |v:t_func|
11580 List: 3 |v:t_list|
11581 Dictionary: 4 |v:t_dict|
11582 Float: 5 |v:t_float|
11583 Boolean: 6 |v:t_bool| (v:false and v:true)
11584 None: 7 |v:t_none| (v:null and v:none)
11585 Job: 8 |v:t_job|
11586 Channel: 9 |v:t_channel|
11587 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090011588 Class: 12 |v:t_class|
11589 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010011590 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011591 Enum: 15 |v:t_enum|
11592 EnumValue: 16 |v:t_enumvalue|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011593 For backward compatibility, this method can be used: >
11594 :if type(myvar) == type(0)
11595 :if type(myvar) == type("")
11596 :if type(myvar) == type(function("tr"))
11597 :if type(myvar) == type([])
11598 :if type(myvar) == type({})
11599 :if type(myvar) == type(0.0)
11600 :if type(myvar) == type(v:false)
11601 :if type(myvar) == type(v:none)
11602< To check if the v:t_ variables exist use this: >
11603 :if exists('v:t_number')
11604
11605< Can also be used as a |method|: >
11606 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011607<
11608 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011609
11610
11611typename({expr}) *typename()*
11612 Return a string representation of the type of {expr}.
11613 Example: >
11614 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000011615< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011616
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011617 Return type: |String|
11618
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011619
11620undofile({name}) *undofile()*
11621 Return the name of the undo file that would be used for a file
11622 with name {name} when writing. This uses the 'undodir'
11623 option, finding directories that exist. It does not check if
11624 the undo file exists.
11625 {name} is always expanded to the full path, since that is what
11626 is used internally.
11627 If {name} is empty undofile() returns an empty string, since a
11628 buffer without a file name will not write an undo file.
11629 Useful in combination with |:wundo| and |:rundo|.
11630 When compiled without the |+persistent_undo| option this always
11631 returns an empty string.
11632
11633 Can also be used as a |method|: >
11634 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011635<
11636 Return type: |String|
11637
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011638
Devin J. Pohly5fee1112023-04-23 20:26:59 -050011639undotree([{buf}]) *undotree()*
11640 Return the current state of the undo tree for the current
11641 buffer, or for a specific buffer if {buf} is given. The
11642 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011643 "seq_last" The highest undo sequence number used.
11644 "seq_cur" The sequence number of the current position in
11645 the undo tree. This differs from "seq_last"
11646 when some changes were undone.
11647 "time_cur" Time last used for |:earlier| and related
11648 commands. Use |strftime()| to convert to
11649 something readable.
11650 "save_last" Number of the last file write. Zero when no
11651 write yet.
11652 "save_cur" Number of the current position in the undo
11653 tree.
11654 "synced" Non-zero when the last undo block was synced.
11655 This happens when waiting from input from the
11656 user. See |undo-blocks|.
11657 "entries" A list of dictionaries with information about
11658 undo blocks.
11659
11660 The first item in the "entries" list is the oldest undo item.
11661 Each List item is a |Dictionary| with these items:
11662 "seq" Undo sequence number. Same as what appears in
11663 |:undolist|.
11664 "time" Timestamp when the change happened. Use
11665 |strftime()| to convert to something readable.
11666 "newhead" Only appears in the item that is the last one
11667 that was added. This marks the last change
11668 and where further changes will be added.
11669 "curhead" Only appears in the item that is the last one
11670 that was undone. This marks the current
11671 position in the undo tree, the block that will
11672 be used by a redo command. When nothing was
11673 undone after the last change this item will
11674 not appear anywhere.
11675 "save" Only appears on the last block before a file
11676 write. The number is the write count. The
11677 first write has number 1, the last one the
11678 "save_last" mentioned above.
11679 "alt" Alternate entry. This is again a List of undo
11680 blocks. Each item may again have an "alt"
11681 item.
11682
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011683 Return type: dict<any>
11684
11685
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011686uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
11687 Remove second and succeeding copies of repeated adjacent
11688 {list} items in-place. Returns {list}. If you want a list
11689 to remain unmodified make a copy first: >
11690 :let newlist = uniq(copy(mylist))
11691< The default compare function uses the string representation of
11692 each item. For the use of {func} and {dict} see |sort()|.
11693
Bram Moolenaard592deb2022-06-17 15:42:40 +010011694 Returns zero if {list} is not a |List|.
11695
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011696 Can also be used as a |method|: >
11697 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010011698<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011699 Return type: list<{type}>
11700
11701
Christian Brabandt67672ef2023-04-24 21:09:54 +010011702 *utf16idx()*
11703utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011704 Same as |charidx()| but returns the UTF-16 code unit index of
11705 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010011706
11707 When {charidx} is present and TRUE, {idx} is used as the
11708 character index in the String {string} instead of as the byte
11709 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010011710 An {idx} in the middle of a UTF-8 sequence is rounded
11711 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010011712
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011713 Returns -1 if the arguments are invalid or if there are less
11714 than {idx} bytes in {string}. If there are exactly {idx} bytes
11715 the length of the string in UTF-16 code units is returned.
11716
Christian Brabandt67672ef2023-04-24 21:09:54 +010011717 See |byteidx()| and |byteidxcomp()| for getting the byte index
11718 from the UTF-16 index and |charidx()| for getting the
11719 character index from the UTF-16 index.
11720 Refer to |string-offset-encoding| for more information.
11721 Examples: >
11722 echo utf16idx('a😊😊', 3) returns 2
11723 echo utf16idx('a😊😊', 7) returns 4
11724 echo utf16idx('a😊😊', 1, 0, 1) returns 2
11725 echo utf16idx('a😊😊', 2, 0, 1) returns 4
11726 echo utf16idx('aą́c', 6) returns 2
11727 echo utf16idx('aą́c', 6, 1) returns 4
11728 echo utf16idx('a😊😊', 9) returns -1
11729<
11730 Can also be used as a |method|: >
11731 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011732<
11733 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010011734
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011735
11736values({dict}) *values()*
11737 Return a |List| with all the values of {dict}. The |List| is
11738 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011739 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011740
11741 Can also be used as a |method|: >
11742 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011743<
11744 Return type: list<any>
11745
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011746
zeertzjq825cf812023-08-17 22:55:25 +020011747virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011748 The result is a Number, which is the screen column of the file
11749 position given with {expr}. That is, the last screen position
11750 occupied by the character at that position, when the screen
11751 would be of unlimited width. When there is a <Tab> at the
11752 position, the returned Number will be the column at the end of
11753 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
11754 set to 8, it returns 8. |conceal| is ignored.
11755 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011756
zeertzjq02f3eba2024-06-12 20:45:24 +020011757 For the use of {expr} see |getpos()| and |col()|.
zeertzjqd353d272024-06-13 23:00:25 +080011758 When {expr} is "$", it means the end of the cursor line, so
11759 the result is the number of cells in the cursor line plus one.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011760
11761 When 'virtualedit' is used {expr} can be [lnum, col, off],
11762 where "off" is the offset in screen columns from the start of
11763 the character. E.g., a position within a <Tab> or after the
11764 last character. When "off" is omitted zero is used. When
11765 Virtual editing is active in the current mode, a position
11766 beyond the end of the line can be returned. Also see
11767 |'virtualedit'|
11768
zeertzjq825cf812023-08-17 22:55:25 +020011769 If {list} is present and non-zero then virtcol() returns a
11770 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010011771 character.
11772
zeertzjq825cf812023-08-17 22:55:25 +020011773 With the optional {winid} argument the values are obtained for
11774 that window instead of the current window.
11775
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011776 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +020011777
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011778 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010011779 " With text "foo^Lbar" and cursor on the "^L":
11780
11781 virtcol(".") " returns 5
11782 virtcol(".", 1) " returns [4, 5]
11783 virtcol("$") " returns 9
11784
11785 " With text " there", with 't at 'h':
11786
11787 virtcol("'t") " returns 6
zeertzjq02f3eba2024-06-12 20:45:24 +020011788<
11789 The first column is 1. 0 or [0, 0] is returned for an error.
11790
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011791 A more advanced example that echoes the maximum length of
11792 all lines: >
11793 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
11794
11795< Can also be used as a |method|: >
11796 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011797<
11798 Return type: |Number|
11799
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011800
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011801virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
11802 The result is a Number, which is the byte index of the
11803 character in window {winid} at buffer line {lnum} and virtual
11804 column {col}.
11805
zeertzjqb583eda2023-10-14 11:32:28 +020011806 If buffer line {lnum} is an empty line, 0 is returned.
11807
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011808 If {col} is greater than the last virtual column in line
11809 {lnum}, then the byte index of the character at the last
11810 virtual column is returned.
11811
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020011812 For a multi-byte character, the column number of the first
11813 byte in the character is returned.
11814
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011815 The {winid} argument can be the window number or the
11816 |window-ID|. If this is zero, then the current window is used.
11817
11818 Returns -1 if the window {winid} doesn't exist or the buffer
11819 line {lnum} or virtual column {col} is invalid.
11820
11821 See also |screenpos()|, |virtcol()| and |col()|.
11822
11823 Can also be used as a |method|: >
11824 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011825<
11826 Return type: |Number|
11827
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011828
11829visualmode([{expr}]) *visualmode()*
11830 The result is a String, which describes the last Visual mode
11831 used in the current buffer. Initially it returns an empty
11832 string, but once Visual mode has been used, it returns "v",
11833 "V", or "<CTRL-V>" (a single CTRL-V character) for
11834 character-wise, line-wise, or block-wise Visual mode
11835 respectively.
11836 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011837 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011838< This enters the same Visual mode as before. It is also useful
11839 in scripts if you wish to act differently depending on the
11840 Visual mode that was used.
11841 If Visual mode is active, use |mode()| to get the Visual mode
11842 (e.g., in a |:vmap|).
11843 If {expr} is supplied and it evaluates to a non-zero Number or
11844 a non-empty String, then the Visual mode will be cleared and
11845 the old value is returned. See |non-zero-arg|.
11846
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011847 Return type: |String|
11848
11849
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011850wildmenumode() *wildmenumode()*
11851 Returns |TRUE| when the wildmenu is active and |FALSE|
11852 otherwise. See 'wildmenu' and 'wildmode'.
11853 This can be used in mappings to handle the 'wildcharm' option
11854 gracefully. (Makes only sense with |mapmode-c| mappings).
11855
11856 For example to make <c-j> work like <down> in wildmode, use: >
11857 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
11858<
11859 (Note, this needs the 'wildcharm' option set appropriately).
11860
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011861 Return type: |Number|
11862
11863
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011864win_execute({id}, {command} [, {silent}]) *win_execute()*
11865 Like `execute()` but in the context of window {id}.
11866 The window will temporarily be made the current window,
11867 without triggering autocommands or changing directory. When
11868 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010011869 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011870 Example: >
11871 call win_execute(winid, 'set syntax=python')
11872< Doing the same with `setwinvar()` would not trigger
11873 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011874 *E994*
11875 Not all commands are allowed in popup windows.
11876 When window {id} does not exist then no error is given and
11877 an empty string is returned.
11878
11879 Can also be used as a |method|, the base is passed as the
11880 second argument: >
11881 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011882<
11883 Return type: |String|
11884
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011885
11886win_findbuf({bufnr}) *win_findbuf()*
11887 Returns a |List| with |window-ID|s for windows that contain
11888 buffer {bufnr}. When there is none the list is empty.
11889
11890 Can also be used as a |method|: >
11891 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011892<
11893 Return type: list<number> or list<any>
11894
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011895
11896win_getid([{win} [, {tab}]]) *win_getid()*
11897 Get the |window-ID| for the specified window.
11898 When {win} is missing use the current window.
11899 With {win} this is the window number. The top window has
11900 number 1.
11901 Without {tab} use the current tab, otherwise the tab with
11902 number {tab}. The first tab has number one.
11903 Return zero if the window cannot be found.
11904
11905 Can also be used as a |method|: >
11906 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011907<
11908 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011909
11910
11911win_gettype([{nr}]) *win_gettype()*
11912 Return the type of the window:
11913 "autocmd" autocommand window. Temporary window
11914 used to execute autocommands.
11915 "command" command-line window |cmdwin|
11916 (empty) normal window
11917 "loclist" |location-list-window|
11918 "popup" popup window |popup|
11919 "preview" preview window |preview-window|
11920 "quickfix" |quickfix-window|
11921 "unknown" window {nr} not found
11922
11923 When {nr} is omitted return the type of the current window.
11924 When {nr} is given return the type of this window by number or
11925 |window-ID|.
11926
11927 Also see the 'buftype' option. When running a terminal in a
11928 popup window then 'buftype' is "terminal" and win_gettype()
11929 returns "popup".
11930
11931 Can also be used as a |method|: >
11932 GetWinid()->win_gettype()
11933<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011934 Return type: |String|
11935
11936
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011937win_gotoid({expr}) *win_gotoid()*
11938 Go to window with ID {expr}. This may also change the current
11939 tabpage.
11940 Return TRUE if successful, FALSE if the window cannot be found.
11941
11942 Can also be used as a |method|: >
11943 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011944<
11945 Return type: |Number|
11946
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011947
11948win_id2tabwin({expr}) *win_id2tabwin()*
11949 Return a list with the tab number and window number of window
11950 with ID {expr}: [tabnr, winnr].
11951 Return [0, 0] if the window cannot be found.
11952
11953 Can also be used as a |method|: >
11954 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011955<
11956 Return type: list<number>
11957
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011958
11959win_id2win({expr}) *win_id2win()*
11960 Return the window number of window with ID {expr}.
11961 Return 0 if the window cannot be found in the current tabpage.
11962
11963 Can also be used as a |method|: >
11964 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011965<
11966 Return type: |Number|
11967
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011968
Daniel Steinbergee630312022-01-10 13:36:34 +000011969win_move_separator({nr}, {offset}) *win_move_separator()*
11970 Move window {nr}'s vertical separator (i.e., the right border)
11971 by {offset} columns, as if being dragged by the mouse. {nr}
11972 can be a window number or |window-ID|. A positive {offset}
11973 moves right and a negative {offset} moves left. Moving a
11974 window's vertical separator will change the width of the
11975 window and the width of other windows adjacent to the vertical
11976 separator. The magnitude of movement may be smaller than
11977 specified (e.g., as a consequence of maintaining
11978 'winminwidth'). Returns TRUE if the window can be found and
11979 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011980 This will fail for the rightmost window and a full-width
11981 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000011982 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000011983
11984 Can also be used as a |method|: >
11985 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011986<
11987 Return type: |Number|
11988
Daniel Steinbergee630312022-01-10 13:36:34 +000011989
11990win_move_statusline({nr}, {offset}) *win_move_statusline()*
11991 Move window {nr}'s status line (i.e., the bottom border) by
11992 {offset} rows, as if being dragged by the mouse. {nr} can be a
11993 window number or |window-ID|. A positive {offset} moves down
11994 and a negative {offset} moves up. Moving a window's status
11995 line will change the height of the window and the height of
11996 other windows adjacent to the status line. The magnitude of
11997 movement may be smaller than specified (e.g., as a consequence
11998 of maintaining 'winminheight'). Returns TRUE if the window can
11999 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012000 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000012001
12002 Can also be used as a |method|: >
12003 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012004<
12005 Return type: |Number|
12006
Daniel Steinbergee630312022-01-10 13:36:34 +000012007
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012008win_screenpos({nr}) *win_screenpos()*
12009 Return the screen position of window {nr} as a list with two
12010 numbers: [row, col]. The first window always has position
12011 [1, 1], unless there is a tabline, then it is [2, 1].
12012 {nr} can be the window number or the |window-ID|. Use zero
12013 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012014 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012015
12016 Can also be used as a |method|: >
12017 GetWinid()->win_screenpos()
12018<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012019 Return type: list<number>
12020
12021
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012022win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012023 Temporarily switch to window {target}, then move window {nr}
12024 to a new split adjacent to {target}.
12025 Unlike commands such as |:split|, no new windows are created
12026 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012027
12028 Both {nr} and {target} can be window numbers or |window-ID|s.
12029 Both must be in the current tab page.
12030
12031 Returns zero for success, non-zero for failure.
12032
12033 {options} is a |Dictionary| with the following optional entries:
12034 "vertical" When TRUE, the split is created vertically,
12035 like with |:vsplit|.
12036 "rightbelow" When TRUE, the split is made below or to the
12037 right (if vertical). When FALSE, it is done
12038 above or to the left (if vertical). When not
12039 present, the values of 'splitbelow' and
12040 'splitright' are used.
12041
12042 Can also be used as a |method|: >
12043 GetWinid()->win_splitmove(target)
12044<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012045 Return type: |Number|
12046
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012047
12048 *winbufnr()*
12049winbufnr({nr}) The result is a Number, which is the number of the buffer
12050 associated with window {nr}. {nr} can be the window number or
12051 the |window-ID|.
12052 When {nr} is zero, the number of the buffer in the current
12053 window is returned.
12054 When window {nr} doesn't exist, -1 is returned.
12055 Example: >
12056 :echo "The file in the current window is " . bufname(winbufnr(0))
12057<
12058 Can also be used as a |method|: >
12059 FindWindow()->winbufnr()->bufname()
12060<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012061 Return type: |Number|
12062
12063
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012064 *wincol()*
12065wincol() The result is a Number, which is the virtual column of the
12066 cursor in the window. This is counting screen cells from the
12067 left side of the window. The leftmost column is one.
12068
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012069 Return type: |Number|
12070
12071
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012072 *windowsversion()*
12073windowsversion()
12074 The result is a String. For MS-Windows it indicates the OS
12075 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12076 Windows XP is "5.1". For non-MS-Windows systems the result is
12077 an empty string.
12078
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012079 Return type: |String|
12080
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012081winheight({nr}) *winheight()*
12082 The result is a Number, which is the height of window {nr}.
12083 {nr} can be the window number or the |window-ID|.
12084 When {nr} is zero, the height of the current window is
12085 returned. When window {nr} doesn't exist, -1 is returned.
12086 An existing window always has a height of zero or more.
12087 This excludes any window toolbar line.
12088 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012089 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012090
12091< Can also be used as a |method|: >
12092 GetWinid()->winheight()
12093<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012094 Return type: |Number|
12095
12096
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012097winlayout([{tabnr}]) *winlayout()*
12098 The result is a nested List containing the layout of windows
12099 in a tabpage.
12100
12101 Without {tabnr} use the current tabpage, otherwise the tabpage
12102 with number {tabnr}. If the tabpage {tabnr} is not found,
12103 returns an empty list.
12104
12105 For a leaf window, it returns:
12106 ['leaf', {winid}]
12107 For horizontally split windows, which form a column, it
12108 returns:
12109 ['col', [{nested list of windows}]]
12110 For vertically split windows, which form a row, it returns:
12111 ['row', [{nested list of windows}]]
12112
12113 Example: >
12114 " Only one window in the tab page
12115 :echo winlayout()
12116 ['leaf', 1000]
12117 " Two horizontally split windows
12118 :echo winlayout()
12119 ['col', [['leaf', 1000], ['leaf', 1001]]]
12120 " The second tab page, with three horizontally split
12121 " windows, with two vertically split windows in the
12122 " middle window
12123 :echo winlayout(2)
12124 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12125 ['leaf', 1001]]], ['leaf', 1000]]]
12126<
12127 Can also be used as a |method|: >
12128 GetTabnr()->winlayout()
12129<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012130 Return type: list<any>
12131
12132
12133winline() *winline()*
12134 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012135 in the window. This is counting screen lines from the top of
12136 the window. The first line is one.
12137 If the cursor was moved the view on the file will be updated
12138 first, this may cause a scroll.
12139
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012140 Return type: |Number|
12141
12142
12143winnr([{arg}]) *winnr()*
12144 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012145 window. The top window has number 1.
12146 Returns zero for a popup window.
12147
12148 The optional argument {arg} supports the following values:
12149 $ the number of the last window (the window
12150 count).
12151 # the number of the last accessed window (where
12152 |CTRL-W_p| goes to). If there is no previous
12153 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012154 returned. May refer to the current window in
12155 some cases (e.g. when evaluating 'statusline'
12156 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012157 {N}j the number of the Nth window below the
12158 current window (where |CTRL-W_j| goes to).
12159 {N}k the number of the Nth window above the current
12160 window (where |CTRL-W_k| goes to).
12161 {N}h the number of the Nth window left of the
12162 current window (where |CTRL-W_h| goes to).
12163 {N}l the number of the Nth window right of the
12164 current window (where |CTRL-W_l| goes to).
12165 The number can be used with |CTRL-W_w| and ":wincmd w"
12166 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012167 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012168 Also see |tabpagewinnr()| and |win_getid()|.
12169 Examples: >
12170 let window_count = winnr('$')
12171 let prev_window = winnr('#')
12172 let wnum = winnr('3k')
12173
12174< Can also be used as a |method|: >
12175 GetWinval()->winnr()
12176<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012177 Return type: |Number|
12178
12179
12180winrestcmd() *winrestcmd()*
12181 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012182 the current window sizes. Only works properly when no windows
12183 are opened or closed and the current window and tab page is
12184 unchanged.
12185 Example: >
12186 :let cmd = winrestcmd()
12187 :call MessWithWindowSizes()
12188 :exe cmd
12189<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012190 Return type: |String|
12191
12192
12193winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012194 Uses the |Dictionary| returned by |winsaveview()| to restore
12195 the view of the current window.
12196 Note: The {dict} does not have to contain all values, that are
12197 returned by |winsaveview()|. If values are missing, those
12198 settings won't be restored. So you can use: >
12199 :call winrestview({'curswant': 4})
12200<
12201 This will only set the curswant value (the column the cursor
12202 wants to move on vertical movements) of the cursor to column 5
12203 (yes, that is 5), while all other settings will remain the
12204 same. This is useful, if you set the cursor position manually.
12205
12206 If you have changed the values the result is unpredictable.
12207 If the window size changed the result won't be the same.
12208
12209 Can also be used as a |method|: >
12210 GetView()->winrestview()
12211<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012212 Return type: |Number|
12213
12214
12215winsaveview() *winsaveview()*
12216 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012217 the view of the current window. Use |winrestview()| to
12218 restore the view.
12219 This is useful if you have a mapping that jumps around in the
12220 buffer and you want to go back to the original view.
12221 This does not save fold information. Use the 'foldenable'
12222 option to temporarily switch off folding, so that folds are
12223 not opened when moving around. This may have side effects.
12224 The return value includes:
12225 lnum cursor line number
12226 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012227 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012228 returns)
12229 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012230 curswant column for vertical movement (Note:
12231 the first column is zero, as opposed
12232 to what |getcurpos()| returns). After
12233 |$| command it will be a very large
12234 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012235 topline first line in the window
12236 topfill filler lines, only in diff mode
12237 leftcol first column displayed; only used when
12238 'wrap' is off
12239 skipcol columns skipped
12240 Note that no option values are saved.
12241
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012242 Return type: dict<number>
12243
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012244
12245winwidth({nr}) *winwidth()*
12246 The result is a Number, which is the width of window {nr}.
12247 {nr} can be the window number or the |window-ID|.
12248 When {nr} is zero, the width of the current window is
12249 returned. When window {nr} doesn't exist, -1 is returned.
12250 An existing window always has a width of zero or more.
12251 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012252 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012253 :if winwidth(0) <= 50
12254 : 50 wincmd |
12255 :endif
12256< For getting the terminal or screen size, see the 'columns'
12257 option.
12258
12259 Can also be used as a |method|: >
12260 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012261<
12262 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012263
12264
12265wordcount() *wordcount()*
12266 The result is a dictionary of byte/chars/word statistics for
12267 the current buffer. This is the same info as provided by
12268 |g_CTRL-G|
12269 The return value includes:
12270 bytes Number of bytes in the buffer
12271 chars Number of chars in the buffer
12272 words Number of words in the buffer
12273 cursor_bytes Number of bytes before cursor position
12274 (not in Visual mode)
12275 cursor_chars Number of chars before cursor position
12276 (not in Visual mode)
12277 cursor_words Number of words before cursor position
12278 (not in Visual mode)
12279 visual_bytes Number of bytes visually selected
12280 (only in Visual mode)
12281 visual_chars Number of chars visually selected
12282 (only in Visual mode)
12283 visual_words Number of words visually selected
12284 (only in Visual mode)
12285
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012286 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012287
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012288
12289writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012290 When {object} is a |List| write it to file {fname}. Each list
12291 item is separated with a NL. Each list item must be a String
12292 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012293 All NL characters are replaced with a NUL character.
12294 Inserting CR characters needs to be done before passing {list}
12295 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012296
12297 When {object} is a |Blob| write the bytes to file {fname}
12298 unmodified, also when binary mode is not specified.
12299
12300 {flags} must be a String. These characters are recognized:
12301
12302 'b' Binary mode is used: There will not be a NL after the
12303 last list item. An empty item at the end does cause the
12304 last line in the file to end in a NL.
12305
12306 'a' Append mode is used, lines are appended to the file: >
12307 :call writefile(["foo"], "event.log", "a")
12308 :call writefile(["bar"], "event.log", "a")
12309<
12310 'D' Delete the file when the current function ends. This
12311 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012312 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012313< Fails when not in a function. Also see |:defer|.
12314
12315 's' fsync() is called after writing the file. This flushes
12316 the file to disk, if possible. This takes more time but
12317 avoids losing the file if the system crashes.
12318
12319 'S' fsync() is not called, even when 'fsync' is set.
12320
12321 When {flags} does not contain "S" or "s" then fsync() is
12322 called if the 'fsync' option is set.
12323
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012324 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012325
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012326 When the write fails -1 is returned, otherwise 0. There is an
12327 error message if the file can't be created or when writing
12328 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012329
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012330 Also see |readfile()|.
12331 To copy a file byte for byte: >
12332 :let fl = readfile("foo", "b")
12333 :call writefile(fl, "foocopy", "b")
12334
12335< Can also be used as a |method|: >
12336 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012337<
12338 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012339
12340
12341xor({expr}, {expr}) *xor()*
12342 Bitwise XOR on the two arguments. The arguments are converted
12343 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012344 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012345 Example: >
12346 :let bits = xor(bits, 0x80)
12347<
12348 Can also be used as a |method|: >
12349 :let bits = bits->xor(0x80)
12350<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012351 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012352
12353==============================================================================
123543. Feature list *feature-list*
12355
12356There are three types of features:
123571. Features that are only supported when they have been enabled when Vim
12358 was compiled |+feature-list|. Example: >
12359 :if has("cindent")
12360< *gui_running*
123612. Features that are only supported when certain conditions have been met.
12362 Example: >
12363 :if has("gui_running")
12364< *has-patch*
123653. Beyond a certain version or at a certain version and including a specific
12366 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12367 later, or it is version 7.4 and patch 248 was included. Example: >
12368 :if has("patch-7.4.248")
12369< Note that it's possible for patch 248 to be omitted even though 249 is
12370 included. Only happens when cherry-picking patches.
12371 Note that this form only works for patch 7.4.237 and later, before that
12372 you need to check for the patch and the v:version. Example (checking
12373 version 6.2.148 or later): >
12374 :if v:version > 602 || (v:version == 602 && has("patch148"))
12375
12376Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12377use: `if exists('+shellslash')`
12378
12379
12380acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012381all_builtin_terms Compiled with all builtin terminals enabled. (always
12382 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012383amiga Amiga version of Vim.
12384arabic Compiled with Arabic support |Arabic|.
12385arp Compiled with ARP support (Amiga).
12386autocmd Compiled with autocommand support. (always true)
12387autochdir Compiled with support for 'autochdir'
12388autoservername Automatically enable |clientserver|
12389balloon_eval Compiled with |balloon-eval| support.
12390balloon_multiline GUI supports multiline balloons.
12391beos BeOS version of Vim.
12392browse Compiled with |:browse| support, and browse() will
12393 work.
12394browsefilter Compiled with support for |browsefilter|.
12395bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012396builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012397byte_offset Compiled with support for 'o' in 'statusline'
12398channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012399cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012400clientserver Compiled with remote invocation support |clientserver|.
12401clipboard Compiled with 'clipboard' support.
12402clipboard_working Compiled with 'clipboard' support and it can be used.
12403cmdline_compl Compiled with |cmdline-completion| support.
12404cmdline_hist Compiled with |cmdline-history| support.
12405cmdline_info Compiled with 'showcmd' and 'ruler' support.
12406comments Compiled with |'comments'| support.
12407compatible Compiled to be very Vi compatible.
12408conpty Platform where |ConPTY| can be used.
12409cryptv Compiled with encryption support |encryption|.
12410cscope Compiled with |cscope| support.
12411cursorbind Compiled with |'cursorbind'| (always true)
12412debug Compiled with "DEBUG" defined.
12413dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012414dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012415dialog_gui Compiled with GUI dialog support.
12416diff Compiled with |vimdiff| and 'diff' support.
12417digraphs Compiled with support for digraphs.
12418directx Compiled with support for DirectX and 'renderoptions'.
12419dnd Compiled with support for the "~ register |quote_~|.
12420drop_file Compiled with |drop_file| support.
12421ebcdic Compiled on a machine with ebcdic character set.
12422emacs_tags Compiled with support for Emacs tags.
12423eval Compiled with expression evaluation support. Always
12424 true, of course!
12425ex_extra |+ex_extra| (always true)
12426extra_search Compiled with support for |'incsearch'| and
12427 |'hlsearch'|
12428farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012429file_in_path Compiled with support for |gf| and |<cfile>| (always
12430 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012431filterpipe When 'shelltemp' is off pipes are used for shell
12432 read/write/filter commands
12433find_in_path Compiled with support for include file searches
12434 |+find_in_path|.
12435float Compiled with support for |Float|.
12436fname_case Case in file names matters (for Amiga and MS-Windows
12437 this is not present).
12438folding Compiled with |folding| support.
12439footer Compiled with GUI footer support. |gui-footer|
12440fork Compiled to use fork()/exec() instead of system().
12441gettext Compiled with message translation |multi-lang|
12442gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012443gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012444gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12445gui_gtk Compiled with GTK+ GUI (any version).
12446gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12447gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12448gui_haiku Compiled with Haiku GUI.
12449gui_mac Compiled with Macintosh GUI.
12450gui_motif Compiled with Motif GUI.
12451gui_photon Compiled with Photon GUI.
12452gui_running Vim is running in the GUI, or it will start soon.
12453gui_win32 Compiled with MS-Windows Win32 GUI.
12454gui_win32s idem, and Win32s system being used (Windows 3.1)
12455haiku Haiku version of Vim.
12456hangul_input Compiled with Hangul input support. |hangul|
12457hpux HP-UX version of Vim.
12458iconv Can use iconv() for conversion.
12459insert_expand Compiled with support for CTRL-X expansion commands in
12460 Insert mode. (always true)
12461job Compiled with support for |channel| and |job|
12462ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012463jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012464keymap Compiled with 'keymap' support.
12465lambda Compiled with |lambda| support.
12466langmap Compiled with 'langmap' support.
12467libcall Compiled with |libcall()| support.
12468linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12469 'breakindent' support.
12470linux Linux version of Vim.
12471lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012472 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012473listcmds Compiled with commands for the buffer list |:files|
12474 and the argument list |arglist|.
12475localmap Compiled with local mappings and abbr. |:map-local|
12476lua Compiled with Lua interface |Lua|.
12477mac Any Macintosh version of Vim cf. osx
12478macunix Synonym for osxdarwin
12479menu Compiled with support for |:menu|.
12480mksession Compiled with support for |:mksession|.
12481modify_fname Compiled with file name modifiers. |filename-modifiers|
12482 (always true)
12483mouse Compiled with support for mouse.
12484mouse_dec Compiled with support for Dec terminal mouse.
12485mouse_gpm Compiled with support for gpm (Linux console mouse)
12486mouse_gpm_enabled GPM mouse is working
12487mouse_netterm Compiled with support for netterm mouse.
12488mouse_pterm Compiled with support for qnx pterm mouse.
12489mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12490mouse_sgr Compiled with support for sgr mouse.
12491mouse_urxvt Compiled with support for urxvt mouse.
12492mouse_xterm Compiled with support for xterm mouse.
12493mouseshape Compiled with support for 'mouseshape'.
12494multi_byte Compiled with support for 'encoding' (always true)
12495multi_byte_encoding 'encoding' is set to a multibyte encoding.
12496multi_byte_ime Compiled with support for IME input method.
12497multi_lang Compiled with support for multiple languages.
12498mzscheme Compiled with MzScheme interface |mzscheme|.
12499nanotime Compiled with sub-second time stamp checks.
12500netbeans_enabled Compiled with support for |netbeans| and connected.
12501netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012502num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012503ole Compiled with OLE automation support for Win32.
12504osx Compiled for macOS cf. mac
12505osxdarwin Compiled for macOS, with |mac-darwin-feature|
12506packages Compiled with |packages| support.
12507path_extra Compiled with up/downwards search in 'path' and 'tags'
12508perl Compiled with Perl interface.
12509persistent_undo Compiled with support for persistent undo history.
12510postscript Compiled with PostScript file printing.
12511printer Compiled with |:hardcopy| support.
12512profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012513prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012514python Python 2.x interface available. |has-python|
12515python_compiled Compiled with Python 2.x interface. |has-python|
12516python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12517python3 Python 3.x interface available. |has-python|
12518python3_compiled Compiled with Python 3.x interface. |has-python|
12519python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012520python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012521pythonx Python 2.x and/or 3.x interface available. |python_x|
12522qnx QNX version of Vim.
12523quickfix Compiled with |quickfix| support.
12524reltime Compiled with |reltime()| support.
12525rightleft Compiled with 'rightleft' support.
12526ruby Compiled with Ruby interface |ruby|.
12527scrollbind Compiled with 'scrollbind' support. (always true)
12528showcmd Compiled with 'showcmd' support.
12529signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012530smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012531sodium Compiled with libsodium for better crypt support
12532sound Compiled with sound support, e.g. `sound_playevent()`
12533spell Compiled with spell checking support |spell|.
12534startuptime Compiled with |--startuptime| support.
12535statusline Compiled with support for 'statusline', 'rulerformat'
12536 and special formats of 'titlestring' and 'iconstring'.
12537sun SunOS version of Vim.
12538sun_workshop Support for Sun |workshop| has been removed.
12539syntax Compiled with syntax highlighting support |syntax|.
12540syntax_items There are active syntax highlighting items for the
12541 current buffer.
12542system Compiled to use system() instead of fork()/exec().
12543tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012544 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012545tag_old_static Support for old static tags was removed, see
12546 |tag-old-static|.
12547tcl Compiled with Tcl interface.
12548termguicolors Compiled with true color in terminal support.
12549terminal Compiled with |terminal| support.
12550terminfo Compiled with terminfo instead of termcap.
12551termresponse Compiled with support for |t_RV| and |v:termresponse|.
12552textobjects Compiled with support for |text-objects|.
12553textprop Compiled with support for |text-properties|.
12554tgetent Compiled with tgetent support, able to use a termcap
12555 or terminfo file.
12556timers Compiled with |timer_start()| support.
12557title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012558 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012559toolbar Compiled with support for |gui-toolbar|.
12560ttyin input is a terminal (tty)
12561ttyout output is a terminal (tty)
12562unix Unix version of Vim. *+unix*
12563unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
12564user_commands User-defined commands. (always true)
12565vartabs Compiled with variable tabstop support |'vartabstop'|.
12566vcon Win32: Virtual console support is working, can use
12567 'termguicolors'. Also see |+vtp|.
12568vertsplit Compiled with vertically split windows |:vsplit|.
12569 (always true)
12570vim_starting True while initial source'ing takes place. |startup|
12571 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000012572vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012573viminfo Compiled with viminfo support.
12574vimscript-1 Compiled Vim script version 1 support
12575vimscript-2 Compiled Vim script version 2 support
12576vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010012577vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012578virtualedit Compiled with 'virtualedit' option. (always true)
12579visual Compiled with Visual mode. (always true)
12580visualextra Compiled with extra Visual mode commands. (always
12581 true) |blockwise-operators|.
12582vms VMS version of Vim.
12583vreplace Compiled with |gR| and |gr| commands. (always true)
12584vtp Compiled for vcon support |+vtp| (check vcon to find
12585 out if it works in the current console).
12586wildignore Compiled with 'wildignore' option.
12587wildmenu Compiled with 'wildmenu' option.
12588win16 old version for MS-Windows 3.1 (always false)
12589win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
12590 64 bits)
12591win32unix Win32 version of Vim, using Unix files (Cygwin)
12592win64 Win64 version of Vim (MS-Windows 64 bit).
12593win95 Win32 version for MS-Windows 95/98/ME (always false)
12594winaltkeys Compiled with 'winaltkeys' option.
12595windows Compiled with support for more than one window.
12596 (always true)
12597writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020012598xattr Compiled with extended attributes support |xattr|
12599 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012600xfontset Compiled with X fontset support |xfontset|.
12601xim Compiled with X input method support |xim|.
12602xpm Compiled with pixmap support.
12603xpm_w32 Compiled with pixmap support for Win32. (Only for
12604 backward compatibility. Use "xpm" instead.)
12605xsmp Compiled with X session management support.
12606xsmp_interact Compiled with interactive X session management support.
12607xterm_clipboard Compiled with support for xterm clipboard.
12608xterm_save Compiled with support for saving and restoring the
12609 xterm screen.
12610x11 Compiled with X11 support.
12611
12612
12613==============================================================================
126144. Matching a pattern in a String *string-match*
12615
12616This is common between several functions. A regexp pattern as explained at
12617|pattern| is normally used to find a match in the buffer lines. When a
12618pattern is used to find a match in a String, almost everything works in the
12619same way. The difference is that a String is handled like it is one line.
12620When it contains a "\n" character, this is not seen as a line break for the
12621pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
12622>
12623 :let a = "aaaa\nxxxx"
12624 :echo matchstr(a, "..\n..")
12625 aa
12626 xx
12627 :echo matchstr(a, "a.x")
12628 a
12629 x
12630
12631Don't forget that "^" will only match at the first character of the String and
12632"$" at the last character of the string. They don't match after or before a
12633"\n".
12634
12635 vim:tw=78:ts=8:noet:ft=help:norl: