blob: ff7078ea881ac2c38b048f274f9b1c44a7ec1971 [file] [log] [blame]
Christian Brabandtc509c002024-06-14 20:22:05 +02001*builtin.txt* For Vim version 9.1. Last change: 2024 Jun 14
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7Builtin functions *builtin-functions*
8
Bram Moolenaarf269eab2022-10-03 18:04:35 +01009Note: Expression evaluation can be disabled at compile time, the builtin
10functions are not available then. See |+eval| and |no-eval-feature|.
11
12For functions grouped by what they are used for see |function-list|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000013
141. Overview |builtin-function-list|
152. Details |builtin-function-details|
163. Feature list |feature-list|
174. Matching a pattern in a String |string-match|
18
19==============================================================================
201. Overview *builtin-function-list*
21
22Use CTRL-] on the function name to jump to the full explanation.
23
24USAGE RESULT DESCRIPTION ~
25
26abs({expr}) Float or Number absolute value of {expr}
27acos({expr}) Float arc cosine of {expr}
28add({object}, {item}) List/Blob append {item} to {object}
29and({expr}, {expr}) Number bitwise AND
30append({lnum}, {text}) Number append {text} below line {lnum}
31appendbufline({expr}, {lnum}, {text})
32 Number append {text} below line {lnum}
33 in buffer {expr}
34argc([{winid}]) Number number of files in the argument list
35argidx() Number current index in the argument list
36arglistid([{winnr} [, {tabnr}]]) Number argument list id
37argv({nr} [, {winid}]) String {nr} entry of the argument list
38argv([-1, {winid}]) List the argument list
39asin({expr}) Float arc sine of {expr}
40assert_beeps({cmd}) Number assert {cmd} causes a beep
41assert_equal({exp}, {act} [, {msg}])
42 Number assert {exp} is equal to {act}
43assert_equalfile({fname-one}, {fname-two} [, {msg}])
44 Number assert file contents are equal
45assert_exception({error} [, {msg}])
46 Number assert {error} is in v:exception
47assert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]])
48 Number assert {cmd} fails
49assert_false({actual} [, {msg}])
50 Number assert {actual} is false
51assert_inrange({lower}, {upper}, {actual} [, {msg}])
52 Number assert {actual} is inside the range
53assert_match({pat}, {text} [, {msg}])
54 Number assert {pat} matches {text}
55assert_nobeep({cmd}) Number assert {cmd} does not cause a beep
56assert_notequal({exp}, {act} [, {msg}])
57 Number assert {exp} is not equal {act}
58assert_notmatch({pat}, {text} [, {msg}])
59 Number assert {pat} not matches {text}
60assert_report({msg}) Number report a test failure
61assert_true({actual} [, {msg}]) Number assert {actual} is true
62atan({expr}) Float arc tangent of {expr}
63atan2({expr1}, {expr2}) Float arc tangent of {expr1} / {expr2}
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +010064autocmd_add({acmds}) Bool add a list of autocmds and groups
65autocmd_delete({acmds}) Bool delete a list of autocmds and groups
66autocmd_get([{opts}]) List return a list of autocmds
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000067balloon_gettext() String current text in the balloon
68balloon_show({expr}) none show {expr} inside the balloon
69balloon_split({msg}) List split {msg} as used for a balloon
70blob2list({blob}) List convert {blob} into a list of numbers
71browse({save}, {title}, {initdir}, {default})
72 String put up a file requester
73browsedir({title}, {initdir}) String put up a directory requester
74bufadd({name}) Number add a buffer to the buffer list
75bufexists({buf}) Number |TRUE| if buffer {buf} exists
76buflisted({buf}) Number |TRUE| if buffer {buf} is listed
77bufload({buf}) Number load buffer {buf} if not loaded yet
78bufloaded({buf}) Number |TRUE| if buffer {buf} is loaded
79bufname([{buf}]) String Name of the buffer {buf}
80bufnr([{buf} [, {create}]]) Number Number of the buffer {buf}
81bufwinid({buf}) Number window ID of buffer {buf}
82bufwinnr({buf}) Number window number of buffer {buf}
83byte2line({byte}) Number line number at byte count {byte}
Christian Brabandt67672ef2023-04-24 21:09:54 +010084byteidx({expr}, {nr} [, {utf16}])
85 Number byte index of {nr}'th char in {expr}
86byteidxcomp({expr}, {nr} [, {utf16}])
87 Number byte index of {nr}'th char in {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000088call({func}, {arglist} [, {dict}])
89 any call {func} with arguments {arglist}
90ceil({expr}) Float round {expr} up
91ch_canread({handle}) Number check if there is something to read
92ch_close({handle}) none close {handle}
93ch_close_in({handle}) none close in part of {handle}
94ch_evalexpr({handle}, {expr} [, {options}])
95 any evaluate {expr} on JSON {handle}
96ch_evalraw({handle}, {string} [, {options}])
97 any evaluate {string} on raw {handle}
98ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
99ch_getjob({channel}) Job get the Job of {channel}
100ch_info({handle}) String info about channel {handle}
101ch_log({msg} [, {handle}]) none write {msg} in the channel log file
102ch_logfile({fname} [, {mode}]) none start logging channel activity
103ch_open({address} [, {options}])
104 Channel open a channel to {address}
105ch_read({handle} [, {options}]) String read from {handle}
106ch_readblob({handle} [, {options}])
107 Blob read Blob from {handle}
108ch_readraw({handle} [, {options}])
109 String read raw from {handle}
110ch_sendexpr({handle}, {expr} [, {options}])
111 any send {expr} over JSON {handle}
112ch_sendraw({handle}, {expr} [, {options}])
113 any send {expr} over raw {handle}
114ch_setoptions({handle}, {options})
115 none set options for {handle}
116ch_status({handle} [, {options}])
117 String status of channel {handle}
118changenr() Number current change number
119char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr}
120charclass({string}) Number character class of {string}
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000121charcol({expr} [, {winid}]) Number column number of cursor or mark
Christian Brabandt67672ef2023-04-24 21:09:54 +0100122charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000123 Number char index of byte {idx} in {string}
124chdir({dir}) String change current working directory
125cindent({lnum}) Number C indent for line {lnum}
126clearmatches([{win}]) none clear all matches
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000127col({expr} [, {winid}]) Number column byte index of cursor or mark
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000128complete({startcol}, {matches}) none set Insert mode completion
129complete_add({expr}) Number add completion match
130complete_check() Number check for key typed during completion
131complete_info([{what}]) Dict get current completion information
132confirm({msg} [, {choices} [, {default} [, {type}]]])
133 Number number of choice picked by user
134copy({expr}) any make a shallow copy of {expr}
135cos({expr}) Float cosine of {expr}
136cosh({expr}) Float hyperbolic cosine of {expr}
137count({comp}, {expr} [, {ic} [, {start}]])
138 Number count how many {expr} are in {comp}
139cscope_connection([{num}, {dbpath} [, {prepend}]])
140 Number checks existence of cscope connection
141cursor({lnum}, {col} [, {off}])
142 Number move cursor to {lnum}, {col}, {off}
143cursor({list}) Number move cursor to position in {list}
144debugbreak({pid}) Number interrupt process being debugged
145deepcopy({expr} [, {noref}]) any make a full copy of {expr}
146delete({fname} [, {flags}]) Number delete the file or directory {fname}
147deletebufline({buf}, {first} [, {last}])
148 Number delete lines from buffer {buf}
149did_filetype() Number |TRUE| if FileType autocmd event used
Yegappan Lakshmananfa378352024-02-01 22:05:27 +0100150diff({fromlist}, {tolist} [, {options}])
151 List diff two Lists of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000152diff_filler({lnum}) Number diff filler lines about {lnum}
153diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
154digraph_get({chars}) String get the |digraph| of {chars}
155digraph_getlist([{listall}]) List get all |digraph|s
156digraph_set({chars}, {digraph}) Boolean register |digraph|
157digraph_setlist({digraphlist}) Boolean register multiple |digraph|s
158echoraw({expr}) none output {expr} as-is
159empty({expr}) Number |TRUE| if {expr} is empty
160environ() Dict return environment variables
Sean Dewarb0efa492023-07-08 10:35:19 +0100161err_teapot([{expr}]) none give E418, or E503 if {expr} is |TRUE|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000162escape({string}, {chars}) String escape {chars} in {string} with '\'
163eval({string}) any evaluate {string} into its value
164eventhandler() Number |TRUE| if inside an event handler
165executable({expr}) Number 1 if executable {expr} exists
166execute({command}) String execute {command} and get the output
167exepath({expr}) String full path of the command {expr}
168exists({expr}) Number |TRUE| if {expr} exists
169exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
170exp({expr}) Float exponential of {expr}
171expand({expr} [, {nosuf} [, {list}]])
172 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100173expandcmd({string} [, {options}])
174 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000175extend({expr1}, {expr2} [, {expr3}])
176 List/Dict insert items of {expr2} into {expr1}
177extendnew({expr1}, {expr2} [, {expr3}])
178 List/Dict like |extend()| but creates a new
179 List or Dictionary
180feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
Shougo Matsushita60c87432024-06-03 22:59:27 +0200181filecopy({from}, {to}) Number |TRUE| if copying file {from} to {to}
182 worked
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000183filereadable({file}) Number |TRUE| if {file} is a readable file
184filewritable({file}) Number |TRUE| if {file} is a writable file
185filter({expr1}, {expr2}) List/Dict/Blob/String
186 remove items from {expr1} where
187 {expr2} is 0
188finddir({name} [, {path} [, {count}]])
189 String find directory {name} in {path}
190findfile({name} [, {path} [, {count}]])
191 String find file {name} in {path}
192flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
193flattennew({list} [, {maxdepth}])
194 List flatten a copy of {list}
195float2nr({expr}) Number convert Float {expr} to a Number
196floor({expr}) Float round {expr} down
197fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
198fnameescape({fname}) String escape special characters in {fname}
199fnamemodify({fname}, {mods}) String modify file name
200foldclosed({lnum}) Number first line of fold at {lnum} if closed
201foldclosedend({lnum}) Number last line of fold at {lnum} if closed
202foldlevel({lnum}) Number fold level at {lnum}
203foldtext() String line displayed for closed fold
204foldtextresult({lnum}) String text for closed fold at {lnum}
Ernie Raele79e2072024-01-13 11:47:33 +0100205foreach({expr1}, {expr2}) List/Dict/Blob/String
206 for each item in {expr1} call {expr2}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000207foreground() Number bring the Vim window to the foreground
Bram Moolenaaraa534142022-09-15 21:46:02 +0100208fullcommand({name} [, {vim9}]) String get full command from {name}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000209funcref({name} [, {arglist}] [, {dict}])
210 Funcref reference to function {name}
211function({name} [, {arglist}] [, {dict}])
212 Funcref named reference to function {name}
213garbagecollect([{atexit}]) none free memory, breaking cyclic references
214get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
215get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
216get({func}, {what}) any get property of funcref/partial {func}
217getbufinfo([{buf}]) List information about buffers
218getbufline({buf}, {lnum} [, {end}])
219 List lines {lnum} to {end} of buffer {buf}
Bram Moolenaarce30ccc2022-11-21 19:57:04 +0000220getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000221getbufvar({buf}, {varname} [, {def}])
222 any variable {varname} in buffer {buf}
Kota Kato66bb9ae2023-01-17 18:31:56 +0000223getcellwidths() List get character cell width overrides
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000224getchangelist([{buf}]) List list of change list items
Doug Kearns9cd9e752024-04-07 17:42:17 +0200225getchar([{expr}]) Number or String
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000226 get one character from the user
227getcharmod() Number modifiers for the last typed character
228getcharpos({expr}) List position of cursor, mark, etc.
229getcharsearch() Dict last character search
Doug Kearns9cd9e752024-04-07 17:42:17 +0200230getcharstr([{expr}]) String get one character from the user
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100231getcmdcompltype() String return the type of the current
232 command-line completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000233getcmdline() String return the current command-line
234getcmdpos() Number return cursor position in command-line
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100235getcmdscreenpos() Number return cursor screen position in
236 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000237getcmdtype() String return current command-line type
238getcmdwintype() String return current command-line window type
239getcompletion({pat}, {type} [, {filtered}])
240 List list of cmdline completion matches
241getcurpos([{winnr}]) List position of the cursor
242getcursorcharpos([{winnr}]) List character position of the cursor
243getcwd([{winnr} [, {tabnr}]]) String get the current working directory
244getenv({name}) String return environment variable
245getfontname([{name}]) String name of font being used
246getfperm({fname}) String file permissions of file {fname}
247getfsize({fname}) Number size in bytes of file {fname}
248getftime({fname}) Number last modification time of file
249getftype({fname}) String description of type of file {fname}
250getimstatus() Number |TRUE| if the IME status is active
251getjumplist([{winnr} [, {tabnr}]])
252 List list of jump list items
253getline({lnum}) String line {lnum} of current buffer
254getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
255getloclist({nr}) List list of location list items
256getloclist({nr}, {what}) Dict get specific location list properties
257getmarklist([{buf}]) List list of global/local marks
258getmatches([{win}]) List list of current matches
259getmousepos() Dict last known mouse position
Bram Moolenaar24dc19c2022-11-14 19:49:15 +0000260getmouseshape() String current mouse shape name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000261getpid() Number process ID of Vim
262getpos({expr}) List position of cursor, mark, etc.
263getqflist() List list of quickfix items
264getqflist({what}) Dict get specific quickfix list properties
265getreg([{regname} [, 1 [, {list}]]])
266 String or List contents of a register
267getreginfo([{regname}]) Dict information about a register
Shougo Matsushita19b71882024-02-28 22:48:12 +0100268getregion({pos1}, {pos2} [, {opts}])
Shougo Matsushita3f905ab2024-02-21 00:02:45 +0100269 List get the text from {pos1} to {pos2}
Shougo Matsushitab4757e62024-05-07 20:49:24 +0200270getregionpos({pos1}, {pos2} [, {opts}])
271 List get a list of positions for a region
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000272getregtype([{regname}]) String type of a register
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +0100273getscriptinfo([{opts}]) List list of sourced scripts
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000274gettabinfo([{expr}]) List list of tab pages
275gettabvar({nr}, {varname} [, {def}])
276 any variable {varname} in tab {nr} or {def}
277gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
278 any {name} in {winnr} in tab page {tabnr}
279gettagstack([{nr}]) Dict get the tag stack of window {nr}
280gettext({text}) String lookup translation of {text}
281getwininfo([{winid}]) List list of info about each window
Bram Moolenaar938ae282023-02-20 20:44:55 +0000282getwinpos([{timeout}]) List X and Y coord in pixels of Vim window
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000283getwinposx() Number X coord in pixels of the Vim window
284getwinposy() Number Y coord in pixels of the Vim window
285getwinvar({nr}, {varname} [, {def}])
286 any variable {varname} in window {nr}
287glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
288 any expand file wildcards in {expr}
289glob2regpat({expr}) String convert a glob pat into a search pat
290globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
291 String do glob({expr}) for all dirs in {path}
292has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
293has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
294haslocaldir([{winnr} [, {tabnr}]])
295 Number |TRUE| if the window executed |:lcd|
296 or |:tcd|
297hasmapto({what} [, {mode} [, {abbr}]])
298 Number |TRUE| if mapping to {what} exists
299histadd({history}, {item}) Number add an item to a history
300histdel({history} [, {item}]) Number remove an item from a history
301histget({history} [, {index}]) String get the item {index} from a history
302histnr({history}) Number highest index of a history
303hlID({name}) Number syntax ID of highlight group {name}
304hlexists({name}) Number |TRUE| if highlight group {name} exists
305hlget([{name} [, {resolve}]]) List get highlight group attributes
306hlset({list}) Number set highlight group attributes
307hostname() String name of the machine Vim is running on
308iconv({expr}, {from}, {to}) String convert encoding of {expr}
309indent({lnum}) Number indent of line {lnum}
310index({object}, {expr} [, {start} [, {ic}]])
311 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100312indexof({object}, {expr} [, {opts}]])
313 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000314input({prompt} [, {text} [, {completion}]])
315 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100316inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000317 String like input() but in a GUI dialog
318inputlist({textlist}) Number let the user pick from a choice list
319inputrestore() Number restore typeahead
320inputsave() Number save and clear typeahead
321inputsecret({prompt} [, {text}]) String like input() but hiding the text
322insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
LemonBoyafe04662023-08-23 21:08:11 +0200323instanceof({object}, {class}) Number |TRUE| if {object} is an instance of {class}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000324interrupt() none interrupt script execution
325invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100326isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000327isdirectory({directory}) Number |TRUE| if {directory} is a directory
328isinf({expr}) Number determine if {expr} is infinity value
329 (positive or negative)
330islocked({expr}) Number |TRUE| if {expr} is locked
331isnan({expr}) Number |TRUE| if {expr} is NaN
332items({dict}) List key-value pairs in {dict}
333job_getchannel({job}) Channel get the channel handle for {job}
334job_info([{job}]) Dict get information about {job}
335job_setoptions({job}, {options}) none set options for {job}
336job_start({command} [, {options}])
337 Job start a job
338job_status({job}) String get the status of {job}
339job_stop({job} [, {how}]) Number stop {job}
340join({list} [, {sep}]) String join {list} items into one String
341js_decode({string}) any decode JS style JSON
342js_encode({expr}) String encode JS style JSON
343json_decode({string}) any decode JSON
344json_encode({expr}) String encode JSON
345keys({dict}) List keys in {dict}
zeertzjqcdc83932022-09-12 13:38:41 +0100346keytrans({string}) String translate internal keycodes to a form
347 that can be used by |:map|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000348len({expr}) Number the length of {expr}
349libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
350libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
351line({expr} [, {winid}]) Number line nr of cursor, last line or mark
352line2byte({lnum}) Number byte count of line {lnum}
353lispindent({lnum}) Number Lisp indent for line {lnum}
354list2blob({list}) Blob turn {list} of numbers into a Blob
355list2str({list} [, {utf8}]) String turn {list} of numbers into a String
356listener_add({callback} [, {buf}])
357 Number add a callback to listen to changes
358listener_flush([{buf}]) none invoke listener callbacks
359listener_remove({id}) none remove a listener callback
360localtime() Number current time
361log({expr}) Float natural logarithm (base e) of {expr}
362log10({expr}) Float logarithm of Float {expr} to base 10
363luaeval({expr} [, {expr}]) any evaluate |Lua| expression
364map({expr1}, {expr2}) List/Dict/Blob/String
365 change each item in {expr1} to {expr2}
366maparg({name} [, {mode} [, {abbr} [, {dict}]]])
367 String or Dict
368 rhs of mapping {name} in mode {mode}
369mapcheck({name} [, {mode} [, {abbr}]])
370 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100371maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000372mapnew({expr1}, {expr2}) List/Dict/Blob/String
373 like |map()| but creates a new List or
374 Dictionary
375mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
376match({expr}, {pat} [, {start} [, {count}]])
377 Number position where {pat} matches in {expr}
378matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
379 Number highlight {pattern} with {group}
380matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
381 Number highlight positions with {group}
382matcharg({nr}) List arguments of |:match|
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100383matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict})
384 List all the {pat} matches in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000385matchdelete({id} [, {win}]) Number delete match identified by {id}
386matchend({expr}, {pat} [, {start} [, {count}]])
387 Number position where {pat} ends in {expr}
388matchfuzzy({list}, {str} [, {dict}])
389 List fuzzy match {str} in {list}
390matchfuzzypos({list}, {str} [, {dict}])
391 List fuzzy match {str} in {list}
392matchlist({expr}, {pat} [, {start} [, {count}]])
393 List match and submatches of {pat} in {expr}
394matchstr({expr}, {pat} [, {start} [, {count}]])
395 String {count}'th match of {pat} in {expr}
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100396matchstrlist({list}, {pat} [, {dict})
397 List all the {pat} matches in {list}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000398matchstrpos({expr}, {pat} [, {start} [, {count}]])
399 List {count}'th match of {pat} in {expr}
400max({expr}) Number maximum value of items in {expr}
401menu_info({name} [, {mode}]) Dict get menu item information
402min({expr}) Number minimum value of items in {expr}
Bram Moolenaar938ae282023-02-20 20:44:55 +0000403mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000404 Number create directory {name}
Doug Kearns9cd9e752024-04-07 17:42:17 +0200405mode([{expr}]) String current editing mode
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000406mzeval({expr}) any evaluate |MzScheme| expression
407nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
408nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
409or({expr}, {expr}) Number bitwise OR
410pathshorten({expr} [, {len}]) String shorten directory names in a path
411perleval({expr}) any evaluate |Perl| expression
412popup_atcursor({what}, {options}) Number create popup window near the cursor
413popup_beval({what}, {options}) Number create popup window for 'ballooneval'
414popup_clear() none close all popup windows
415popup_close({id} [, {result}]) none close popup window {id}
416popup_create({what}, {options}) Number create a popup window
417popup_dialog({what}, {options}) Number create a popup window used as a dialog
418popup_filter_menu({id}, {key}) Number filter for a menu popup window
419popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100420popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000421popup_findinfo() Number get window ID of info popup window
422popup_findpreview() Number get window ID of preview popup window
423popup_getoptions({id}) Dict get options of popup window {id}
424popup_getpos({id}) Dict get position of popup window {id}
425popup_hide({id}) none hide popup menu {id}
426popup_list() List get a list of window IDs of all popups
427popup_locate({row}, {col}) Number get window ID of popup at position
428popup_menu({what}, {options}) Number create a popup window used as a menu
429popup_move({id}, {options}) none set position of popup window {id}
430popup_notification({what}, {options})
431 Number create a notification popup window
432popup_setoptions({id}, {options})
433 none set options for popup window {id}
434popup_settext({id}, {text}) none set the text of popup window {id}
435popup_show({id}) none unhide popup window {id}
436pow({x}, {y}) Float {x} to the power of {y}
437prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
438printf({fmt}, {expr1}...) String format text
439prompt_getprompt({buf}) String get prompt text
440prompt_setcallback({buf}, {expr}) none set prompt callback function
441prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
442prompt_setprompt({buf}, {text}) none set prompt text
443prop_add({lnum}, {col}, {props}) none add one text property
444prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
445 none add multiple text properties
446prop_clear({lnum} [, {lnum-end} [, {props}]])
447 none remove all text properties
448prop_find({props} [, {direction}])
449 Dict search for a text property
450prop_list({lnum} [, {props}]) List text properties in {lnum}
451prop_remove({props} [, {lnum} [, {lnum-end}]])
452 Number remove a text property
453prop_type_add({name}, {props}) none define a new property type
454prop_type_change({name}, {props})
455 none change an existing property type
456prop_type_delete({name} [, {props}])
457 none delete a property type
458prop_type_get({name} [, {props}])
459 Dict get property type values
460prop_type_list([{props}]) List get list of property types
461pum_getpos() Dict position and size of pum if visible
462pumvisible() Number whether popup menu is visible
463py3eval({expr}) any evaluate |python3| expression
464pyeval({expr}) any evaluate |Python| expression
465pyxeval({expr}) any evaluate |python_x| expression
466rand([{expr}]) Number get pseudo-random number
467range({expr} [, {max} [, {stride}]])
468 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100469readblob({fname} [, {offset} [, {size}]])
470 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000471readdir({dir} [, {expr} [, {dict}]])
472 List file names in {dir} selected by {expr}
473readdirex({dir} [, {expr} [, {dict}]])
474 List file info in {dir} selected by {expr}
475readfile({fname} [, {type} [, {max}]])
476 List get list of lines from file {fname}
477reduce({object}, {func} [, {initial}])
478 any reduce {object} using {func}
479reg_executing() String get the executing register name
480reg_recording() String get the recording register name
481reltime([{start} [, {end}]]) List get time value
482reltimefloat({time}) Float turn the time value into a Float
483reltimestr({time}) String turn time value into a String
484remote_expr({server}, {string} [, {idvar} [, {timeout}]])
485 String send expression
486remote_foreground({server}) Number bring Vim server to the foreground
487remote_peek({serverid} [, {retvar}])
488 Number check for reply string
489remote_read({serverid} [, {timeout}])
490 String read reply string
491remote_send({server}, {string} [, {idvar}])
492 String send key sequence
493remote_startserver({name}) none become server {name}
494remove({list}, {idx} [, {end}]) any/List
495 remove items {idx}-{end} from {list}
496remove({blob}, {idx} [, {end}]) Number/Blob
497 remove bytes {idx}-{end} from {blob}
498remove({dict}, {key}) any remove entry {key} from {dict}
499rename({from}, {to}) Number rename (move) file from {from} to {to}
Bakudankun375141e2022-09-09 18:46:47 +0100500repeat({expr}, {count}) List/Blob/String
501 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000502resolve({filename}) String get filename a shortcut points to
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +0100503reverse({obj}) List/Blob/String
504 reverse {obj}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000505round({expr}) Float round off {expr}
506rubyeval({expr}) any evaluate |Ruby| expression
507screenattr({row}, {col}) Number attribute at screen position
508screenchar({row}, {col}) Number character at screen position
509screenchars({row}, {col}) List List of characters at screen position
510screencol() Number current cursor column
511screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
512screenrow() Number current cursor row
513screenstring({row}, {col}) String characters at screen position
514search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
515 Number search for {pattern}
516searchcount([{options}]) Dict get or update search stats
517searchdecl({name} [, {global} [, {thisblock}]])
518 Number search for variable declaration
519searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
520 Number search for other end of start/end pair
521searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
522 List search for other end of start/end pair
523searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
524 List search for {pattern}
525server2client({clientid}, {string})
526 Number send reply string
527serverlist() String get a list of available servers
528setbufline({expr}, {lnum}, {text})
529 Number set line {lnum} to {text} in buffer
530 {expr}
531setbufvar({buf}, {varname}, {val})
532 none set {varname} in buffer {buf} to {val}
533setcellwidths({list}) none set character cell width overrides
534setcharpos({expr}, {list}) Number set the {expr} position to {list}
535setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100536setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000537setcmdpos({pos}) Number set cursor position in command-line
538setcursorcharpos({list}) Number move cursor to position in {list}
539setenv({name}, {val}) none set environment variable
540setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
541setline({lnum}, {line}) Number set line {lnum} to {line}
542setloclist({nr}, {list} [, {action}])
543 Number modify location list using {list}
544setloclist({nr}, {list}, {action}, {what})
545 Number modify specific location list props
546setmatches({list} [, {win}]) Number restore a list of matches
547setpos({expr}, {list}) Number set the {expr} position to {list}
548setqflist({list} [, {action}]) Number modify quickfix list using {list}
549setqflist({list}, {action}, {what})
550 Number modify specific quickfix list props
551setreg({n}, {v} [, {opt}]) Number set register to value and type
552settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
553settabwinvar({tabnr}, {winnr}, {varname}, {val})
554 none set {varname} in window {winnr} in tab
555 page {tabnr} to {val}
556settagstack({nr}, {dict} [, {action}])
557 Number modify tag stack using {dict}
558setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
559sha256({string}) String SHA256 checksum of {string}
560shellescape({string} [, {special}])
561 String escape {string} for use as shell
562 command argument
563shiftwidth([{col}]) Number effective value of 'shiftwidth'
564sign_define({name} [, {dict}]) Number define or update a sign
565sign_define({list}) List define or update a list of signs
566sign_getdefined([{name}]) List get a list of defined signs
567sign_getplaced([{buf} [, {dict}]])
568 List get a list of placed signs
569sign_jump({id}, {group}, {buf})
570 Number jump to a sign
571sign_place({id}, {group}, {name}, {buf} [, {dict}])
572 Number place a sign
573sign_placelist({list}) List place a list of signs
574sign_undefine([{name}]) Number undefine a sign
575sign_undefine({list}) List undefine a list of signs
576sign_unplace({group} [, {dict}])
577 Number unplace a sign
578sign_unplacelist({list}) List unplace a list of signs
579simplify({filename}) String simplify filename as much as possible
580sin({expr}) Float sine of {expr}
581sinh({expr}) Float hyperbolic sine of {expr}
582slice({expr}, {start} [, {end}]) String, List or Blob
583 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000584sort({list} [, {how} [, {dict}]])
585 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000586sound_clear() none stop playing all sounds
587sound_playevent({name} [, {callback}])
588 Number play an event sound
589sound_playfile({path} [, {callback}])
590 Number play sound file {path}
591sound_stop({id}) none stop playing sound {id}
592soundfold({word}) String sound-fold {word}
593spellbadword() String badly spelled word at cursor
594spellsuggest({word} [, {max} [, {capital}]])
595 List spelling suggestions
596split({expr} [, {pat} [, {keepempty}]])
597 List make |List| from {pat} separated {expr}
598sqrt({expr}) Float square root of {expr}
599srand([{expr}]) List get seed for |rand()|
600state([{what}]) String current state of Vim
601str2float({expr} [, {quoted}]) Float convert String to Float
602str2list({expr} [, {utf8}]) List convert each character of {expr} to
603 ASCII/UTF-8 value
604str2nr({expr} [, {base} [, {quoted}]])
605 Number convert String to Number
606strcharlen({expr}) Number character length of the String {expr}
607strcharpart({str}, {start} [, {len} [, {skipcc}]])
608 String {len} characters of {str} at
609 character {start}
610strchars({expr} [, {skipcc}]) Number character count of the String {expr}
611strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
612strftime({format} [, {time}]) String format time with a specified format
613strgetchar({str}, {index}) Number get char {index} from {str}
614stridx({haystack}, {needle} [, {start}])
615 Number index of {needle} in {haystack}
616string({expr}) String String representation of {expr} value
617strlen({expr}) Number length of the String {expr}
618strpart({str}, {start} [, {len} [, {chars}]])
619 String {len} bytes/chars of {str} at
620 byte {start}
621strptime({format}, {timestring})
622 Number Convert {timestring} to unix timestamp
623strridx({haystack}, {needle} [, {start}])
624 Number last index of {needle} in {haystack}
625strtrans({expr}) String translate string to make it printable
Christian Brabandt67672ef2023-04-24 21:09:54 +0100626strutf16len({string} [, {countcc}])
627 Number number of UTF-16 code units in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000628strwidth({expr}) Number display cell length of the String {expr}
629submatch({nr} [, {list}]) String or List
630 specific match in ":s" or substitute()
631substitute({expr}, {pat}, {sub}, {flags})
632 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000633swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000634swapinfo({fname}) Dict information about swap file {fname}
635swapname({buf}) String swap file of buffer {buf}
636synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
637synIDattr({synID}, {what} [, {mode}])
638 String attribute {what} of syntax ID {synID}
639synIDtrans({synID}) Number translated syntax ID of {synID}
640synconcealed({lnum}, {col}) List info about concealing
641synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
642system({expr} [, {input}]) String output of shell command/filter {expr}
643systemlist({expr} [, {input}]) List output of shell command/filter {expr}
644tabpagebuflist([{arg}]) List list of buffer numbers in tab page
645tabpagenr([{arg}]) Number number of current or last tab page
646tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
647tagfiles() List tags files used
648taglist({expr} [, {filename}]) List list of tags matching {expr}
649tan({expr}) Float tangent of {expr}
650tanh({expr}) Float hyperbolic tangent of {expr}
651tempname() String name for a temporary file
652term_dumpdiff({filename}, {filename} [, {options}])
653 Number display difference between two dumps
654term_dumpload({filename} [, {options}])
655 Number displaying a screen dump
656term_dumpwrite({buf}, {filename} [, {options}])
657 none dump terminal window contents
658term_getaltscreen({buf}) Number get the alternate screen flag
659term_getansicolors({buf}) List get ANSI palette in GUI color mode
660term_getattr({attr}, {what}) Number get the value of attribute {what}
661term_getcursor({buf}) List get the cursor position of a terminal
662term_getjob({buf}) Job get the job associated with a terminal
663term_getline({buf}, {row}) String get a line of text from a terminal
664term_getscrolled({buf}) Number get the scroll count of a terminal
665term_getsize({buf}) List get the size of a terminal
666term_getstatus({buf}) String get the status of a terminal
667term_gettitle({buf}) String get the title of a terminal
668term_gettty({buf}, [{input}]) String get the tty name of a terminal
669term_list() List get the list of terminal buffers
670term_scrape({buf}, {row}) List get row of a terminal screen
671term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
672term_setansicolors({buf}, {colors})
673 none set ANSI palette in GUI color mode
674term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
675term_setkill({buf}, {how}) none set signal to stop job in terminal
676term_setrestore({buf}, {command}) none set command to restore terminal
677term_setsize({buf}, {rows}, {cols})
678 none set the size of a terminal
679term_start({cmd} [, {options}]) Number open a terminal window and run a job
680term_wait({buf} [, {time}]) Number wait for screen to be updated
681terminalprops() Dict properties of the terminal
682test_alloc_fail({id}, {countdown}, {repeat})
683 none make memory allocation fail
684test_autochdir() none enable 'autochdir' during startup
685test_feedinput({string}) none add key sequence to input buffer
686test_garbagecollect_now() none free memory right now for testing
687test_garbagecollect_soon() none free memory soon for testing
688test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000689test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000690test_ignore_error({expr}) none ignore a specific error
Christopher Plewright20b795e2022-12-20 20:01:58 +0000691test_mswin_event({event}, {args})
692 bool generate MS-Windows event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000693test_null_blob() Blob null value for testing
694test_null_channel() Channel null value for testing
695test_null_dict() Dict null value for testing
696test_null_function() Funcref null value for testing
697test_null_job() Job null value for testing
698test_null_list() List null value for testing
699test_null_partial() Funcref null value for testing
700test_null_string() String null value for testing
701test_option_not_set({name}) none reset flag indicating option was set
702test_override({expr}, {val}) none test with Vim internal overrides
703test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000704test_setmouse({row}, {col}) none set the mouse position for testing
705test_settime({expr}) none set current time for testing
Doug Kearns9cd9e752024-04-07 17:42:17 +0200706test_srand_seed([{seed}]) none set seed for testing srand()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000707test_unknown() any unknown value for testing
708test_void() any void value for testing
709timer_info([{id}]) List information about timers
710timer_pause({id}, {pause}) none pause or unpause a timer
711timer_start({time}, {callback} [, {options}])
712 Number create a timer
713timer_stop({timer}) none stop a timer
714timer_stopall() none stop all timers
715tolower({expr}) String the String {expr} switched to lowercase
716toupper({expr}) String the String {expr} switched to uppercase
717tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
718 to chars in {tostr}
719trim({text} [, {mask} [, {dir}]])
720 String trim characters in {mask} from {text}
721trunc({expr}) Float truncate Float {expr}
722type({expr}) Number type of value {expr}
723typename({expr}) String representation of the type of {expr}
724undofile({name}) String undo file name for {name}
Devin J. Pohly5fee1112023-04-23 20:26:59 -0500725undotree([{buf}]) List undo file tree for buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000726uniq({list} [, {func} [, {dict}]])
727 List remove adjacent duplicates from a list
Christian Brabandt67672ef2023-04-24 21:09:54 +0100728utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
729 Number UTF-16 index of byte {idx} in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000730values({dict}) List values in {dict}
zeertzjq825cf812023-08-17 22:55:25 +0200731virtcol({expr} [, {list} [, {winid}])
732 Number or List
LemonBoy0f7a3e12022-05-26 12:10:37 +0100733 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100734virtcol2col({winid}, {lnum}, {col})
735 Number byte index of a character on screen
Doug Kearns9cd9e752024-04-07 17:42:17 +0200736visualmode([{expr}]) String last visual mode used
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000737wildmenumode() Number whether 'wildmenu' mode is active
738win_execute({id}, {command} [, {silent}])
739 String execute {command} in window {id}
740win_findbuf({bufnr}) List find windows containing {bufnr}
741win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
742win_gettype([{nr}]) String type of window {nr}
743win_gotoid({expr}) Number go to window with ID {expr}
744win_id2tabwin({expr}) List get tab and window nr from window ID
745win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000746win_move_separator({nr}) Number move window vertical separator
747win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000748win_screenpos({nr}) List get screen position of window {nr}
749win_splitmove({nr}, {target} [, {options}])
750 Number move window {nr} to split of {target}
751winbufnr({nr}) Number buffer number of window {nr}
752wincol() Number window column of the cursor
753windowsversion() String MS-Windows OS version
754winheight({nr}) Number height of window {nr}
755winlayout([{tabnr}]) List layout of windows in tab {tabnr}
756winline() Number window line of the cursor
757winnr([{expr}]) Number number of current window
758winrestcmd() String returns command to restore window sizes
759winrestview({dict}) none restore view of current window
760winsaveview() Dict save view of current window
761winwidth({nr}) Number width of window {nr}
762wordcount() Dict get byte/char/word statistics
763writefile({object}, {fname} [, {flags}])
764 Number write |Blob| or |List| of lines to file
765xor({expr}, {expr}) Number bitwise XOR
766
767==============================================================================
7682. Details *builtin-function-details*
769
770Not all functions are here, some have been moved to a help file covering the
771specific functionality.
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200772Return type specifies the type for |Vim9-script|, see |vim9-types|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000773
774abs({expr}) *abs()*
775 Return the absolute value of {expr}. When {expr} evaluates to
776 a |Float| abs() returns a |Float|. When {expr} can be
777 converted to a |Number| abs() returns a |Number|. Otherwise
778 abs() gives an error message and returns -1.
779 Examples: >
780 echo abs(1.456)
781< 1.456 >
782 echo abs(-5.456)
783< 5.456 >
784 echo abs(-4)
785< 4
786
787 Can also be used as a |method|: >
788 Compute()->abs()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200789<
790 Return type: |Number| or |Float| depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000791
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000792
793acos({expr}) *acos()*
794 Return the arc cosine of {expr} measured in radians, as a
795 |Float| in the range of [0, pi].
796 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100797 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000798 Examples: >
799 :echo acos(0)
800< 1.570796 >
801 :echo acos(-0.5)
802< 2.094395
803
804 Can also be used as a |method|: >
805 Compute()->acos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200806<
807 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000808
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000809
810add({object}, {expr}) *add()*
811 Append the item {expr} to |List| or |Blob| {object}. Returns
812 the resulting |List| or |Blob|. Examples: >
813 :let alist = add([1, 2, 3], item)
814 :call add(mylist, "woodstock")
815< Note that when {expr} is a |List| it is appended as a single
816 item. Use |extend()| to concatenate |Lists|.
817 When {object} is a |Blob| then {expr} must be a number.
818 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100819 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000820
821 Can also be used as a |method|: >
822 mylist->add(val1)->add(val2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200823<
824 Return type: list<{type}> (depending on the given |List|) or
825 |Blob|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000826
827
828and({expr}, {expr}) *and()*
829 Bitwise AND on the two arguments. The arguments are converted
830 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100831 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000832 Example: >
833 :let flag = and(bits, 0x80)
834< Can also be used as a |method|: >
835 :let flag = bits->and(0x80)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200836<
837 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000838
839
840append({lnum}, {text}) *append()*
841 When {text} is a |List|: Append each item of the |List| as a
842 text line below line {lnum} in the current buffer.
843 Otherwise append {text} as one text line below line {lnum} in
844 the current buffer.
845 Any type of item is accepted and converted to a String.
846 {lnum} can be zero to insert a line before the first one.
847 {lnum} is used like with |getline()|.
848 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000849 0 for success. When {text} is an empty list zero is returned,
850 no matter the value of {lnum}.
851 In |Vim9| script an invalid argument or negative number
852 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000853 :let failed = append(line('$'), "# THE END")
854 :let failed = append(0, ["Chapter 1", "the beginning"])
855
856< Can also be used as a |method| after a List, the base is
857 passed as the second argument: >
858 mylist->append(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200859<
860 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000861
862
863appendbufline({buf}, {lnum}, {text}) *appendbufline()*
864 Like |append()| but append the text in buffer {buf}.
865
866 This function works only for loaded buffers. First call
867 |bufload()| if needed.
868
869 For the use of {buf}, see |bufname()|.
870
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000871 {lnum} is the line number to append below. Note that using
872 |line()| would use the current buffer, not the one appending
873 to. Use "$" to append at the end of the buffer. Other string
874 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000875
876 On success 0 is returned, on failure 1 is returned.
877 In |Vim9| script an error is given for an invalid {lnum}.
878
879 If {buf} is not a valid buffer or {lnum} is not valid, an
880 error message is given. Example: >
881 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000882< However, when {text} is an empty list then no error is given
883 for an invalid {lnum}, since {lnum} isn't actually used.
884
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000885 Can also be used as a |method| after a List, the base is
886 passed as the second argument: >
887 mylist->appendbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200888<
889 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000890
891
892argc([{winid}]) *argc()*
893 The result is the number of files in the argument list. See
894 |arglist|.
895 If {winid} is not supplied, the argument list of the current
896 window is used.
897 If {winid} is -1, the global argument list is used.
898 Otherwise {winid} specifies the window of which the argument
899 list is used: either the window number or the window ID.
900 Returns -1 if the {winid} argument is invalid.
901
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200902 Return type: |Number|
903
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000904 *argidx()*
905argidx() The result is the current index in the argument list. 0 is
906 the first file. argc() - 1 is the last one. See |arglist|.
907
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200908 Return type: |Number|
909
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000910 *arglistid()*
911arglistid([{winnr} [, {tabnr}]])
912 Return the argument list ID. This is a number which
913 identifies the argument list being used. Zero is used for the
914 global argument list. See |arglist|.
915 Returns -1 if the arguments are invalid.
916
917 Without arguments use the current window.
918 With {winnr} only use this window in the current tab page.
919 With {winnr} and {tabnr} use the window in the specified tab
920 page.
921 {winnr} can be the window number or the |window-ID|.
922
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200923 Return type: |Number|
924
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000925 *argv()*
926argv([{nr} [, {winid}]])
927 The result is the {nr}th file in the argument list. See
928 |arglist|. "argv(0)" is the first one. Example: >
929 :let i = 0
930 :while i < argc()
931 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000932 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000933 : let i = i + 1
934 :endwhile
935< Without the {nr} argument, or when {nr} is -1, a |List| with
936 the whole |arglist| is returned.
937
938 The {winid} argument specifies the window ID, see |argc()|.
939 For the Vim command line arguments see |v:argv|.
940
Bram Moolenaar016188f2022-06-06 20:52:59 +0100941 Returns an empty string if {nr}th argument is not present in
942 the argument list. Returns an empty List if the {winid}
943 argument is invalid.
944
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200945 Return type: |String|
946
947
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000948asin({expr}) *asin()*
949 Return the arc sine of {expr} measured in radians, as a |Float|
950 in the range of [-pi/2, pi/2].
951 {expr} must evaluate to a |Float| or a |Number| in the range
952 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100953 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
954 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000955 Examples: >
956 :echo asin(0.8)
957< 0.927295 >
958 :echo asin(-0.5)
959< -0.523599
960
961 Can also be used as a |method|: >
962 Compute()->asin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200963<
964 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000965
966assert_ functions are documented here: |assert-functions-details|
967
968
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000969atan({expr}) *atan()*
970 Return the principal value of the arc tangent of {expr}, in
971 the range [-pi/2, +pi/2] radians, as a |Float|.
972 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100973 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000974 Examples: >
975 :echo atan(100)
976< 1.560797 >
977 :echo atan(-4.01)
978< -1.326405
979
980 Can also be used as a |method|: >
981 Compute()->atan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200982<
983 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000984
985
986atan2({expr1}, {expr2}) *atan2()*
987 Return the arc tangent of {expr1} / {expr2}, measured in
988 radians, as a |Float| in the range [-pi, pi].
989 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100990 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
991 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000992 Examples: >
993 :echo atan2(-1, 1)
994< -0.785398 >
995 :echo atan2(1, -1)
996< 2.356194
997
998 Can also be used as a |method|: >
999 Compute()->atan2(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001000<
1001 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001002
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001003
1004autocmd_add({acmds}) *autocmd_add()*
1005 Adds a List of autocmds and autocmd groups.
1006
1007 The {acmds} argument is a List where each item is a Dict with
1008 the following optional items:
1009 bufnr buffer number to add a buffer-local autocmd.
1010 If this item is specified, then the "pattern"
1011 item is ignored.
1012 cmd Ex command to execute for this autocmd event
1013 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001014 This can be either a String with a single
1015 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001016 group autocmd group name. Refer to |autocmd-groups|.
1017 If this group doesn't exist then it is
1018 created. If not specified or empty, then the
1019 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001020 nested boolean flag, set to v:true to add a nested
1021 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +01001022 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001023 which executes only once. Refer to
1024 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001025 pattern autocmd pattern string. Refer to
1026 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001027 present, then this item is ignored. This can
1028 be a String with a single pattern or a List of
1029 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001030 replace boolean flag, set to v:true to remove all the
1031 commands associated with the specified autocmd
1032 event and group and add the {cmd}. This is
1033 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +01001034 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001035
1036 Returns v:true on success and v:false on failure.
1037 Examples: >
1038 " Create a buffer-local autocmd for buffer 5
1039 let acmd = {}
1040 let acmd.group = 'MyGroup'
1041 let acmd.event = 'BufEnter'
1042 let acmd.bufnr = 5
1043 let acmd.cmd = 'call BufEnterFunc()'
1044 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00001045<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001046 Can also be used as a |method|: >
1047 GetAutocmdList()->autocmd_add()
1048<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001049 Return type: |vim9-boolean|
1050
1051
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001052autocmd_delete({acmds}) *autocmd_delete()*
1053 Deletes a List of autocmds and autocmd groups.
1054
1055 The {acmds} argument is a List where each item is a Dict with
1056 the following optional items:
1057 bufnr buffer number to delete a buffer-local autocmd.
1058 If this item is specified, then the "pattern"
1059 item is ignored.
1060 cmd Ex command for this autocmd event
1061 event autocmd event name. Refer to |autocmd-events|.
1062 If '*' then all the autocmd events in this
1063 group are deleted.
1064 group autocmd group name. Refer to |autocmd-groups|.
1065 If not specified or empty, then the default
1066 group is used.
1067 nested set to v:true for a nested autocmd.
1068 Refer to |autocmd-nested|.
1069 once set to v:true for an autocmd which executes
1070 only once. Refer to |autocmd-once|.
1071 pattern autocmd pattern string. Refer to
1072 |autocmd-patterns|. If "bufnr" item is
1073 present, then this item is ignored.
1074
1075 If only {group} is specified in a {acmds} entry and {event},
1076 {pattern} and {cmd} are not specified, then that autocmd group
1077 is deleted.
1078
Bram Moolenaar016188f2022-06-06 20:52:59 +01001079 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001080 Examples: >
1081 " :autocmd! BufLeave *.vim
1082 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1083 call autocmd_delete([acmd]})
1084 " :autocmd! MyGroup1 BufLeave
1085 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1086 call autocmd_delete([acmd])
1087 " :autocmd! MyGroup2 BufEnter *.c
1088 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1089 \ pattern: '*.c'}
1090 " :autocmd! MyGroup2 * *.c
1091 let acmd = #{group: 'MyGroup2', event: '*',
1092 \ pattern: '*.c'}
1093 call autocmd_delete([acmd])
1094 " :autocmd! MyGroup3
1095 let acmd = #{group: 'MyGroup3'}
1096 call autocmd_delete([acmd])
1097<
1098 Can also be used as a |method|: >
1099 GetAutocmdList()->autocmd_delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001100<
1101 Return type: |vim9-boolean|
1102
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001103
1104autocmd_get([{opts}]) *autocmd_get()*
1105 Returns a |List| of autocmds. If {opts} is not supplied, then
1106 returns the autocmds for all the events in all the groups.
1107
1108 The optional {opts} Dict argument supports the following
1109 items:
1110 group Autocmd group name. If specified, returns only
1111 the autocmds defined in this group. If the
1112 specified group doesn't exist, results in an
1113 error message. If set to an empty string,
1114 then the default autocmd group is used.
1115 event Autocmd event name. If specified, returns only
1116 the autocmds defined for this event. If set
1117 to "*", then returns autocmds for all the
1118 events. If the specified event doesn't exist,
1119 results in an error message.
1120 pattern Autocmd pattern. If specified, returns only
1121 the autocmds defined for this pattern.
1122 A combination of the above three times can be supplied in
1123 {opts}.
1124
1125 Each Dict in the returned List contains the following items:
1126 bufnr For buffer-local autocmds, buffer number where
1127 the autocmd is defined.
1128 cmd Command executed for this autocmd.
1129 event Autocmd event name.
1130 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001131 nested Boolean flag, set to v:true for a nested
1132 autocmd. See |autocmd-nested|.
1133 once Boolean flag, set to v:true, if the autocmd
1134 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001135 pattern Autocmd pattern. For a buffer-local
1136 autocmd, this will be of the form "<buffer=n>".
1137 If there are multiple commands for an autocmd event in a
1138 group, then separate items are returned for each command.
1139
Bram Moolenaar016188f2022-06-06 20:52:59 +01001140 Returns an empty List if an autocmd with the specified group
1141 or event or pattern is not found.
1142
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001143 Examples: >
1144 " :autocmd MyGroup
1145 echo autocmd_get(#{group: 'Mygroup'})
1146 " :autocmd G BufUnload
1147 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1148 " :autocmd G * *.ts
1149 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1150 echo autocmd_get(acmd)
1151 " :autocmd Syntax
1152 echo autocmd_get(#{event: 'Syntax'})
1153 " :autocmd G BufEnter *.ts
1154 let acmd = #{group: 'G', event: 'BufEnter',
1155 \ pattern: '*.ts'}
1156 echo autocmd_get(acmd)
1157<
1158 Can also be used as a |method|: >
1159 Getopts()->autocmd_get()
1160<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001161 Return type: list<dict<any>>
1162
1163
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001164balloon_gettext() *balloon_gettext()*
1165 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001166 not used for the List. Returns an empty string if balloon
1167 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001168
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001169 Return type: |String|
1170
1171
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001172balloon_show({expr}) *balloon_show()*
1173 Show {expr} inside the balloon. For the GUI {expr} is used as
1174 a string. For a terminal {expr} can be a list, which contains
1175 the lines of the balloon. If {expr} is not a list it will be
1176 split with |balloon_split()|.
1177 If {expr} is an empty string any existing balloon is removed.
1178
1179 Example: >
1180 func GetBalloonContent()
1181 " ... initiate getting the content
1182 return ''
1183 endfunc
1184 set balloonexpr=GetBalloonContent()
1185
1186 func BalloonCallback(result)
1187 call balloon_show(a:result)
1188 endfunc
1189< Can also be used as a |method|: >
1190 GetText()->balloon_show()
1191<
1192 The intended use is that fetching the content of the balloon
1193 is initiated from 'balloonexpr'. It will invoke an
1194 asynchronous method, in which a callback invokes
1195 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001196 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001197
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001198 When showing a balloon is not possible then nothing happens,
1199 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001200 {only available when compiled with the |+balloon_eval| or
1201 |+balloon_eval_term| feature}
1202
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001203 Return type: |Number|
1204
1205
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001206balloon_split({msg}) *balloon_split()*
1207 Split String {msg} into lines to be displayed in a balloon.
1208 The splits are made for the current window size and optimize
1209 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001210 Returns a |List| with the split lines. Returns an empty List
1211 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001212 Can also be used as a |method|: >
1213 GetText()->balloon_split()->balloon_show()
1214
1215< {only available when compiled with the |+balloon_eval_term|
1216 feature}
1217
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001218 Return type: list<any> or list<string>
1219
1220
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001221blob2list({blob}) *blob2list()*
1222 Return a List containing the number value of each byte in Blob
1223 {blob}. Examples: >
1224 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1225 blob2list(0z) returns []
1226< Returns an empty List on error. |list2blob()| does the
1227 opposite.
1228
1229 Can also be used as a |method|: >
1230 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001231<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001232 Return type: list<any> or list<number>
1233
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001234 *browse()*
1235browse({save}, {title}, {initdir}, {default})
1236 Put up a file requester. This only works when "has("browse")"
1237 returns |TRUE| (only in some GUI versions).
1238 The input fields are:
1239 {save} when |TRUE|, select file to write
1240 {title} title for the requester
1241 {initdir} directory to start browsing in
1242 {default} default file name
1243 An empty string is returned when the "Cancel" button is hit,
1244 something went wrong, or browsing is not possible.
1245
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001246 Return type: |String|
1247
1248
1249browsedir({title}, {initdir}) *browsedir()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001250 Put up a directory requester. This only works when
1251 "has("browse")" returns |TRUE| (only in some GUI versions).
1252 On systems where a directory browser is not supported a file
1253 browser is used. In that case: select a file in the directory
1254 to be used.
1255 The input fields are:
1256 {title} title for the requester
1257 {initdir} directory to start browsing in
1258 When the "Cancel" button is hit, something went wrong, or
1259 browsing is not possible, an empty string is returned.
1260
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001261 Return type: |String|
1262
1263
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001264bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001265 Add a buffer to the buffer list with name {name} (must be a
1266 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001267 If a buffer for file {name} already exists, return that buffer
1268 number. Otherwise return the buffer number of the newly
1269 created buffer. When {name} is an empty string then a new
1270 buffer is always created.
1271 The buffer will not have 'buflisted' set and not be loaded
1272 yet. To add some text to the buffer use this: >
1273 let bufnr = bufadd('someName')
1274 call bufload(bufnr)
1275 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001276< Returns 0 on error.
1277 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001278 let bufnr = 'somename'->bufadd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001279<
1280 Return type: |Number|
1281
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001282
1283bufexists({buf}) *bufexists()*
1284 The result is a Number, which is |TRUE| if a buffer called
1285 {buf} exists.
1286 If the {buf} argument is a number, buffer numbers are used.
1287 Number zero is the alternate buffer for the current window.
1288
1289 If the {buf} argument is a string it must match a buffer name
1290 exactly. The name can be:
1291 - Relative to the current directory.
1292 - A full path.
1293 - The name of a buffer with 'buftype' set to "nofile".
1294 - A URL name.
1295 Unlisted buffers will be found.
1296 Note that help files are listed by their short name in the
1297 output of |:buffers|, but bufexists() requires using their
1298 long name to be able to find them.
1299 bufexists() may report a buffer exists, but to use the name
1300 with a |:buffer| command you may need to use |expand()|. Esp
1301 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1302 Use "bufexists(0)" to test for the existence of an alternate
1303 file name.
1304
1305 Can also be used as a |method|: >
1306 let exists = 'somename'->bufexists()
1307<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001308 Return type: |Number|
1309
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001310 Obsolete name: buffer_exists(). *buffer_exists()*
1311
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001312
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001313buflisted({buf}) *buflisted()*
1314 The result is a Number, which is |TRUE| if a buffer called
1315 {buf} exists and is listed (has the 'buflisted' option set).
1316 The {buf} argument is used like with |bufexists()|.
1317
1318 Can also be used as a |method|: >
1319 let listed = 'somename'->buflisted()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001320<
1321 Return type: |Number|
1322
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001323
1324bufload({buf}) *bufload()*
1325 Ensure the buffer {buf} is loaded. When the buffer name
1326 refers to an existing file then the file is read. Otherwise
1327 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001328 then there is no change. If the buffer is not related to a
Daniel Steinbergc2bd2052023-08-09 12:10:59 -04001329 file then no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001330 If there is an existing swap file for the file of the buffer,
1331 there will be no dialog, the buffer will be loaded anyway.
1332 The {buf} argument is used like with |bufexists()|.
1333
1334 Can also be used as a |method|: >
1335 eval 'somename'->bufload()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001336<
1337 Return type: |Number|
1338
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001339
1340bufloaded({buf}) *bufloaded()*
1341 The result is a Number, which is |TRUE| if a buffer called
1342 {buf} exists and is loaded (shown in a window or hidden).
1343 The {buf} argument is used like with |bufexists()|.
1344
1345 Can also be used as a |method|: >
1346 let loaded = 'somename'->bufloaded()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001347<
1348 Return type: |Number|
1349
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001350
1351bufname([{buf}]) *bufname()*
1352 The result is the name of a buffer. Mostly as it is displayed
1353 by the `:ls` command, but not using special names such as
1354 "[No Name]".
1355 If {buf} is omitted the current buffer is used.
1356 If {buf} is a Number, that buffer number's name is given.
1357 Number zero is the alternate buffer for the current window.
1358 If {buf} is a String, it is used as a |file-pattern| to match
1359 with the buffer names. This is always done like 'magic' is
1360 set and 'cpoptions' is empty. When there is more than one
1361 match an empty string is returned.
1362 "" or "%" can be used for the current buffer, "#" for the
1363 alternate buffer.
1364 A full match is preferred, otherwise a match at the start, end
1365 or middle of the buffer name is accepted. If you only want a
1366 full match then put "^" at the start and "$" at the end of the
1367 pattern.
1368 Listed buffers are found first. If there is a single match
1369 with a listed buffer, that one is returned. Next unlisted
1370 buffers are searched for.
1371 If the {buf} is a String, but you want to use it as a buffer
1372 number, force it to be a Number by adding zero to it: >
1373 :echo bufname("3" + 0)
1374< Can also be used as a |method|: >
1375 echo bufnr->bufname()
1376
1377< If the buffer doesn't exist, or doesn't have a name, an empty
1378 string is returned. >
1379 bufname("#") alternate buffer name
1380 bufname(3) name of buffer 3
1381 bufname("%") name of current buffer
1382 bufname("file2") name of buffer where "file2" matches.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001383<
1384 Return type: |String|
1385 *buffer_name()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001386 Obsolete name: buffer_name().
1387
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001388
1389bufnr([{buf} [, {create}]]) *bufnr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001390 The result is the number of a buffer, as it is displayed by
1391 the `:ls` command. For the use of {buf}, see |bufname()|
1392 above.
1393
1394 If the buffer doesn't exist, -1 is returned. Or, if the
1395 {create} argument is present and TRUE, a new, unlisted,
1396 buffer is created and its number is returned. Example: >
1397 let newbuf = bufnr('Scratch001', 1)
1398< Using an empty name uses the current buffer. To create a new
1399 buffer with an empty name use |bufadd()|.
1400
1401 bufnr("$") is the last buffer: >
1402 :let last_buffer = bufnr("$")
1403< The result is a Number, which is the highest buffer number
1404 of existing buffers. Note that not all buffers with a smaller
1405 number necessarily exist, because ":bwipeout" may have removed
1406 them. Use bufexists() to test for the existence of a buffer.
1407
1408 Can also be used as a |method|: >
1409 echo bufref->bufnr()
1410<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001411 Return type: |Number|
1412
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001413 Obsolete name: buffer_number(). *buffer_number()*
1414 *last_buffer_nr()*
1415 Obsolete name for bufnr("$"): last_buffer_nr().
1416
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001417
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001418bufwinid({buf}) *bufwinid()*
1419 The result is a Number, which is the |window-ID| of the first
1420 window associated with buffer {buf}. For the use of {buf},
1421 see |bufname()| above. If buffer {buf} doesn't exist or
1422 there is no such window, -1 is returned. Example: >
1423
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001424 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001425<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001426 Only deals with the current tab page. See |win_findbuf()| for
1427 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001428
1429 Can also be used as a |method|: >
1430 FindBuffer()->bufwinid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001431<
1432 Return type: |Number|
1433
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001434
1435bufwinnr({buf}) *bufwinnr()*
1436 Like |bufwinid()| but return the window number instead of the
1437 |window-ID|.
1438 If buffer {buf} doesn't exist or there is no such window, -1
1439 is returned. Example: >
1440
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001441 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001442
1443< The number can be used with |CTRL-W_w| and ":wincmd w"
1444 |:wincmd|.
1445
1446 Can also be used as a |method|: >
1447 FindBuffer()->bufwinnr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001448<
1449 Return type: |Number|
1450
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001451
1452byte2line({byte}) *byte2line()*
1453 Return the line number that contains the character at byte
1454 count {byte} in the current buffer. This includes the
1455 end-of-line character, depending on the 'fileformat' option
1456 for the current buffer. The first character has byte count
1457 one.
1458 Also see |line2byte()|, |go| and |:goto|.
1459
Bram Moolenaar016188f2022-06-06 20:52:59 +01001460 Returns -1 if the {byte} value is invalid.
1461
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001462 Can also be used as a |method|: >
1463 GetOffset()->byte2line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001464<
1465 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001466
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001467 {not available when compiled without the |+byte_offset|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001468 feature}
1469
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001470
Christian Brabandt67672ef2023-04-24 21:09:54 +01001471byteidx({expr}, {nr} [, {utf16}]) *byteidx()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001472 Return byte index of the {nr}'th character in the String
1473 {expr}. Use zero for the first character, it then returns
1474 zero.
1475 If there are no multibyte characters the returned value is
1476 equal to {nr}.
1477 Composing characters are not counted separately, their byte
1478 length is added to the preceding base character. See
1479 |byteidxcomp()| below for counting composing characters
1480 separately.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001481 When {utf16} is present and TRUE, {nr} is used as the UTF-16
1482 index in the String {expr} instead of as the character index.
1483 The UTF-16 index is the index in the string when it is encoded
1484 with 16-bit words. If the specified UTF-16 index is in the
1485 middle of a character (e.g. in a 4-byte character), then the
1486 byte index of the first byte in the character is returned.
1487 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001488 Example : >
1489 echo matchstr(str, ".", byteidx(str, 3))
1490< will display the fourth character. Another way to do the
1491 same: >
1492 let s = strpart(str, byteidx(str, 3))
1493 echo strpart(s, 0, byteidx(s, 1))
1494< Also see |strgetchar()| and |strcharpart()|.
1495
1496 If there are less than {nr} characters -1 is returned.
1497 If there are exactly {nr} characters the length of the string
1498 in bytes is returned.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001499 See |charidx()| and |utf16idx()| for getting the character and
1500 UTF-16 index respectively from the byte index.
1501 Examples: >
1502 echo byteidx('a😊😊', 2) returns 5
1503 echo byteidx('a😊😊', 2, 1) returns 1
1504 echo byteidx('a😊😊', 3, 1) returns 5
1505<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001506 Can also be used as a |method|: >
1507 GetName()->byteidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001508<
1509 Return type: |Number|
1510
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001511
Christian Brabandt67672ef2023-04-24 21:09:54 +01001512byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001513 Like byteidx(), except that a composing character is counted
1514 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001515 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001516 echo byteidx(s, 1)
1517 echo byteidxcomp(s, 1)
1518 echo byteidxcomp(s, 2)
1519< The first and third echo result in 3 ('e' plus composing
1520 character is 3 bytes), the second echo results in 1 ('e' is
1521 one byte).
1522 Only works differently from byteidx() when 'encoding' is set
1523 to a Unicode encoding.
1524
1525 Can also be used as a |method|: >
1526 GetName()->byteidxcomp(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001527<
1528 Return type: |Number|
1529
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001530
1531call({func}, {arglist} [, {dict}]) *call()* *E699*
1532 Call function {func} with the items in |List| {arglist} as
1533 arguments.
1534 {func} can either be a |Funcref| or the name of a function.
1535 a:firstline and a:lastline are set to the cursor line.
1536 Returns the return value of the called function.
1537 {dict} is for functions with the "dict" attribute. It will be
1538 used to set the local variable "self". |Dictionary-function|
1539
1540 Can also be used as a |method|: >
1541 GetFunc()->call([arg, arg], dict)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001542<
1543 Return type: any, depending on {func}
1544
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001545
1546ceil({expr}) *ceil()*
1547 Return the smallest integral value greater than or equal to
1548 {expr} as a |Float| (round up).
1549 {expr} must evaluate to a |Float| or a |Number|.
1550 Examples: >
1551 echo ceil(1.456)
1552< 2.0 >
1553 echo ceil(-5.456)
1554< -5.0 >
1555 echo ceil(4.0)
1556< 4.0
1557
Bram Moolenaar016188f2022-06-06 20:52:59 +01001558 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1559
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001560 Can also be used as a |method|: >
1561 Compute()->ceil()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001562<
1563 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001564
1565
1566ch_ functions are documented here: |channel-functions-details|
1567
1568
1569changenr() *changenr()*
1570 Return the number of the most recent change. This is the same
1571 number as what is displayed with |:undolist| and can be used
1572 with the |:undo| command.
1573 When a change was made it is the number of that change. After
1574 redo it is the number of the redone change. After undo it is
1575 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001576 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001577
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001578 Return type: |Number|
1579
1580
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001581char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001582 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001583 Examples: >
1584 char2nr(" ") returns 32
1585 char2nr("ABC") returns 65
1586< When {utf8} is omitted or zero, the current 'encoding' is used.
1587 Example for "utf-8": >
1588 char2nr("á") returns 225
1589 char2nr("á"[0]) returns 195
1590< When {utf8} is TRUE, always treat as UTF-8 characters.
1591 A combining character is a separate character.
1592 |nr2char()| does the opposite.
1593 To turn a string into a list of character numbers: >
1594 let str = "ABC"
1595 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1596< Result: [65, 66, 67]
1597
Bram Moolenaar016188f2022-06-06 20:52:59 +01001598 Returns 0 if {string} is not a |String|.
1599
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001600 Can also be used as a |method|: >
1601 GetChar()->char2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001602<
1603 Return type: |Number|
1604
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001605
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001606charclass({string}) *charclass()*
1607 Return the character class of the first character in {string}.
1608 The character class is one of:
1609 0 blank
1610 1 punctuation
1611 2 word character
1612 3 emoji
1613 other specific Unicode class
1614 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001615 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001616
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001617 Return type: |Number|
1618
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001619
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001620charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001621 Same as |col()| but returns the character index of the column
1622 position given with {expr} instead of the byte position.
1623
1624 Example:
1625 With the cursor on '세' in line 5 with text "여보세요": >
1626 charcol('.') returns 3
1627 col('.') returns 7
1628
1629< Can also be used as a |method|: >
1630 GetPos()->col()
1631<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001632 Return type: |Number|
1633
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001634 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001635charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001636 Return the character index of the byte at {idx} in {string}.
1637 The index of the first character is zero.
1638 If there are no multibyte characters the returned value is
1639 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001640
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001641 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001642 are not counted separately, their byte length is added to the
1643 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001644 When {countcc} is |TRUE|, then composing characters are
1645 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001646
1647 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1648 index in the String {expr} instead of as the byte index.
1649
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001650 Returns -1 if the arguments are invalid or if there are less
1651 than {idx} bytes. If there are exactly {idx} bytes the length
1652 of the string in characters is returned.
1653
1654 An error is given and -1 is returned if the first argument is
1655 not a string, the second argument is not a number or when the
1656 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001657
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001658 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001659 from the character index and |utf16idx()| for getting the
1660 UTF-16 index from the character index.
1661 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001662 Examples: >
1663 echo charidx('áb́ć', 3) returns 1
1664 echo charidx('áb́ć', 6, 1) returns 4
1665 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001666 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001667<
1668 Can also be used as a |method|: >
1669 GetName()->charidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001670<
1671 Return type: |Number|
1672
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001673
1674chdir({dir}) *chdir()*
1675 Change the current working directory to {dir}. The scope of
1676 the directory change depends on the directory of the current
1677 window:
1678 - If the current window has a window-local directory
1679 (|:lcd|), then changes the window local directory.
1680 - Otherwise, if the current tabpage has a local
1681 directory (|:tcd|) then changes the tabpage local
1682 directory.
1683 - Otherwise, changes the global directory.
1684 {dir} must be a String.
1685 If successful, returns the previous working directory. Pass
1686 this to another chdir() to restore the directory.
1687 On failure, returns an empty string.
1688
1689 Example: >
1690 let save_dir = chdir(newdir)
1691 if save_dir != ""
1692 " ... do some work
1693 call chdir(save_dir)
1694 endif
1695
1696< Can also be used as a |method|: >
1697 GetDir()->chdir()
1698<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001699 Return type: |String|
1700
1701
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001702cindent({lnum}) *cindent()*
1703 Get the amount of indent for line {lnum} according the C
1704 indenting rules, as with 'cindent'.
1705 The indent is counted in spaces, the value of 'tabstop' is
1706 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001707 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001708 See |C-indenting|.
1709
1710 Can also be used as a |method|: >
1711 GetLnum()->cindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001712<
1713 Return type: |Number|
1714
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001715
1716clearmatches([{win}]) *clearmatches()*
1717 Clears all matches previously defined for the current window
1718 by |matchadd()| and the |:match| commands.
1719 If {win} is specified, use the window with this number or
1720 window ID instead of the current window.
1721
1722 Can also be used as a |method|: >
1723 GetWin()->clearmatches()
1724<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001725 Return type: |Number|
1726
1727
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001728col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001729 The result is a Number, which is the byte index of the column
zeertzjq02f3eba2024-06-12 20:45:24 +02001730 position given with {expr}.
1731 For accepted positions see |getpos()|.
zeertzjqd353d272024-06-13 23:00:25 +08001732 When {expr} is "$", it means the end of the cursor line, so
1733 the result is the number of bytes in the cursor line plus one.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001734 Additionally {expr} can be [lnum, col]: a |List| with the line
1735 and column number. Most useful when the column is "$", to get
1736 the last column of a specific line. When "lnum" or "col" is
1737 out of range then col() returns zero.
zeertzjq02f3eba2024-06-12 20:45:24 +02001738
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001739 With the optional {winid} argument the values are obtained for
1740 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02001741
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001742 To get the line number use |line()|. To get both use
1743 |getpos()|.
1744 For the screen column position use |virtcol()|. For the
1745 character position use |charcol()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02001746
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001747 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +02001748
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001749 Examples: >
1750 col(".") column of cursor
1751 col("$") length of cursor line plus one
1752 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001753 col("'" .. markname) column of mark markname
zeertzjq02f3eba2024-06-12 20:45:24 +02001754<
1755 The first column is 1. Returns 0 if {expr} is invalid or when
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001756 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001757 For an uppercase mark the column may actually be in another
1758 buffer.
1759 For the cursor position, when 'virtualedit' is active, the
1760 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001761 line. Also, when using a <Cmd> mapping the cursor isn't
1762 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001763 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001764
1765< Can also be used as a |method|: >
1766 GetPos()->col()
1767<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001768 Return type: |Number|
1769
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001770
1771complete({startcol}, {matches}) *complete()* *E785*
1772 Set the matches for Insert mode completion.
1773 Can only be used in Insert mode. You need to use a mapping
1774 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1775 or with an expression mapping.
1776 {startcol} is the byte offset in the line where the completed
1777 text start. The text up to the cursor is the original text
1778 that will be replaced by the matches. Use col('.') for an
1779 empty string. "col('.') - 1" will replace one character by a
1780 match.
1781 {matches} must be a |List|. Each |List| item is one match.
1782 See |complete-items| for the kind of items that are possible.
1783 "longest" in 'completeopt' is ignored.
1784 Note that the after calling this function you need to avoid
1785 inserting anything that would cause completion to stop.
1786 The match can be selected with CTRL-N and CTRL-P as usual with
1787 Insert mode completion. The popup menu will appear if
1788 specified, see |ins-completion-menu|.
1789 Example: >
1790 inoremap <F5> <C-R>=ListMonths()<CR>
1791
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001792 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001793 call complete(col('.'), ['January', 'February', 'March',
1794 \ 'April', 'May', 'June', 'July', 'August', 'September',
1795 \ 'October', 'November', 'December'])
1796 return ''
1797 endfunc
1798< This isn't very useful, but it shows how it works. Note that
1799 an empty string is returned to avoid a zero being inserted.
1800
1801 Can also be used as a |method|, the base is passed as the
1802 second argument: >
1803 GetMatches()->complete(col('.'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001804<
1805 Return type: |Number|
1806
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001807
1808complete_add({expr}) *complete_add()*
1809 Add {expr} to the list of matches. Only to be used by the
1810 function specified with the 'completefunc' option.
1811 Returns 0 for failure (empty string or out of memory),
1812 1 when the match was added, 2 when the match was already in
1813 the list.
1814 See |complete-functions| for an explanation of {expr}. It is
1815 the same as one item in the list that 'omnifunc' would return.
1816
1817 Can also be used as a |method|: >
1818 GetMoreMatches()->complete_add()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001819<
1820 Return type: |Number|
1821
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001822
1823complete_check() *complete_check()*
1824 Check for a key typed while looking for completion matches.
1825 This is to be used when looking for matches takes some time.
1826 Returns |TRUE| when searching for matches is to be aborted,
1827 zero otherwise.
1828 Only to be used by the function specified with the
1829 'completefunc' option.
1830
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001831 Return type: |Number|
1832
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001833
1834complete_info([{what}]) *complete_info()*
1835 Returns a |Dictionary| with information about Insert mode
1836 completion. See |ins-completion|.
1837 The items are:
1838 mode Current completion mode name string.
1839 See |complete_info_mode| for the values.
1840 pum_visible |TRUE| if popup menu is visible.
1841 See |pumvisible()|.
1842 items List of completion matches. Each item is a
1843 dictionary containing the entries "word",
1844 "abbr", "menu", "kind", "info" and "user_data".
1845 See |complete-items|.
1846 selected Selected item index. First index is zero.
1847 Index is -1 if no item is selected (showing
1848 typed text only, or the last completion after
1849 no item is selected when using the <Up> or
1850 <Down> keys)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01001851 inserted Inserted string. [NOT IMPLEMENTED YET]
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001852
1853 *complete_info_mode*
1854 mode values are:
1855 "" Not in completion mode
1856 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1857 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1858 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1859 |i_CTRL-X_CTRL-Y|
1860 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1861 "files" File names |i_CTRL-X_CTRL-F|
1862 "tags" Tags |i_CTRL-X_CTRL-]|
1863 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1864 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1865 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1866 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1867 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1868 "function" User defined completion |i_CTRL-X_CTRL-U|
1869 "omni" Omni completion |i_CTRL-X_CTRL-O|
1870 "spell" Spelling suggestions |i_CTRL-X_s|
1871 "eval" |complete()| completion
1872 "unknown" Other internal modes
1873
1874 If the optional {what} list argument is supplied, then only
1875 the items listed in {what} are returned. Unsupported items in
1876 {what} are silently ignored.
1877
1878 To get the position and size of the popup menu, see
1879 |pum_getpos()|. It's also available in |v:event| during the
1880 |CompleteChanged| event.
1881
Bram Moolenaar016188f2022-06-06 20:52:59 +01001882 Returns an empty |Dictionary| on error.
1883
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001884 Examples: >
1885 " Get all items
1886 call complete_info()
1887 " Get only 'mode'
1888 call complete_info(['mode'])
1889 " Get only 'mode' and 'pum_visible'
1890 call complete_info(['mode', 'pum_visible'])
1891
1892< Can also be used as a |method|: >
1893 GetItems()->complete_info()
1894<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001895 Return type: dict<any>
1896
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001897 *confirm()*
1898confirm({msg} [, {choices} [, {default} [, {type}]]])
1899 confirm() offers the user a dialog, from which a choice can be
1900 made. It returns the number of the choice. For the first
1901 choice this is 1.
1902 Note: confirm() is only supported when compiled with dialog
glepnirdf461152024-04-04 22:23:29 +02001903 support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001904
1905 {msg} is displayed in a |dialog| with {choices} as the
1906 alternatives. When {choices} is missing or empty, "&OK" is
1907 used (and translated).
1908 {msg} is a String, use '\n' to include a newline. Only on
1909 some systems the string is wrapped when it doesn't fit.
1910
1911 {choices} is a String, with the individual choices separated
1912 by '\n', e.g. >
1913 confirm("Save changes?", "&Yes\n&No\n&Cancel")
1914< The letter after the '&' is the shortcut key for that choice.
1915 Thus you can type 'c' to select "Cancel". The shortcut does
1916 not need to be the first letter: >
1917 confirm("file has been modified", "&Save\nSave &All")
1918< For the console, the first letter of each choice is used as
1919 the default shortcut key. Case is ignored.
1920
1921 The optional {default} argument is the number of the choice
1922 that is made if the user hits <CR>. Use 1 to make the first
1923 choice the default one. Use 0 to not set a default. If
1924 {default} is omitted, 1 is used.
1925
1926 The optional {type} String argument gives the type of dialog.
1927 This is only used for the icon of the GTK, Mac, Motif and
1928 Win32 GUI. It can be one of these values: "Error",
1929 "Question", "Info", "Warning" or "Generic". Only the first
1930 character is relevant. When {type} is omitted, "Generic" is
1931 used.
1932
1933 If the user aborts the dialog by pressing <Esc>, CTRL-C,
1934 or another valid interrupt key, confirm() returns 0.
1935
1936 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01001937 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001938 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01001939 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001940 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001941 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001942 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001943 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001944 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01001945 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001946< In a GUI dialog, buttons are used. The layout of the buttons
1947 depends on the 'v' flag in 'guioptions'. If it is included,
1948 the buttons are always put vertically. Otherwise, confirm()
1949 tries to put the buttons in one horizontal line. If they
1950 don't fit, a vertical layout is used anyway. For some systems
1951 the horizontal layout is always used.
1952
1953 Can also be used as a |method|in: >
1954 BuildMessage()->confirm("&Yes\n&No")
1955<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001956 Return type: |Number|
1957
1958
1959copy({expr}) *copy()*
1960 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001961 different from using {expr} directly.
1962 When {expr} is a |List| a shallow copy is created. This means
1963 that the original |List| can be changed without changing the
1964 copy, and vice versa. But the items are identical, thus
1965 changing an item changes the contents of both |Lists|.
1966 A |Dictionary| is copied in a similar way as a |List|.
1967 Also see |deepcopy()|.
1968 Can also be used as a |method|: >
1969 mylist->copy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001970<
1971 Return type: any, depending on {expr}
1972
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001973
1974cos({expr}) *cos()*
1975 Return the cosine of {expr}, measured in radians, as a |Float|.
1976 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001977 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001978 Examples: >
1979 :echo cos(100)
1980< 0.862319 >
1981 :echo cos(-4.01)
1982< -0.646043
1983
1984 Can also be used as a |method|: >
1985 Compute()->cos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001986<
1987 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001988
1989
1990cosh({expr}) *cosh()*
1991 Return the hyperbolic cosine of {expr} as a |Float| in the range
1992 [1, inf].
1993 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001994 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001995 Examples: >
1996 :echo cosh(0.5)
1997< 1.127626 >
1998 :echo cosh(-0.5)
1999< -1.127626
2000
2001 Can also be used as a |method|: >
2002 Compute()->cosh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002003<
2004 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002005
2006
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07002007count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002008 Return the number of times an item with value {expr} appears
2009 in |String|, |List| or |Dictionary| {comp}.
2010
2011 If {start} is given then start with the item with this index.
2012 {start} can only be used with a |List|.
2013
2014 When {ic} is given and it's |TRUE| then case is ignored.
2015
2016 When {comp} is a string then the number of not overlapping
2017 occurrences of {expr} is returned. Zero is returned when
2018 {expr} is an empty string.
2019
2020 Can also be used as a |method|: >
2021 mylist->count(val)
2022<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002023 Return type: |Number|
2024
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002025 *cscope_connection()*
2026cscope_connection([{num} , {dbpath} [, {prepend}]])
2027 Checks for the existence of a |cscope| connection. If no
2028 parameters are specified, then the function returns:
2029 0, if cscope was not available (not compiled in), or
2030 if there are no cscope connections;
2031 1, if there is at least one cscope connection.
2032
2033 If parameters are specified, then the value of {num}
2034 determines how existence of a cscope connection is checked:
2035
2036 {num} Description of existence check
2037 ----- ------------------------------
2038 0 Same as no parameters (e.g., "cscope_connection()").
2039 1 Ignore {prepend}, and use partial string matches for
2040 {dbpath}.
2041 2 Ignore {prepend}, and use exact string matches for
2042 {dbpath}.
2043 3 Use {prepend}, use partial string matches for both
2044 {dbpath} and {prepend}.
2045 4 Use {prepend}, use exact string matches for both
2046 {dbpath} and {prepend}.
2047
2048 Note: All string comparisons are case sensitive!
2049
2050 Examples. Suppose we had the following (from ":cs show"): >
2051
2052 # pid database name prepend path
2053 0 27664 cscope.out /usr/local
2054<
2055 Invocation Return Val ~
2056 ---------- ---------- >
2057 cscope_connection() 1
2058 cscope_connection(1, "out") 1
2059 cscope_connection(2, "out") 0
2060 cscope_connection(3, "out") 0
2061 cscope_connection(3, "out", "local") 1
2062 cscope_connection(4, "out") 0
2063 cscope_connection(4, "out", "local") 0
2064 cscope_connection(4, "cscope.out", "/usr/local") 1
2065<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002066 Return type: |Number|
2067
2068
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002069cursor({lnum}, {col} [, {off}]) *cursor()*
2070cursor({list})
2071 Positions the cursor at the column (byte count) {col} in the
2072 line {lnum}. The first column is one.
2073
2074 When there is one argument {list} this is used as a |List|
2075 with two, three or four item:
2076 [{lnum}, {col}]
2077 [{lnum}, {col}, {off}]
2078 [{lnum}, {col}, {off}, {curswant}]
2079 This is like the return value of |getpos()| or |getcurpos()|,
2080 but without the first item.
2081
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01002082 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002083 |setcursorcharpos()|.
2084
2085 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01002086 {lnum} is used like with |getline()|, except that if {lnum} is
2087 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002088 If {lnum} is greater than the number of lines in the buffer,
2089 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002090 If {col} is greater than the number of bytes in the line,
2091 the cursor will be positioned at the last character in the
2092 line.
2093 If {col} is zero, the cursor will stay in the current column.
2094 If {curswant} is given it is used to set the preferred column
2095 for vertical movement. Otherwise {col} is used.
2096
2097 When 'virtualedit' is used {off} specifies the offset in
2098 screen columns from the start of the character. E.g., a
2099 position within a <Tab> or after the last character.
2100 Returns 0 when the position could be set, -1 otherwise.
2101
2102 Can also be used as a |method|: >
2103 GetCursorPos()->cursor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002104<
2105 Return type: |Number|
2106
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002107
2108debugbreak({pid}) *debugbreak()*
2109 Specifically used to interrupt a program being debugged. It
2110 will cause process {pid} to get a SIGTRAP. Behavior for other
2111 processes is undefined. See |terminal-debugger|.
2112 {only available on MS-Windows}
2113
Bram Moolenaar016188f2022-06-06 20:52:59 +01002114 Returns |TRUE| if successfully interrupted the program.
2115 Otherwise returns |FALSE|.
2116
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002117 Can also be used as a |method|: >
2118 GetPid()->debugbreak()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002119<
2120 Return type: |Number|
2121
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002122
2123deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
2124 Make a copy of {expr}. For Numbers and Strings this isn't
2125 different from using {expr} directly.
2126 When {expr} is a |List| a full copy is created. This means
2127 that the original |List| can be changed without changing the
2128 copy, and vice versa. When an item is a |List| or
2129 |Dictionary|, a copy for it is made, recursively. Thus
2130 changing an item in the copy does not change the contents of
2131 the original |List|.
2132 A |Dictionary| is copied in a similar way as a |List|.
2133
2134 When {noref} is omitted or zero a contained |List| or
2135 |Dictionary| is only copied once. All references point to
2136 this single copy. With {noref} set to 1 every occurrence of a
2137 |List| or |Dictionary| results in a new copy. This also means
2138 that a cyclic reference causes deepcopy() to fail.
2139 *E724*
2140 Nesting is possible up to 100 levels. When there is an item
2141 that refers back to a higher level making a deep copy with
2142 {noref} set to 1 will fail.
2143 Also see |copy()|.
2144
2145 Can also be used as a |method|: >
2146 GetObject()->deepcopy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002147<
2148 Return type: any, depending on {expr}
2149
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002150
2151delete({fname} [, {flags}]) *delete()*
2152 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002153 name {fname}.
2154
2155 This also works when {fname} is a symbolic link. The symbolic
2156 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002157
2158 When {flags} is "d": Deletes the directory by the name
2159 {fname}. This fails when directory {fname} is not empty.
2160
2161 When {flags} is "rf": Deletes the directory by the name
2162 {fname} and everything in it, recursively. BE CAREFUL!
2163 Note: on MS-Windows it is not possible to delete a directory
2164 that is being used.
2165
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002166 The result is a Number, which is 0/false if the delete
2167 operation was successful and -1/true when the deletion failed
2168 or partly failed.
2169
2170 Use |remove()| to delete an item from a |List|.
2171 To delete a line from the buffer use |:delete| or
2172 |deletebufline()|.
2173
2174 Can also be used as a |method|: >
2175 GetName()->delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002176<
2177 Return type: |Number|
2178
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002179
2180deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2181 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2182 If {last} is omitted then delete line {first} only.
2183 On success 0 is returned, on failure 1 is returned.
2184
2185 This function works only for loaded buffers. First call
2186 |bufload()| if needed.
2187
2188 For the use of {buf}, see |bufname()| above.
2189
2190 {first} and {last} are used like with |getline()|. Note that
2191 when using |line()| this refers to the current buffer. Use "$"
2192 to refer to the last line in buffer {buf}.
2193
2194 Can also be used as a |method|: >
2195 GetBuffer()->deletebufline(1)
2196<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002197 Return type: |Number|
2198
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002199 *did_filetype()*
2200did_filetype() Returns |TRUE| when autocommands are being executed and the
2201 FileType event has been triggered at least once. Can be used
2202 to avoid triggering the FileType event again in the scripts
2203 that detect the file type. |FileType|
2204 Returns |FALSE| when `:setf FALLBACK` was used.
2205 When editing another file, the counter is reset, thus this
2206 really checks if the FileType event has been triggered for the
2207 current buffer. This allows an autocommand that starts
2208 editing another buffer to set 'filetype' and load a syntax
2209 file.
2210
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002211 Return type: |Number|
2212
2213
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002214diff({fromlist}, {tolist} [, {options}]) *diff()*
2215 Returns a String or a List containing the diff between the
2216 strings in {fromlist} and {tolist}. Uses the Vim internal
2217 diff library to compute the diff.
2218
2219 *E106*
2220 The optional "output" item in {options} specifies the returned
2221 diff format. The following values are supported:
2222 indices Return a List of the starting and ending
2223 indices and a count of the strings in each
2224 diff hunk.
2225 unified Return the unified diff output as a String.
2226 This is the default.
2227
2228 If the "output" item in {options} is "indices", then a List is
2229 returned. Each List item contains a Dict with the following
2230 items for each diff hunk:
2231 from_idx start index in {fromlist} for this diff hunk.
2232 from_count number of strings in {fromlist} that are
2233 added/removed/modified in this diff hunk.
2234 to_idx start index in {tolist} for this diff hunk.
2235 to_count number of strings in {tolist} that are
2236 added/removed/modified in this diff hunk.
2237
2238 The {options} Dict argument also specifies diff options
2239 (similar to 'diffopt') and supports the following items:
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002240 algorithm Dict specifying the diff algorithm to
2241 use. Supported boolean items are
2242 "myers", "minimal", "patience" and
2243 "histogram".
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002244 context diff context length. Default is 0.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002245 iblank ignore changes where lines are all
2246 blank.
2247 icase ignore changes in case of text.
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002248 indent-heuristic use the indent heuristic for the
2249 internal diff library.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002250 iwhite ignore changes in amount of white
2251 space.
2252 iwhiteall ignore all white space changes.
2253 iwhiteeol ignore white space changes at end of
2254 line.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002255 For more information about these options, refer to 'diffopt'.
2256
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002257 To compute the unified diff, all the items in {fromlist} are
2258 concatenated into a string using a newline separator and the
2259 same for {tolist}. The unified diff output uses line numbers.
2260
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002261 Returns an empty List or String if {fromlist} and {tolist} are
2262 identical.
2263
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002264 Examples: >
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002265 :echo diff(['abc'], ['xxx'])
2266 @@ -1 +1 @@
2267 -abc
2268 +xxx
2269
2270 :echo diff(['abc'], ['xxx'], {'output': 'indices'})
2271 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}]
2272 :echo diff(readfile('oldfile'), readfile('newfile'))
2273 :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$'))
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002274<
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002275 For more examples, refer to |diff-func-examples|
2276
2277 Can also be used as a |method|: >
2278 GetFromList->diff(to_list)
2279<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002280 Return type: |String| or list<dict<number>> or list<any>
2281 depending on {options}
2282
2283
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002284diff_filler({lnum}) *diff_filler()*
2285 Returns the number of filler lines above line {lnum}.
2286 These are the lines that were inserted at this point in
2287 another diff'ed window. These filler lines are shown in the
2288 display but don't exist in the buffer.
2289 {lnum} is used like with |getline()|. Thus "." is the current
2290 line, "'m" mark m, etc.
2291 Returns 0 if the current window is not in diff mode.
2292
2293 Can also be used as a |method|: >
2294 GetLnum()->diff_filler()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002295<
2296 Return type: |Number|
2297
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002298
2299diff_hlID({lnum}, {col}) *diff_hlID()*
2300 Returns the highlight ID for diff mode at line {lnum} column
2301 {col} (byte index). When the current line does not have a
2302 diff change zero is returned.
2303 {lnum} is used like with |getline()|. Thus "." is the current
2304 line, "'m" mark m, etc.
2305 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2306 line.
2307 The highlight ID can be used with |synIDattr()| to obtain
2308 syntax information about the highlighting.
2309
2310 Can also be used as a |method|: >
2311 GetLnum()->diff_hlID(col)
2312<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002313 Return type: |Number|
2314
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002315
2316digraph_get({chars}) *digraph_get()* *E1214*
2317 Return the digraph of {chars}. This should be a string with
2318 exactly two characters. If {chars} are not just two
2319 characters, or the digraph of {chars} does not exist, an error
2320 is given and an empty string is returned.
2321
2322 The character will be converted from Unicode to 'encoding'
2323 when needed. This does require the conversion to be
2324 available, it might fail.
2325
2326 Also see |digraph_getlist()|.
2327
2328 Examples: >
2329 " Get a built-in digraph
2330 :echo digraph_get('00') " Returns '∞'
2331
2332 " Get a user-defined digraph
2333 :call digraph_set('aa', 'あ')
2334 :echo digraph_get('aa') " Returns 'あ'
2335<
2336 Can also be used as a |method|: >
2337 GetChars()->digraph_get()
2338<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002339 Return type: |String|
2340
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002341 This function works only when compiled with the |+digraphs|
2342 feature. If this feature is disabled, this function will
2343 display an error message.
2344
2345
2346digraph_getlist([{listall}]) *digraph_getlist()*
2347 Return a list of digraphs. If the {listall} argument is given
2348 and it is TRUE, return all digraphs, including the default
2349 digraphs. Otherwise, return only user-defined digraphs.
2350
2351 The characters will be converted from Unicode to 'encoding'
2352 when needed. This does require the conservation to be
2353 available, it might fail.
2354
2355 Also see |digraph_get()|.
2356
2357 Examples: >
2358 " Get user-defined digraphs
2359 :echo digraph_getlist()
2360
2361 " Get all the digraphs, including default digraphs
2362 :echo digraph_getlist(1)
2363<
2364 Can also be used as a |method|: >
2365 GetNumber()->digraph_getlist()
2366<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002367 Return type: list<list<string>>
2368
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002369 This function works only when compiled with the |+digraphs|
2370 feature. If this feature is disabled, this function will
2371 display an error message.
2372
2373
Bram Moolenaara2baa732022-02-04 16:09:54 +00002374digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002375 Add digraph {chars} to the list. {chars} must be a string
2376 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002377 encoded character. *E1215*
2378 Be careful, composing characters are NOT ignored. This
2379 function is similar to |:digraphs| command, but useful to add
2380 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002381
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002382 The function returns v:true if |digraph| is registered. If
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002383 this fails an error message is given and v:false is returned.
2384
2385 If you want to define multiple digraphs at once, you can use
2386 |digraph_setlist()|.
2387
2388 Example: >
2389 call digraph_set(' ', 'あ')
2390<
2391 Can be used as a |method|: >
2392 GetString()->digraph_set('あ')
2393<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002394 Return type: |vim9-boolean|
2395
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002396 This function works only when compiled with the |+digraphs|
2397 feature. If this feature is disabled, this function will
2398 display an error message.
2399
2400
2401digraph_setlist({digraphlist}) *digraph_setlist()*
2402 Similar to |digraph_set()| but this function can add multiple
2403 digraphs at once. {digraphlist} is a list composed of lists,
2404 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002405 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002406 Example: >
2407 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2408<
2409 It is similar to the following: >
2410 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2411 call digraph_set(chars, digraph)
2412 endfor
2413< Except that the function returns after the first error,
2414 following digraphs will not be added.
2415
2416 Can be used as a |method|: >
2417 GetList()->digraph_setlist()
2418<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002419 Return type: |vim9-boolean|
2420
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002421 This function works only when compiled with the |+digraphs|
2422 feature. If this feature is disabled, this function will
2423 display an error message.
2424
2425
2426echoraw({string}) *echoraw()*
2427 Output {string} as-is, including unprintable characters.
2428 This can be used to output a terminal code. For example, to
2429 disable modifyOtherKeys: >
2430 call echoraw(&t_TE)
2431< and to enable it again: >
2432 call echoraw(&t_TI)
2433< Use with care, you can mess up the terminal this way.
2434
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002435 Return type: |Number|
2436
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002437
2438empty({expr}) *empty()*
2439 Return the Number 1 if {expr} is empty, zero otherwise.
2440 - A |List| or |Dictionary| is empty when it does not have any
2441 items.
2442 - A |String| is empty when its length is zero.
2443 - A |Number| and |Float| are empty when their value is zero.
2444 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2445 - A |Job| is empty when it failed to start.
2446 - A |Channel| is empty when it is closed.
2447 - A |Blob| is empty when its length is zero.
mityu7f0bba22024-03-29 10:14:41 +01002448 - An |Object| is empty, when the empty() method in the object
2449 (if present) returns true. |object-empty()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002450
2451 For a long |List| this is much faster than comparing the
2452 length with zero.
2453
2454 Can also be used as a |method|: >
2455 mylist->empty()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002456<
2457 Return type: |Number|
2458
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002459
2460environ() *environ()*
2461 Return all of environment variables as dictionary. You can
2462 check if an environment variable exists like this: >
2463 :echo has_key(environ(), 'HOME')
2464< Note that the variable name may be CamelCase; to ignore case
2465 use this: >
2466 :echo index(keys(environ()), 'HOME', 0, 1) != -1
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002467<
2468 Return type: dict<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002469
Bram Moolenaar416bd912023-07-07 23:19:18 +01002470
2471err_teapot([{expr}]) *err_teapot()*
2472 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002473 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002474 If {expr} is present and it is TRUE error 503 is given,
2475 indicating that coffee is temporarily not available.
2476 If {expr} is present it must be a String.
2477
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002478 Return type: |Number|
2479
Bram Moolenaar416bd912023-07-07 23:19:18 +01002480
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002481escape({string}, {chars}) *escape()*
2482 Escape the characters in {chars} that occur in {string} with a
2483 backslash. Example: >
2484 :echo escape('c:\program files\vim', ' \')
2485< results in: >
2486 c:\\program\ files\\vim
2487< Also see |shellescape()| and |fnameescape()|.
2488
2489 Can also be used as a |method|: >
2490 GetText()->escape(' \')
2491<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002492 Return type: |String|
2493
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002494 *eval()*
2495eval({string}) Evaluate {string} and return the result. Especially useful to
2496 turn the result of |string()| back into the original value.
2497 This works for Numbers, Floats, Strings, Blobs and composites
2498 of them. Also works for |Funcref|s that refer to existing
Aliaksei Budavei95740222024-04-04 23:05:33 +03002499 functions. In |Vim9| script, it can be used to obtain |enum|
2500 values from their fully qualified names.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002501
2502 Can also be used as a |method|: >
2503 argv->join()->eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002504<
2505 Return type: any, depending on {string}
2506
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002507
2508eventhandler() *eventhandler()*
2509 Returns 1 when inside an event handler. That is that Vim got
2510 interrupted while waiting for the user to type a character,
2511 e.g., when dropping a file on Vim. This means interactive
2512 commands cannot be used. Otherwise zero is returned.
2513
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002514 Return type: |Number|
2515
2516
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002517executable({expr}) *executable()*
2518 This function checks if an executable with the name {expr}
2519 exists. {expr} must be the name of the program without any
2520 arguments.
2521 executable() uses the value of $PATH and/or the normal
2522 searchpath for programs. *PATHEXT*
2523 On MS-Windows the ".exe", ".bat", etc. can optionally be
2524 included. Then the extensions in $PATHEXT are tried. Thus if
2525 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2526 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2527 by itself can be used in $PATHEXT to try using the name
2528 without an extension. When 'shell' looks like a Unix shell,
2529 then the name is also tried without adding an extension.
2530 On MS-Windows it only checks if the file exists and is not a
2531 directory, not if it's really executable.
2532 On MS-Windows an executable in the same directory as Vim is
Yasuhiro Matsumoto05cf63e2022-05-03 11:02:28 +01002533 normally found. Since this directory is added to $PATH it
2534 should also work to execute it |win32-PATH|. This can be
2535 disabled by setting the $NoDefaultCurrentDirectoryInExePath
2536 environment variable. *NoDefaultCurrentDirectoryInExePath*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002537 The result is a Number:
2538 1 exists
2539 0 does not exist
2540 -1 not implemented on this system
2541 |exepath()| can be used to get the full path of an executable.
2542
2543 Can also be used as a |method|: >
2544 GetCommand()->executable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002545<
2546 Return type: |Number|
2547
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002548
2549execute({command} [, {silent}]) *execute()*
2550 Execute an Ex command or commands and return the output as a
2551 string.
2552 {command} can be a string or a List. In case of a List the
2553 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002554 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002555 redir => var
2556 {command}
2557 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002558< Except that line continuation in {command} is not recognized.
2559
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002560 The optional {silent} argument can have these values:
2561 "" no `:silent` used
2562 "silent" `:silent` used
2563 "silent!" `:silent!` used
2564 The default is "silent". Note that with "silent!", unlike
2565 `:redir`, error messages are dropped. When using an external
2566 command the screen may be messed up, use `system()` instead.
2567 *E930*
2568 It is not possible to use `:redir` anywhere in {command}.
2569
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002570 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002571 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002572
2573< To execute a command in another window than the current one
2574 use `win_execute()`.
2575
2576 When used recursively the output of the recursive call is not
2577 included in the output of the higher level call.
2578
2579 Can also be used as a |method|: >
2580 GetCommand()->execute()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002581<
2582 Return type: |Number|
2583
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002584
2585exepath({expr}) *exepath()*
2586 If {expr} is an executable and is either an absolute path, a
2587 relative path or found in $PATH, return the full path.
2588 Note that the current directory is used when {expr} starts
2589 with "./", which may be a problem for Vim: >
2590 echo exepath(v:progpath)
2591< If {expr} cannot be found in $PATH or is not executable then
2592 an empty string is returned.
2593
2594 Can also be used as a |method|: >
2595 GetCommand()->exepath()
2596<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002597 Return type: |String|
2598
2599
2600exists({expr}) *exists()*
2601 The result is a Number, which is |TRUE| if {expr} is defined,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002602 zero otherwise.
2603
2604 Note: In a compiled |:def| function the evaluation is done at
2605 runtime. Use `exists_compiled()` to evaluate the expression
2606 at compile time.
2607
2608 For checking for a supported feature use |has()|.
2609 For checking if a file exists use |filereadable()|.
2610
2611 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002612 varname internal variable (see
2613 dict.key |internal-variables|). Also works
2614 list[i] for |curly-braces-names|, |Dictionary|
Yegappan Lakshmanana2ebb6e2024-02-25 08:40:10 +01002615 import.Func entries, |List| items, class and
2616 class.Func object methods, imported items, etc.
2617 object.Func Does not work for local variables in a
2618 class.varname compiled `:def` function.
2619 object.varname Also works for a function in |Vim9|
Bram Moolenaar944697a2022-02-20 19:48:20 +00002620 script, since it can be used as a
2621 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002622 Beware that evaluating an index may
2623 cause an error message for an invalid
2624 expression. E.g.: >
2625 :let l = [1, 2, 3]
2626 :echo exists("l[5]")
2627< 0 >
2628 :echo exists("l[xx]")
2629< E121: Undefined variable: xx
2630 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002631 &option-name Vim option (only checks if it exists,
2632 not if it really works)
2633 +option-name Vim option that works.
2634 $ENVNAME environment variable (could also be
2635 done by comparing with an empty
2636 string)
2637 *funcname built-in function (see |functions|)
2638 or user defined function (see
2639 |user-functions|) that is implemented.
2640 Also works for a variable that is a
2641 Funcref.
2642 ?funcname built-in function that could be
2643 implemented; to be used to check if
2644 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002645 :cmdname Ex command: built-in command, user
2646 command or command modifier |:command|.
2647 Returns:
2648 1 for match with start of a command
2649 2 full match with a command
2650 3 matches several user commands
2651 To check for a supported command
2652 always check the return value to be 2.
2653 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002654 :3match The |:3match| command (but you
2655 probably should not use it, it is
2656 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002657 #event autocommand defined for this event
2658 #event#pattern autocommand defined for this event and
2659 pattern (the pattern is taken
2660 literally and compared to the
2661 autocommand patterns character by
2662 character)
2663 #group autocommand group exists
2664 #group#event autocommand defined for this group and
2665 event.
2666 #group#event#pattern
2667 autocommand defined for this group,
2668 event and pattern.
2669 ##event autocommand for this event is
2670 supported.
2671
2672 Examples: >
2673 exists("&shortname")
2674 exists("$HOSTNAME")
2675 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002676 exists("*s:MyFunc") " only for legacy script
2677 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002678 exists("bufcount")
2679 exists(":Make")
2680 exists("#CursorHold")
2681 exists("#BufReadPre#*.gz")
2682 exists("#filetypeindent")
2683 exists("#filetypeindent#FileType")
2684 exists("#filetypeindent#FileType#*")
2685 exists("##ColorScheme")
2686< There must be no space between the symbol (&/$/*/#) and the
2687 name.
2688 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002689 a few cases this is ignored. That may become stricter in the
2690 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002691 Working example: >
2692 exists(":make")
2693< NOT working example: >
2694 exists(":make install")
2695
2696< Note that the argument must be a string, not the name of the
2697 variable itself. For example: >
2698 exists(bufcount)
2699< This doesn't check for existence of the "bufcount" variable,
2700 but gets the value of "bufcount", and checks if that exists.
2701
2702 Can also be used as a |method|: >
2703 Varname()->exists()
2704<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002705 Return type: |String|
2706
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002707
2708exists_compiled({expr}) *exists_compiled()*
2709 Like `exists()` but evaluated at compile time. This is useful
2710 to skip a block where a function is used that would otherwise
2711 give an error: >
2712 if exists_compiled('*ThatFunction')
2713 ThatFunction('works')
2714 endif
2715< If `exists()` were used then a compilation error would be
2716 given if ThatFunction() is not defined.
2717
2718 {expr} must be a literal string. *E1232*
2719 Can only be used in a |:def| function. *E1233*
2720 This does not work to check for arguments or local variables.
2721
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002722 Return type: |String|
2723
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002724
2725exp({expr}) *exp()*
2726 Return the exponential of {expr} as a |Float| in the range
2727 [0, inf].
2728 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002729 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002730 Examples: >
2731 :echo exp(2)
2732< 7.389056 >
2733 :echo exp(-1)
2734< 0.367879
2735
2736 Can also be used as a |method|: >
2737 Compute()->exp()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002738<
2739 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002740
2741
2742expand({string} [, {nosuf} [, {list}]]) *expand()*
2743 Expand wildcards and the following special keywords in
2744 {string}. 'wildignorecase' applies.
2745
2746 If {list} is given and it is |TRUE|, a List will be returned.
2747 Otherwise the result is a String and when there are several
2748 matches, they are separated by <NL> characters. [Note: in
2749 version 5.0 a space was used, which caused problems when a
2750 file name contains a space]
2751
2752 If the expansion fails, the result is an empty string. A name
2753 for a non-existing file is not included, unless {string} does
2754 not start with '%', '#' or '<', see below.
2755
Christian Brabandtec9c3262024-02-21 20:40:05 +01002756 For a |:terminal| window '%' expands to a '!' followed by
h-east53753f62024-05-05 18:42:31 +02002757 the command or shell that is run. |terminal-bufname|
Christian Brabandtec9c3262024-02-21 20:40:05 +01002758
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002759 When {string} starts with '%', '#' or '<', the expansion is
2760 done like for the |cmdline-special| variables with their
2761 associated modifiers. Here is a short overview:
2762
2763 % current file name
2764 # alternate file name
2765 #n alternate file name n
2766 <cfile> file name under the cursor
2767 <afile> autocmd file name
2768 <abuf> autocmd buffer number (as a String!)
2769 <amatch> autocmd matched name
2770 <cexpr> C expression under the cursor
2771 <sfile> sourced script file or function name
2772 <slnum> sourced script line number or function
2773 line number
2774 <sflnum> script file line number, also when in
2775 a function
2776 <SID> "<SNR>123_" where "123" is the
2777 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002778 <script> sourced script file, or script file
2779 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002780 <stack> call stack
2781 <cword> word under the cursor
2782 <cWORD> WORD under the cursor
2783 <client> the {clientid} of the last received
2784 message |server2client()|
2785 Modifiers:
2786 :p expand to full path
2787 :h head (last path component removed)
2788 :t tail (last path component only)
2789 :r root (one extension removed)
2790 :e extension only
2791
2792 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002793 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002794< Note that when expanding a string that starts with '%', '#' or
2795 '<', any following text is ignored. This does NOT work: >
2796 :let doesntwork = expand("%:h.bak")
2797< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002798 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002799< Also note that expanding "<cfile>" and others only returns the
2800 referenced file name without further expansion. If "<cfile>"
2801 is "~/.cshrc", you need to do another expand() to have the
2802 "~/" expanded into the path of the home directory: >
2803 :echo expand(expand("<cfile>"))
2804<
2805 There cannot be white space between the variables and the
2806 following modifier. The |fnamemodify()| function can be used
2807 to modify normal file names.
2808
2809 When using '%' or '#', and the current or alternate file name
2810 is not defined, an empty string is used. Using "%:p" in a
2811 buffer with no name, results in the current directory, with a
2812 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002813 When 'verbose' is set then expanding '%', '#' and <> items
2814 will result in an error message if the argument cannot be
2815 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002816
2817 When {string} does not start with '%', '#' or '<', it is
2818 expanded like a file name is expanded on the command line.
2819 'suffixes' and 'wildignore' are used, unless the optional
2820 {nosuf} argument is given and it is |TRUE|.
2821 Names for non-existing files are included. The "**" item can
2822 be used to search in a directory tree. For example, to find
2823 all "README" files in the current directory and below: >
2824 :echo expand("**/README")
2825<
2826 expand() can also be used to expand variables and environment
2827 variables that are only known in a shell. But this can be
2828 slow, because a shell may be used to do the expansion. See
2829 |expr-env-expand|.
2830 The expanded variable is still handled like a list of file
2831 names. When an environment variable cannot be expanded, it is
2832 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2833 "$FOOBAR".
2834
2835 See |glob()| for finding existing files. See |system()| for
2836 getting the raw output of an external command.
2837
2838 Can also be used as a |method|: >
2839 Getpattern()->expand()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002840<
2841 Return type: |String| or list<string> depending on {list}
2842
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002843
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002844expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002845 Expand special items in String {string} like what is done for
2846 an Ex command such as `:edit`. This expands special keywords,
2847 like with |expand()|, and environment variables, anywhere in
2848 {string}. "~user" and "~/path" are only expanded at the
2849 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002850
2851 The following items are supported in the {options} Dict
2852 argument:
2853 errmsg If set to TRUE, error messages are displayed
2854 if an error is encountered during expansion.
2855 By default, error messages are not displayed.
2856
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002857 Returns the expanded string. If an error is encountered
2858 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002859
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002860 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002861 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002862 make /path/runtime/doc/builtin.o
2863 :echo expandcmd('make %<.o', {'errmsg': v:true})
2864<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002865 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002866 GetCommand()->expandcmd()
2867<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002868 Return type: |String| or list<string> depending on {list}
2869
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002870extend({expr1}, {expr2} [, {expr3}]) *extend()*
2871 {expr1} and {expr2} must be both |Lists| or both
2872 |Dictionaries|.
2873
2874 If they are |Lists|: Append {expr2} to {expr1}.
2875 If {expr3} is given insert the items of {expr2} before the
2876 item with index {expr3} in {expr1}. When {expr3} is zero
2877 insert before the first item. When {expr3} is equal to
2878 len({expr1}) then {expr2} is appended.
2879 Examples: >
2880 :echo sort(extend(mylist, [7, 5]))
2881 :call extend(mylist, [2, 3], 1)
2882< When {expr1} is the same List as {expr2} then the number of
2883 items copied is equal to the original length of the List.
2884 E.g., when {expr3} is 1 you get N new copies of the first item
2885 (where N is the original length of the List).
2886 Use |add()| to concatenate one item to a list. To concatenate
2887 two lists into a new list use the + operator: >
2888 :let newlist = [1, 2, 3] + [4, 5]
2889<
2890 If they are |Dictionaries|:
2891 Add all entries from {expr2} to {expr1}.
2892 If a key exists in both {expr1} and {expr2} then {expr3} is
2893 used to decide what to do:
2894 {expr3} = "keep": keep the value of {expr1}
2895 {expr3} = "force": use the value of {expr2}
2896 {expr3} = "error": give an error message *E737*
2897 When {expr3} is omitted then "force" is assumed.
2898
2899 {expr1} is changed when {expr2} is not empty. If necessary
2900 make a copy of {expr1} first.
2901 {expr2} remains unchanged.
2902 When {expr1} is locked and {expr2} is not empty the operation
2903 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002904 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002905
2906 Can also be used as a |method|: >
2907 mylist->extend(otherlist)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002908<
2909 Return type: list<{type}> or dict<{type}> depending on {expr1}
2910 and {expr2}, in case of error: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002911
2912
2913extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
2914 Like |extend()| but instead of adding items to {expr1} a new
2915 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00002916 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002917
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002918 Return type: list<{type}> or dict<{type}> depending on {expr1}
2919 and {expr2}, in case of error: |Number|
2920
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002921
2922feedkeys({string} [, {mode}]) *feedkeys()*
2923 Characters in {string} are queued for processing as if they
2924 come from a mapping or were typed by the user.
2925
2926 By default the string is added to the end of the typeahead
2927 buffer, thus if a mapping is still being executed the
2928 characters come after them. Use the 'i' flag to insert before
2929 other characters, they will be executed next, before any
2930 characters from a mapping.
2931
2932 The function does not wait for processing of keys contained in
2933 {string}.
2934
2935 To include special keys into {string}, use double-quotes
2936 and "\..." notation |expr-quote|. For example,
2937 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
2938 feedkeys('\<CR>') pushes 5 characters.
2939 A special code that might be useful is <Ignore>, it exits the
2940 wait for a character without doing anything. *<Ignore>*
2941
2942 {mode} is a String, which can contain these character flags:
2943 'm' Remap keys. This is default. If {mode} is absent,
2944 keys are remapped.
2945 'n' Do not remap keys.
2946 't' Handle keys as if typed; otherwise they are handled as
2947 if coming from a mapping. This matters for undo,
2948 opening folds, etc.
2949 'L' Lowlevel input. Only works for Unix or when using the
2950 GUI. Keys are used as if they were coming from the
2951 terminal. Other flags are not used. *E980*
2952 When a CTRL-C interrupts and 't' is included it sets
2953 the internal "got_int" flag.
2954 'i' Insert the string instead of appending (see above).
2955 'x' Execute commands until typeahead is empty. This is
2956 similar to using ":normal!". You can call feedkeys()
2957 several times without 'x' and then one time with 'x'
2958 (possibly with an empty {string}) to execute all the
2959 typeahead. Note that when Vim ends in Insert mode it
2960 will behave as if <Esc> is typed, to avoid getting
2961 stuck, waiting for a character to be typed before the
2962 script continues.
2963 Note that if you manage to call feedkeys() while
2964 executing commands, thus calling it recursively, then
2965 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00002966 'c' Remove any script context when executing, so that
2967 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01002968 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01002969 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002970 '!' When used with 'x' will not end Insert mode. Can be
2971 used in a test when a timer is set to exit Insert mode
2972 a little later. Useful for testing CursorHoldI.
2973
2974 Return value is always 0.
2975
2976 Can also be used as a |method|: >
2977 GetInput()->feedkeys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002978<
2979 Return type: |String| or list<string> depending on {list}
2980
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002981
Shougo Matsushita60c87432024-06-03 22:59:27 +02002982filecopy({from}, {to}) *filecopy()*
2983 Copy the file pointed to by the name {from} to {to}. The
2984 result is a Number, which is |TRUE| if the file was copied
2985 successfully, and |FALSE| when it failed.
2986 If a file with name {to} already exists, it will fail.
2987 Note that it does not handle directories (yet).
2988
2989 This function is not available in the |sandbox|.
2990
2991 Can also be used as a |method|: >
2992 GetOldName()->filecopy(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002993<
2994 Return type: |Number|
2995
Shougo Matsushita60c87432024-06-03 22:59:27 +02002996
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002997filereadable({file}) *filereadable()*
2998 The result is a Number, which is |TRUE| when a file with the
2999 name {file} exists, and can be read. If {file} doesn't exist,
3000 or is a directory, the result is |FALSE|. {file} is any
3001 expression, which is used as a String.
3002 If you don't care about the file being readable you can use
3003 |glob()|.
3004 {file} is used as-is, you may want to expand wildcards first: >
3005 echo filereadable('~/.vimrc')
3006 0
3007 echo filereadable(expand('~/.vimrc'))
3008 1
3009
3010< Can also be used as a |method|: >
3011 GetName()->filereadable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003012<
3013 Return type: |Number|
3014
3015 *file_readable()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003016 Obsolete name: file_readable().
3017
3018
3019filewritable({file}) *filewritable()*
3020 The result is a Number, which is 1 when a file with the
3021 name {file} exists, and can be written. If {file} doesn't
3022 exist, or is not writable, the result is 0. If {file} is a
3023 directory, and we can write to it, the result is 2.
3024
3025 Can also be used as a |method|: >
3026 GetName()->filewritable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003027<
3028 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003029
3030
3031filter({expr1}, {expr2}) *filter()*
3032 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3033 For each item in {expr1} evaluate {expr2} and when the result
3034 is zero or false remove the item from the |List| or
3035 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003036 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003037
3038 {expr2} must be a |string| or |Funcref|.
3039
3040 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3041 of the current item. For a |Dictionary| |v:key| has the key
3042 of the current item and for a |List| |v:key| has the index of
3043 the current item. For a |Blob| |v:key| has the index of the
3044 current byte. For a |String| |v:key| has the index of the
3045 current character.
3046 Examples: >
3047 call filter(mylist, 'v:val !~ "OLD"')
3048< Removes the items where "OLD" appears. >
3049 call filter(mydict, 'v:key >= 8')
3050< Removes the items with a key below 8. >
3051 call filter(var, 0)
3052< Removes all the items, thus clears the |List| or |Dictionary|.
3053
3054 Note that {expr2} is the result of expression and is then
3055 used as an expression again. Often it is good to use a
3056 |literal-string| to avoid having to double backslashes.
3057
3058 If {expr2} is a |Funcref| it must take two arguments:
3059 1. the key or the index of the current item.
3060 2. the value of the current item.
3061 The function must return |TRUE| if the item should be kept.
3062 Example that keeps the odd items of a list: >
3063 func Odd(idx, val)
3064 return a:idx % 2 == 1
3065 endfunc
3066 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003067< It is shorter when using a |lambda|. In |Vim9| syntax: >
3068 call filter(myList, (idx, val) => idx * val <= 42)
3069< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003070 call filter(myList, {idx, val -> idx * val <= 42})
3071< If you do not use "val" you can leave it out: >
3072 call filter(myList, {idx -> idx % 2 == 1})
3073<
3074 In |Vim9| script the result must be true, false, zero or one.
3075 Other values will result in a type error.
3076
3077 For a |List| and a |Dictionary| the operation is done
3078 in-place. If you want it to remain unmodified make a copy
3079 first: >
3080 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
3081
3082< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00003083 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003084 When an error is encountered while evaluating {expr2} no
3085 further items in {expr1} are processed.
3086 When {expr2} is a Funcref errors inside a function are ignored,
3087 unless it was defined with the "abort" flag.
3088
3089 Can also be used as a |method|: >
3090 mylist->filter(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003091<
3092 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
3093 depending on {expr1}
3094
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003095
3096finddir({name} [, {path} [, {count}]]) *finddir()*
3097 Find directory {name} in {path}. Supports both downwards and
3098 upwards recursive directory searches. See |file-searching|
3099 for the syntax of {path}.
3100
3101 Returns the path of the first found match. When the found
3102 directory is below the current directory a relative path is
3103 returned. Otherwise a full path is returned.
3104 If {path} is omitted or empty then 'path' is used.
3105
3106 If the optional {count} is given, find {count}'s occurrence of
3107 {name} in {path} instead of the first one.
3108 When {count} is negative return all the matches in a |List|.
3109
Bram Moolenaar016188f2022-06-06 20:52:59 +01003110 Returns an empty string if the directory is not found.
3111
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003112 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003113
3114 Can also be used as a |method|: >
3115 GetName()->finddir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003116<
3117 Return type: |String|
3118
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003119
3120findfile({name} [, {path} [, {count}]]) *findfile()*
3121 Just like |finddir()|, but find a file instead of a directory.
3122 Uses 'suffixesadd'.
3123 Example: >
3124 :echo findfile("tags.vim", ".;")
3125< Searches from the directory of the current file upwards until
3126 it finds the file "tags.vim".
3127
3128 Can also be used as a |method|: >
3129 GetName()->findfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003130<
3131 Return type: |String|
3132
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003133
3134flatten({list} [, {maxdepth}]) *flatten()*
3135 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
3136 the result is a |List| without nesting, as if {maxdepth} is
3137 a very large number.
3138 The {list} is changed in place, use |flattennew()| if you do
3139 not want that.
3140 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00003141 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003142 *E900*
3143 {maxdepth} means how deep in nested lists changes are made.
3144 {list} is not modified when {maxdepth} is 0.
3145 {maxdepth} must be positive number.
3146
3147 If there is an error the number zero is returned.
3148
3149 Example: >
3150 :echo flatten([1, [2, [3, 4]], 5])
3151< [1, 2, 3, 4, 5] >
3152 :echo flatten([1, [2, [3, 4]], 5], 1)
3153< [1, 2, [3, 4], 5]
3154
3155 Can also be used as a |method|: >
3156 mylist->flatten()
3157<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003158 Return type: list<{type}>
3159
3160
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003161flattennew({list} [, {maxdepth}]) *flattennew()*
3162 Like |flatten()| but first make a copy of {list}.
3163
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003164 Return type: list<{type}>
3165
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003166
3167float2nr({expr}) *float2nr()*
3168 Convert {expr} to a Number by omitting the part after the
3169 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00003170 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003171 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003172 When the value of {expr} is out of range for a |Number| the
3173 result is truncated to 0x7fffffff or -0x7fffffff (or when
3174 64-bit Number support is enabled, 0x7fffffffffffffff or
3175 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
3176 64-bit Number support is enabled, -0x8000000000000000).
3177 Examples: >
3178 echo float2nr(3.95)
3179< 3 >
3180 echo float2nr(-23.45)
3181< -23 >
3182 echo float2nr(1.0e100)
3183< 2147483647 (or 9223372036854775807) >
3184 echo float2nr(-1.0e150)
3185< -2147483647 (or -9223372036854775807) >
3186 echo float2nr(1.0e-100)
3187< 0
3188
3189 Can also be used as a |method|: >
3190 Compute()->float2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003191<
3192 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003193
3194
3195floor({expr}) *floor()*
3196 Return the largest integral value less than or equal to
3197 {expr} as a |Float| (round down).
3198 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003199 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003200 Examples: >
3201 echo floor(1.856)
3202< 1.0 >
3203 echo floor(-5.456)
3204< -6.0 >
3205 echo floor(4.0)
3206< 4.0
3207
3208 Can also be used as a |method|: >
3209 Compute()->floor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003210<
3211 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003212
3213
3214fmod({expr1}, {expr2}) *fmod()*
3215 Return the remainder of {expr1} / {expr2}, even if the
3216 division is not representable. Returns {expr1} - i * {expr2}
3217 for some integer i such that if {expr2} is non-zero, the
3218 result has the same sign as {expr1} and magnitude less than
3219 the magnitude of {expr2}. If {expr2} is zero, the value
3220 returned is zero. The value returned is a |Float|.
3221 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003222 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
3223 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003224 Examples: >
3225 :echo fmod(12.33, 1.22)
3226< 0.13 >
3227 :echo fmod(-12.33, 1.22)
3228< -0.13
3229
3230 Can also be used as a |method|: >
3231 Compute()->fmod(1.22)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003232<
3233 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003234
3235
3236fnameescape({string}) *fnameescape()*
3237 Escape {string} for use as file name command argument. All
3238 characters that have a special meaning, such as '%' and '|'
3239 are escaped with a backslash.
3240 For most systems the characters escaped are
3241 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3242 appears in a filename, it depends on the value of 'isfname'.
3243 A leading '+' and '>' is also escaped (special after |:edit|
3244 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01003245 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003246 Example: >
3247 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003248 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003249< results in executing: >
3250 edit \+some\ str\%nge\|name
3251<
3252 Can also be used as a |method|: >
3253 GetName()->fnameescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003254<
3255 Return type: |String|
3256
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003257
3258fnamemodify({fname}, {mods}) *fnamemodify()*
3259 Modify file name {fname} according to {mods}. {mods} is a
3260 string of characters like it is used for file names on the
3261 command line. See |filename-modifiers|.
3262 Example: >
3263 :echo fnamemodify("main.c", ":p:h")
3264< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01003265 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01003266< If {mods} is empty or an unsupported modifier is used then
3267 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01003268 When {fname} is empty then with {mods} ":h" returns ".", so
3269 that `:cd` can be used with it. This is different from
3270 expand('%:h') without a buffer name, which returns an empty
3271 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003272 Note: Environment variables don't work in {fname}, use
3273 |expand()| first then.
3274
3275 Can also be used as a |method|: >
3276 GetName()->fnamemodify(':p:h')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003277<
3278 Return type: |String|
3279
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003280
3281foldclosed({lnum}) *foldclosed()*
3282 The result is a Number. If the line {lnum} is in a closed
3283 fold, the result is the number of the first line in that fold.
3284 If the line {lnum} is not in a closed fold, -1 is returned.
3285 {lnum} is used like with |getline()|. Thus "." is the current
3286 line, "'m" mark m, etc.
3287
3288 Can also be used as a |method|: >
3289 GetLnum()->foldclosed()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003290<
3291 Return type: |Number|
3292
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003293
3294foldclosedend({lnum}) *foldclosedend()*
3295 The result is a Number. If the line {lnum} is in a closed
3296 fold, the result is the number of the last line in that fold.
3297 If the line {lnum} is not in a closed fold, -1 is returned.
3298 {lnum} is used like with |getline()|. Thus "." is the current
3299 line, "'m" mark m, etc.
3300
3301 Can also be used as a |method|: >
3302 GetLnum()->foldclosedend()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003303<
3304 Return type: |Number|
3305
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003306
3307foldlevel({lnum}) *foldlevel()*
3308 The result is a Number, which is the foldlevel of line {lnum}
3309 in the current buffer. For nested folds the deepest level is
3310 returned. If there is no fold at line {lnum}, zero is
3311 returned. It doesn't matter if the folds are open or closed.
3312 When used while updating folds (from 'foldexpr') -1 is
3313 returned for lines where folds are still to be updated and the
3314 foldlevel is unknown. As a special case the level of the
3315 previous line is usually available.
3316 {lnum} is used like with |getline()|. Thus "." is the current
3317 line, "'m" mark m, etc.
3318
3319 Can also be used as a |method|: >
3320 GetLnum()->foldlevel()
3321<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003322 Return type: |Number|
3323
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003324 *foldtext()*
3325foldtext() Returns a String, to be displayed for a closed fold. This is
3326 the default function used for the 'foldtext' option and should
3327 only be called from evaluating 'foldtext'. It uses the
3328 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3329 The returned string looks like this: >
3330 +-- 45 lines: abcdef
3331< The number of leading dashes depends on the foldlevel. The
3332 "45" is the number of lines in the fold. "abcdef" is the text
3333 in the first non-blank line of the fold. Leading white space,
3334 "//" or "/*" and the text from the 'foldmarker' and
3335 'commentstring' options is removed.
3336 When used to draw the actual foldtext, the rest of the line
3337 will be filled with the fold char from the 'fillchars'
3338 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003339 Returns an empty string when there is no fold.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003340
3341 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003342 {not available when compiled without the |+folding| feature}
3343
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003344
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003345foldtextresult({lnum}) *foldtextresult()*
3346 Returns the text that is displayed for the closed fold at line
3347 {lnum}. Evaluates 'foldtext' in the appropriate context.
3348 When there is no closed fold at {lnum} an empty string is
3349 returned.
3350 {lnum} is used like with |getline()|. Thus "." is the current
3351 line, "'m" mark m, etc.
3352 Useful when exporting folded text, e.g., to HTML.
3353 {not available when compiled without the |+folding| feature}
3354
3355
3356 Can also be used as a |method|: >
3357 GetLnum()->foldtextresult()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003358<
3359 Return type: |String|
3360
Ernie Raele79e2072024-01-13 11:47:33 +01003361
3362foreach({expr1}, {expr2}) *foreach()*
3363 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3364 For each item in {expr1} execute {expr2}. {expr1} is not
erraelc92b8be2024-01-14 10:11:07 -08003365 modified; its values may be, as with |:lockvar| 1. |E741|
Ernie Raele79e2072024-01-13 11:47:33 +01003366 See |map()| and |filter()| to modify {expr1}.
3367
3368 {expr2} must be a |string| or |Funcref|.
3369
3370 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3371 of the current item. For a |Dictionary| |v:key| has the key
3372 of the current item and for a |List| |v:key| has the index of
3373 the current item. For a |Blob| |v:key| has the index of the
3374 current byte. For a |String| |v:key| has the index of the
3375 current character.
3376 Examples: >
3377 call foreach(mylist, 'used[v:val] = true')
3378< This records the items that are in the {expr1} list.
3379
3380 Note that {expr2} is the result of expression and is then used
3381 as a command. Often it is good to use a |literal-string| to
3382 avoid having to double backslashes.
3383
3384 If {expr2} is a |Funcref| it must take two arguments:
3385 1. the key or the index of the current item.
3386 2. the value of the current item.
3387 With a legacy script lambda you don't get an error if it only
3388 accepts one argument, but with a Vim9 lambda you get "E1106:
3389 One argument too many", the number of arguments must match.
3390 If the function returns a value, it is ignored.
3391
3392 Returns {expr1} in all cases.
3393 When an error is encountered while executing {expr2} no
3394 further items in {expr1} are processed.
3395 When {expr2} is a Funcref errors inside a function are ignored,
3396 unless it was defined with the "abort" flag.
3397
3398 Can also be used as a |method|: >
3399 mylist->foreach(expr2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003400<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003401 Return type: |String|, |Blob| list<{type}> or dict<{type}>
3402 depending on {expr1}
3403
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003404 *foreground()*
3405foreground() Move the Vim window to the foreground. Useful when sent from
3406 a client to a Vim server. |remote_send()|
3407 On Win32 systems this might not work, the OS does not always
3408 allow a window to bring itself to the foreground. Use
3409 |remote_foreground()| instead.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003410
3411 Return type: |Number|
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003412 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003413 Win32 console version}
3414
Bram Moolenaaraa534142022-09-15 21:46:02 +01003415fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003416 Get the full command name from a short abbreviated command
3417 name; see |20.2| for details on command abbreviations.
3418
3419 The string argument {name} may start with a `:` and can
3420 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003421 Returns an empty string if a command doesn't exist, if it's
3422 ambiguous (for user-defined commands) or cannot be shortened
3423 this way. |vim9-no-shorten|
3424
3425 Without the {vim9} argument uses the current script version.
3426 If {vim9} is present and FALSE then legacy script rules are
3427 used. When {vim9} is present and TRUE then Vim9 rules are
3428 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003429
3430 For example `fullcommand('s')`, `fullcommand('sub')`,
3431 `fullcommand(':%substitute')` all return "substitute".
3432
3433 Can also be used as a |method|: >
3434 GetName()->fullcommand()
3435<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003436 Return type: |String|
3437
3438
3439funcref({name} [, {arglist}] [, {dict}]) *funcref()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003440 Just like |function()|, but the returned Funcref will lookup
3441 the function by reference, not by name. This matters when the
3442 function {name} is redefined later.
3443
3444 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003445 It only works for an autoloaded function if it has already
3446 been loaded (to avoid mistakenly loading the autoload script
3447 when only intending to use the function name, use |function()|
3448 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003449 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003450
3451 Can also be used as a |method|: >
3452 GetFuncname()->funcref([arg])
3453<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003454 Return type: func(...): any or |Number| on error
3455
Dominique Pellee764d1b2023-03-12 21:20:59 +00003456 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003457function({name} [, {arglist}] [, {dict}])
3458 Return a |Funcref| variable that refers to function {name}.
3459 {name} can be the name of a user defined function or an
3460 internal function.
3461
3462 {name} can also be a Funcref or a partial. When it is a
3463 partial the dict stored in it will be used and the {dict}
3464 argument is not allowed. E.g.: >
3465 let FuncWithArg = function(dict.Func, [arg])
3466 let Broken = function(dict.Func, [arg], dict)
3467<
3468 When using the Funcref the function will be found by {name},
3469 also when it was redefined later. Use |funcref()| to keep the
3470 same function.
3471
3472 When {arglist} or {dict} is present this creates a partial.
3473 That means the argument list and/or the dictionary is stored in
3474 the Funcref and will be used when the Funcref is called.
3475
3476 The arguments are passed to the function in front of other
3477 arguments, but after any argument from |method|. Example: >
3478 func Callback(arg1, arg2, name)
3479 ...
3480 let Partial = function('Callback', ['one', 'two'])
3481 ...
3482 call Partial('name')
3483< Invokes the function as with: >
3484 call Callback('one', 'two', 'name')
3485
3486< With a |method|: >
3487 func Callback(one, two, three)
3488 ...
3489 let Partial = function('Callback', ['two'])
3490 ...
3491 eval 'one'->Partial('three')
3492< Invokes the function as with: >
3493 call Callback('one', 'two', 'three')
3494
3495< The function() call can be nested to add more arguments to the
3496 Funcref. The extra arguments are appended to the list of
3497 arguments. Example: >
3498 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003499 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003500 let Func = function('Callback', ['one'])
3501 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003502 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003503 call Func2('name')
3504< Invokes the function as with: >
3505 call Callback('one', 'two', 'name')
3506
3507< The Dictionary is only useful when calling a "dict" function.
3508 In that case the {dict} is passed in as "self". Example: >
3509 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003510 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003511 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003512 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003513 let context = {"name": "example"}
3514 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003515 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003516 call Func() " will echo: called for example
3517< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003518 arguments, these two are equivalent, if Callback() is defined
3519 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003520 let Func = function('Callback', context)
3521 let Func = context.Callback
3522
3523< The argument list and the Dictionary can be combined: >
3524 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003525 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003526 let context = {"name": "example"}
3527 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003528 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003529 call Func(500)
3530< Invokes the function as with: >
3531 call context.Callback('one', 500)
3532<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003533 Returns 0 on error.
3534
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003535 Can also be used as a |method|: >
3536 GetFuncname()->function([arg])
3537
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003538<
3539 Return type: func(...): any or |Number| on error
3540
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003541
3542garbagecollect([{atexit}]) *garbagecollect()*
3543 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3544 that have circular references.
3545
3546 There is hardly ever a need to invoke this function, as it is
3547 automatically done when Vim runs out of memory or is waiting
3548 for the user to press a key after 'updatetime'. Items without
3549 circular references are always freed when they become unused.
3550 This is useful if you have deleted a very big |List| and/or
3551 |Dictionary| with circular references in a script that runs
3552 for a long time.
3553
3554 When the optional {atexit} argument is one, garbage
3555 collection will also be done when exiting Vim, if it wasn't
3556 done before. This is useful when checking for memory leaks.
3557
3558 The garbage collection is not done immediately but only when
3559 it's safe to perform. This is when waiting for the user to
3560 type a character. To force garbage collection immediately use
3561 |test_garbagecollect_now()|.
3562
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003563 Return type: |String|
3564
3565
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003566get({list}, {idx} [, {default}]) *get()*
3567 Get item {idx} from |List| {list}. When this item is not
3568 available return {default}. Return zero when {default} is
3569 omitted.
3570 Preferably used as a |method|: >
3571 mylist->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003572<
3573 Return type: any, depending on {list}
3574
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003575get({blob}, {idx} [, {default}])
3576 Get byte {idx} from |Blob| {blob}. When this byte is not
3577 available return {default}. Return -1 when {default} is
3578 omitted.
3579 Preferably used as a |method|: >
3580 myblob->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003581<
3582 Return type: |Number|
3583
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003584get({dict}, {key} [, {default}])
3585 Get item with key {key} from |Dictionary| {dict}. When this
3586 item is not available return {default}. Return zero when
3587 {default} is omitted. Useful example: >
3588 let val = get(g:, 'var_name', 'default')
3589< This gets the value of g:var_name if it exists, and uses
3590 'default' when it does not exist.
3591 Preferably used as a |method|: >
3592 mydict->get(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003593<
3594 Return type: any, depending on {list}
3595
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003596get({func}, {what})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00003597 Get item {what} from Funcref {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003598 {what} are:
3599 "name" The function name
3600 "func" The function
3601 "dict" The dictionary
3602 "args" The list with arguments
Bram Moolenaar016188f2022-06-06 20:52:59 +01003603 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003604 Preferably used as a |method|: >
3605 myfunc->get(what)
3606<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003607 Return type: any, depending on {func}
3608
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003609 *getbufinfo()*
3610getbufinfo([{buf}])
3611getbufinfo([{dict}])
3612 Get information about buffers as a List of Dictionaries.
3613
3614 Without an argument information about all the buffers is
3615 returned.
3616
3617 When the argument is a |Dictionary| only the buffers matching
3618 the specified criteria are returned. The following keys can
3619 be specified in {dict}:
3620 buflisted include only listed buffers.
3621 bufloaded include only loaded buffers.
3622 bufmodified include only modified buffers.
3623
3624 Otherwise, {buf} specifies a particular buffer to return
3625 information for. For the use of {buf}, see |bufname()|
3626 above. If the buffer is found the returned List has one item.
3627 Otherwise the result is an empty list.
3628
3629 Each returned List item is a dictionary with the following
3630 entries:
3631 bufnr Buffer number.
3632 changed TRUE if the buffer is modified.
3633 changedtick Number of changes made to the buffer.
Sean Dewar1fb41032023-08-16 17:15:05 +01003634 command TRUE if the buffer belongs to the
3635 command-line window |cmdwin|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003636 hidden TRUE if the buffer is hidden.
3637 lastused Timestamp in seconds, like
3638 |localtime()|, when the buffer was
3639 last used.
3640 {only with the |+viminfo| feature}
3641 listed TRUE if the buffer is listed.
3642 lnum Line number used for the buffer when
3643 opened in the current window.
3644 Only valid if the buffer has been
3645 displayed in the window in the past.
3646 If you want the line number of the
3647 last known cursor position in a given
3648 window, use |line()|: >
3649 :echo line('.', {winid})
3650<
3651 linecount Number of lines in the buffer (only
3652 valid when loaded)
3653 loaded TRUE if the buffer is loaded.
3654 name Full path to the file in the buffer.
3655 signs List of signs placed in the buffer.
3656 Each list item is a dictionary with
3657 the following fields:
3658 id sign identifier
3659 lnum line number
3660 name sign name
3661 variables A reference to the dictionary with
3662 buffer-local variables.
3663 windows List of |window-ID|s that display this
3664 buffer
3665 popups List of popup |window-ID|s that
3666 display this buffer
3667
3668 Examples: >
3669 for buf in getbufinfo()
3670 echo buf.name
3671 endfor
3672 for buf in getbufinfo({'buflisted':1})
3673 if buf.changed
3674 ....
3675 endif
3676 endfor
3677<
3678 To get buffer-local options use: >
3679 getbufvar({bufnr}, '&option_name')
3680<
3681 Can also be used as a |method|: >
3682 GetBufnr()->getbufinfo()
3683<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003684 Return type: list<dict<any>>
3685
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003686
3687 *getbufline()*
3688getbufline({buf}, {lnum} [, {end}])
3689 Return a |List| with the lines starting from {lnum} to {end}
3690 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003691 |List| with only the line {lnum} is returned. See
3692 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003693
3694 For the use of {buf}, see |bufname()| above.
3695
3696 For {lnum} and {end} "$" can be used for the last line of the
3697 buffer. Otherwise a number must be used.
3698
3699 When {lnum} is smaller than 1 or bigger than the number of
3700 lines in the buffer, an empty |List| is returned.
3701
3702 When {end} is greater than the number of lines in the buffer,
3703 it is treated as {end} is set to the number of lines in the
3704 buffer. When {end} is before {lnum} an empty |List| is
3705 returned.
3706
3707 This function works only for loaded buffers. For unloaded and
3708 non-existing buffers, an empty |List| is returned.
3709
3710 Example: >
3711 :let lines = getbufline(bufnr("myfile"), 1, "$")
3712
3713< Can also be used as a |method|: >
3714 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003715<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003716 Return type: list<string>
3717
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003718 *getbufoneline()*
3719getbufoneline({buf}, {lnum})
3720 Just like `getbufline()` but only get one line and return it
3721 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003722
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003723 Return type: |String|
3724
3725
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003726getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3727 The result is the value of option or local buffer variable
3728 {varname} in buffer {buf}. Note that the name without "b:"
3729 must be used.
3730 The {varname} argument is a string.
3731 When {varname} is empty returns a |Dictionary| with all the
3732 buffer-local variables.
3733 When {varname} is equal to "&" returns a |Dictionary| with all
3734 the buffer-local options.
3735 Otherwise, when {varname} starts with "&" returns the value of
3736 a buffer-local option.
3737 This also works for a global or buffer-local option, but it
3738 doesn't work for a global variable, window-local variable or
3739 window-local option.
3740 For the use of {buf}, see |bufname()| above.
3741 When the buffer or variable doesn't exist {def} or an empty
3742 string is returned, there is no error message.
3743 Examples: >
3744 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003745 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003746
3747< Can also be used as a |method|: >
3748 GetBufnr()->getbufvar(varname)
3749<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003750 Return type: any, depending on {varname}
3751
3752
Kota Kato66bb9ae2023-01-17 18:31:56 +00003753getcellwidths() *getcellwidths()*
3754 Returns a |List| of cell widths of character ranges overridden
3755 by |setcellwidths()|. The format is equal to the argument of
3756 |setcellwidths()|. If no character ranges have their cell
3757 widths overridden, an empty List is returned.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003758<
3759 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003760
3761
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003762getchangelist([{buf}]) *getchangelist()*
3763 Returns the |changelist| for the buffer {buf}. For the use
3764 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3765 exist, an empty list is returned.
3766
3767 The returned list contains two entries: a list with the change
3768 locations and the current position in the list. Each
3769 entry in the change list is a dictionary with the following
3770 entries:
3771 col column number
3772 coladd column offset for 'virtualedit'
3773 lnum line number
3774 If buffer {buf} is the current buffer, then the current
3775 position refers to the position in the list. For other
3776 buffers, it is set to the length of the list.
3777
3778 Can also be used as a |method|: >
3779 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003780<
3781 Return type: list<any>
3782
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003783
Doug Kearns9cd9e752024-04-07 17:42:17 +02003784getchar([{expr}]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003785 Get a single character from the user or input stream.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003786 If {expr} is omitted, wait until a character is available.
3787 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003788 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003789 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003790 not consumed. Return zero if no character available.
3791 If you prefer always getting a string use |getcharstr()|.
3792
Doug Kearns9cd9e752024-04-07 17:42:17 +02003793 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003794 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003795 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003796 Otherwise a String is returned with the encoded character.
3797 For a special key it's a String with a sequence of bytes
3798 starting with 0x80 (decimal: 128). This is the same value as
3799 the String "\<Key>", e.g., "\<Left>". The returned value is
3800 also a String when a modifier (shift, control, alt) was used
3801 that is not included in the character.
3802
Doug Kearns9cd9e752024-04-07 17:42:17 +02003803 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003804 while Vim waits to see if this is the start of an escape
3805 sequence.
3806
Doug Kearns9cd9e752024-04-07 17:42:17 +02003807 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003808 one-byte character it is the character itself as a number.
3809 Use nr2char() to convert it to a String.
3810
3811 Use getcharmod() to obtain any additional modifiers.
3812
3813 When the user clicks a mouse button, the mouse event will be
3814 returned. The position can then be found in |v:mouse_col|,
3815 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3816 |getmousepos()| can also be used. Mouse move events will be
3817 ignored.
3818 This example positions the mouse as it would normally happen: >
3819 let c = getchar()
3820 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003821 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003822 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003823 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003824 endif
3825<
3826 When using bracketed paste only the first character is
3827 returned, the rest of the pasted text is dropped.
3828 |xterm-bracketed-paste|.
3829
3830 There is no prompt, you will somehow have to make clear to the
3831 user that a character has to be typed. The screen is not
3832 redrawn, e.g. when resizing the window. When using a popup
3833 window it should work better with a |popup-filter|.
3834
3835 There is no mapping for the character.
3836 Key codes are replaced, thus when the user presses the <Del>
3837 key you get the code for the <Del> key, not the raw character
3838 sequence. Examples: >
3839 getchar() == "\<Del>"
3840 getchar() == "\<S-Left>"
3841< This example redefines "f" to ignore case: >
3842 :nmap f :call FindChar()<CR>
3843 :function FindChar()
3844 : let c = nr2char(getchar())
3845 : while col('.') < col('$') - 1
3846 : normal l
3847 : if getline('.')[col('.') - 1] ==? c
3848 : break
3849 : endif
3850 : endwhile
3851 :endfunction
3852<
3853 You may also receive synthetic characters, such as
3854 |<CursorHold>|. Often you will want to ignore this and get
3855 another character: >
3856 :function GetKey()
3857 : let c = getchar()
3858 : while c == "\<CursorHold>"
3859 : let c = getchar()
3860 : endwhile
3861 : return c
3862 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003863<
3864 Return type: |Number| or |String|
3865
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003866
3867getcharmod() *getcharmod()*
3868 The result is a Number which is the state of the modifiers for
3869 the last obtained character with getchar() or in another way.
3870 These values are added together:
3871 2 shift
3872 4 control
3873 8 alt (meta)
3874 16 meta (when it's different from ALT)
3875 32 mouse double click
3876 64 mouse triple click
3877 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01003878 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003879 Only the modifiers that have not been included in the
3880 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01003881 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003882
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003883 Return type: |Number|
3884
3885
3886getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003887 Get the position for String {expr}. Same as |getpos()| but the
3888 column number in the returned List is a character index
3889 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00003890 If |getpos()| returns a very large column number, equal to
3891 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003892 of the last character.
3893
3894 Example:
3895 With the cursor on '세' in line 5 with text "여보세요": >
3896 getcharpos('.') returns [0, 5, 3, 0]
3897 getpos('.') returns [0, 5, 7, 0]
3898<
3899 Can also be used as a |method|: >
3900 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003901<
3902 Return type: list<number>
3903
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003904
3905getcharsearch() *getcharsearch()*
3906 Return the current character search information as a {dict}
3907 with the following entries:
3908
3909 char character previously used for a character
3910 search (|t|, |f|, |T|, or |F|); empty string
3911 if no character search has been performed
3912 forward direction of character search; 1 for forward,
3913 0 for backward
3914 until type of character search; 1 for a |t| or |T|
3915 character search, 0 for an |f| or |F|
3916 character search
3917
3918 This can be useful to always have |;| and |,| search
3919 forward/backward regardless of the direction of the previous
3920 character search: >
3921 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
3922 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
3923< Also see |setcharsearch()|.
3924
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003925 Return type: dict<any>
3926
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003927
Doug Kearns9cd9e752024-04-07 17:42:17 +02003928getcharstr([{expr}]) *getcharstr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003929 Get a single character from the user or input stream as a
3930 string.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003931 If {expr} is omitted, wait until a character is available.
3932 If {expr} is 0 or false, only get a character when one is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003933 available. Return an empty string otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003934 If {expr} is 1 or true, only check if a character is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003935 available, it is not consumed. Return an empty string
3936 if no character is available.
3937 Otherwise this works like |getchar()|, except that a number
3938 result is converted to a string.
3939
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003940 Return type: |String|
3941
3942
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003943getcmdcompltype() *getcmdcompltype()*
3944 Return the type of the current command-line completion.
3945 Only works when the command line is being edited, thus
3946 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01003947 See |:command-completion| for the return string.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003948 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
3949 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003950 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003951
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003952 Return type: |String|
3953
3954
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003955getcmdline() *getcmdline()*
3956 Return the current command-line. Only works when the command
3957 line is being edited, thus requires use of |c_CTRL-\_e| or
3958 |c_CTRL-R_=|.
3959 Example: >
3960 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003961< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()| and
3962 |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003963 Returns an empty string when entering a password or using
3964 |inputsecret()|.
3965
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003966 Return type: |String|
3967
3968
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003969getcmdpos() *getcmdpos()*
3970 Return the position of the cursor in the command line as a
3971 byte count. The first column is 1.
3972 Only works when editing the command line, thus requires use of
3973 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3974 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003975 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
3976 |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003977
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003978 Return type: |Number|
3979
3980
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003981getcmdscreenpos() *getcmdscreenpos()*
3982 Return the screen position of the cursor in the command line
3983 as a byte count. The first column is 1.
3984 Instead of |getcmdpos()|, it adds the prompt position.
3985 Only works when editing the command line, thus requires use of
3986 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3987 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003988 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
3989 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003990
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003991 Return type: |Number|
3992
3993
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003994getcmdtype() *getcmdtype()*
3995 Return the current command-line type. Possible return values
3996 are:
3997 : normal Ex command
3998 > debug mode command |debug-mode|
3999 / forward search command
4000 ? backward search command
4001 @ |input()| command
4002 - |:insert| or |:append| command
4003 = |i_CTRL-R_=|
4004 Only works when editing the command line, thus requires use of
4005 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4006 Returns an empty string otherwise.
4007 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4008
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004009 Return type: |String|
4010
4011
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004012getcmdwintype() *getcmdwintype()*
4013 Return the current |command-line-window| type. Possible return
4014 values are the same as |getcmdtype()|. Returns an empty string
4015 when not in the command-line window.
4016
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004017 Return type: |String|
4018
4019
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004020getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4021 Return a list of command-line completion matches. The String
4022 {type} argument specifies what for. The following completion
4023 types are supported:
4024
4025 arglist file names in argument list
4026 augroup autocmd groups
4027 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004028 behave |:behave| suboptions
4029 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004030 color color schemes
4031 command Ex command
4032 cmdline |cmdline-completion| result
4033 compiler compilers
4034 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004035 custom,{func} custom completion, defined via {func}
4036 customlist,{func} custom completion, defined via {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004037 diff_buffer |:diffget| and |:diffput| completion
4038 dir directory names
4039 environment environment variable names
4040 event autocommand events
4041 expression Vim expression
4042 file file and directory names
4043 file_in_path file and directory names in |'path'|
4044 filetype filetype names |'filetype'|
4045 function function name
4046 help help subjects
4047 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004048 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004049 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004050 locale locale names (as output of locale -a)
4051 mapclear buffer argument
4052 mapping mapping name
4053 menu menus
4054 messages |:messages| suboptions
4055 option options
4056 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004057 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004058 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004059 shellcmd Shell command
4060 sign |:sign| suboptions
4061 syntax syntax file names |'syntax'|
4062 syntime |:syntime| suboptions
4063 tag tags
4064 tag_listfiles tags, file names
4065 user user names
4066 var user variables
4067
4068 If {pat} is an empty string, then all the matches are
4069 returned. Otherwise only items matching {pat} are returned.
4070 See |wildcards| for the use of special characters in {pat}.
4071
4072 If the optional {filtered} flag is set to 1, then 'wildignore'
4073 is applied to filter the results. Otherwise all the matches
4074 are returned. The 'wildignorecase' option always applies.
4075
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004076 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4077 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004078 regular expression matching is used. Thus this function
4079 follows the user preference, what happens on the command line.
4080 If you do not want this you can make 'wildoptions' empty
4081 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004082
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004083 If {type} is "cmdline", then the |cmdline-completion| result is
4084 returned. For example, to complete the possible values after
4085 a ":call" command: >
4086 echo getcompletion('call ', 'cmdline')
4087<
4088 If there are no matches, an empty list is returned. An
4089 invalid value for {type} produces an error.
4090
4091 Can also be used as a |method|: >
4092 GetPattern()->getcompletion('color')
4093<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004094 Return type: list<string>
4095
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004096 *getcurpos()*
4097getcurpos([{winid}])
4098 Get the position of the cursor. This is like getpos('.'), but
4099 includes an extra "curswant" item in the list:
4100 [0, lnum, col, off, curswant] ~
4101 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004102 cursor vertically. After |$| command it will be a very large
4103 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004104 |getpos()|.
4105 The first "bufnum" item is always zero. The byte position of
4106 the cursor is returned in 'col'. To get the character
4107 position, use |getcursorcharpos()|.
4108
4109 The optional {winid} argument can specify the window. It can
4110 be the window number or the |window-ID|. The last known
4111 cursor position is returned, this may be invalid for the
4112 current value of the buffer if it is not the current window.
4113 If {winid} is invalid a list with zeroes is returned.
4114
4115 This can be used to save and restore the cursor position: >
4116 let save_cursor = getcurpos()
4117 MoveTheCursorAround
4118 call setpos('.', save_cursor)
4119< Note that this only works within the window. See
4120 |winrestview()| for restoring more state.
4121
4122 Can also be used as a |method|: >
4123 GetWinid()->getcurpos()
4124<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004125 Return type: list<number>
4126
4127
4128getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004129 Same as |getcurpos()| but the column number in the returned
4130 List is a character index instead of a byte index.
4131
4132 Example:
4133 With the cursor on '보' in line 3 with text "여보세요": >
4134 getcursorcharpos() returns [0, 3, 2, 0, 3]
4135 getcurpos() returns [0, 3, 4, 0, 3]
4136<
4137 Can also be used as a |method|: >
4138 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004139<
4140 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004141
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004142
4143getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004144 The result is a String, which is the name of the current
4145 working directory. 'autochdir' is ignored.
4146
4147 With {winnr} return the local current directory of this window
4148 in the current tab page. {winnr} can be the window number or
4149 the |window-ID|.
4150 If {winnr} is -1 return the name of the global working
4151 directory. See also |haslocaldir()|.
4152
4153 With {winnr} and {tabnr} return the local current directory of
4154 the window in the specified tab page. If {winnr} is -1 return
4155 the working directory of the tabpage.
4156 If {winnr} is zero use the current window, if {tabnr} is zero
4157 use the current tabpage.
4158 Without any arguments, return the actual working directory of
4159 the current window.
4160 Return an empty string if the arguments are invalid.
4161
4162 Examples: >
4163 " Get the working directory of the current window
4164 :echo getcwd()
4165 :echo getcwd(0)
4166 :echo getcwd(0, 0)
4167 " Get the working directory of window 3 in tabpage 2
4168 :echo getcwd(3, 2)
4169 " Get the global working directory
4170 :echo getcwd(-1)
4171 " Get the working directory of tabpage 3
4172 :echo getcwd(-1, 3)
4173 " Get the working directory of current tabpage
4174 :echo getcwd(-1, 0)
4175
4176< Can also be used as a |method|: >
4177 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004178<
4179 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004180
4181getenv({name}) *getenv()*
4182 Return the value of environment variable {name}. The {name}
4183 argument is a string, without a leading '$'. Example: >
4184 myHome = getenv('HOME')
4185
4186< When the variable does not exist |v:null| is returned. That
4187 is different from a variable set to an empty string, although
4188 some systems interpret the empty value as the variable being
4189 deleted. See also |expr-env|.
4190
4191 Can also be used as a |method|: >
4192 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004193<
4194 Return type: |String| or |Number|
4195
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004196
4197getfontname([{name}]) *getfontname()*
4198 Without an argument returns the name of the normal font being
4199 used. Like what is used for the Normal highlight group
4200 |hl-Normal|.
4201 With an argument a check is done whether String {name} is a
4202 valid font name. If not then an empty string is returned.
4203 Otherwise the actual font name is returned, or {name} if the
4204 GUI does not support obtaining the real name.
4205 Only works when the GUI is running, thus not in your vimrc or
4206 gvimrc file. Use the |GUIEnter| autocommand to use this
4207 function just after the GUI has started.
4208 Note that the GTK GUI accepts any font name, thus checking for
4209 a valid name does not work.
4210
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004211 Return type: |String|
4212
4213
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004214getfperm({fname}) *getfperm()*
4215 The result is a String, which is the read, write, and execute
4216 permissions of the given file {fname}.
4217 If {fname} does not exist or its directory cannot be read, an
4218 empty string is returned.
4219 The result is of the form "rwxrwxrwx", where each group of
4220 "rwx" flags represent, in turn, the permissions of the owner
4221 of the file, the group the file belongs to, and other users.
4222 If a user does not have a given permission the flag for this
4223 is replaced with the string "-". Examples: >
4224 :echo getfperm("/etc/passwd")
4225 :echo getfperm(expand("~/.vimrc"))
4226< This will hopefully (from a security point of view) display
4227 the string "rw-r--r--" or even "rw-------".
4228
4229 Can also be used as a |method|: >
4230 GetFilename()->getfperm()
4231<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004232 Return type: |String|
4233
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004234 For setting permissions use |setfperm()|.
4235
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004236
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004237getfsize({fname}) *getfsize()*
4238 The result is a Number, which is the size in bytes of the
4239 given file {fname}.
4240 If {fname} is a directory, 0 is returned.
4241 If the file {fname} can't be found, -1 is returned.
4242 If the size of {fname} is too big to fit in a Number then -2
4243 is returned.
4244
4245 Can also be used as a |method|: >
4246 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004247<
4248 Return type: |Number|
4249
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004250
4251getftime({fname}) *getftime()*
4252 The result is a Number, which is the last modification time of
4253 the given file {fname}. The value is measured as seconds
4254 since 1st Jan 1970, and may be passed to strftime(). See also
4255 |localtime()| and |strftime()|.
4256 If the file {fname} can't be found -1 is returned.
4257
4258 Can also be used as a |method|: >
4259 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004260<
4261 Return type: |Number|
4262
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004263
4264getftype({fname}) *getftype()*
4265 The result is a String, which is a description of the kind of
4266 file of the given file {fname}.
4267 If {fname} does not exist an empty string is returned.
4268 Here is a table over different kinds of files and their
4269 results:
4270 Normal file "file"
4271 Directory "dir"
4272 Symbolic link "link"
4273 Block device "bdev"
4274 Character device "cdev"
4275 Socket "socket"
4276 FIFO "fifo"
4277 All other "other"
4278 Example: >
4279 getftype("/home")
4280< Note that a type such as "link" will only be returned on
4281 systems that support it. On some systems only "dir" and
4282 "file" are returned. On MS-Windows a symbolic link to a
4283 directory returns "dir" instead of "link".
4284
4285 Can also be used as a |method|: >
4286 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004287<
4288 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004289
4290getimstatus() *getimstatus()*
4291 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004292 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004293 See 'imstatusfunc'.
4294
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004295 Return type: |Number|
4296
4297
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004298getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4299 Returns the |jumplist| for the specified window.
4300
4301 Without arguments use the current window.
4302 With {winnr} only use this window in the current tab page.
4303 {winnr} can also be a |window-ID|.
4304 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004305 page. If {winnr} or {tabnr} is invalid, an empty list is
4306 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004307
4308 The returned list contains two entries: a list with the jump
4309 locations and the last used jump position number in the list.
4310 Each entry in the jump location list is a dictionary with
4311 the following entries:
4312 bufnr buffer number
4313 col column number
4314 coladd column offset for 'virtualedit'
4315 filename filename if available
4316 lnum line number
4317
4318 Can also be used as a |method|: >
4319 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004320<
4321 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004322
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004323 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004324getline({lnum} [, {end}])
4325 Without {end} the result is a String, which is line {lnum}
4326 from the current buffer. Example: >
4327 getline(1)
4328< When {lnum} is a String that doesn't start with a
4329 digit, |line()| is called to translate the String into a Number.
4330 To get the line under the cursor: >
4331 getline(".")
4332< When {lnum} is a number smaller than 1 or bigger than the
4333 number of lines in the buffer, an empty string is returned.
4334
4335 When {end} is given the result is a |List| where each item is
4336 a line from the current buffer in the range {lnum} to {end},
4337 including line {end}.
4338 {end} is used in the same way as {lnum}.
4339 Non-existing lines are silently omitted.
4340 When {end} is before {lnum} an empty |List| is returned.
4341 Example: >
4342 :let start = line('.')
4343 :let end = search("^$") - 1
4344 :let lines = getline(start, end)
4345
4346< Can also be used as a |method|: >
4347 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004348<
4349 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004350
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004351 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004352 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004353
4354getloclist({nr} [, {what}]) *getloclist()*
4355 Returns a |List| with all the entries in the location list for
4356 window {nr}. {nr} can be the window number or the |window-ID|.
4357 When {nr} is zero the current window is used.
4358
4359 For a location list window, the displayed location list is
4360 returned. For an invalid window number {nr}, an empty list is
4361 returned. Otherwise, same as |getqflist()|.
4362
4363 If the optional {what} dictionary argument is supplied, then
4364 returns the items listed in {what} as a dictionary. Refer to
4365 |getqflist()| for the supported items in {what}.
4366
4367 In addition to the items supported by |getqflist()| in {what},
4368 the following item is supported by |getloclist()|:
4369
4370 filewinid id of the window used to display files
4371 from the location list. This field is
4372 applicable only when called from a
4373 location list window. See
4374 |location-list-file-window| for more
4375 details.
4376
4377 Returns a |Dictionary| with default values if there is no
4378 location list for the window {nr}.
4379 Returns an empty Dictionary if window {nr} does not exist.
4380
4381 Examples (See also |getqflist-examples|): >
4382 :echo getloclist(3, {'all': 0})
4383 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004384<
4385 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004386
4387
4388getmarklist([{buf}]) *getmarklist()*
4389 Without the {buf} argument returns a |List| with information
4390 about all the global marks. |mark|
4391
4392 If the optional {buf} argument is specified, returns the
4393 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004394 see |bufname()|. If {buf} is invalid, an empty list is
4395 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004396
4397 Each item in the returned List is a |Dict| with the following:
4398 mark name of the mark prefixed by "'"
4399 pos a |List| with the position of the mark:
4400 [bufnum, lnum, col, off]
4401 Refer to |getpos()| for more information.
4402 file file name
4403
4404 Refer to |getpos()| for getting information about a specific
4405 mark.
4406
4407 Can also be used as a |method|: >
4408 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004409<
4410 Return type: list<dict<any>> or list<any>
4411
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004412
4413getmatches([{win}]) *getmatches()*
4414 Returns a |List| with all matches previously defined for the
4415 current window by |matchadd()| and the |:match| commands.
4416 |getmatches()| is useful in combination with |setmatches()|,
4417 as |setmatches()| can restore a list of matches saved by
4418 |getmatches()|.
4419 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004420 window ID instead of the current window. If {win} is invalid,
4421 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004422 Example: >
4423 :echo getmatches()
4424< [{'group': 'MyGroup1', 'pattern': 'TODO',
4425 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4426 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4427 :let m = getmatches()
4428 :call clearmatches()
4429 :echo getmatches()
4430< [] >
4431 :call setmatches(m)
4432 :echo getmatches()
4433< [{'group': 'MyGroup1', 'pattern': 'TODO',
4434 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4435 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4436 :unlet m
4437<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004438 Return type: list<dict<any>> or list<any>
4439
4440
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004441getmousepos() *getmousepos()*
4442 Returns a |Dictionary| with the last known position of the
4443 mouse. This can be used in a mapping for a mouse click or in
4444 a filter of a popup window. The items are:
4445 screenrow screen row
4446 screencol screen column
4447 winid Window ID of the click
4448 winrow row inside "winid"
4449 wincol column inside "winid"
4450 line text line inside "winid"
4451 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004452 coladd offset (in screen columns) from the
4453 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004454 All numbers are 1-based.
4455
4456 If not over a window, e.g. when in the command line, then only
4457 "screenrow" and "screencol" are valid, the others are zero.
4458
4459 When on the status line below a window or the vertical
4460 separator right of a window, the "line" and "column" values
4461 are zero.
4462
4463 When the position is after the text then "column" is the
4464 length of the text in bytes plus one.
4465
4466 If the mouse is over a popup window then that window is used.
4467
4468 When using |getchar()| the Vim variables |v:mouse_lnum|,
4469 |v:mouse_col| and |v:mouse_winid| also provide these values.
4470
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004471 Return type: dict<number>
4472
4473
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004474getmouseshape() *getmouseshape()*
4475 Returns the name of the currently showing mouse pointer.
4476 When the |+mouseshape| feature is not supported or the shape
4477 is unknown an empty string is returned.
4478 This function is mainly intended for testing.
4479
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004480 Return type: |String|
4481
4482
4483getpid() *getpid()*
4484 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004485 On Unix and MS-Windows this is a unique number, until Vim
4486 exits.
4487
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004488 Return type: |Number|
4489
4490
4491getpos({expr}) *getpos()*
zeertzjq02f3eba2024-06-12 20:45:24 +02004492 Get the position for String {expr}.
4493 The accepted values for {expr} are: *E1209*
4494 . The cursor position.
4495 $ The last line in the current buffer.
4496 'x Position of mark x (if the mark is not set, 0 is
zeertzjqd353d272024-06-13 23:00:25 +08004497 returned for all values).
zeertzjq02f3eba2024-06-12 20:45:24 +02004498 w0 First line visible in current window (one if the
4499 display isn't updated, e.g. in silent Ex mode).
4500 w$ Last line visible in current window (this is one
4501 less than "w0" if no lines are visible).
4502 v When not in Visual mode, returns the cursor
4503 position. In Visual mode, returns the other end
4504 of the Visual area. A good way to think about
4505 this is that in Visual mode "v" and "." complement
4506 each other. While "." refers to the cursor
4507 position, "v" refers to where |v_o| would move the
4508 cursor. As a result, you can use "v" and "."
4509 together to work on all of a selection in
4510 characterwise Visual mode. If the cursor is at
4511 the end of a characterwise Visual area, "v" refers
4512 to the start of the same Visual area. And if the
4513 cursor is at the start of a characterwise Visual
4514 area, "v" refers to the end of the same Visual
4515 area. "v" differs from |'<| and |'>| in that it's
4516 updated right away.
4517 Note that a mark in another file can be used. The line number
4518 then applies to another buffer.
4519
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004520 The result is a |List| with four numbers:
4521 [bufnum, lnum, col, off]
4522 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4523 is the buffer number of the mark.
4524 "lnum" and "col" are the position in the buffer. The first
4525 column is 1.
4526 The "off" number is zero, unless 'virtualedit' is used. Then
4527 it is the offset in screen columns from the start of the
4528 character. E.g., a position within a <Tab> or after the last
4529 character.
zeertzjq02f3eba2024-06-12 20:45:24 +02004530
4531 For getting the cursor position see |getcurpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004532 The column number in the returned List is the byte position
4533 within the line. To get the character position in the line,
4534 use |getcharpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02004535
4536 Note that for '< and '> Visual mode matters: when it is "V"
4537 (visual line mode) the column of '< is zero and the column of
4538 '> is a large number equal to |v:maxcol|.
naohiro ono56200ee2022-01-01 14:59:44 +00004539 A very large column number equal to |v:maxcol| can be returned,
4540 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004541 If {expr} is invalid, returns a list with all zeros.
zeertzjq02f3eba2024-06-12 20:45:24 +02004542
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004543 This can be used to save and restore the position of a mark: >
4544 let save_a_mark = getpos("'a")
4545 ...
4546 call setpos("'a", save_a_mark)
zeertzjqd353d272024-06-13 23:00:25 +08004547<
4548 Also see |getcharpos()|, |getcurpos()| and |setpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004549
4550 Can also be used as a |method|: >
4551 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004552<
4553 Return type: list<number>
4554
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004555
4556getqflist([{what}]) *getqflist()*
4557 Returns a |List| with all the current quickfix errors. Each
4558 list item is a dictionary with these entries:
4559 bufnr number of buffer that has the file name, use
4560 bufname() to get the name
4561 module module name
4562 lnum line number in the buffer (first line is 1)
4563 end_lnum
4564 end of line number if the item is multiline
4565 col column number (first column is 1)
4566 end_col end of column number if the item has range
4567 vcol |TRUE|: "col" is visual column
4568 |FALSE|: "col" is byte index
4569 nr error number
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004570 pattern search list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004571 text description of the error
4572 type type of the error, 'E', '1', etc.
4573 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004574 user_data
4575 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004576 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004577
4578 When there is no error list or it's empty, an empty list is
4579 returned. Quickfix list entries with a non-existing buffer
4580 number are returned with "bufnr" set to zero (Note: some
4581 functions accept buffer number zero for the alternate buffer,
4582 you may need to explicitly check for zero).
4583
4584 Useful application: Find pattern matches in multiple files and
4585 do something with them: >
4586 :vimgrep /theword/jg *.c
4587 :for d in getqflist()
4588 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4589 :endfor
4590<
4591 If the optional {what} dictionary argument is supplied, then
4592 returns only the items listed in {what} as a dictionary. The
4593 following string items are supported in {what}:
4594 changedtick get the total number of changes made
4595 to the list |quickfix-changedtick|
4596 context get the |quickfix-context|
4597 efm errorformat to use when parsing "lines". If
4598 not present, then the 'errorformat' option
4599 value is used.
4600 id get information for the quickfix list with
4601 |quickfix-ID|; zero means the id for the
4602 current list or the list specified by "nr"
4603 idx get information for the quickfix entry at this
4604 index in the list specified by 'id' or 'nr'.
4605 If set to zero, then uses the current entry.
4606 See |quickfix-index|
4607 items quickfix list entries
4608 lines parse a list of lines using 'efm' and return
4609 the resulting entries. Only a |List| type is
4610 accepted. The current quickfix list is not
4611 modified. See |quickfix-parse|.
4612 nr get information for this quickfix list; zero
4613 means the current quickfix list and "$" means
4614 the last quickfix list
4615 qfbufnr number of the buffer displayed in the quickfix
4616 window. Returns 0 if the quickfix buffer is
4617 not present. See |quickfix-buffer|.
4618 size number of entries in the quickfix list
4619 title get the list title |quickfix-title|
4620 winid get the quickfix |window-ID|
4621 all all of the above quickfix properties
4622 Non-string items in {what} are ignored. To get the value of a
4623 particular item, set it to zero.
4624 If "nr" is not present then the current quickfix list is used.
4625 If both "nr" and a non-zero "id" are specified, then the list
4626 specified by "id" is used.
4627 To get the number of lists in the quickfix stack, set "nr" to
4628 "$" in {what}. The "nr" value in the returned dictionary
4629 contains the quickfix stack size.
4630 When "lines" is specified, all the other items except "efm"
4631 are ignored. The returned dictionary contains the entry
4632 "items" with the list of entries.
4633
4634 The returned dictionary contains the following entries:
4635 changedtick total number of changes made to the
4636 list |quickfix-changedtick|
4637 context quickfix list context. See |quickfix-context|
4638 If not present, set to "".
4639 id quickfix list ID |quickfix-ID|. If not
4640 present, set to 0.
4641 idx index of the quickfix entry in the list. If not
4642 present, set to 0.
4643 items quickfix list entries. If not present, set to
4644 an empty list.
4645 nr quickfix list number. If not present, set to 0
4646 qfbufnr number of the buffer displayed in the quickfix
4647 window. If not present, set to 0.
4648 size number of entries in the quickfix list. If not
4649 present, set to 0.
4650 title quickfix list title text. If not present, set
4651 to "".
4652 winid quickfix |window-ID|. If not present, set to 0
4653
4654 Examples (See also |getqflist-examples|): >
4655 :echo getqflist({'all': 1})
4656 :echo getqflist({'nr': 2, 'title': 1})
4657 :echo getqflist({'lines' : ["F1:10:L10"]})
4658<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004659 Return type: list<dict<any>> or list<any>
4660
4661
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004662getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4663 The result is a String, which is the contents of register
4664 {regname}. Example: >
4665 :let cliptext = getreg('*')
4666< When register {regname} was not set the result is an empty
4667 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004668 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004669
4670 getreg('=') returns the last evaluated value of the expression
4671 register. (For use in maps.)
4672 getreg('=', 1) returns the expression itself, so that it can
4673 be restored with |setreg()|. For other registers the extra
4674 argument is ignored, thus you can always give it.
4675
4676 If {list} is present and |TRUE|, the result type is changed
4677 to |List|. Each list item is one text line. Use it if you care
4678 about zero bytes possibly present inside register: without
4679 third argument both NLs and zero bytes are represented as NLs
4680 (see |NL-used-for-Nul|).
4681 When the register was not set an empty list is returned.
4682
4683 If {regname} is "", the unnamed register '"' is used.
4684 If {regname} is not specified, |v:register| is used.
4685 In |Vim9-script| {regname} must be one character.
4686
4687 Can also be used as a |method|: >
4688 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004689<
4690 Return type: |String|
4691
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004692
4693getreginfo([{regname}]) *getreginfo()*
4694 Returns detailed information about register {regname} as a
4695 Dictionary with the following entries:
4696 regcontents List of lines contained in register
4697 {regname}, like
4698 |getreg|({regname}, 1, 1).
4699 regtype the type of register {regname}, as in
4700 |getregtype()|.
4701 isunnamed Boolean flag, v:true if this register
4702 is currently pointed to by the unnamed
4703 register.
4704 points_to for the unnamed register, gives the
4705 single letter name of the register
4706 currently pointed to (see |quotequote|).
4707 For example, after deleting a line
4708 with `dd`, this field will be "1",
4709 which is the register that got the
4710 deleted text.
4711
4712 The {regname} argument is a string. If {regname} is invalid
4713 or not set, an empty Dictionary will be returned.
4714 If {regname} is "" or "@", the unnamed register '"' is used.
4715 If {regname} is not specified, |v:register| is used.
4716 The returned Dictionary can be passed to |setreg()|.
4717 In |Vim9-script| {regname} must be one character.
4718
4719 Can also be used as a |method|: >
4720 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004721<
4722 Return type: dict<any>
4723
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004724
Shougo Matsushita19b71882024-02-28 22:48:12 +01004725getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004726 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01004727 buffer.
4728
4729 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004730 See |getpos()| for the format of the list. It's possible
4731 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01004732 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01004733
4734 The optional argument {opts} is a Dict and supports the
4735 following items:
4736
zeertzjqafc22952024-05-24 19:07:12 +02004737 type Specify the region's selection type.
4738 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02004739 except that the width can be omitted
4740 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02004741 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01004742
zeertzjq87410ab2024-03-02 06:00:23 +08004743 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02004744 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08004745 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01004746
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004747 You can get the last selection type by |visualmode()|.
4748 If Visual mode is active, use |mode()| to get the Visual mode
4749 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08004750 This function is useful to get text starting and ending in
4751 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004752
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004753 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004754 Note that:
4755 - Order of {pos1} and {pos2} doesn't matter, it will always
4756 return content from the upper left position to the lower
4757 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08004758 - If 'virtualedit' is enabled and the region is past the end
4759 of the lines, resulting lines are padded with spaces.
4760 - If the region is blockwise and it starts or ends in the
4761 middle of a multi-cell character, it is not included but
4762 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004763 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01004764 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004765 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01004766 - It is evaluated in current window context, which makes a
4767 difference if the buffer is displayed in a window with
4768 different 'virtualedit' or 'list' values.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004769
4770 Examples: >
4771 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01004772 \ <Cmd>echow getregion(
4773 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004774<
4775 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01004776 getpos('.')->getregion(getpos("'a"))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004777
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004778<
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004779getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
4780 Same as |getregion()|, but returns a list of positions
4781 describing the buffer text segments bound by {pos1} and
4782 {pos2}.
4783 The segments are a pair of positions for every line: >
4784 [[{start_pos}, {end_pos}], ...]
4785<
4786 The position is a |List| with four numbers:
4787 [bufnum, lnum, col, off]
4788 "bufnum" is the buffer number.
4789 "lnum" and "col" are the position in the buffer. The first
4790 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02004791 If the "off" number of a starting position is non-zero, it is
4792 the offset in screen columns from the start of the character.
4793 E.g., a position within a <Tab> or after the last character.
4794 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02004795 the offset of the character's first cell not included in the
4796 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004797
zeertzjq2b09de92024-05-24 07:48:51 +02004798 Apart from the options supported by |getregion()|, {opts} also
4799 supports the following:
4800
4801 eol If |TRUE|, indicate positions beyond
4802 the end of a line with "col" values
4803 one more than the length of the line.
4804 If |FALSE|, positions are limited
4805 within their lines, and if a line is
4806 empty or the selection is entirely
4807 beyond the end of a line, a "col"
4808 value of 0 is used for both positions.
4809 (default: |FALSE|)
4810
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004811 Can also be used as a |method|: >
4812 getpos('.')->getregionpos(getpos("'a"))
4813<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004814 Return type: list<string>
4815
4816
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004817getregtype([{regname}]) *getregtype()*
4818 The result is a String, which is type of register {regname}.
4819 The value will be one of:
4820 "v" for |characterwise| text
4821 "V" for |linewise| text
4822 "<CTRL-V>{width}" for |blockwise-visual| text
4823 "" for an empty or unknown register
4824 <CTRL-V> is one character with value 0x16.
4825 The {regname} argument is a string. If {regname} is "", the
4826 unnamed register '"' is used. If {regname} is not specified,
4827 |v:register| is used.
4828 In |Vim9-script| {regname} must be one character.
4829
4830 Can also be used as a |method|: >
4831 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004832<
4833 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004834
Bram Moolenaar71badf92023-04-22 22:40:14 +01004835getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004836 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01004837 scripts in the order they were sourced, like what
4838 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004839
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004840 The optional Dict argument {opts} supports the following
4841 optional items:
4842 name Script name match pattern. If specified,
4843 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01004844 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004845 "name" are returned.
4846 sid Script ID |<SID>|. If specified, only
4847 information about the script with ID "sid" is
4848 returned and "name" is ignored.
4849
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004850 Each item in the returned List is a |Dict| with the following
4851 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004852 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01004853 `import autoload` but was not actually sourced
4854 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004855 functions List of script-local function names defined in
4856 the script. Present only when a particular
4857 script is specified using the "sid" item in
4858 {opts}.
4859 name Vim script file name.
4860 sid Script ID |<SID>|.
4861 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01004862 this script name links to, if any, otherwise
4863 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004864 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00004865 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004866 specified using the "sid" item in {opts}.
4867 Note that this is a copy, the value of
4868 script-local variables cannot be changed using
4869 this dictionary.
h_east59858792023-10-25 22:47:05 +09004870 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01004871
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004872 Examples: >
4873 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08004874 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004875<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004876 Return type: list<dict<any>>
4877
4878
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004879gettabinfo([{tabnr}]) *gettabinfo()*
4880 If {tabnr} is not specified, then information about all the
4881 tab pages is returned as a |List|. Each List item is a
4882 |Dictionary|. Otherwise, {tabnr} specifies the tab page
4883 number and information about that one is returned. If the tab
4884 page does not exist an empty List is returned.
4885
4886 Each List item is a |Dictionary| with the following entries:
4887 tabnr tab page number.
4888 variables a reference to the dictionary with
4889 tabpage-local variables
4890 windows List of |window-ID|s in the tab page.
4891
4892 Can also be used as a |method|: >
4893 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004894<
4895 Return type: list<dict<any>>
4896
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004897
4898gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
4899 Get the value of a tab-local variable {varname} in tab page
4900 {tabnr}. |t:var|
4901 Tabs are numbered starting with one.
4902 The {varname} argument is a string. When {varname} is empty a
4903 dictionary with all tab-local variables is returned.
4904 Note that the name without "t:" must be used.
4905 When the tab or variable doesn't exist {def} or an empty
4906 string is returned, there is no error message.
4907
4908 Can also be used as a |method|: >
4909 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004910<
4911 Return type: any, depending on {varname}
4912
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004913
4914gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
4915 Get the value of window-local variable {varname} in window
4916 {winnr} in tab page {tabnr}.
4917 The {varname} argument is a string. When {varname} is empty a
4918 dictionary with all window-local variables is returned.
4919 When {varname} is equal to "&" get the values of all
4920 window-local options in a |Dictionary|.
4921 Otherwise, when {varname} starts with "&" get the value of a
4922 window-local option.
4923 Note that {varname} must be the name without "w:".
4924 Tabs are numbered starting with one. For the current tabpage
4925 use |getwinvar()|.
4926 {winnr} can be the window number or the |window-ID|.
4927 When {winnr} is zero the current window is used.
4928 This also works for a global option, buffer-local option and
4929 window-local option, but it doesn't work for a global variable
4930 or buffer-local variable.
4931 When the tab, window or variable doesn't exist {def} or an
4932 empty string is returned, there is no error message.
4933 Examples: >
4934 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004935 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004936<
4937 To obtain all window-local variables use: >
4938 gettabwinvar({tabnr}, {winnr}, '&')
4939
4940< Can also be used as a |method|: >
4941 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004942<
4943 Return type: any, depending on {varname}
4944
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004945
4946gettagstack([{winnr}]) *gettagstack()*
4947 The result is a Dict, which is the tag stack of window {winnr}.
4948 {winnr} can be the window number or the |window-ID|.
4949 When {winnr} is not specified, the current window is used.
4950 When window {winnr} doesn't exist, an empty Dict is returned.
4951
4952 The returned dictionary contains the following entries:
4953 curidx Current index in the stack. When at
4954 top of the stack, set to (length + 1).
4955 Index of bottom of the stack is 1.
4956 items List of items in the stack. Each item
4957 is a dictionary containing the
4958 entries described below.
4959 length Number of entries in the stack.
4960
4961 Each item in the stack is a dictionary with the following
4962 entries:
4963 bufnr buffer number of the current jump
4964 from cursor position before the tag jump.
4965 See |getpos()| for the format of the
4966 returned list.
4967 matchnr current matching tag number. Used when
4968 multiple matching tags are found for a
4969 name.
4970 tagname name of the tag
4971
4972 See |tagstack| for more information about the tag stack.
4973
4974 Can also be used as a |method|: >
4975 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004976<
4977 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004978
4979
4980gettext({text}) *gettext()*
4981 Translate String {text} if possible.
4982 This is mainly for use in the distributed Vim scripts. When
4983 generating message translations the {text} is extracted by
4984 xgettext, the translator can add the translated message in the
4985 .po file and Vim will lookup the translation when gettext() is
4986 called.
4987 For {text} double quoted strings are preferred, because
4988 xgettext does not understand escaping in single quoted
4989 strings.
4990
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004991 Return type: |String|
4992
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004993
4994getwininfo([{winid}]) *getwininfo()*
4995 Returns information about windows as a |List| with Dictionaries.
4996
4997 If {winid} is given Information about the window with that ID
4998 is returned, as a |List| with one item. If the window does not
4999 exist the result is an empty list.
5000
5001 Without {winid} information about all the windows in all the
5002 tab pages is returned.
5003
5004 Each List item is a |Dictionary| with the following entries:
5005 botline last complete displayed buffer line
5006 bufnr number of buffer in the window
5007 height window height (excluding winbar)
5008 loclist 1 if showing a location list
5009 {only with the +quickfix feature}
5010 quickfix 1 if quickfix or location list window
5011 {only with the +quickfix feature}
5012 terminal 1 if a terminal window
5013 {only with the +terminal feature}
5014 tabnr tab page number
5015 topline first displayed buffer line
5016 variables a reference to the dictionary with
5017 window-local variables
5018 width window width
5019 winbar 1 if the window has a toolbar, 0
5020 otherwise
5021 wincol leftmost screen column of the window;
5022 "col" from |win_screenpos()|
5023 textoff number of columns occupied by any
5024 'foldcolumn', 'signcolumn' and line
5025 number in front of the text
5026 winid |window-ID|
5027 winnr window number
5028 winrow topmost screen line of the window;
5029 "row" from |win_screenpos()|
5030
5031 Can also be used as a |method|: >
5032 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005033<
5034 Return type: list<dict<any>>
5035
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005036
5037getwinpos([{timeout}]) *getwinpos()*
5038 The result is a |List| with two numbers, the result of
5039 |getwinposx()| and |getwinposy()| combined:
5040 [x-pos, y-pos]
5041 {timeout} can be used to specify how long to wait in msec for
5042 a response from the terminal. When omitted 100 msec is used.
5043 Use a longer time for a remote terminal.
5044 When using a value less than 10 and no response is received
5045 within that time, a previously reported position is returned,
5046 if available. This can be used to poll for the position and
5047 do some work in the meantime: >
5048 while 1
5049 let res = getwinpos(1)
5050 if res[0] >= 0
5051 break
5052 endif
5053 " Do some work here
5054 endwhile
5055<
5056
5057 Can also be used as a |method|: >
5058 GetTimeout()->getwinpos()
5059<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005060 Return type: list<number>
5061
5062
5063getwinposx() *getwinposx()*
5064 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005065 the left hand side of the GUI Vim window. Also works for an
5066 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005067 The result will be -1 if the information is not available
5068 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005069 The value can be used with `:winpos`.
5070
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005071 Return type: |Number|
5072
5073
5074getwinposy() *getwinposy()*
5075 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005076 the top of the GUI Vim window. Also works for an xterm (uses
5077 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005078 The result will be -1 if the information is not available
5079 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005080 The value can be used with `:winpos`.
5081
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005082 Return type: |Number|
5083
5084
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005085getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5086 Like |gettabwinvar()| for the current tabpage.
5087 Examples: >
5088 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005089 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005090
5091< Can also be used as a |method|: >
5092 GetWinnr()->getwinvar(varname)
5093<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005094 Return type: any, depending on {varname}
5095
5096
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005097glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5098 Expand the file wildcards in {expr}. See |wildcards| for the
5099 use of special characters.
5100
5101 Unless the optional {nosuf} argument is given and is |TRUE|,
5102 the 'suffixes' and 'wildignore' options apply: Names matching
5103 one of the patterns in 'wildignore' will be skipped and
5104 'suffixes' affect the ordering of matches.
5105 'wildignorecase' always applies.
5106
5107 When {list} is present and it is |TRUE| the result is a |List|
5108 with all matching files. The advantage of using a List is,
5109 you also get filenames containing newlines correctly.
5110 Otherwise the result is a String and when there are several
5111 matches, they are separated by <NL> characters.
5112
5113 If the expansion fails, the result is an empty String or List.
5114
5115 You can also use |readdir()| if you need to do complicated
5116 things, such as limiting the number of matches.
5117
5118 A name for a non-existing file is not included. A symbolic
5119 link is only included if it points to an existing file.
5120 However, when the {alllinks} argument is present and it is
5121 |TRUE| then all symbolic links are included.
5122
5123 For most systems backticks can be used to get files names from
5124 any external command. Example: >
5125 :let tagfiles = glob("`find . -name tags -print`")
5126 :let &tags = substitute(tagfiles, "\n", ",", "g")
5127< The result of the program inside the backticks should be one
5128 item per line. Spaces inside an item are allowed.
5129
5130 See |expand()| for expanding special Vim variables. See
5131 |system()| for getting the raw output of an external command.
5132
5133 Can also be used as a |method|: >
5134 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005135<
5136 Return type: |String| or list<string> or list<any> depending
5137 on {list}
5138
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005139
5140glob2regpat({string}) *glob2regpat()*
5141 Convert a file pattern, as used by glob(), into a search
5142 pattern. The result can be used to match with a string that
5143 is a file name. E.g. >
5144 if filename =~ glob2regpat('Make*.mak')
5145< This is equivalent to: >
5146 if filename =~ '^Make.*\.mak$'
5147< When {string} is an empty string the result is "^$", match an
5148 empty string.
5149 Note that the result depends on the system. On MS-Windows
5150 a backslash usually means a path separator.
5151
5152 Can also be used as a |method|: >
5153 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005154<
5155 Return type: |String|
5156
5157 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005158globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5159 Perform glob() for String {expr} on all directories in {path}
5160 and concatenate the results. Example: >
5161 :echo globpath(&rtp, "syntax/c.vim")
5162<
5163 {path} is a comma-separated list of directory names. Each
5164 directory name is prepended to {expr} and expanded like with
5165 |glob()|. A path separator is inserted when needed.
5166 To add a comma inside a directory name escape it with a
5167 backslash. Note that on MS-Windows a directory may have a
5168 trailing backslash, remove it if you put a comma after it.
5169 If the expansion fails for one of the directories, there is no
5170 error message.
5171
5172 Unless the optional {nosuf} argument is given and is |TRUE|,
5173 the 'suffixes' and 'wildignore' options apply: Names matching
5174 one of the patterns in 'wildignore' will be skipped and
5175 'suffixes' affect the ordering of matches.
5176
5177 When {list} is present and it is |TRUE| the result is a |List|
5178 with all matching files. The advantage of using a List is, you
5179 also get filenames containing newlines correctly. Otherwise
5180 the result is a String and when there are several matches,
5181 they are separated by <NL> characters. Example: >
5182 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5183<
5184 {alllinks} is used as with |glob()|.
5185
5186 The "**" item can be used to search in a directory tree.
5187 For example, to find all "README.txt" files in the directories
5188 in 'runtimepath' and below: >
5189 :echo globpath(&rtp, "**/README.txt")
5190< Upwards search and limiting the depth of "**" is not
5191 supported, thus using 'path' will not always work properly.
5192
5193 Can also be used as a |method|, the base is passed as the
5194 second argument: >
5195 GetExpr()->globpath(&rtp)
5196<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005197 Return type: |String| or list<string> or list<any> depending
5198 on {list}
5199
5200
5201has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005202 When {check} is omitted or is zero: The result is a Number,
5203 which is 1 if the feature {feature} is supported, zero
5204 otherwise. The {feature} argument is a string, case is
5205 ignored. See |feature-list| below.
5206
5207 When {check} is present and not zero: The result is a Number,
5208 which is 1 if the feature {feature} could ever be supported,
5209 zero otherwise. This is useful to check for a typo in
5210 {feature} and to detect dead code. Keep in mind that an older
5211 Vim version will not know about a feature added later and
5212 features that have been abandoned will not be known by the
5213 current Vim version.
5214
5215 Also see |exists()| and |exists_compiled()|.
5216
5217 Note that to skip code that has a syntax error when the
5218 feature is not available, Vim may skip the rest of the line
5219 and miss a following `endif`. Therefore put the `endif` on a
5220 separate line: >
5221 if has('feature')
5222 let x = this->breaks->without->the->feature
5223 endif
5224< If the `endif` would be moved to the second line as "| endif" it
5225 would not be found.
5226
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005227 Return type: |Number|
5228
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005229
5230has_key({dict}, {key}) *has_key()*
5231 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005232 has an entry with key {key}. FALSE otherwise.
5233 The {key} argument is a string. In |Vim9| script a number is
5234 also accepted (and converted to a string) but no other types.
5235 In legacy script the usual automatic conversion to string is
5236 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005237
5238 Can also be used as a |method|: >
5239 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005240<
5241 Return type: |Number|
5242
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005243
5244haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5245 The result is a Number:
5246 1 when the window has set a local directory via |:lcd|
5247 2 when the tab-page has set a local directory via |:tcd|
5248 0 otherwise.
5249
5250 Without arguments use the current window.
5251 With {winnr} use this window in the current tab page.
5252 With {winnr} and {tabnr} use the window in the specified tab
5253 page.
5254 {winnr} can be the window number or the |window-ID|.
5255 If {winnr} is -1 it is ignored and only the tabpage is used.
5256 Return 0 if the arguments are invalid.
5257 Examples: >
5258 if haslocaldir() == 1
5259 " window local directory case
5260 elseif haslocaldir() == 2
5261 " tab-local directory case
5262 else
5263 " global directory case
5264 endif
5265
5266 " current window
5267 :echo haslocaldir()
5268 :echo haslocaldir(0)
5269 :echo haslocaldir(0, 0)
5270 " window n in current tab page
5271 :echo haslocaldir(n)
5272 :echo haslocaldir(n, 0)
5273 " window n in tab page m
5274 :echo haslocaldir(n, m)
5275 " tab page m
5276 :echo haslocaldir(-1, m)
5277<
5278 Can also be used as a |method|: >
5279 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005280<
5281 Return type: |Number|
5282
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005283
5284hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5285 The result is a Number, which is TRUE if there is a mapping
5286 that contains {what} in somewhere in the rhs (what it is
5287 mapped to) and this mapping exists in one of the modes
5288 indicated by {mode}.
5289 The arguments {what} and {mode} are strings.
5290 When {abbr} is there and it is |TRUE| use abbreviations
5291 instead of mappings. Don't forget to specify Insert and/or
5292 Command-line mode.
5293 Both the global mappings and the mappings local to the current
5294 buffer are checked for a match.
5295 If no matching mapping is found FALSE is returned.
5296 The following characters are recognized in {mode}:
5297 n Normal mode
5298 v Visual and Select mode
5299 x Visual mode
5300 s Select mode
5301 o Operator-pending mode
5302 i Insert mode
5303 l Language-Argument ("r", "f", "t", etc.)
5304 c Command-line mode
5305 When {mode} is omitted, "nvo" is used.
5306
5307 This function is useful to check if a mapping already exists
5308 to a function in a Vim script. Example: >
5309 :if !hasmapto('\ABCdoit')
5310 : map <Leader>d \ABCdoit
5311 :endif
5312< This installs the mapping to "\ABCdoit" only if there isn't
5313 already a mapping to "\ABCdoit".
5314
5315 Can also be used as a |method|: >
5316 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005317<
5318 Return type: |Number|
5319
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005320
5321histadd({history}, {item}) *histadd()*
5322 Add the String {item} to the history {history} which can be
5323 one of: *hist-names*
5324 "cmd" or ":" command line history
5325 "search" or "/" search pattern history
5326 "expr" or "=" typed expression history
5327 "input" or "@" input line history
5328 "debug" or ">" debug command history
5329 empty the current or last used history
5330 The {history} string does not need to be the whole name, one
5331 character is sufficient.
5332 If {item} does already exist in the history, it will be
5333 shifted to become the newest entry.
5334 The result is a Number: TRUE if the operation was successful,
5335 otherwise FALSE is returned.
5336
5337 Example: >
5338 :call histadd("input", strftime("%Y %b %d"))
5339 :let date=input("Enter date: ")
5340< This function is not available in the |sandbox|.
5341
5342 Can also be used as a |method|, the base is passed as the
5343 second argument: >
5344 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005345<
5346 Return type: |Number|
5347
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005348
5349histdel({history} [, {item}]) *histdel()*
5350 Clear {history}, i.e. delete all its entries. See |hist-names|
5351 for the possible values of {history}.
5352
5353 If the parameter {item} evaluates to a String, it is used as a
5354 regular expression. All entries matching that expression will
5355 be removed from the history (if there are any).
5356 Upper/lowercase must match, unless "\c" is used |/\c|.
5357 If {item} evaluates to a Number, it will be interpreted as
5358 an index, see |:history-indexing|. The respective entry will
5359 be removed if it exists.
5360
5361 The result is TRUE for a successful operation, otherwise FALSE
5362 is returned.
5363
5364 Examples:
5365 Clear expression register history: >
5366 :call histdel("expr")
5367<
5368 Remove all entries starting with "*" from the search history: >
5369 :call histdel("/", '^\*')
5370<
5371 The following three are equivalent: >
5372 :call histdel("search", histnr("search"))
5373 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005374 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005375<
5376 To delete the last search pattern and use the last-but-one for
5377 the "n" command and 'hlsearch': >
5378 :call histdel("search", -1)
5379 :let @/ = histget("search", -1)
5380<
5381 Can also be used as a |method|: >
5382 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005383<
5384 Return type: |Number|
5385
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005386
5387histget({history} [, {index}]) *histget()*
5388 The result is a String, the entry with Number {index} from
5389 {history}. See |hist-names| for the possible values of
5390 {history}, and |:history-indexing| for {index}. If there is
5391 no such entry, an empty String is returned. When {index} is
5392 omitted, the most recent item from the history is used.
5393
5394 Examples:
5395 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005396 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005397
5398< Define an Ex command ":H {num}" that supports re-execution of
5399 the {num}th entry from the output of |:history|. >
5400 :command -nargs=1 H execute histget("cmd", 0+<args>)
5401<
5402 Can also be used as a |method|: >
5403 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005404<
5405 Return type: |String|
5406
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005407
5408histnr({history}) *histnr()*
5409 The result is the Number of the current entry in {history}.
5410 See |hist-names| for the possible values of {history}.
5411 If an error occurred, -1 is returned.
5412
5413 Example: >
5414 :let inp_index = histnr("expr")
5415
5416< Can also be used as a |method|: >
5417 GetHistory()->histnr()
5418<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005419 Return type: |Number|
5420
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005421hlexists({name}) *hlexists()*
5422 The result is a Number, which is TRUE if a highlight group
5423 called {name} exists. This is when the group has been
5424 defined in some way. Not necessarily when highlighting has
5425 been defined for it, it may also have been used for a syntax
5426 item.
5427 *highlight_exists()*
5428 Obsolete name: highlight_exists().
5429
5430 Can also be used as a |method|: >
5431 GetName()->hlexists()
5432<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005433 Return type: |Number|
5434
5435
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005436hlget([{name} [, {resolve}]]) *hlget()*
5437 Returns a List of all the highlight group attributes. If the
5438 optional {name} is specified, then returns a List with only
5439 the attributes of the specified highlight group. Returns an
5440 empty List if the highlight group {name} is not present.
5441
5442 If the optional {resolve} argument is set to v:true and the
5443 highlight group {name} is linked to another group, then the
5444 link is resolved recursively and the attributes of the
5445 resolved highlight group are returned.
5446
5447 Each entry in the returned List is a Dictionary with the
5448 following items:
5449 cleared boolean flag, set to v:true if the highlight
5450 group attributes are cleared or not yet
5451 specified. See |highlight-clear|.
5452 cterm cterm attributes. See |highlight-cterm|.
5453 ctermbg cterm background color.
5454 See |highlight-ctermbg|.
5455 ctermfg cterm foreground color.
5456 See |highlight-ctermfg|.
5457 ctermul cterm underline color. See |highlight-ctermul|.
5458 default boolean flag, set to v:true if the highlight
5459 group link is a default link. See
5460 |highlight-default|.
5461 font highlight group font. See |highlight-font|.
5462 gui gui attributes. See |highlight-gui|.
5463 guibg gui background color. See |highlight-guibg|.
5464 guifg gui foreground color. See |highlight-guifg|.
5465 guisp gui special color. See |highlight-guisp|.
5466 id highlight group ID.
5467 linksto linked highlight group name.
5468 See |:highlight-link|.
5469 name highlight group name. See |group-name|.
5470 start start terminal keycode. See |highlight-start|.
5471 stop stop terminal keycode. See |highlight-stop|.
5472 term term attributes. See |highlight-term|.
5473
5474 The 'term', 'cterm' and 'gui' items in the above Dictionary
5475 have a dictionary value with the following optional boolean
5476 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5477 'reverse', 'inverse' and 'strikethrough'.
5478
5479 Example(s): >
5480 :echo hlget()
5481 :echo hlget('ModeMsg')
5482 :echo hlget('Number', v:true)
5483<
5484 Can also be used as a |method|: >
5485 GetName()->hlget()
5486<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005487 Return type: list<dict<any>>
5488
5489
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005490hlset({list}) *hlset()*
5491 Creates or modifies the attributes of a List of highlight
5492 groups. Each item in {list} is a dictionary containing the
5493 attributes of a highlight group. See |hlget()| for the list of
5494 supported items in this dictionary.
5495
5496 In addition to the items described in |hlget()|, the following
5497 additional items are supported in the dictionary:
5498
5499 force boolean flag to force the creation of
5500 a link for an existing highlight group
5501 with attributes.
5502
5503 The highlight group is identified using the 'name' item and
5504 the 'id' item (if supplied) is ignored. If a highlight group
5505 with a specified name doesn't exist, then it is created.
5506 Otherwise the attributes of an existing highlight group are
5507 modified.
5508
5509 If an empty dictionary value is used for the 'term' or 'cterm'
5510 or 'gui' entries, then the corresponding attributes are
5511 cleared. If the 'cleared' item is set to v:true, then all the
5512 attributes of the highlight group are cleared.
5513
5514 The 'linksto' item can be used to link a highlight group to
5515 another highlight group. See |:highlight-link|.
5516
5517 Returns zero for success, -1 for failure.
5518
5519 Example(s): >
5520 " add bold attribute to the Visual highlight group
5521 :call hlset([#{name: 'Visual',
5522 \ term: #{reverse: 1 , bold: 1}}])
5523 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5524 :let l = hlget()
5525 :call hlset(l)
5526 " clear the Search highlight group
5527 :call hlset([#{name: 'Search', cleared: v:true}])
5528 " clear the 'term' attributes for a highlight group
5529 :call hlset([#{name: 'Title', term: {}}])
5530 " create the MyHlg group linking it to DiffAdd
5531 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5532 " remove the MyHlg group link
5533 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5534 " clear the attributes and a link
5535 :call hlset([#{name: 'MyHlg', cleared: v:true,
5536 \ linksto: 'NONE'}])
5537<
5538 Can also be used as a |method|: >
5539 GetAttrList()->hlset()
5540<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005541 Return type: |Number|
5542
5543hlID({name}) *hlID()*
5544 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005545 with name {name}. When the highlight group doesn't exist,
5546 zero is returned.
5547 This can be used to retrieve information about the highlight
5548 group. For example, to get the background color of the
5549 "Comment" group: >
5550 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5551< *highlightID()*
5552 Obsolete name: highlightID().
5553
5554 Can also be used as a |method|: >
5555 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005556<
5557 Return type: |Number|
5558
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005559
5560hostname() *hostname()*
5561 The result is a String, which is the name of the machine on
5562 which Vim is currently running. Machine names greater than
5563 256 characters long are truncated.
5564
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005565 Return type: |String|
5566
5567
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005568iconv({string}, {from}, {to}) *iconv()*
5569 The result is a String, which is the text {string} converted
5570 from encoding {from} to encoding {to}.
5571 When the conversion completely fails an empty string is
5572 returned. When some characters could not be converted they
5573 are replaced with "?".
5574 The encoding names are whatever the iconv() library function
5575 can accept, see ":!man 3 iconv".
5576 Most conversions require Vim to be compiled with the |+iconv|
5577 feature. Otherwise only UTF-8 to latin1 conversion and back
5578 can be done.
5579 This can be used to display messages with special characters,
5580 no matter what 'encoding' is set to. Write the message in
5581 UTF-8 and use: >
5582 echo iconv(utf8_str, "utf-8", &enc)
5583< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5584 from/to UCS-2 is automatically changed to use UTF-8. You
5585 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5586
5587 Can also be used as a |method|: >
5588 GetText()->iconv('latin1', 'utf-8')
5589<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005590 Return type: |String|
5591
5592
5593indent({lnum}) *indent()*
5594 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005595 current buffer. The indent is counted in spaces, the value
5596 of 'tabstop' is relevant. {lnum} is used just like in
5597 |getline()|.
5598 When {lnum} is invalid -1 is returned. In |Vim9| script an
5599 error is given.
5600
5601 Can also be used as a |method|: >
5602 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005603<
5604 Return type: |Number|
5605
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005606
5607index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005608 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005609 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005610
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005611 If {object} is a |List| return the lowest index where the item
5612 has a value equal to {expr}. There is no automatic
5613 conversion, so the String "4" is different from the Number 4.
5614 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005615 of 'ignorecase' is not used here, case matters as indicated by
5616 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005617
5618 If {object} is |Blob| return the lowest index where the byte
5619 value is equal to {expr}.
5620
5621 If {start} is given then start looking at the item with index
5622 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005623
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005624 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5625 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005626
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005627 -1 is returned when {expr} is not found in {object}.
5628 Example: >
5629 :let idx = index(words, "the")
5630 :if index(numbers, 123) >= 0
5631
5632< Can also be used as a |method|: >
5633 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005634<
5635 Return type: |Number|
5636
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005637
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005638indexof({object}, {expr} [, {opts}]) *indexof()*
5639 Returns the index of an item in {object} where {expr} is
5640 v:true. {object} must be a |List| or a |Blob|.
5641
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005642 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005643 List until the expression is v:true and return the index of
5644 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005645
5646 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005647 Blob until the expression is v:true and return the index of
5648 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005649
5650 {expr} must be a |string| or |Funcref|.
5651
5652 If {expr} is a |string|: If {object} is a |List|, inside
5653 {expr} |v:key| has the index of the current List item and
5654 |v:val| has the value of the item. If {object} is a |Blob|,
5655 inside {expr} |v:key| has the index of the current byte and
5656 |v:val| has the byte value.
5657
5658 If {expr} is a |Funcref| it must take two arguments:
5659 1. the key or the index of the current item.
5660 2. the value of the current item.
5661 The function must return |TRUE| if the item is found and the
5662 search should stop.
5663
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005664 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005665 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005666 startidx start evaluating {expr} at the item with this
5667 index; may be negative for an item relative to
5668 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005669 Returns -1 when {expr} evaluates to v:false for all the items.
5670 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005671 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
5672 :echo indexof(l, "v:val.n == 20")
5673 :echo indexof(l, {i, v -> v.n == 30})
5674 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005675
5676< Can also be used as a |method|: >
5677 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005678<
5679 Return type: |Number|
5680
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005681
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005682input({prompt} [, {text} [, {completion}]]) *input()*
5683 The result is a String, which is whatever the user typed on
5684 the command-line. The {prompt} argument is either a prompt
5685 string, or a blank string (for no prompt). A '\n' can be used
5686 in the prompt to start a new line.
5687 The highlighting set with |:echohl| is used for the prompt.
5688 The input is entered just like a command-line, with the same
5689 editing commands and mappings. There is a separate history
5690 for lines typed for input().
5691 Example: >
5692 :if input("Coffee or beer? ") == "beer"
5693 : echo "Cheers!"
5694 :endif
5695<
5696 If the optional {text} argument is present and not empty, this
5697 is used for the default reply, as if the user typed this.
5698 Example: >
5699 :let color = input("Color? ", "white")
5700
5701< The optional {completion} argument specifies the type of
5702 completion supported for the input. Without it completion is
5703 not performed. The supported completion types are the same as
5704 that can be supplied to a user-defined command using the
5705 "-complete=" argument. Refer to |:command-completion| for
5706 more information. Example: >
5707 let fname = input("File: ", "", "file")
5708<
5709 NOTE: This function must not be used in a startup file, for
5710 the versions that only run in GUI mode (e.g., the Win32 GUI).
5711 Note: When input() is called from within a mapping it will
5712 consume remaining characters from that mapping, because a
5713 mapping is handled like the characters were typed.
5714 Use |inputsave()| before input() and |inputrestore()|
5715 after input() to avoid that. Another solution is to avoid
5716 that further characters follow in the mapping, e.g., by using
5717 |:execute| or |:normal|.
5718
5719 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005720 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005721 :function GetFoo()
5722 : call inputsave()
5723 : let g:Foo = input("enter search pattern: ")
5724 : call inputrestore()
5725 :endfunction
5726
5727< Can also be used as a |method|: >
5728 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005729<
5730 Return type: |String|
5731
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005732
5733inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
5734 Like |input()|, but when the GUI is running and text dialogs
5735 are supported, a dialog window pops up to input the text.
5736 Example: >
5737 :let n = inputdialog("value for shiftwidth", shiftwidth())
5738 :if n != ""
5739 : let &sw = n
5740 :endif
5741< When the dialog is cancelled {cancelreturn} is returned. When
5742 omitted an empty string is returned.
5743 Hitting <Enter> works like pressing the OK button. Hitting
5744 <Esc> works like pressing the Cancel button.
5745 NOTE: Command-line completion is not supported.
5746
5747 Can also be used as a |method|: >
5748 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005749<
5750 Return type: |String|
5751
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005752
5753inputlist({textlist}) *inputlist()*
5754 {textlist} must be a |List| of strings. This |List| is
5755 displayed, one string per line. The user will be prompted to
5756 enter a number, which is returned.
5757 The user can also select an item by clicking on it with the
5758 mouse, if the mouse is enabled in the command line ('mouse' is
5759 "a" or includes "c"). For the first string 0 is returned.
5760 When clicking above the first item a negative number is
5761 returned. When clicking on the prompt one more than the
5762 length of {textlist} is returned.
5763 Make sure {textlist} has less than 'lines' entries, otherwise
5764 it won't work. It's a good idea to put the entry number at
5765 the start of the string. And put a prompt in the first item.
5766 Example: >
5767 let color = inputlist(['Select color:', '1. red',
5768 \ '2. green', '3. blue'])
5769
5770< Can also be used as a |method|: >
5771 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005772<
5773 Return type: |Number|
5774
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005775
5776inputrestore() *inputrestore()*
5777 Restore typeahead that was saved with a previous |inputsave()|.
5778 Should be called the same number of times inputsave() is
5779 called. Calling it more often is harmless though.
5780 Returns TRUE when there is nothing to restore, FALSE otherwise.
5781
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005782 Return type: |Number|
5783
5784
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005785inputsave() *inputsave()*
5786 Preserve typeahead (also from mappings) and clear it, so that
5787 a following prompt gets input from the user. Should be
5788 followed by a matching inputrestore() after the prompt. Can
5789 be used several times, in which case there must be just as
5790 many inputrestore() calls.
5791 Returns TRUE when out of memory, FALSE otherwise.
5792
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005793 Return type: |Number|
5794
5795
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005796inputsecret({prompt} [, {text}]) *inputsecret()*
5797 This function acts much like the |input()| function with but
5798 two exceptions:
5799 a) the user's response will be displayed as a sequence of
5800 asterisks ("*") thereby keeping the entry secret, and
5801 b) the user's response will not be recorded on the input
5802 |history| stack.
5803 The result is a String, which is whatever the user actually
5804 typed on the command-line in response to the issued prompt.
5805 NOTE: Command-line completion is not supported.
5806
5807 Can also be used as a |method|: >
5808 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005809<
5810 Return type: |String|
5811
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005812
5813insert({object}, {item} [, {idx}]) *insert()*
5814 When {object} is a |List| or a |Blob| insert {item} at the start
5815 of it.
5816
5817 If {idx} is specified insert {item} before the item with index
5818 {idx}. If {idx} is zero it goes before the first item, just
5819 like omitting {idx}. A negative {idx} is also possible, see
5820 |list-index|. -1 inserts just before the last item.
5821
5822 Returns the resulting |List| or |Blob|. Examples: >
5823 :let mylist = insert([2, 3, 5], 1)
5824 :call insert(mylist, 4, -1)
5825 :call insert(mylist, 6, len(mylist))
5826< The last example can be done simpler with |add()|.
5827 Note that when {item} is a |List| it is inserted as a single
5828 item. Use |extend()| to concatenate |Lists|.
5829
5830 Can also be used as a |method|: >
5831 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005832<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005833 Return type: |Number|
5834
5835
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005836 *instanceof()* *E614* *E616* *E693*
5837instanceof({object}, {class})
5838 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01005839 argument is a direct or indirect instance of a |Class|,
5840 |Interface|, or class |:type| alias specified by {class}.
5841 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005842 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02005843 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01005844 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02005845
5846< Can also be used as a |method|: >
5847 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005848<
5849 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02005850
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005851interrupt() *interrupt()*
5852 Interrupt script execution. It works more or less like the
5853 user typing CTRL-C, most commands won't execute and control
5854 returns to the user. This is useful to abort execution
5855 from lower down, e.g. in an autocommand. Example: >
5856 :function s:check_typoname(file)
5857 : if fnamemodify(a:file, ':t') == '['
5858 : echomsg 'Maybe typo'
5859 : call interrupt()
5860 : endif
5861 :endfunction
5862 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005863<
5864 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005865
5866invert({expr}) *invert()*
5867 Bitwise invert. The argument is converted to a number. A
5868 List, Dict or Float argument causes an error. Example: >
5869 :let bits = invert(bits)
5870< Can also be used as a |method|: >
5871 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005872<
5873 Return type: |Number|
5874
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005875
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005876isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01005877 The result is a Number, which is |TRUE| when {path} is an
5878 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005879 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01005880 On MS-Windows, it is considered absolute when it starts with an
5881 optional drive prefix and is followed by a '\' or '/'. UNC paths
5882 are always absolute.
5883 Example: >
5884 echo isabsolutepath('/usr/share/') " 1
5885 echo isabsolutepath('./foobar') " 0
5886 echo isabsolutepath('C:\Windows') " 1
5887 echo isabsolutepath('foobar') " 0
5888 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005889<
LemonBoydca1d402022-04-28 15:26:33 +01005890 Can also be used as a |method|: >
5891 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005892<
5893 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01005894
5895
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005896isdirectory({directory}) *isdirectory()*
5897 The result is a Number, which is |TRUE| when a directory
5898 with the name {directory} exists. If {directory} doesn't
5899 exist, or isn't a directory, the result is |FALSE|. {directory}
5900 is any expression, which is used as a String.
5901
5902 Can also be used as a |method|: >
5903 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005904<
5905 Return type: |Number|
5906
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005907
5908isinf({expr}) *isinf()*
5909 Return 1 if {expr} is a positive infinity, or -1 a negative
5910 infinity, otherwise 0. >
5911 :echo isinf(1.0 / 0.0)
5912< 1 >
5913 :echo isinf(-1.0 / 0.0)
5914< -1
5915
5916 Can also be used as a |method|: >
5917 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005918<
5919 Return type: |Number|
5920
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005921
5922islocked({expr}) *islocked()* *E786*
5923 The result is a Number, which is |TRUE| when {expr} is the
5924 name of a locked variable.
5925 The string argument {expr} must be the name of a variable,
5926 |List| item or |Dictionary| entry, not the variable itself!
5927 Example: >
5928 :let alist = [0, ['a', 'b'], 2, 3]
5929 :lockvar 1 alist
5930 :echo islocked('alist') " 1
5931 :echo islocked('alist[1]') " 0
5932
Bram Moolenaar9da17d72022-02-09 21:50:44 +00005933< When {expr} is a variable that does not exist -1 is returned.
5934 If {expr} uses a range, list or dict index that is out of
5935 range or does not exist you get an error message. Use
5936 |exists()| to check for existence.
5937 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005938
5939 Can also be used as a |method|: >
5940 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005941<
5942 Return type: |Number|
5943
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005944
5945isnan({expr}) *isnan()*
5946 Return |TRUE| if {expr} is a float with value NaN. >
5947 echo isnan(0.0 / 0.0)
5948< 1
5949
5950 Can also be used as a |method|: >
5951 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005952<
5953 Return type: |Number|
5954
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005955
5956items({dict}) *items()*
5957 Return a |List| with all the key-value pairs of {dict}. Each
5958 |List| item is a list with two items: the key of a {dict}
5959 entry and the value of this entry. The |List| is in arbitrary
5960 order. Also see |keys()| and |values()|.
5961 Example: >
5962 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005963 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005964 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01005965<
5966 A List or a String argument is also supported. In these
5967 cases, items() returns a List with the index and the value at
5968 the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005969
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01005970 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005971 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005972<
5973 Return type: list<list<any>> or list<any>
5974
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005975
5976job_ functions are documented here: |job-functions-details|
5977
5978
5979join({list} [, {sep}]) *join()*
5980 Join the items in {list} together into one String.
5981 When {sep} is specified it is put in between the items. If
5982 {sep} is omitted a single space is used.
5983 Note that {sep} is not added at the end. You might want to
5984 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005985 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005986< String items are used as-is. |Lists| and |Dictionaries| are
5987 converted into a string like with |string()|.
5988 The opposite function is |split()|.
5989
5990 Can also be used as a |method|: >
5991 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005992<
5993 Return type: |String|
5994
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005995
5996js_decode({string}) *js_decode()*
5997 This is similar to |json_decode()| with these differences:
5998 - Object key names do not have to be in quotes.
5999 - Strings can be in single quotes.
6000 - Empty items in an array (between two commas) are allowed and
6001 result in v:none items.
6002
6003 Can also be used as a |method|: >
6004 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006005<
6006 Return type: any, depending on {varname}
6007
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006008
6009js_encode({expr}) *js_encode()*
6010 This is similar to |json_encode()| with these differences:
6011 - Object key names are not in quotes.
6012 - v:none items in an array result in an empty item between
6013 commas.
6014 For example, the Vim object:
6015 [1,v:none,{"one":1},v:none] ~
6016 Will be encoded as:
6017 [1,,{one:1},,] ~
6018 While json_encode() would produce:
6019 [1,null,{"one":1},null] ~
6020 This encoding is valid for JavaScript. It is more efficient
6021 than JSON, especially when using an array with optional items.
6022
6023 Can also be used as a |method|: >
6024 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006025<
6026 Return type: |String|
6027
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006028
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006029json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006030 This parses a JSON formatted string and returns the equivalent
6031 in Vim values. See |json_encode()| for the relation between
6032 JSON and Vim values.
6033 The decoding is permissive:
6034 - A trailing comma in an array and object is ignored, e.g.
6035 "[1, 2, ]" is the same as "[1, 2]".
6036 - Integer keys are accepted in objects, e.g. {1:2} is the
6037 same as {"1":2}.
6038 - More floating point numbers are recognized, e.g. "1." for
6039 "1.0", or "001.2" for "1.2". Special floating point values
6040 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6041 are accepted.
6042 - Leading zeroes in integer numbers are ignored, e.g. "012"
6043 for "12" or "-012" for "-12".
6044 - Capitalization is ignored in literal names null, true or
6045 false, e.g. "NULL" for "null", "True" for "true".
6046 - Control characters U+0000 through U+001F which are not
6047 escaped in strings are accepted, e.g. " " (tab
6048 character in string) for "\t".
6049 - An empty JSON expression or made of only spaces is accepted
6050 and results in v:none.
6051 - Backslash in an invalid 2-character sequence escape is
6052 ignored, e.g. "\a" is decoded as "a".
6053 - A correct surrogate pair in JSON strings should normally be
6054 a 12 character sequence such as "\uD834\uDD1E", but
6055 json_decode() silently accepts truncated surrogate pairs
6056 such as "\uD834" or "\uD834\u"
6057 *E938*
6058 A duplicate key in an object, valid in rfc7159, is not
6059 accepted by json_decode() as the result must be a valid Vim
6060 type, e.g. this fails: {"a":"b", "a":"c"}
6061
6062 Can also be used as a |method|: >
6063 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006064<
6065 Return type: any, depending on {varname}
6066
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006067
6068json_encode({expr}) *json_encode()*
6069 Encode {expr} as JSON and return this as a string.
6070 The encoding is specified in:
6071 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006072 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006073 |Number| decimal number
6074 |Float| floating point number
6075 Float nan "NaN"
6076 Float inf "Infinity"
6077 Float -inf "-Infinity"
6078 |String| in double quotes (possibly null)
6079 |Funcref| not possible, error
6080 |List| as an array (possibly null); when
6081 used recursively: []
6082 |Dict| as an object (possibly null); when
6083 used recursively: {}
6084 |Blob| as an array of the individual bytes
6085 v:false "false"
6086 v:true "true"
6087 v:none "null"
6088 v:null "null"
6089 Note that NaN and Infinity are passed on as values. This is
6090 missing in the JSON standard, but several implementations do
6091 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006092 If a string contains an illegal character then the replacement
6093 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006094
6095 Can also be used as a |method|: >
6096 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006097<
6098 Return type: |String|
6099
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006100
6101keys({dict}) *keys()*
6102 Return a |List| with all the keys of {dict}. The |List| is in
6103 arbitrary order. Also see |items()| and |values()|.
6104
6105 Can also be used as a |method|: >
6106 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006107<
6108 Return type: list<string>
6109
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006110
zeertzjqcdc83932022-09-12 13:38:41 +01006111keytrans({string}) *keytrans()*
6112 Turn the internal byte representation of keys into a form that
6113 can be used for |:map|. E.g. >
6114 :let xx = "\<C-Home>"
6115 :echo keytrans(xx)
6116< <C-Home>
6117
6118 Can also be used as a |method|: >
6119 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006120<
6121 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006122
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006123
6124len({expr}) *len()* *E701*
6125 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006126 When {expr} is a String or a Number the length in bytes is
6127 used, as with |strlen()|.
6128 When {expr} is a |List| the number of items in the |List| is
6129 returned.
6130 When {expr} is a |Blob| the number of bytes is returned.
6131 When {expr} is a |Dictionary| the number of entries in the
6132 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006133 When {expr} is an |Object|, invokes the len() method in the
6134 object (if present) to get the length (|object-len()|).
6135 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006136
6137 Can also be used as a |method|: >
6138 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006139<
6140 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006141
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006142
6143 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006144libcall({libname}, {funcname}, {argument})
6145 Call function {funcname} in the run-time library {libname}
6146 with single argument {argument}.
6147 This is useful to call functions in a library that you
6148 especially made to be used with Vim. Since only one argument
6149 is possible, calling standard library functions is rather
6150 limited.
6151 The result is the String returned by the function. If the
6152 function returns NULL, this will appear as an empty string ""
6153 to Vim.
6154 If the function returns a number, use libcallnr()!
6155 If {argument} is a number, it is passed to the function as an
6156 int; if {argument} is a string, it is passed as a
6157 null-terminated string.
6158 This function will fail in |restricted-mode|.
6159
6160 libcall() allows you to write your own 'plug-in' extensions to
6161 Vim without having to recompile the program. It is NOT a
6162 means to call system functions! If you try to do so Vim will
6163 very probably crash.
6164
6165 For Win32, the functions you write must be placed in a DLL
6166 and use the normal C calling convention (NOT Pascal which is
6167 used in Windows System DLLs). The function must take exactly
6168 one parameter, either a character pointer or a long integer,
6169 and must return a character pointer or NULL. The character
6170 pointer returned must point to memory that will remain valid
6171 after the function has returned (e.g. in static data in the
6172 DLL). If it points to allocated memory, that memory will
6173 leak away. Using a static buffer in the function should work,
6174 it's then freed when the DLL is unloaded.
6175
6176 WARNING: If the function returns a non-valid pointer, Vim may
6177 crash! This also happens if the function returns a number,
6178 because Vim thinks it's a pointer.
6179 For Win32 systems, {libname} should be the filename of the DLL
6180 without the ".DLL" suffix. A full path is only required if
6181 the DLL is not in the usual places.
6182 For Unix: When compiling your own plugins, remember that the
6183 object code must be compiled as position-independent ('PIC').
6184 {only in Win32 and some Unix versions, when the |+libcall|
6185 feature is present}
6186 Examples: >
6187 :echo libcall("libc.so", "getenv", "HOME")
6188
6189< Can also be used as a |method|, the base is passed as the
6190 third argument: >
6191 GetValue()->libcall("libc.so", "getenv")
6192<
6193 *libcallnr()*
6194libcallnr({libname}, {funcname}, {argument})
6195 Just like |libcall()|, but used for a function that returns an
6196 int instead of a string.
6197 {only in Win32 on some Unix versions, when the |+libcall|
6198 feature is present}
6199 Examples: >
6200 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6201 :call libcallnr("libc.so", "printf", "Hello World!\n")
6202 :call libcallnr("libc.so", "sleep", 10)
6203<
6204 Can also be used as a |method|, the base is passed as the
6205 third argument: >
6206 GetValue()->libcallnr("libc.so", "printf")
6207<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006208 Return type: |String|
6209
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006210
6211line({expr} [, {winid}]) *line()*
6212 The result is a Number, which is the line number of the file
6213 position given with {expr}. The {expr} argument is a string.
zeertzjq02f3eba2024-06-12 20:45:24 +02006214 See |getpos()| for accepted positions.
6215
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006216 To get the column number use |col()|. To get both use
6217 |getpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02006218
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006219 With the optional {winid} argument the values are obtained for
6220 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02006221
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006222 Returns 0 for invalid values of {expr} and {winid}.
zeertzjq02f3eba2024-06-12 20:45:24 +02006223
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006224 Examples: >
6225 line(".") line number of the cursor
6226 line(".", winid) idem, in window "winid"
6227 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006228 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006229<
6230 To jump to the last known position when opening a file see
6231 |last-position-jump|.
6232
6233 Can also be used as a |method|: >
6234 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006235<
6236 Return type: |Number|
6237
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006238
6239line2byte({lnum}) *line2byte()*
6240 Return the byte count from the start of the buffer for line
6241 {lnum}. This includes the end-of-line character, depending on
6242 the 'fileformat' option for the current buffer. The first
6243 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6244 This can also be used to get the byte count for the line just
6245 below the last line: >
6246 line2byte(line("$") + 1)
6247< This is the buffer size plus one. If 'fileencoding' is empty
6248 it is the file size plus one. {lnum} is used like with
6249 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6250 feature has been disabled at compile time, -1 is returned.
6251 Also see |byte2line()|, |go| and |:goto|.
6252
6253 Can also be used as a |method|: >
6254 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006255<
6256 Return type: |Number|
6257
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006258
6259lispindent({lnum}) *lispindent()*
6260 Get the amount of indent for line {lnum} according the lisp
6261 indenting rules, as with 'lisp'.
6262 The indent is counted in spaces, the value of 'tabstop' is
6263 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006264 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006265 error is given.
6266
6267 Can also be used as a |method|: >
6268 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006269<
6270 Return type: |Number|
6271
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006272
6273list2blob({list}) *list2blob()*
6274 Return a Blob concatenating all the number values in {list}.
6275 Examples: >
6276 list2blob([1, 2, 3, 4]) returns 0z01020304
6277 list2blob([]) returns 0z
6278< Returns an empty Blob on error. If one of the numbers is
6279 negative or more than 255 error *E1239* is given.
6280
6281 |blob2list()| does the opposite.
6282
6283 Can also be used as a |method|: >
6284 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006285<
6286 Return type: |Blob|
6287
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006288
6289list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006290 Convert each number in {list} to a character string and
6291 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006292 list2str([32]) returns " "
6293 list2str([65, 66, 67]) returns "ABC"
6294< The same can be done (slowly) with: >
6295 join(map(list, {nr, val -> nr2char(val)}), '')
6296< |str2list()| does the opposite.
6297
6298 When {utf8} is omitted or zero, the current 'encoding' is used.
6299 When {utf8} is TRUE, always return UTF-8 characters.
6300 With UTF-8 composing characters work as expected: >
6301 list2str([97, 769]) returns "á"
6302<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006303 Returns an empty string on error.
6304
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006305 Can also be used as a |method|: >
6306 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006307<
6308 Return type: |String|
6309
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006310
6311listener_add({callback} [, {buf}]) *listener_add()*
6312 Add a callback function that will be invoked when changes have
6313 been made to buffer {buf}.
6314 {buf} refers to a buffer name or number. For the accepted
6315 values, see |bufname()|. When {buf} is omitted the current
6316 buffer is used.
6317 Returns a unique ID that can be passed to |listener_remove()|.
6318
6319 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006320 bufnr the buffer that was changed
6321 start first changed line number
6322 end first line number below the change
6323 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006324 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006325 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006326
6327 Example: >
6328 func Listener(bufnr, start, end, added, changes)
6329 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6330 endfunc
6331 call listener_add('Listener', bufnr)
6332
Bram Moolenaar944697a2022-02-20 19:48:20 +00006333< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006334 dictionary with these entries:
6335 lnum the first line number of the change
6336 end the first line below the change
6337 added number of lines added; negative if lines were
6338 deleted
6339 col first column in "lnum" that was affected by
6340 the change; one if unknown or the whole line
6341 was affected; this is a byte index, first
6342 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006343 When lines are inserted (not when a line is split, e.g. by
6344 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006345 lnum line above which the new line is added
6346 end equal to "lnum"
6347 added number of lines inserted
6348 col 1
6349 When lines are deleted the values are:
6350 lnum the first deleted line
6351 end the line below the first deleted line, before
6352 the deletion was done
6353 added negative, number of lines deleted
6354 col 1
6355 When lines are changed:
6356 lnum the first changed line
6357 end the line below the last changed line
6358 added 0
6359 col first column with a change or 1
6360
6361 The entries are in the order the changes were made, thus the
6362 most recent change is at the end. The line numbers are valid
6363 when the callback is invoked, but later changes may make them
6364 invalid, thus keeping a copy for later might not work.
6365
6366 The {callback} is invoked just before the screen is updated,
6367 when |listener_flush()| is called or when a change is being
6368 made that changes the line count in a way it causes a line
6369 number in the list of changes to become invalid.
6370
6371 The {callback} is invoked with the text locked, see
6372 |textlock|. If you do need to make changes to the buffer, use
6373 a timer to do this later |timer_start()|.
6374
6375 The {callback} is not invoked when the buffer is first loaded.
6376 Use the |BufReadPost| autocmd event to handle the initial text
6377 of a buffer.
6378 The {callback} is also not invoked when the buffer is
6379 unloaded, use the |BufUnload| autocmd event for that.
6380
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006381 Returns zero if {callback} or {buf} is invalid.
6382
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006383 Can also be used as a |method|, the base is passed as the
6384 second argument: >
6385 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006386<
6387 Return type: |Number|
6388
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006389
6390listener_flush([{buf}]) *listener_flush()*
6391 Invoke listener callbacks for buffer {buf}. If there are no
6392 pending changes then no callbacks are invoked.
6393
6394 {buf} refers to a buffer name or number. For the accepted
6395 values, see |bufname()|. When {buf} is omitted the current
6396 buffer is used.
6397
6398 Can also be used as a |method|: >
6399 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006400<
6401 Return type: |Number|
6402
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006403
6404listener_remove({id}) *listener_remove()*
6405 Remove a listener previously added with listener_add().
6406 Returns FALSE when {id} could not be found, TRUE when {id} was
6407 removed.
6408
6409 Can also be used as a |method|: >
6410 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006411<
6412 Return type: |Number|
6413
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006414
6415localtime() *localtime()*
6416 Return the current time, measured as seconds since 1st Jan
6417 1970. See also |strftime()|, |strptime()| and |getftime()|.
6418
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006419 Return type: |Number|
6420
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006421
6422log({expr}) *log()*
6423 Return the natural logarithm (base e) of {expr} as a |Float|.
6424 {expr} must evaluate to a |Float| or a |Number| in the range
6425 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006426 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006427 Examples: >
6428 :echo log(10)
6429< 2.302585 >
6430 :echo log(exp(5))
6431< 5.0
6432
6433 Can also be used as a |method|: >
6434 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006435<
6436 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006437
6438
6439log10({expr}) *log10()*
6440 Return the logarithm of Float {expr} to base 10 as a |Float|.
6441 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006442 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006443 Examples: >
6444 :echo log10(1000)
6445< 3.0 >
6446 :echo log10(0.01)
6447< -2.0
6448
6449 Can also be used as a |method|: >
6450 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006451<
6452 Return type: |Float|
6453
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006454
6455luaeval({expr} [, {expr}]) *luaeval()*
6456 Evaluate Lua expression {expr} and return its result converted
6457 to Vim data structures. Second {expr} may hold additional
6458 argument accessible as _A inside first {expr}.
6459 Strings are returned as they are.
6460 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006461 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006462 Dictionaries and lists obtained by vim.eval() are returned
6463 as-is.
6464 Other objects are returned as zero without any errors.
6465 See |lua-luaeval| for more details.
6466 Note that in a `:def` function local variables are not visible
6467 to {expr}.
6468
6469 Can also be used as a |method|: >
6470 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006471<
6472 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006473
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006474 {only available when compiled with the |+lua| feature}
6475
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006476
6477map({expr1}, {expr2}) *map()*
6478 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006479 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006480 item in {expr1} with the result of evaluating {expr2}.
6481 For a |Blob| each byte is replaced.
6482 For a |String|, each character, including composing
6483 characters, is replaced.
6484 If the item type changes you may want to use |mapnew()| to
6485 create a new List or Dictionary. This is required when using
6486 Vim9 script.
6487
6488 {expr2} must be a |String| or |Funcref|.
6489
6490 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6491 of the current item. For a |Dictionary| |v:key| has the key
6492 of the current item and for a |List| |v:key| has the index of
6493 the current item. For a |Blob| |v:key| has the index of the
6494 current byte. For a |String| |v:key| has the index of the
6495 current character.
6496 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006497 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006498< This puts "> " before and " <" after each item in "mylist".
6499
6500 Note that {expr2} is the result of an expression and is then
6501 used as an expression again. Often it is good to use a
6502 |literal-string| to avoid having to double backslashes. You
6503 still have to double ' quotes
6504
6505 If {expr2} is a |Funcref| it is called with two arguments:
6506 1. The key or the index of the current item.
6507 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006508 With a legacy script lambda you don't get an error if it only
6509 accepts one argument, but with a Vim9 lambda you get "E1106:
6510 One argument too many", the number of arguments must match.
6511
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006512 The function must return the new value of the item. Example
6513 that changes each value by "key-value": >
6514 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006515 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006516 endfunc
6517 call map(myDict, function('KeyValue'))
6518< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006519 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006520< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006521 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006522< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006523 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006524<
6525 The operation is done in-place for a |List| and |Dictionary|.
6526 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006527 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006528
6529< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6530 or a new |Blob| or |String|.
6531 When an error is encountered while evaluating {expr2} no
6532 further items in {expr1} are processed.
6533 When {expr2} is a Funcref errors inside a function are ignored,
6534 unless it was defined with the "abort" flag.
6535
6536 Can also be used as a |method|: >
6537 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006538<
6539 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6540 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006541
6542
6543maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6544 When {dict} is omitted or zero: Return the rhs of mapping
6545 {name} in mode {mode}. The returned String has special
6546 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006547 listing. When {dict} is TRUE a dictionary is returned, see
6548 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006549
6550 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006551 returned if {dict} is FALSE, otherwise returns an empty Dict.
6552 When the mapping for {name} is empty, then "<Nop>" is
6553 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006554
6555 The {name} can have special key names, like in the ":map"
6556 command.
6557
6558 {mode} can be one of these strings:
6559 "n" Normal
6560 "v" Visual (including Select)
6561 "o" Operator-pending
6562 "i" Insert
6563 "c" Cmd-line
6564 "s" Select
6565 "x" Visual
6566 "l" langmap |language-mapping|
6567 "t" Terminal-Job
6568 "" Normal, Visual and Operator-pending
6569 When {mode} is omitted, the modes for "" are used.
6570
6571 When {abbr} is there and it is |TRUE| use abbreviations
6572 instead of mappings.
6573
6574 When {dict} is there and it is |TRUE| return a dictionary
6575 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006576 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006577 "lhs" The {lhs} of the mapping as it would be typed
6578 "lhsraw" The {lhs} of the mapping as raw bytes
6579 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6580 form, only present when it differs from "lhsraw"
6581 "rhs" The {rhs} of the mapping as typed.
6582 "silent" 1 for a |:map-silent| mapping, else 0.
6583 "noremap" 1 if the {rhs} of the mapping is not remappable.
6584 "script" 1 if mapping was defined with <script>.
6585 "expr" 1 for an expression mapping (|:map-<expr>|).
6586 "buffer" 1 for a buffer local mapping (|:map-local|).
6587 "mode" Modes for which the mapping is defined. In
6588 addition to the modes mentioned above, these
6589 characters will be used:
6590 " " Normal, Visual and Operator-pending
6591 "!" Insert and Commandline mode
6592 (|mapmode-ic|)
6593 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006594 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006595 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006596 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006597 "lnum" The line number in "sid", zero if unknown.
6598 "nowait" Do not wait for other, longer mappings.
6599 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006600 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006601 "mode_bits" Vim's internal binary representation of "mode".
6602 |mapset()| ignores this; only "mode" is used.
6603 See |maplist()| for usage examples. The values
6604 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006605
6606 The dictionary can be used to restore a mapping with
6607 |mapset()|.
6608
6609 The mappings local to the current buffer are checked first,
6610 then the global mappings.
6611 This function can be used to map a key even when it's already
6612 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006613 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006614
6615< Can also be used as a |method|: >
6616 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006617<
6618 Return type: |String| or dict<any> depending on {dict}
6619
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006620
6621mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6622 Check if there is a mapping that matches with {name} in mode
6623 {mode}. See |maparg()| for {mode} and special names in
6624 {name}.
6625 When {abbr} is there and it is |TRUE| use abbreviations
6626 instead of mappings.
6627 A match happens with a mapping that starts with {name} and
6628 with a mapping which is equal to the start of {name}.
6629
6630 matches mapping "a" "ab" "abc" ~
6631 mapcheck("a") yes yes yes
6632 mapcheck("abc") yes yes yes
6633 mapcheck("ax") yes no no
6634 mapcheck("b") no no no
6635
6636 The difference with maparg() is that mapcheck() finds a
6637 mapping that matches with {name}, while maparg() only finds a
6638 mapping for {name} exactly.
6639 When there is no mapping that starts with {name}, an empty
6640 String is returned. If there is one, the RHS of that mapping
6641 is returned. If there are several mappings that start with
6642 {name}, the RHS of one of them is returned. This will be
6643 "<Nop>" if the RHS is empty.
6644 The mappings local to the current buffer are checked first,
6645 then the global mappings.
6646 This function can be used to check if a mapping can be added
6647 without being ambiguous. Example: >
6648 :if mapcheck("_vv") == ""
6649 : map _vv :set guifont=7x13<CR>
6650 :endif
6651< This avoids adding the "_vv" mapping when there already is a
6652 mapping for "_v" or for "_vvv".
6653
6654 Can also be used as a |method|: >
6655 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006656<
6657 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006658
6659
Ernie Rael09661202022-04-25 14:40:44 +01006660maplist([{abbr}]) *maplist()*
6661 Returns a |List| of all mappings. Each List item is a |Dict|,
6662 the same as what is returned by |maparg()|, see
6663 |mapping-dict|. When {abbr} is there and it is |TRUE| use
6664 abbreviations instead of mappings.
6665
6666 Example to show all mappings with 'MultiMatch' in rhs: >
6667 vim9script
6668 echo maplist()->filter(
6669 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01006670< It can be tricky to find mappings for particular |:map-modes|.
6671 |mapping-dict|'s "mode_bits" can simplify this. For example,
6672 the mode_bits for Normal, Insert or Command-line modes are
6673 0x19. To find all the mappings available in those modes you
6674 can do: >
6675 vim9script
6676 var saved_maps = []
6677 for m in maplist()
6678 if and(m.mode_bits, 0x19) != 0
6679 saved_maps->add(m)
6680 endif
6681 endfor
6682 echo saved_maps->mapnew((_, m) => m.lhs)
6683< The values of the mode_bits are defined in Vim's src/vim.h
6684 file and they can be discovered at runtime using
6685 |:map-commands| and "maplist()". Example: >
6686 vim9script
6687 omap xyzzy <Nop>
6688 var op_bit = maplist()->filter(
6689 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
6690 ounmap xyzzy
6691 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006692<
6693 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01006694
6695
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006696mapnew({expr1}, {expr2}) *mapnew()*
6697 Like |map()| but instead of replacing items in {expr1} a new
6698 List or Dictionary is created and returned. {expr1} remains
6699 unchanged. Items can still be changed by {expr2}, if you
6700 don't want that use |deepcopy()| first.
6701
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006702 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6703 depending on {expr1}
6704
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006705
6706mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01006707mapset({dict})
6708 Restore a mapping from a dictionary, possibly returned by
6709 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
6710 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006711 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01006712 feature allows copying mappings from one buffer to another.
6713 The dict.mode value may restore a single mapping that covers
6714 more than one mode, like with mode values of '!', ' ', 'nox',
6715 or 'v'. *E1276*
6716
6717 In the first form, {mode} and {abbr} should be the same as
6718 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006719 {mode} is used to define the mode in which the mapping is set,
6720 not the "mode" entry in {dict}.
6721 Example for saving and restoring a mapping: >
6722 let save_map = maparg('K', 'n', 0, 1)
6723 nnoremap K somethingelse
6724 ...
6725 call mapset('n', 0, save_map)
6726< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01006727 e.g. with `:map!`, you need to save/restore the mapping for
6728 all of them, when they might differ.
6729
6730 In the second form, with {dict} as the only argument, mode
6731 and abbr are taken from the dict.
6732 Example: >
6733 vim9script
6734 var save_maps = maplist()->filter(
6735 (_, m) => m.lhs == 'K')
6736 nnoremap K somethingelse
6737 cnoremap K somethingelse2
6738 # ...
6739 unmap K
6740 for d in save_maps
6741 mapset(d)
6742 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006743<
6744 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006745
6746
6747match({expr}, {pat} [, {start} [, {count}]]) *match()*
6748 When {expr} is a |List| then this returns the index of the
6749 first item where {pat} matches. Each item is used as a
6750 String, |Lists| and |Dictionaries| are used as echoed.
6751
6752 Otherwise, {expr} is used as a String. The result is a
6753 Number, which gives the index (byte offset) in {expr} where
6754 {pat} matches.
6755
6756 A match at the first character or |List| item returns zero.
6757 If there is no match -1 is returned.
6758
6759 For getting submatches see |matchlist()|.
6760 Example: >
6761 :echo match("testing", "ing") " results in 4
6762 :echo match([1, 'x'], '\a') " results in 1
6763< See |string-match| for how {pat} is used.
6764 *strpbrk()*
6765 Vim doesn't have a strpbrk() function. But you can do: >
6766 :let sepidx = match(line, '[.,;: \t]')
6767< *strcasestr()*
6768 Vim doesn't have a strcasestr() function. But you can add
6769 "\c" to the pattern to ignore case: >
6770 :let idx = match(haystack, '\cneedle')
6771<
6772 If {start} is given, the search starts from byte index
6773 {start} in a String or item {start} in a |List|.
6774 The result, however, is still the index counted from the
6775 first character/item. Example: >
6776 :echo match("testing", "ing", 2)
6777< result is again "4". >
6778 :echo match("testing", "ing", 4)
6779< result is again "4". >
6780 :echo match("testing", "t", 2)
6781< result is "3".
6782 For a String, if {start} > 0 then it is like the string starts
6783 {start} bytes later, thus "^" will match at {start}. Except
6784 when {count} is given, then it's like matches before the
6785 {start} byte are ignored (this is a bit complicated to keep it
6786 backwards compatible).
6787 For a String, if {start} < 0, it will be set to 0. For a list
6788 the index is counted from the end.
6789 If {start} is out of range ({start} > strlen({expr}) for a
6790 String or {start} > len({expr}) for a |List|) -1 is returned.
6791
6792 When {count} is given use the {count}'th match. When a match
6793 is found in a String the search for the next one starts one
6794 character further. Thus this example results in 1: >
6795 echo match("testing", "..", 0, 2)
6796< In a |List| the search continues in the next item.
6797 Note that when {count} is added the way {start} works changes,
6798 see above.
6799
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01006800 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006801 See |pattern| for the patterns that are accepted.
6802 The 'ignorecase' option is used to set the ignore-caseness of
6803 the pattern. 'smartcase' is NOT used. The matching is always
6804 done like 'magic' is set and 'cpoptions' is empty.
6805 Note that a match at the start is preferred, thus when the
6806 pattern is using "*" (any number of matches) it tends to find
6807 zero matches at the start instead of a number of matches
6808 further down in the text.
6809
6810 Can also be used as a |method|: >
6811 GetText()->match('word')
6812 GetList()->match('word')
6813<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006814 Return type: |Number|
6815
6816
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006817 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006818matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
6819 Defines a pattern to be highlighted in the current window (a
6820 "match"). It will be highlighted with {group}. Returns an
6821 identification number (ID), which can be used to delete the
6822 match using |matchdelete()|. The ID is bound to the window.
6823 Matching is case sensitive and magic, unless case sensitivity
6824 or magicness are explicitly overridden in {pattern}. The
6825 'magic', 'smartcase' and 'ignorecase' options are not used.
6826 The "Conceal" value is special, it causes the match to be
6827 concealed.
6828
6829 The optional {priority} argument assigns a priority to the
6830 match. A match with a high priority will have its
6831 highlighting overrule that of a match with a lower priority.
6832 A priority is specified as an integer (negative numbers are no
6833 exception). If the {priority} argument is not specified, the
6834 default priority is 10. The priority of 'hlsearch' is zero,
6835 hence all matches with a priority greater than zero will
6836 overrule it. Syntax highlighting (see 'syntax') is a separate
6837 mechanism, and regardless of the chosen priority a match will
6838 always overrule syntax highlighting.
6839
6840 The optional {id} argument allows the request for a specific
6841 match ID. If a specified ID is already taken, an error
6842 message will appear and the match will not be added. An ID
6843 is specified as a positive integer (zero excluded). IDs 1, 2
6844 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01006845 respectively. 3 is reserved for use by the |matchparen|
6846 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01006847 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01006848 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006849
6850 The optional {dict} argument allows for further custom
6851 values. Currently this is used to specify a match specific
6852 conceal character that will be shown for |hl-Conceal|
6853 highlighted matches. The dict can have the following members:
6854
6855 conceal Special character to show instead of the
6856 match (only for |hl-Conceal| highlighted
6857 matches, see |:syn-cchar|)
6858 window Instead of the current window use the
6859 window with this number or window ID.
6860
6861 The number of matches is not limited, as it is the case with
6862 the |:match| commands.
6863
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006864 Returns -1 on error.
6865
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006866 Example: >
6867 :highlight MyGroup ctermbg=green guibg=green
6868 :let m = matchadd("MyGroup", "TODO")
6869< Deletion of the pattern: >
6870 :call matchdelete(m)
6871
6872< A list of matches defined by |matchadd()| and |:match| are
6873 available from |getmatches()|. All matches can be deleted in
6874 one operation by |clearmatches()|.
6875
6876 Can also be used as a |method|: >
6877 GetGroup()->matchadd('TODO')
6878<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006879 Return type: |Number|
6880
6881
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006882 *matchaddpos()*
6883matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
6884 Same as |matchadd()|, but requires a list of positions {pos}
6885 instead of a pattern. This command is faster than |matchadd()|
6886 because it does not require to handle regular expressions and
6887 sets buffer line boundaries to redraw screen. It is supposed
6888 to be used when fast match additions and deletions are
6889 required, for example to highlight matching parentheses.
6890
6891 {pos} is a list of positions. Each position can be one of
6892 these:
6893 - A number. This whole line will be highlighted. The first
6894 line has number 1.
6895 - A list with one number, e.g., [23]. The whole line with this
6896 number will be highlighted.
6897 - A list with two numbers, e.g., [23, 11]. The first number is
6898 the line number, the second one is the column number (first
6899 column is 1, the value must correspond to the byte index as
6900 |col()| would return). The character at this position will
6901 be highlighted.
6902 - A list with three numbers, e.g., [23, 11, 3]. As above, but
6903 the third number gives the length of the highlight in bytes.
6904
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006905 Returns -1 on error.
6906
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006907 Example: >
6908 :highlight MyGroup ctermbg=green guibg=green
6909 :let m = matchaddpos("MyGroup", [[23, 24], 34])
6910< Deletion of the pattern: >
6911 :call matchdelete(m)
6912
6913< Matches added by |matchaddpos()| are returned by
6914 |getmatches()|.
6915
6916 Can also be used as a |method|: >
6917 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006918<
6919 Return type: |Number|
6920
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006921
6922matcharg({nr}) *matcharg()*
6923 Selects the {nr} match item, as set with a |:match|,
6924 |:2match| or |:3match| command.
6925 Return a |List| with two elements:
6926 The name of the highlight group used
6927 The pattern used.
6928 When {nr} is not 1, 2 or 3 returns an empty |List|.
6929 When there is no match item set returns ['', ''].
6930 This is useful to save and restore a |:match|.
6931 Highlighting matches using the |:match| commands are limited
6932 to three matches. |matchadd()| does not have this limitation.
6933
6934 Can also be used as a |method|: >
6935 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006936<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006937 Return type: list<string>
6938
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006939 *matchbufline()*
6940matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
6941 Returns the |List| of matches in lines from {lnum} to {end} in
6942 buffer {buf} where {pat} matches.
6943
6944 {lnum} and {end} can either be a line number or the string "$"
6945 to refer to the last line in {buf}.
6946
6947 The {dict} argument supports following items:
6948 submatches include submatch information (|/\(|)
6949
6950 For each match, a |Dict| with the following items is returned:
6951 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08006952 lnum line number where there is a match
6953 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006954 Note that there can be multiple matches in a single line.
6955
6956 This function works only for loaded buffers. First call
6957 |bufload()| if needed.
6958
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01006959 See |match-pattern| for information about the effect of some
6960 option settings on the pattern.
6961
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006962 When {buf} is not a valid buffer, the buffer is not loaded or
6963 {lnum} or {end} is not valid then an error is given and an
6964 empty |List| is returned.
6965
6966 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08006967 " Assuming line 3 in buffer 5 contains "a"
6968 :echo matchbufline(5, '\<\k\+\>', 3, 3)
6969 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
6970 " Assuming line 4 in buffer 10 contains "tik tok"
6971 :echo matchbufline(10, '\<\k\+\>', 1, 4)
6972 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006973<
6974 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08006975 "\1", "\2", etc. are also returned. Example: >
6976 " Assuming line 2 in buffer 2 contains "acd"
6977 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006978 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08006979 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006980< The "submatches" List always contains 9 items. If a submatch
6981 is not found, then an empty string is returned for that
6982 submatch.
6983
6984 Can also be used as a |method|: >
6985 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006986<
6987 Return type: list<dict<any>> or list<any>
6988
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006989
6990matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
6991 Deletes a match with ID {id} previously defined by |matchadd()|
6992 or one of the |:match| commands. Returns 0 if successful,
6993 otherwise -1. See example for |matchadd()|. All matches can
6994 be deleted in one operation by |clearmatches()|.
6995 If {win} is specified, use the window with this number or
6996 window ID instead of the current window.
6997
6998 Can also be used as a |method|: >
6999 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007000<
7001 Return type: |Number|
7002
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007003
7004matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
7005 Same as |match()|, but return the index of first character
7006 after the match. Example: >
7007 :echo matchend("testing", "ing")
7008< results in "7".
7009 *strspn()* *strcspn()*
7010 Vim doesn't have a strspn() or strcspn() function, but you can
7011 do it with matchend(): >
7012 :let span = matchend(line, '[a-zA-Z]')
7013 :let span = matchend(line, '[^a-zA-Z]')
7014< Except that -1 is returned when there are no matches.
7015
7016 The {start}, if given, has the same meaning as for |match()|. >
7017 :echo matchend("testing", "ing", 2)
7018< results in "7". >
7019 :echo matchend("testing", "ing", 5)
7020< result is "-1".
7021 When {expr} is a |List| the result is equal to |match()|.
7022
7023 Can also be used as a |method|: >
7024 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007025<
7026 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007027
7028
7029matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7030 If {list} is a list of strings, then returns a |List| with all
7031 the strings in {list} that fuzzy match {str}. The strings in
7032 the returned list are sorted based on the matching score.
7033
7034 The optional {dict} argument always supports the following
7035 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007036 matchseq When this item is present return only matches
7037 that contain the characters in {str} in the
7038 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007039 limit Maximum number of matches in {list} to be
7040 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007041
7042 If {list} is a list of dictionaries, then the optional {dict}
7043 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007044 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007045 {str}. The value of this item should be a
7046 string.
7047 text_cb |Funcref| that will be called for every item
7048 in {list} to get the text for fuzzy matching.
7049 This should accept a dictionary item as the
7050 argument and return the text for that item to
7051 use for fuzzy matching.
7052
7053 {str} is treated as a literal string and regular expression
7054 matching is NOT supported. The maximum supported {str} length
7055 is 256.
7056
7057 When {str} has multiple words each separated by white space,
7058 then the list of strings that have all the words is returned.
7059
7060 If there are no matching strings or there is an error, then an
7061 empty list is returned. If length of {str} is greater than
7062 256, then returns an empty list.
7063
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007064 When {limit} is given, matchfuzzy() will find up to this
7065 number of matches in {list} and return them in sorted order.
7066
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007067 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007068 matching strings.
7069
7070 Example: >
7071 :echo matchfuzzy(["clay", "crow"], "cay")
7072< results in ["clay"]. >
7073 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7074< results in a list of buffer names fuzzy matching "ndl". >
7075 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7076< results in a list of buffer information dicts with buffer
7077 names fuzzy matching "ndl". >
7078 :echo getbufinfo()->matchfuzzy("spl",
7079 \ {'text_cb' : {v -> v.name}})
7080< results in a list of buffer information dicts with buffer
7081 names fuzzy matching "spl". >
7082 :echo v:oldfiles->matchfuzzy("test")
7083< results in a list of file names fuzzy matching "test". >
7084 :let l = readfile("buffer.c")->matchfuzzy("str")
7085< results in a list of lines in "buffer.c" fuzzy matching "str". >
7086 :echo ['one two', 'two one']->matchfuzzy('two one')
7087< results in ['two one', 'one two']. >
7088 :echo ['one two', 'two one']->matchfuzzy('two one',
7089 \ {'matchseq': 1})
7090< results in ['two one'].
7091
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007092 Return type: list<string> or list<any>
7093
7094
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007095matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7096 Same as |matchfuzzy()|, but returns the list of matched
7097 strings, the list of character positions where characters
7098 in {str} matches and a list of matching scores. You can
7099 use |byteidx()| to convert a character position to a byte
7100 position.
7101
7102 If {str} matches multiple times in a string, then only the
7103 positions for the best match is returned.
7104
7105 If there are no matching strings or there is an error, then a
7106 list with three empty list items is returned.
7107
7108 Example: >
7109 :echo matchfuzzypos(['testing'], 'tsg')
7110< results in [['testing'], [[0, 2, 6]], [99]] >
7111 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7112< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7113 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7114< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7115
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007116 Return type: list<list<any>>
7117
7118
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007119matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7120 Same as |match()|, but return a |List|. The first item in the
7121 list is the matched string, same as what matchstr() would
7122 return. Following items are submatches, like "\1", "\2", etc.
7123 in |:substitute|. When an optional submatch didn't match an
7124 empty string is used. Example: >
7125 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7126< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7127 When there is no match an empty list is returned.
7128
7129 You can pass in a List, but that is not very useful.
7130
7131 Can also be used as a |method|: >
7132 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007133<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007134 Return type: list<string> or list<any>
7135
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007136 *matchstrlist()*
7137matchstrlist({list}, {pat} [, {dict}])
7138 Returns the |List| of matches in {list} where {pat} matches.
7139 {list} is a |List| of strings. {pat} is matched against each
7140 string in {list}.
7141
7142 The {dict} argument supports following items:
7143 submatches include submatch information (|/\(|)
7144
7145 For each match, a |Dict| with the following items is returned:
7146 byteidx starting byte index of the match.
7147 idx index in {list} of the match.
7148 text matched string
7149 submatches a List of submatches. Present only if
7150 "submatches" is set to v:true in {dict}.
7151
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007152 See |match-pattern| for information about the effect of some
7153 option settings on the pattern.
7154
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007155 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007156 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7157 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7158 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7159 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007160<
7161 If "submatches" is present and is v:true, then submatches like
7162 "\1", "\2", etc. are also returned. Example: >
7163 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7164 \ #{submatches: v:true})
7165 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7166< The "submatches" List always contains 9 items. If a submatch
7167 is not found, then an empty string is returned for that
7168 submatch.
7169
7170 Can also be used as a |method|: >
7171 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007172<
7173 Return type: list<dict<any>> or list<any>
7174
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007175
7176matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7177 Same as |match()|, but return the matched string. Example: >
7178 :echo matchstr("testing", "ing")
7179< results in "ing".
7180 When there is no match "" is returned.
7181 The {start}, if given, has the same meaning as for |match()|. >
7182 :echo matchstr("testing", "ing", 2)
7183< results in "ing". >
7184 :echo matchstr("testing", "ing", 5)
7185< result is "".
7186 When {expr} is a |List| then the matching item is returned.
7187 The type isn't changed, it's not necessarily a String.
7188
7189 Can also be used as a |method|: >
7190 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007191<
7192 Return type: |String|
7193
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007194
7195matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7196 Same as |matchstr()|, but return the matched string, the start
7197 position and the end position of the match. Example: >
7198 :echo matchstrpos("testing", "ing")
7199< results in ["ing", 4, 7].
7200 When there is no match ["", -1, -1] is returned.
7201 The {start}, if given, has the same meaning as for |match()|. >
7202 :echo matchstrpos("testing", "ing", 2)
7203< results in ["ing", 4, 7]. >
7204 :echo matchstrpos("testing", "ing", 5)
7205< result is ["", -1, -1].
7206 When {expr} is a |List| then the matching item, the index
7207 of first item where {pat} matches, the start position and the
7208 end position of the match are returned. >
7209 :echo matchstrpos([1, '__x'], '\a')
7210< result is ["x", 1, 2, 3].
7211 The type isn't changed, it's not necessarily a String.
7212
7213 Can also be used as a |method|: >
7214 GetText()->matchstrpos('word')
7215<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007216 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007217
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007218
7219max({expr}) *max()*
7220 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007221 echo max([apples, pears, oranges])
7222
7223< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7224 it returns the maximum of all values in the Dictionary.
7225 If {expr} is neither a List nor a Dictionary, or one of the
7226 items in {expr} cannot be used as a Number this results in
7227 an error. An empty |List| or |Dictionary| results in zero.
7228
7229 Can also be used as a |method|: >
7230 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007231<
7232 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007233
7234
7235menu_info({name} [, {mode}]) *menu_info()*
7236 Return information about the specified menu {name} in
7237 mode {mode}. The menu name should be specified without the
7238 shortcut character ('&'). If {name} is "", then the top-level
7239 menu names are returned.
7240
7241 {mode} can be one of these strings:
7242 "n" Normal
7243 "v" Visual (including Select)
7244 "o" Operator-pending
7245 "i" Insert
7246 "c" Cmd-line
7247 "s" Select
7248 "x" Visual
7249 "t" Terminal-Job
7250 "" Normal, Visual and Operator-pending
7251 "!" Insert and Cmd-line
7252 When {mode} is omitted, the modes for "" are used.
7253
7254 Returns a |Dictionary| containing the following items:
7255 accel menu item accelerator text |menu-text|
7256 display display name (name without '&')
7257 enabled v:true if this menu item is enabled
7258 Refer to |:menu-enable|
7259 icon name of the icon file (for toolbar)
7260 |toolbar-icon|
7261 iconidx index of a built-in icon
7262 modes modes for which the menu is defined. In
7263 addition to the modes mentioned above, these
7264 characters will be used:
7265 " " Normal, Visual and Operator-pending
7266 name menu item name.
7267 noremenu v:true if the {rhs} of the menu item is not
7268 remappable else v:false.
7269 priority menu order priority |menu-priority|
7270 rhs right-hand-side of the menu item. The returned
7271 string has special characters translated like
7272 in the output of the ":menu" command listing.
7273 When the {rhs} of a menu item is empty, then
7274 "<Nop>" is returned.
7275 script v:true if script-local remapping of {rhs} is
7276 allowed else v:false. See |:menu-script|.
7277 shortcut shortcut key (character after '&' in
7278 the menu name) |menu-shortcut|
7279 silent v:true if the menu item is created
7280 with <silent> argument |:menu-silent|
7281 submenus |List| containing the names of
7282 all the submenus. Present only if the menu
7283 item has submenus.
7284
7285 Returns an empty dictionary if the menu item is not found.
7286
7287 Examples: >
7288 :echo menu_info('Edit.Cut')
7289 :echo menu_info('File.Save', 'n')
7290
7291 " Display the entire menu hierarchy in a buffer
7292 func ShowMenu(name, pfx)
7293 let m = menu_info(a:name)
7294 call append(line('$'), a:pfx .. m.display)
7295 for child in m->get('submenus', [])
7296 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7297 \ a:pfx .. ' ')
7298 endfor
7299 endfunc
7300 new
7301 for topmenu in menu_info('').submenus
7302 call ShowMenu(topmenu, '')
7303 endfor
7304<
7305 Can also be used as a |method|: >
7306 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007307<
7308 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007309
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007310min({expr}) *min()*
7311 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007312 echo min([apples, pears, oranges])
7313
7314< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7315 it returns the minimum of all values in the Dictionary.
7316 If {expr} is neither a List nor a Dictionary, or one of the
7317 items in {expr} cannot be used as a Number this results in
7318 an error. An empty |List| or |Dictionary| results in zero.
7319
7320 Can also be used as a |method|: >
7321 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007322<
7323 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007324
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007325
7326mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007327 Create directory {name}.
7328
Bram Moolenaar938ae282023-02-20 20:44:55 +00007329 When {flags} is present it must be a string. An empty string
7330 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007331
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007332 {flags} can contain these character flags:
7333 "p" intermediate directories will be created as necessary
7334 "D" {name} will be deleted at the end of the current
Christian Brabandtc509c002024-06-14 20:22:05 +02007335 function, but not recursively |:defer|
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007336 "R" {name} will be deleted recursively at the end of the
Christian Brabandtc509c002024-06-14 20:22:05 +02007337 current function |:defer|
Bram Moolenaar938ae282023-02-20 20:44:55 +00007338
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007339 Note that when {name} has more than one part and "p" is used
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007340 some directories may already exist. Only the first one that
7341 is created and what it contains is scheduled to be deleted.
7342 E.g. when using: >
7343 call mkdir('subdir/tmp/autoload', 'pR')
7344< and "subdir" already exists then "subdir/tmp" will be
7345 scheduled for deletion, like with: >
7346 defer delete('subdir/tmp', 'rf')
7347< Note that if scheduling the defer fails the directory is not
7348 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007349
7350 If {prot} is given it is used to set the protection bits of
7351 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7352 the user, readable for others). Use 0o700 to make it
7353 unreadable for others. This is only used for the last part of
7354 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
7355 created with 0o755.
7356 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007357 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007358
7359< This function is not available in the |sandbox|.
7360
7361 There is no error if the directory already exists and the "p"
7362 flag is passed (since patch 8.0.1708). However, without the
7363 "p" option the call will fail.
7364
7365 The function result is a Number, which is TRUE if the call was
7366 successful or FALSE if the directory creation failed or partly
7367 failed.
7368
7369 Not available on all systems. To check use: >
7370 :if exists("*mkdir")
7371
7372< Can also be used as a |method|: >
7373 GetName()->mkdir()
7374<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007375 Return type: |Number|
7376
7377
7378mode([{expr}]) *mode()*
7379 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007380 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007381 a non-empty String (|non-zero-arg|), then the full mode is
7382 returned, otherwise only the first letter is returned.
7383 Also see |state()|.
7384
7385 n Normal
7386 no Operator-pending
7387 nov Operator-pending (forced characterwise |o_v|)
7388 noV Operator-pending (forced linewise |o_V|)
7389 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7390 CTRL-V is one character
7391 niI Normal using |i_CTRL-O| in |Insert-mode|
7392 niR Normal using |i_CTRL-O| in |Replace-mode|
7393 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7394 nt Terminal-Normal (insert goes to Terminal-Job mode)
7395 v Visual by character
7396 vs Visual by character using |v_CTRL-O| in Select mode
7397 V Visual by line
7398 Vs Visual by line using |v_CTRL-O| in Select mode
7399 CTRL-V Visual blockwise
7400 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7401 s Select by character
7402 S Select by line
7403 CTRL-S Select blockwise
7404 i Insert
7405 ic Insert mode completion |compl-generic|
7406 ix Insert mode |i_CTRL-X| completion
7407 R Replace |R|
7408 Rc Replace mode completion |compl-generic|
7409 Rx Replace mode |i_CTRL-X| completion
7410 Rv Virtual Replace |gR|
7411 Rvc Virtual Replace mode completion |compl-generic|
7412 Rvx Virtual Replace mode |i_CTRL-X| completion
7413 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007414 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007415 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007416 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007417 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007418 ce Normal Ex mode |Q|
7419 r Hit-enter prompt
7420 rm The -- more -- prompt
7421 r? A |:confirm| query of some sort
7422 ! Shell or external command is executing
7423 t Terminal-Job mode: keys go to the job
7424
7425 This is useful in the 'statusline' option or when used
7426 with |remote_expr()| In most other places it always returns
7427 "c" or "n".
7428 Note that in the future more modes and more specific modes may
7429 be added. It's better not to compare the whole string but only
7430 the leading character(s).
7431 Also see |visualmode()|.
7432
7433 Can also be used as a |method|: >
7434 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007435<
7436 Return type: |String|
7437
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007438
7439mzeval({expr}) *mzeval()*
7440 Evaluate MzScheme expression {expr} and return its result
7441 converted to Vim data structures.
7442 Numbers and strings are returned as they are.
7443 Pairs (including lists and improper lists) and vectors are
7444 returned as Vim |Lists|.
7445 Hash tables are represented as Vim |Dictionary| type with keys
7446 converted to strings.
7447 All other types are converted to string with display function.
7448 Examples: >
7449 :mz (define l (list 1 2 3))
7450 :mz (define h (make-hash)) (hash-set! h "list" l)
7451 :echo mzeval("l")
7452 :echo mzeval("h")
7453<
7454 Note that in a `:def` function local variables are not visible
7455 to {expr}.
7456
7457 Can also be used as a |method|: >
7458 GetExpr()->mzeval()
7459<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007460 Return type: any, depending on {expr}
7461
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007462 {only available when compiled with the |+mzscheme| feature}
7463
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007464
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007465nextnonblank({lnum}) *nextnonblank()*
7466 Return the line number of the first line at or below {lnum}
7467 that is not blank. Example: >
7468 if getline(nextnonblank(1)) =~ "Java"
7469< When {lnum} is invalid or there is no non-blank line at or
7470 below it, zero is returned.
7471 {lnum} is used like with |getline()|.
7472 See also |prevnonblank()|.
7473
7474 Can also be used as a |method|: >
7475 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007476<
7477 Return type: |Number|
7478
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007479
7480nr2char({expr} [, {utf8}]) *nr2char()*
7481 Return a string with a single character, which has the number
7482 value {expr}. Examples: >
7483 nr2char(64) returns "@"
7484 nr2char(32) returns " "
7485< When {utf8} is omitted or zero, the current 'encoding' is used.
7486 Example for "utf-8": >
7487 nr2char(300) returns I with bow character
7488< When {utf8} is TRUE, always return UTF-8 characters.
7489 Note that a NUL character in the file is specified with
7490 nr2char(10), because NULs are represented with newline
7491 characters. nr2char(0) is a real NUL and terminates the
7492 string, thus results in an empty string.
7493 To turn a list of character numbers into a string: >
7494 let list = [65, 66, 67]
7495 let str = join(map(list, {_, val -> nr2char(val)}), '')
7496< Result: "ABC"
7497
7498 Can also be used as a |method|: >
7499 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007500<
7501 Return type: |String|
7502
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007503
7504or({expr}, {expr}) *or()*
7505 Bitwise OR on the two arguments. The arguments are converted
7506 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007507 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007508 Example: >
7509 :let bits = or(bits, 0x80)
7510< Can also be used as a |method|: >
7511 :let bits = bits->or(0x80)
7512
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007513< Rationale: The reason this is a function and not using the "|"
7514 character like many languages, is that Vi has always used "|"
7515 to separate commands. In many places it would not be clear if
7516 "|" is an operator or a command separator.
7517
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007518 Return type: |Number|
7519
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007520
7521pathshorten({path} [, {len}]) *pathshorten()*
7522 Shorten directory names in the path {path} and return the
7523 result. The tail, the file name, is kept as-is. The other
7524 components in the path are reduced to {len} letters in length.
7525 If {len} is omitted or smaller than 1 then 1 is used (single
7526 letters). Leading '~' and '.' characters are kept. Examples: >
7527 :echo pathshorten('~/.vim/autoload/myfile.vim')
7528< ~/.v/a/myfile.vim ~
7529>
7530 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7531< ~/.vi/au/myfile.vim ~
7532 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007533 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007534
7535 Can also be used as a |method|: >
7536 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007537<
7538 Return type: |String|
7539
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007540
7541perleval({expr}) *perleval()*
7542 Evaluate Perl expression {expr} in scalar context and return
7543 its result converted to Vim data structures. If value can't be
7544 converted, it is returned as a string Perl representation.
7545 Note: If you want an array or hash, {expr} must return a
7546 reference to it.
7547 Example: >
7548 :echo perleval('[1 .. 4]')
7549< [1, 2, 3, 4]
7550
7551 Note that in a `:def` function local variables are not visible
7552 to {expr}.
7553
7554 Can also be used as a |method|: >
7555 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007556<
7557 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007558
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007559 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007560
7561
7562popup_ functions are documented here: |popup-functions|
7563
7564
7565pow({x}, {y}) *pow()*
7566 Return the power of {x} to the exponent {y} as a |Float|.
7567 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007568 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007569 Examples: >
7570 :echo pow(3, 3)
7571< 27.0 >
7572 :echo pow(2, 16)
7573< 65536.0 >
7574 :echo pow(32, 0.20)
7575< 2.0
7576
7577 Can also be used as a |method|: >
7578 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007579<
7580 Return type: |Number|
7581
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007582
7583prevnonblank({lnum}) *prevnonblank()*
7584 Return the line number of the first line at or above {lnum}
7585 that is not blank. Example: >
7586 let ind = indent(prevnonblank(v:lnum - 1))
7587< When {lnum} is invalid or there is no non-blank line at or
7588 above it, zero is returned.
7589 {lnum} is used like with |getline()|.
7590 Also see |nextnonblank()|.
7591
7592 Can also be used as a |method|: >
7593 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007594<
7595 Return type: |Number|
7596
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007597
7598printf({fmt}, {expr1} ...) *printf()*
7599 Return a String with {fmt}, where "%" items are replaced by
7600 the formatted form of their respective arguments. Example: >
7601 printf("%4d: E%d %.30s", lnum, errno, msg)
7602< May result in:
7603 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7604
7605 When used as a |method| the base is passed as the second
7606 argument: >
7607 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007608<
7609 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007610
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007611 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007612 %s string
7613 %6S string right-aligned in 6 display cells
7614 %6s string right-aligned in 6 bytes
7615 %.9s string truncated to 9 bytes
7616 %c single byte
7617 %d decimal number
7618 %5d decimal number padded with spaces to 5 characters
7619 %x hex number
7620 %04x hex number padded with zeros to at least 4 characters
7621 %X hex number using upper case letters
7622 %o octal number
7623 %08b binary number padded with zeros to at least 8 chars
7624 %f floating point number as 12.23, inf, -inf or nan
7625 %F floating point number as 12.23, INF, -INF or NAN
7626 %e floating point number as 1.23e3, inf, -inf or nan
7627 %E floating point number as 1.23E3, INF, -INF or NAN
7628 %g floating point number, as %f or %e depending on value
7629 %G floating point number, as %F or %E depending on value
7630 %% the % character itself
7631
7632 Conversion specifications start with '%' and end with the
7633 conversion type. All other characters are copied unchanged to
7634 the result.
7635
7636 The "%" starts a conversion specification. The following
7637 arguments appear in sequence:
7638
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007639 % [pos-argument] [flags] [field-width] [.precision] type
7640
7641 pos-argument
7642 At most one positional argument specifier. These
7643 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007644
7645 flags
7646 Zero or more of the following flags:
7647
7648 # The value should be converted to an "alternate
7649 form". For c, d, and s conversions, this option
7650 has no effect. For o conversions, the precision
7651 of the number is increased to force the first
7652 character of the output string to a zero (except
7653 if a zero value is printed with an explicit
7654 precision of zero).
7655 For b and B conversions, a non-zero result has
7656 the string "0b" (or "0B" for B conversions)
7657 prepended to it.
7658 For x and X conversions, a non-zero result has
7659 the string "0x" (or "0X" for X conversions)
7660 prepended to it.
7661
7662 0 (zero) Zero padding. For all conversions the converted
7663 value is padded on the left with zeros rather
7664 than blanks. If a precision is given with a
7665 numeric conversion (d, b, B, o, x, and X), the 0
7666 flag is ignored.
7667
7668 - A negative field width flag; the converted value
7669 is to be left adjusted on the field boundary.
7670 The converted value is padded on the right with
7671 blanks, rather than on the left with blanks or
7672 zeros. A - overrides a 0 if both are given.
7673
7674 ' ' (space) A blank should be left before a positive
7675 number produced by a signed conversion (d).
7676
7677 + A sign must always be placed before a number
7678 produced by a signed conversion. A + overrides
7679 a space if both are used.
7680
7681 field-width
7682 An optional decimal digit string specifying a minimum
7683 field width. If the converted value has fewer bytes
7684 than the field width, it will be padded with spaces on
7685 the left (or right, if the left-adjustment flag has
7686 been given) to fill out the field width. For the S
7687 conversion the count is in cells.
7688
7689 .precision
7690 An optional precision, in the form of a period '.'
7691 followed by an optional digit string. If the digit
7692 string is omitted, the precision is taken as zero.
7693 This gives the minimum number of digits to appear for
7694 d, o, x, and X conversions, the maximum number of
7695 bytes to be printed from a string for s conversions,
7696 or the maximum number of cells to be printed from a
7697 string for S conversions.
7698 For floating point it is the number of digits after
7699 the decimal point.
7700
7701 type
7702 A character that specifies the type of conversion to
7703 be applied, see below.
7704
7705 A field width or precision, or both, may be indicated by an
7706 asterisk '*' instead of a digit string. In this case, a
7707 Number argument supplies the field width or precision. A
7708 negative field width is treated as a left adjustment flag
7709 followed by a positive field width; a negative precision is
7710 treated as though it were missing. Example: >
7711 :echo printf("%d: %.*s", nr, width, line)
7712< This limits the length of the text used from "line" to
7713 "width" bytes.
7714
Dominique Pellé17dca3c2023-12-14 20:36:32 +01007715 If the argument to be formatted is specified using a
7716 positional argument specifier, and a '*' is used to indicate
7717 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007718 precision, the argument(s) to be used must also be specified
7719 using a {n$} positional argument specifier. See |printf-$|.
7720
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007721 The conversion specifiers and their meanings are:
7722
7723 *printf-d* *printf-b* *printf-B* *printf-o*
7724 *printf-x* *printf-X*
7725 dbBoxX The Number argument is converted to signed decimal
7726 (d), unsigned binary (b and B), unsigned octal (o), or
7727 unsigned hexadecimal (x and X) notation. The letters
7728 "abcdef" are used for x conversions; the letters
7729 "ABCDEF" are used for X conversions.
7730 The precision, if any, gives the minimum number of
7731 digits that must appear; if the converted value
7732 requires fewer digits, it is padded on the left with
7733 zeros.
7734 In no case does a non-existent or small field width
7735 cause truncation of a numeric field; if the result of
7736 a conversion is wider than the field width, the field
7737 is expanded to contain the conversion result.
7738 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02007739 The 'l' modifier indicates the argument is a long
7740 integer. The size will be 32 bits or 64 bits
7741 depending on your platform.
7742 The "ll" modifier indicates the argument is 64 bits.
7743 The b and B conversion specifiers never take a width
7744 modifier and always assume their argument is a 64 bit
7745 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007746 Generally, these modifiers are not useful. They are
7747 ignored when type is known from the argument.
7748
7749 i alias for d
7750 D alias for ld
7751 U alias for lu
7752 O alias for lo
7753
7754 *printf-c*
7755 c The Number argument is converted to a byte, and the
7756 resulting character is written.
7757
7758 *printf-s*
7759 s The text of the String argument is used. If a
7760 precision is specified, no more bytes than the number
7761 specified are used.
7762 If the argument is not a String type, it is
7763 automatically converted to text with the same format
7764 as ":echo".
7765 *printf-S*
7766 S The text of the String argument is used. If a
7767 precision is specified, no more display cells than the
7768 number specified are used.
7769
7770 *printf-f* *E807*
7771 f F The Float argument is converted into a string of the
7772 form 123.456. The precision specifies the number of
7773 digits after the decimal point. When the precision is
7774 zero the decimal point is omitted. When the precision
7775 is not specified 6 is used. A really big number
7776 (out of range or dividing by zero) results in "inf"
7777 or "-inf" with %f (INF or -INF with %F).
7778 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
7779 Example: >
7780 echo printf("%.2f", 12.115)
7781< 12.12
7782 Note that roundoff depends on the system libraries.
7783 Use |round()| when in doubt.
7784
7785 *printf-e* *printf-E*
7786 e E The Float argument is converted into a string of the
7787 form 1.234e+03 or 1.234E+03 when using 'E'. The
7788 precision specifies the number of digits after the
7789 decimal point, like with 'f'.
7790
7791 *printf-g* *printf-G*
7792 g G The Float argument is converted like with 'f' if the
7793 value is between 0.001 (inclusive) and 10000000.0
7794 (exclusive). Otherwise 'e' is used for 'g' and 'E'
7795 for 'G'. When no precision is specified superfluous
7796 zeroes and '+' signs are removed, except for the zero
7797 immediately after the decimal point. Thus 10000000.0
7798 results in 1.0e7.
7799
7800 *printf-%*
7801 % A '%' is written. No argument is converted. The
7802 complete conversion specification is "%%".
7803
7804 When a Number argument is expected a String argument is also
7805 accepted and automatically converted.
7806 When a Float or String argument is expected a Number argument
7807 is also accepted and automatically converted.
7808 Any other argument type results in an error message.
7809
7810 *E766* *E767*
7811 The number of {exprN} arguments must exactly match the number
7812 of "%" items. If there are not sufficient or too many
7813 arguments an error is given. Up to 18 arguments can be used.
7814
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007815 *printf-$*
7816 In certain languages, error and informative messages are
7817 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02007818 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007819 having a different word order, positional arguments may be
7820 used to indicate this. For instance: >
7821
h_east596a9f22023-11-21 21:24:23 +09007822 #, c-format
7823 msgid "%s returning %s"
7824 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007825<
h_east596a9f22023-11-21 21:24:23 +09007826 In this example, the sentence has its 2 string arguments
7827 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007828
h_east596a9f22023-11-21 21:24:23 +09007829 echo printf(
7830 "In The Netherlands, vim's creator's name is: %1$s %2$s",
7831 "Bram", "Moolenaar")
7832< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007833
h_east596a9f22023-11-21 21:24:23 +09007834 echo printf(
7835 "In Belgium, vim's creator's name is: %2$s %1$s",
7836 "Bram", "Moolenaar")
7837< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007838
7839 Width (and precision) can be specified using the '*' specifier.
7840 In this case, you must specify the field width position in the
7841 argument list. >
7842
h_east596a9f22023-11-21 21:24:23 +09007843 echo printf("%1$*2$.*3$d", 1, 2, 3)
7844< 001 >
7845 echo printf("%2$*3$.*1$d", 1, 2, 3)
7846< 2 >
7847 echo printf("%3$*1$.*2$d", 1, 2, 3)
7848< 03 >
7849 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
7850< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007851
7852 You can mix specifying the width and/or precision directly
7853 and via positional arguments: >
7854
h_east596a9f22023-11-21 21:24:23 +09007855 echo printf("%1$4.*2$f", 1.4142135, 6)
7856< 1.414214 >
7857 echo printf("%1$*2$.4f", 1.4142135, 6)
7858< 1.4142 >
7859 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
7860< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007861
Christ van Willegenc35fc032024-03-14 18:30:41 +01007862 You will get an overflow error |E1510|, when the field-width
7863 or precision will result in a string longer than 6400 chars.
7864
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007865 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007866 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09007867 echo printf("%s%1$s", "One", "Two")
7868< E1500: Cannot mix positional and non-positional arguments:
7869 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007870
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007871 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007872 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09007873 echo printf("%3$s%1$s", "One", "Two", "Three")
7874< E1501: format argument 2 unused in $-style format:
7875 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007876
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007877 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007878 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09007879 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
7880< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007881
7882 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09007883 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
7884< E1502: Positional argument 2 used as field width reused as
7885 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007886
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007887 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007888 When a positional argument is used, but not the correct number
7889 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09007890 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
7891< E1503: Positional argument 3 out of bounds: %1$d at width
7892 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007893
7894 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09007895 echo printf("%01$*2$.*3$d %4$d", 1, 2)
7896< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
7897 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007898
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007899 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007900 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09007901 echo printf("%1$s %2$s %1$s", "One", "Two")
7902< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007903
7904 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09007905 echo printf("%1$s %2$s %1$d", "One", "Two")
7906< E1504: Positional argument 1 type used inconsistently:
7907 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007908
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007909 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007910 Various other errors that lead to a format string being
7911 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09007912 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
7913< E1505: Invalid format specifier: %1$d at width %2$d is:
7914 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007915
Christ van Willegenea746f92023-10-05 20:48:36 +02007916 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08007917 This internal error indicates that the logic to parse a
7918 positional format argument ran into a problem that couldn't be
7919 otherwise reported. Please file a bug against Vim if you run
7920 into this, copying the exact format string and parameters that
7921 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02007922
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007923 Return type: |String|
7924
Christ van Willegenea746f92023-10-05 20:48:36 +02007925
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007926prompt_getprompt({buf}) *prompt_getprompt()*
7927 Returns the effective prompt text for buffer {buf}. {buf} can
7928 be a buffer name or number. See |prompt-buffer|.
7929
7930 If the buffer doesn't exist or isn't a prompt buffer, an empty
7931 string is returned.
7932
7933 Can also be used as a |method|: >
7934 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007935<
7936 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007937
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007938 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007939
7940
7941prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
7942 Set prompt callback for buffer {buf} to {expr}. When {expr}
7943 is an empty string the callback is removed. This has only
7944 effect if {buf} has 'buftype' set to "prompt".
7945
7946 The callback is invoked when pressing Enter. The current
7947 buffer will always be the prompt buffer. A new line for a
7948 prompt is added before invoking the callback, thus the prompt
7949 for which the callback was invoked will be in the last but one
7950 line.
7951 If the callback wants to add text to the buffer, it must
7952 insert it above the last line, since that is where the current
7953 prompt is. This can also be done asynchronously.
7954 The callback is invoked with one argument, which is the text
7955 that was entered at the prompt. This can be an empty string
7956 if the user only typed Enter.
7957 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007958 func s:TextEntered(text)
7959 if a:text == 'exit' || a:text == 'quit'
7960 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01007961 " Reset 'modified' to allow the buffer to be closed.
7962 " We assume there is nothing useful to be saved.
7963 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007964 close
7965 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01007966 " Do something useful with "a:text". In this example
7967 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007968 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007969 endif
7970 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01007971 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007972
7973< Can also be used as a |method|: >
7974 GetBuffer()->prompt_setcallback(callback)
7975
7976< {only available when compiled with the |+channel| feature}
7977
7978prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
7979 Set a callback for buffer {buf} to {expr}. When {expr} is an
7980 empty string the callback is removed. This has only effect if
7981 {buf} has 'buftype' set to "prompt".
7982
7983 This callback will be invoked when pressing CTRL-C in Insert
7984 mode. Without setting a callback Vim will exit Insert mode,
7985 as in any buffer.
7986
7987 Can also be used as a |method|: >
7988 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007989<
7990 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007991
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007992 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007993
7994prompt_setprompt({buf}, {text}) *prompt_setprompt()*
7995 Set prompt for buffer {buf} to {text}. You most likely want
7996 {text} to end in a space.
7997 The result is only visible if {buf} has 'buftype' set to
7998 "prompt". Example: >
7999 call prompt_setprompt(bufnr(), 'command: ')
8000<
8001 Can also be used as a |method|: >
8002 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008003<
8004 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008005
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008006 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008007
8008prop_ functions are documented here: |text-prop-functions|
8009
8010pum_getpos() *pum_getpos()*
8011 If the popup menu (see |ins-completion-menu|) is not visible,
8012 returns an empty |Dictionary|, otherwise, returns a
8013 |Dictionary| with the following keys:
8014 height nr of items visible
8015 width screen cells
8016 row top screen row (0 first row)
8017 col leftmost screen column (0 first col)
8018 size total nr of items
8019 scrollbar |TRUE| if scrollbar is visible
8020
8021 The values are the same as in |v:event| during
8022 |CompleteChanged|.
8023
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008024 Return type: dict<any>
8025
8026
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008027pumvisible() *pumvisible()*
8028 Returns non-zero when the popup menu is visible, zero
8029 otherwise. See |ins-completion-menu|.
8030 This can be used to avoid some things that would remove the
8031 popup menu.
8032
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008033 Return type: |Number|
8034
8035
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008036py3eval({expr}) *py3eval()*
8037 Evaluate Python expression {expr} and return its result
8038 converted to Vim data structures.
8039 Numbers and strings are returned as they are (strings are
8040 copied though, Unicode strings are additionally converted to
8041 'encoding').
8042 Lists are represented as Vim |List| type.
8043 Dictionaries are represented as Vim |Dictionary| type with
8044 keys converted to strings.
8045 Note that in a `:def` function local variables are not visible
8046 to {expr}.
8047
8048 Can also be used as a |method|: >
8049 GetExpr()->py3eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008050<
8051 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008052
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008053 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008054
8055 *E858* *E859*
8056pyeval({expr}) *pyeval()*
8057 Evaluate Python expression {expr} and return its result
8058 converted to Vim data structures.
8059 Numbers and strings are returned as they are (strings are
8060 copied though).
8061 Lists are represented as Vim |List| type.
8062 Dictionaries are represented as Vim |Dictionary| type,
8063 non-string keys result in error.
8064 Note that in a `:def` function local variables are not visible
8065 to {expr}.
8066
8067 Can also be used as a |method|: >
8068 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008069<
8070 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008071
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008072 {only available when compiled with the |+python| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008073
8074pyxeval({expr}) *pyxeval()*
8075 Evaluate Python expression {expr} and return its result
8076 converted to Vim data structures.
8077 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8078 See also: |pyeval()|, |py3eval()|
8079
8080 Can also be used as a |method|: >
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008081 < GetExpr()->pyxeval()
8082<
8083 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008084
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008085 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008086 |+python3| feature}
8087
8088rand([{expr}]) *rand()* *random*
8089 Return a pseudo-random Number generated with an xoshiro128**
8090 algorithm using seed {expr}. The returned number is 32 bits,
8091 also on 64 bits systems, for consistency.
8092 {expr} can be initialized by |srand()| and will be updated by
8093 rand(). If {expr} is omitted, an internal seed value is used
8094 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008095 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008096
8097 Examples: >
8098 :echo rand()
8099 :let seed = srand()
8100 :echo rand(seed)
8101 :echo rand(seed) % 16 " random number 0 - 15
8102<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008103 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008104
8105 *E726* *E727*
8106range({expr} [, {max} [, {stride}]]) *range()*
8107 Returns a |List| with Numbers:
8108 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8109 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8110 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8111 {max}] (increasing {expr} with {stride} each time, not
8112 producing a value past {max}).
8113 When the maximum is one before the start the result is an
8114 empty list. When the maximum is more than one before the
8115 start this is an error.
8116 Examples: >
8117 range(4) " [0, 1, 2, 3]
8118 range(2, 4) " [2, 3, 4]
8119 range(2, 9, 3) " [2, 5, 8]
8120 range(2, -2, -1) " [2, 1, 0, -1, -2]
8121 range(0) " []
8122 range(2, 0) " error!
8123<
8124 Can also be used as a |method|: >
8125 GetExpr()->range()
8126<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008127 Return type: list<number>
8128
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008129
K.Takata11df3ae2022-10-19 14:02:40 +01008130readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008131 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008132 If {offset} is specified, read the file from the specified
8133 offset. If it is a negative value, it is used as an offset
8134 from the end of the file. E.g., to read the last 12 bytes: >
8135 readblob('file.bin', -12)
8136< If {size} is specified, only the specified size will be read.
8137 E.g. to read the first 100 bytes of a file: >
8138 readblob('file.bin', 0, 100)
8139< If {size} is -1 or omitted, the whole data starting from
8140 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008141 This can be also used to read the data from a character device
8142 on Unix when {size} is explicitly set. Only if the device
8143 supports seeking {offset} can be used. Otherwise it should be
8144 zero. E.g. to read 10 bytes from a serial console: >
8145 readblob('/dev/ttyS0', 0, 10)
8146< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008147 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008148 When the offset is beyond the end of the file the result is an
8149 empty blob.
8150 When trying to read more bytes than are available the result
8151 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008152 Also see |readfile()| and |writefile()|.
8153
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008154 Return type: |Blob|
8155
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008156
8157readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8158 Return a list with file and directory names in {directory}.
8159 You can also use |glob()| if you don't need to do complicated
8160 things, such as limiting the number of matches.
8161 The list will be sorted (case sensitive), see the {dict}
8162 argument below for changing the sort order.
8163
8164 When {expr} is omitted all entries are included.
8165 When {expr} is given, it is evaluated to check what to do:
8166 If {expr} results in -1 then no further entries will
8167 be handled.
8168 If {expr} results in 0 then this entry will not be
8169 added to the list.
8170 If {expr} results in 1 then this entry will be added
8171 to the list.
8172 The entries "." and ".." are always excluded.
8173 Each time {expr} is evaluated |v:val| is set to the entry name.
8174 When {expr} is a function the name is passed as the argument.
8175 For example, to get a list of files ending in ".txt": >
8176 readdir(dirname, {n -> n =~ '.txt$'})
8177< To skip hidden and backup files: >
8178 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008179< *E857*
8180 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008181 values. Currently this is used to specify if and how sorting
8182 should be performed. The dict can have the following members:
8183
8184 sort How to sort the result returned from the system.
8185 Valid values are:
8186 "none" do not sort (fastest method)
8187 "case" sort case sensitive (byte value of
8188 each character, technically, using
8189 strcmp()) (default)
8190 "icase" sort case insensitive (technically
8191 using strcasecmp())
8192 "collate" sort using the collation order
8193 of the "POSIX" or "C" |locale|
8194 (technically using strcoll())
8195 Other values are silently ignored.
8196
8197 For example, to get a list of all files in the current
8198 directory without sorting the individual entries: >
8199 readdir('.', '1', #{sort: 'none'})
8200< If you want to get a directory tree: >
8201 function! s:tree(dir)
8202 return {a:dir : map(readdir(a:dir),
8203 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008204 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008205 endfunction
8206 echo s:tree(".")
8207<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008208 Returns an empty List on error.
8209
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008210 Can also be used as a |method|: >
8211 GetDirName()->readdir()
8212<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008213 Return type: list<string> or list<any>
8214
8215
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008216readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8217 Extended version of |readdir()|.
8218 Return a list of Dictionaries with file and directory
8219 information in {directory}.
8220 This is useful if you want to get the attributes of file and
8221 directory at the same time as getting a list of a directory.
8222 This is much faster than calling |readdir()| then calling
8223 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8224 each file and directory especially on MS-Windows.
8225 The list will by default be sorted by name (case sensitive),
8226 the sorting can be changed by using the optional {dict}
8227 argument, see |readdir()|.
8228
8229 The Dictionary for file and directory information has the
8230 following items:
8231 group Group name of the entry. (Only on Unix)
8232 name Name of the entry.
8233 perm Permissions of the entry. See |getfperm()|.
8234 size Size of the entry. See |getfsize()|.
8235 time Timestamp of the entry. See |getftime()|.
8236 type Type of the entry.
8237 On Unix, almost same as |getftype()| except:
8238 Symlink to a dir "linkd"
8239 Other symlink "link"
8240 On MS-Windows:
8241 Normal file "file"
8242 Directory "dir"
8243 Junction "junction"
8244 Symlink to a dir "linkd"
8245 Other symlink "link"
8246 Other reparse point "reparse"
8247 user User name of the entry's owner. (Only on Unix)
8248 On Unix, if the entry is a symlink, the Dictionary includes
8249 the information of the target (except the "type" item).
8250 On MS-Windows, it includes the information of the symlink
8251 itself because of performance reasons.
8252
8253 When {expr} is omitted all entries are included.
8254 When {expr} is given, it is evaluated to check what to do:
8255 If {expr} results in -1 then no further entries will
8256 be handled.
8257 If {expr} results in 0 then this entry will not be
8258 added to the list.
8259 If {expr} results in 1 then this entry will be added
8260 to the list.
8261 The entries "." and ".." are always excluded.
8262 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8263 of the entry.
8264 When {expr} is a function the entry is passed as the argument.
8265 For example, to get a list of files ending in ".txt": >
8266 readdirex(dirname, {e -> e.name =~ '.txt$'})
8267<
8268 For example, to get a list of all files in the current
8269 directory without sorting the individual entries: >
8270 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008271<
8272 Can also be used as a |method|: >
8273 GetDirName()->readdirex()
8274<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008275 Return type: list<dict<any>> or list<any>
8276
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008277
8278 *readfile()*
8279readfile({fname} [, {type} [, {max}]])
8280 Read file {fname} and return a |List|, each line of the file
8281 as an item. Lines are broken at NL characters. Macintosh
8282 files separated with CR will result in a single long line
8283 (unless a NL appears somewhere).
8284 All NUL characters are replaced with a NL character.
8285 When {type} contains "b" binary mode is used:
8286 - When the last line ends in a NL an extra empty list item is
8287 added.
8288 - No CR characters are removed.
8289 Otherwise:
8290 - CR characters that appear before a NL are removed.
8291 - Whether the last line ends in a NL or not does not matter.
8292 - When 'encoding' is Unicode any UTF-8 byte order mark is
8293 removed from the text.
8294 When {max} is given this specifies the maximum number of lines
8295 to be read. Useful if you only want to check the first ten
8296 lines of a file: >
8297 :for line in readfile(fname, '', 10)
8298 : if line =~ 'Date' | echo line | endif
8299 :endfor
8300< When {max} is negative -{max} lines from the end of the file
8301 are returned, or as many as there are.
8302 When {max} is zero the result is an empty list.
8303 Note that without {max} the whole file is read into memory.
8304 Also note that there is no recognition of encoding. Read a
8305 file into a buffer if you need to.
8306 Deprecated (use |readblob()| instead): When {type} contains
8307 "B" a |Blob| is returned with the binary data of the file
8308 unmodified.
8309 When the file can't be opened an error message is given and
8310 the result is an empty list.
8311 Also see |writefile()|.
8312
8313 Can also be used as a |method|: >
8314 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008315<
8316 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008317
8318reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8319 {func} is called for every item in {object}, which can be a
8320 |String|, |List| or a |Blob|. {func} is called with two
8321 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008322 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008323
8324 {initial} is the initial result. When omitted, the first item
8325 in {object} is used and {func} is first called for the second
8326 item. If {initial} is not given and {object} is empty no
8327 result can be computed, an E998 error is given.
8328
8329 Examples: >
8330 echo reduce([1, 3, 5], { acc, val -> acc + val })
8331 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8332 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8333 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8334<
8335 Can also be used as a |method|: >
8336 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008337<
8338 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8339 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008340
8341
8342reg_executing() *reg_executing()*
8343 Returns the single letter name of the register being executed.
8344 Returns an empty string when no register is being executed.
8345 See |@|.
8346
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008347 Return type: |String|
8348
8349
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008350reg_recording() *reg_recording()*
8351 Returns the single letter name of the register being recorded.
8352 Returns an empty string when not recording. See |q|.
8353
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008354 Return type: |String|
8355
8356
8357reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008358reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008359reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008360 Return an item that represents a time value. The item is a
8361 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008362 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008363 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008364 string or |reltimefloat()| to convert to a Float. For
8365 example, to see the time spent in function Work(): >
8366 var startTime = reltime()
8367 Work()
8368 echo startTime->reltime()->reltimestr()
8369<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008370 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008371 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008372 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008373 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008374 specified in the argument.
8375 With two arguments it returns the time passed between {start}
8376 and {end}.
8377
8378 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008379 reltime(). If there is an error an empty List is returned in
8380 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008381
8382 Can also be used as a |method|: >
8383 GetStart()->reltime()
8384<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008385 Return type: list<number>
8386
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008387 {only available when compiled with the |+reltime| feature}
8388
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008389
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008390reltimefloat({time}) *reltimefloat()*
8391 Return a Float that represents the time value of {time}.
8392 Example: >
8393 let start = reltime()
8394 call MyFunction()
8395 let seconds = reltimefloat(reltime(start))
8396< See the note of reltimestr() about overhead.
8397 Also see |profiling|.
8398 If there is an error 0.0 is returned in legacy script, in Vim9
8399 script an error is given.
8400
8401 Can also be used as a |method|: >
8402 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008403<
8404 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008405
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008406 {only available when compiled with the |+reltime| feature}
8407
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008408
8409reltimestr({time}) *reltimestr()*
8410 Return a String that represents the time value of {time}.
8411 This is the number of seconds, a dot and the number of
8412 microseconds. Example: >
8413 let start = reltime()
8414 call MyFunction()
8415 echo reltimestr(reltime(start))
8416< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008417 The accuracy depends on the system. Use reltimefloat() for the
8418 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008419 Leading spaces are used to make the string align nicely. You
8420 can use split() to remove it. >
8421 echo split(reltimestr(reltime(start)))[0]
8422< Also see |profiling|.
8423 If there is an error an empty string is returned in legacy
8424 script, in Vim9 script an error is given.
8425
8426 Can also be used as a |method|: >
8427 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008428<
8429 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008430
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008431 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008432
8433 *remote_expr()* *E449*
8434remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008435 Send the {string} to {server}. The {server} argument is a
8436 string, also see |{server}|.
8437
8438 The string is sent as an expression and the result is returned
8439 after evaluation. The result must be a String or a |List|. A
8440 |List| is turned into a String by joining the items with a
8441 line break in between (not at the end), like with join(expr,
8442 "\n").
8443
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008444 If {idvar} is present and not empty, it is taken as the name
8445 of a variable and a {serverid} for later use with
8446 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008447
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008448 If {timeout} is given the read times out after this many
8449 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008450
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008451 See also |clientserver| |RemoteReply|.
8452 This function is not available in the |sandbox|.
8453 {only available when compiled with the |+clientserver| feature}
8454 Note: Any errors will cause a local error message to be issued
8455 and the result will be the empty string.
8456
8457 Variables will be evaluated in the global namespace,
8458 independent of a function currently being active. Except
8459 when in debug mode, then local function variables and
8460 arguments can be evaluated.
8461
8462 Examples: >
8463 :echo remote_expr("gvim", "2+2")
8464 :echo remote_expr("gvim1", "b:current_syntax")
8465<
8466 Can also be used as a |method|: >
8467 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008468<
8469 Return type: |String| or list<{type}>
8470
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008471
8472remote_foreground({server}) *remote_foreground()*
8473 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008474 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008475 This works like: >
8476 remote_expr({server}, "foreground()")
8477< Except that on Win32 systems the client does the work, to work
8478 around the problem that the OS doesn't always allow the server
8479 to bring itself to the foreground.
8480 Note: This does not restore the window if it was minimized,
8481 like foreground() does.
8482 This function is not available in the |sandbox|.
8483
8484 Can also be used as a |method|: >
8485 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008486<
8487 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008488
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008489 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008490 Win32 console version}
8491
8492
8493remote_peek({serverid} [, {retvar}]) *remote_peek()*
8494 Returns a positive number if there are available strings
8495 from {serverid}. Copies any reply string into the variable
8496 {retvar} if specified. {retvar} must be a string with the
8497 name of a variable.
8498 Returns zero if none are available.
8499 Returns -1 if something is wrong.
8500 See also |clientserver|.
8501 This function is not available in the |sandbox|.
8502 {only available when compiled with the |+clientserver| feature}
8503 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008504 :let repl = ""
8505 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008506
8507< Can also be used as a |method|: >
8508 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008509<
8510 Return type: |Number|
8511
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008512
8513remote_read({serverid}, [{timeout}]) *remote_read()*
8514 Return the oldest available reply from {serverid} and consume
8515 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008516 reply is available. Returns an empty string, if a reply is
8517 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008518 See also |clientserver|.
8519 This function is not available in the |sandbox|.
8520 {only available when compiled with the |+clientserver| feature}
8521 Example: >
8522 :echo remote_read(id)
8523
8524< Can also be used as a |method|: >
8525 ServerId()->remote_read()
8526<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008527 Return type: |String|
8528
8529
8530remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008531 Send the {string} to {server}. The {server} argument is a
8532 string, also see |{server}|.
8533
8534 The string is sent as input keys and the function returns
8535 immediately. At the Vim server the keys are not mapped
8536 |:map|.
8537
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008538 If {idvar} is present, it is taken as the name of a variable
8539 and a {serverid} for later use with remote_read() is stored
8540 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008541
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008542 See also |clientserver| |RemoteReply|.
8543 This function is not available in the |sandbox|.
8544 {only available when compiled with the |+clientserver| feature}
8545
8546 Note: Any errors will be reported in the server and may mess
8547 up the display.
8548 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008549 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008550 \ remote_read(serverid)
8551
8552 :autocmd NONE RemoteReply *
8553 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008554 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008555 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8556<
8557 Can also be used as a |method|: >
8558 ServerName()->remote_send(keys)
8559<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008560 Return type: |String|
8561
8562
8563remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008564 Become the server {name}. {name} must be a non-empty string.
8565 This fails if already running as a server, when |v:servername|
8566 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008567
8568 Can also be used as a |method|: >
8569 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008570<
8571 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008572
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008573 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008574
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008575
8576remove({list}, {idx}) *remove()*
8577remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008578 Without {end}: Remove the item at {idx} from |List| {list} and
8579 return the item.
8580 With {end}: Remove items from {idx} to {end} (inclusive) and
8581 return a |List| with these items. When {idx} points to the same
8582 item as {end} a list with one item is returned. When {end}
8583 points to an item before {idx} this is an error.
8584 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008585 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008586 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008587 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008588 :call remove(mylist, 0, 9)
8589<
8590 Use |delete()| to remove a file.
8591
8592 Can also be used as a |method|: >
8593 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008594<
8595 Return type: any, depending on {list}
8596
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008597
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008598remove({blob}, {idx})
8599remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008600 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8601 return the byte.
8602 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8603 return a |Blob| with these bytes. When {idx} points to the same
8604 byte as {end} a |Blob| with one byte is returned. When {end}
8605 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008606 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008607 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008608 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008609 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008610<
8611 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008612
8613remove({dict}, {key})
8614 Remove the entry from {dict} with key {key} and return it.
8615 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008616 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008617< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008618 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008619
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008620 Return type: any, depending on {dict}
8621
8622
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008623rename({from}, {to}) *rename()*
8624 Rename the file by the name {from} to the name {to}. This
8625 should also work to move files across file systems. The
8626 result is a Number, which is 0 if the file was renamed
8627 successfully, and non-zero when the renaming failed.
8628 NOTE: If {to} exists it is overwritten without warning.
8629 This function is not available in the |sandbox|.
8630
8631 Can also be used as a |method|: >
8632 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008633<
8634 Return type: |Number|
8635
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008636
8637repeat({expr}, {count}) *repeat()*
8638 Repeat {expr} {count} times and return the concatenated
8639 result. Example: >
8640 :let separator = repeat('-', 80)
8641< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01008642 When {expr} is a |List| or a |Blob| the result is {expr}
8643 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008644 :let longlist = repeat(['a', 'b'], 3)
8645< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
8646
8647 Can also be used as a |method|: >
8648 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008649<
8650 Return type: |String|, |Blob| or list<{type}> depending on
8651 {expr}
8652
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008653
8654resolve({filename}) *resolve()* *E655*
8655 On MS-Windows, when {filename} is a shortcut (a .lnk file),
8656 returns the path the shortcut points to in a simplified form.
8657 When {filename} is a symbolic link or junction point, return
8658 the full path to the target. If the target of junction is
8659 removed, return {filename}.
8660 On Unix, repeat resolving symbolic links in all path
8661 components of {filename} and return the simplified result.
8662 To cope with link cycles, resolving of symbolic links is
8663 stopped after 100 iterations.
8664 On other systems, return the simplified {filename}.
8665 The simplification step is done as by |simplify()|.
8666 resolve() keeps a leading path component specifying the
8667 current directory (provided the result is still a relative
8668 path name) and also keeps a trailing path separator.
8669
8670 Can also be used as a |method|: >
8671 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008672<
8673 Return type: |String|
8674
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008675
8676reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01008677 Reverse the order of items in {object}. {object} can be a
8678 |List|, a |Blob| or a |String|. For a List and a Blob the
8679 items are reversed in-place and {object} is returned.
8680 For a String a new String is returned.
8681 Returns zero if {object} is not a List, Blob or a String.
8682 If you want a List or Blob to remain unmodified make a copy
8683 first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008684 :let revlist = reverse(copy(mylist))
8685< Can also be used as a |method|: >
8686 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008687<
8688 Return type: |String|, |Blob| or list<{type}> depending on
8689 {object}
8690
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008691
8692round({expr}) *round()*
8693 Round off {expr} to the nearest integral value and return it
8694 as a |Float|. If {expr} lies halfway between two integral
8695 values, then use the larger one (away from zero).
8696 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008697 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008698 Examples: >
8699 echo round(0.456)
8700< 0.0 >
8701 echo round(4.5)
8702< 5.0 >
8703 echo round(-4.5)
8704< -5.0
8705
8706 Can also be used as a |method|: >
8707 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008708<
8709 Return type: |Float|
8710
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008711
8712rubyeval({expr}) *rubyeval()*
8713 Evaluate Ruby expression {expr} and return its result
8714 converted to Vim data structures.
8715 Numbers, floats and strings are returned as they are (strings
8716 are copied though).
8717 Arrays are represented as Vim |List| type.
8718 Hashes are represented as Vim |Dictionary| type.
8719 Other objects are represented as strings resulted from their
8720 "Object#to_s" method.
8721 Note that in a `:def` function local variables are not visible
8722 to {expr}.
8723
8724 Can also be used as a |method|: >
8725 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008726<
8727 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008728
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008729 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008730
8731screenattr({row}, {col}) *screenattr()*
8732 Like |screenchar()|, but return the attribute. This is a rather
8733 arbitrary number that can only be used to compare to the
8734 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008735 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008736
8737 Can also be used as a |method|: >
8738 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008739<
8740 Return type: |Number|
8741
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008742
8743screenchar({row}, {col}) *screenchar()*
8744 The result is a Number, which is the character at position
8745 [row, col] on the screen. This works for every possible
8746 screen position, also status lines, window separators and the
8747 command line. The top left position is row one, column one
8748 The character excludes composing characters. For double-byte
8749 encodings it may only be the first byte.
8750 This is mainly to be used for testing.
8751 Returns -1 when row or col is out of range.
8752
8753 Can also be used as a |method|: >
8754 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008755<
8756 Return type: |Number|
8757
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008758
8759screenchars({row}, {col}) *screenchars()*
8760 The result is a |List| of Numbers. The first number is the same
8761 as what |screenchar()| returns. Further numbers are
8762 composing characters on top of the base character.
8763 This is mainly to be used for testing.
8764 Returns an empty List when row or col is out of range.
8765
8766 Can also be used as a |method|: >
8767 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008768<
8769 Return type: list<number> or list<any>
8770
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008771
8772screencol() *screencol()*
8773 The result is a Number, which is the current screen column of
8774 the cursor. The leftmost column has number 1.
8775 This function is mainly used for testing.
8776
8777 Note: Always returns the current screen column, thus if used
8778 in a command (e.g. ":echo screencol()") it will return the
8779 column inside the command line, which is 1 when the command is
8780 executed. To get the cursor position in the file use one of
8781 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008782 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008783 nnoremap <silent> GG :echom screencol()<CR>
8784 nnoremap GG <Cmd>echom screencol()<CR>
8785<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008786 Return type: |Number|
8787
8788
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008789screenpos({winid}, {lnum}, {col}) *screenpos()*
8790 The result is a Dict with the screen position of the text
8791 character in window {winid} at buffer line {lnum} and column
8792 {col}. {col} is a one-based byte index.
8793 The Dict has these members:
8794 row screen row
8795 col first screen column
8796 endcol last screen column
8797 curscol cursor screen column
8798 If the specified position is not visible, all values are zero.
8799 The "endcol" value differs from "col" when the character
8800 occupies more than one screen cell. E.g. for a Tab "col" can
8801 be 1 and "endcol" can be 8.
8802 The "curscol" value is where the cursor would be placed. For
8803 a Tab it would be the same as "endcol", while for a double
8804 width character it would be the same as "col".
8805 The |conceal| feature is ignored here, the column numbers are
8806 as if 'conceallevel' is zero. You can set the cursor to the
8807 right position and use |screencol()| to get the value with
8808 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008809 If the position is in a closed fold the screen position of the
8810 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008811 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008812
8813 Can also be used as a |method|: >
8814 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008815<
8816 Return type: dict<number> or dict<any>
8817
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008818
8819screenrow() *screenrow()*
8820 The result is a Number, which is the current screen row of the
8821 cursor. The top line has number one.
8822 This function is mainly used for testing.
8823 Alternatively you can use |winline()|.
8824
8825 Note: Same restrictions as with |screencol()|.
8826
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008827 Return type: |Number|
8828
8829
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008830screenstring({row}, {col}) *screenstring()*
8831 The result is a String that contains the base character and
8832 any composing characters at position [row, col] on the screen.
8833 This is like |screenchars()| but returning a String with the
8834 characters.
8835 This is mainly to be used for testing.
8836 Returns an empty String when row or col is out of range.
8837
8838 Can also be used as a |method|: >
8839 GetRow()->screenstring(col)
8840<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008841 Return type: |String|
8842
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008843 *search()*
8844search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
8845 Search for regexp pattern {pattern}. The search starts at the
8846 cursor position (you can use |cursor()| to set it).
8847
8848 When a match has been found its line number is returned.
8849 If there is no match a 0 is returned and the cursor doesn't
8850 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01008851 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008852
8853 {flags} is a String, which can contain these character flags:
8854 'b' search Backward instead of forward
8855 'c' accept a match at the Cursor position
8856 'e' move to the End of the match
8857 'n' do Not move the cursor
8858 'p' return number of matching sub-Pattern (see below)
8859 's' Set the ' mark at the previous location of the cursor
8860 'w' Wrap around the end of the file
8861 'W' don't Wrap around the end of the file
8862 'z' start searching at the cursor column instead of zero
8863 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
8864
8865 If the 's' flag is supplied, the ' mark is set, only if the
8866 cursor is moved. The 's' flag cannot be combined with the 'n'
8867 flag.
8868
8869 'ignorecase', 'smartcase' and 'magic' are used.
8870
8871 When the 'z' flag is not given, forward searching always
8872 starts in column zero and then matches before the cursor are
8873 skipped. When the 'c' flag is present in 'cpo' the next
8874 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01008875 search starts one column after the start of the match. This
8876 matters for overlapping matches. See |cpo-c|. You can also
8877 insert "\ze" to change where the match ends, see |/\ze|.
8878
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008879 When searching backwards and the 'z' flag is given then the
8880 search starts in column zero, thus no match in the current
8881 line will be found (unless wrapping around the end of the
8882 file).
8883
8884 When the {stopline} argument is given then the search stops
8885 after searching this line. This is useful to restrict the
8886 search to a range of lines. Examples: >
8887 let match = search('(', 'b', line("w0"))
8888 let end = search('END', '', line("w$"))
8889< When {stopline} is used and it is not zero this also implies
8890 that the search does not wrap around the end of the file.
8891 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01008892 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008893 When the {timeout} argument is given the search stops when
8894 more than this many milliseconds have passed. Thus when
8895 {timeout} is 500 the search stops after half a second.
8896 The value must not be negative. A zero value is like not
8897 giving the argument.
8898 {only available when compiled with the |+reltime| feature}
8899
8900 If the {skip} expression is given it is evaluated with the
8901 cursor positioned on the start of a match. If it evaluates to
8902 non-zero this match is skipped. This can be used, for
8903 example, to skip a match in a comment or a string.
8904 {skip} can be a string, which is evaluated as an expression, a
8905 function reference or a lambda.
8906 When {skip} is omitted or empty, every match is accepted.
8907 When evaluating {skip} causes an error the search is aborted
8908 and -1 returned.
8909 *search()-sub-match*
8910 With the 'p' flag the returned value is one more than the
8911 first sub-match in \(\). One if none of them matched but the
8912 whole pattern did match.
8913 To get the column number too use |searchpos()|.
8914
8915 The cursor will be positioned at the match, unless the 'n'
8916 flag is used.
8917
8918 Example (goes over all files in the argument list): >
8919 :let n = 1
8920 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008921 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008922 : " start at the last char in the file and wrap for the
8923 : " first search to find match at start of file
8924 : normal G$
8925 : let flags = "w"
8926 : while search("foo", flags) > 0
8927 : s/foo/bar/g
8928 : let flags = "W"
8929 : endwhile
8930 : update " write the file if modified
8931 : let n = n + 1
8932 :endwhile
8933<
8934 Example for using some flags: >
8935 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
8936< This will search for the keywords "if", "else", and "endif"
8937 under or after the cursor. Because of the 'p' flag, it
8938 returns 1, 2, or 3 depending on which keyword is found, or 0
8939 if the search fails. With the cursor on the first word of the
8940 line:
8941 if (foo == 0) | let foo = foo + 1 | endif ~
8942 the function returns 1. Without the 'c' flag, the function
8943 finds the "endif" and returns 3. The same thing happens
8944 without the 'e' flag if the cursor is on the "f" of "if".
8945 The 'n' flag tells the function not to move the cursor.
8946
8947 Can also be used as a |method|: >
8948 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008949<
8950 Return type: |Number|
8951
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008952
8953searchcount([{options}]) *searchcount()*
8954 Get or update the last search count, like what is displayed
8955 without the "S" flag in 'shortmess'. This works even if
8956 'shortmess' does contain the "S" flag.
8957
8958 This returns a |Dictionary|. The dictionary is empty if the
8959 previous pattern was not set and "pattern" was not specified.
8960
8961 key type meaning ~
8962 current |Number| current position of match;
8963 0 if the cursor position is
8964 before the first match
8965 exact_match |Boolean| 1 if "current" is matched on
8966 "pos", otherwise 0
8967 total |Number| total count of matches found
8968 incomplete |Number| 0: search was fully completed
8969 1: recomputing was timed out
8970 2: max count exceeded
8971
8972 For {options} see further down.
8973
8974 To get the last search count when |n| or |N| was pressed, call
8975 this function with `recompute: 0` . This sometimes returns
8976 wrong information because |n| and |N|'s maximum count is 99.
8977 If it exceeded 99 the result must be max count + 1 (100). If
8978 you want to get correct information, specify `recompute: 1`: >
8979
8980 " result == maxcount + 1 (100) when many matches
8981 let result = searchcount(#{recompute: 0})
8982
8983 " Below returns correct result (recompute defaults
8984 " to 1)
8985 let result = searchcount()
8986<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01008987 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008988 function! LastSearchCount() abort
8989 let result = searchcount(#{recompute: 0})
8990 if empty(result)
8991 return ''
8992 endif
8993 if result.incomplete ==# 1 " timed out
8994 return printf(' /%s [?/??]', @/)
8995 elseif result.incomplete ==# 2 " max count exceeded
8996 if result.total > result.maxcount &&
8997 \ result.current > result.maxcount
8998 return printf(' /%s [>%d/>%d]', @/,
8999 \ result.current, result.total)
9000 elseif result.total > result.maxcount
9001 return printf(' /%s [%d/>%d]', @/,
9002 \ result.current, result.total)
9003 endif
9004 endif
9005 return printf(' /%s [%d/%d]', @/,
9006 \ result.current, result.total)
9007 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009008 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009009
9010 " Or if you want to show the count only when
9011 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009012 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009013 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9014<
9015 You can also update the search count, which can be useful in a
9016 |CursorMoved| or |CursorMovedI| autocommand: >
9017
9018 autocmd CursorMoved,CursorMovedI *
9019 \ let s:searchcount_timer = timer_start(
9020 \ 200, function('s:update_searchcount'))
9021 function! s:update_searchcount(timer) abort
9022 if a:timer ==# s:searchcount_timer
9023 call searchcount(#{
9024 \ recompute: 1, maxcount: 0, timeout: 100})
9025 redrawstatus
9026 endif
9027 endfunction
9028<
9029 This can also be used to count matched texts with specified
9030 pattern in the current buffer using "pattern": >
9031
9032 " Count '\<foo\>' in this buffer
9033 " (Note that it also updates search count)
9034 let result = searchcount(#{pattern: '\<foo\>'})
9035
9036 " To restore old search count by old pattern,
9037 " search again
9038 call searchcount()
9039<
9040 {options} must be a |Dictionary|. It can contain:
9041 key type meaning ~
9042 recompute |Boolean| if |TRUE|, recompute the count
9043 like |n| or |N| was executed.
9044 otherwise returns the last
9045 computed result (when |n| or
9046 |N| was used when "S" is not
9047 in 'shortmess', or this
9048 function was called).
9049 (default: |TRUE|)
9050 pattern |String| recompute if this was given
9051 and different with |@/|.
9052 this works as same as the
9053 below command is executed
9054 before calling this function >
9055 let @/ = pattern
9056< (default: |@/|)
9057 timeout |Number| 0 or negative number is no
9058 timeout. timeout milliseconds
9059 for recomputing the result
9060 (default: 0)
9061 maxcount |Number| 0 or negative number is no
9062 limit. max count of matched
9063 text while recomputing the
9064 result. if search exceeded
9065 total count, "total" value
9066 becomes `maxcount + 1`
9067 (default: 99)
9068 pos |List| `[lnum, col, off]` value
9069 when recomputing the result.
9070 this changes "current" result
9071 value. see |cursor()|,
9072 |getpos()|
9073 (default: cursor's position)
9074
9075 Can also be used as a |method|: >
9076 GetSearchOpts()->searchcount()
9077<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009078 Return type: dict<number>
9079
9080
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009081searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9082 Search for the declaration of {name}.
9083
9084 With a non-zero {global} argument it works like |gD|, find
9085 first match in the file. Otherwise it works like |gd|, find
9086 first match in the function.
9087
9088 With a non-zero {thisblock} argument matches in a {} block
9089 that ends before the cursor position are ignored. Avoids
9090 finding variable declarations only valid in another scope.
9091
9092 Moves the cursor to the found match.
9093 Returns zero for success, non-zero for failure.
9094 Example: >
9095 if searchdecl('myvar') == 0
9096 echo getline('.')
9097 endif
9098<
9099 Can also be used as a |method|: >
9100 GetName()->searchdecl()
9101<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009102 Return type: |Number|
9103
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009104 *searchpair()*
9105searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9106 [, {stopline} [, {timeout}]]]])
9107 Search for the match of a nested start-end pair. This can be
9108 used to find the "endif" that matches an "if", while other
9109 if/endif pairs in between are ignored.
9110 The search starts at the cursor. The default is to search
9111 forward, include 'b' in {flags} to search backward.
9112 If a match is found, the cursor is positioned at it and the
9113 line number is returned. If no match is found 0 or -1 is
9114 returned and the cursor doesn't move. No error message is
9115 given.
9116
9117 {start}, {middle} and {end} are patterns, see |pattern|. They
9118 must not contain \( \) pairs. Use of \%( \) is allowed. When
9119 {middle} is not empty, it is found when searching from either
9120 direction, but only when not in a nested start-end pair. A
9121 typical use is: >
9122 searchpair('\<if\>', '\<else\>', '\<endif\>')
9123< By leaving {middle} empty the "else" is skipped.
9124
9125 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9126 |search()|. Additionally:
9127 'r' Repeat until no more matches found; will find the
9128 outer pair. Implies the 'W' flag.
9129 'm' Return number of matches instead of line number with
9130 the match; will be > 1 when 'r' is used.
9131 Note: it's nearly always a good idea to use the 'W' flag, to
9132 avoid wrapping around the end of the file.
9133
9134 When a match for {start}, {middle} or {end} is found, the
9135 {skip} expression is evaluated with the cursor positioned on
9136 the start of the match. It should return non-zero if this
9137 match is to be skipped. E.g., because it is inside a comment
9138 or a string.
9139 When {skip} is omitted or empty, every match is accepted.
9140 When evaluating {skip} causes an error the search is aborted
9141 and -1 returned.
9142 {skip} can be a string, a lambda, a funcref or a partial.
9143 Anything else makes the function fail.
9144 In a `:def` function when the {skip} argument is a string
9145 constant it is compiled into instructions.
9146
9147 For {stopline} and {timeout} see |search()|.
9148
9149 The value of 'ignorecase' is used. 'magic' is ignored, the
9150 patterns are used like it's on.
9151
9152 The search starts exactly at the cursor. A match with
9153 {start}, {middle} or {end} at the next character, in the
9154 direction of searching, is the first one found. Example: >
9155 if 1
9156 if 2
9157 endif 2
9158 endif 1
9159< When starting at the "if 2", with the cursor on the "i", and
9160 searching forwards, the "endif 2" is found. When starting on
9161 the character just before the "if 2", the "endif 1" will be
9162 found. That's because the "if 2" will be found first, and
9163 then this is considered to be a nested if/endif from "if 2" to
9164 "endif 2".
9165 When searching backwards and {end} is more than one character,
9166 it may be useful to put "\zs" at the end of the pattern, so
9167 that when the cursor is inside a match with the end it finds
9168 the matching start.
9169
9170 Example, to find the "endif" command in a Vim script: >
9171
9172 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9173 \ 'getline(".") =~ "^\\s*\""')
9174
9175< The cursor must be at or after the "if" for which a match is
9176 to be found. Note that single-quote strings are used to avoid
9177 having to double the backslashes. The skip expression only
9178 catches comments at the start of a line, not after a command.
9179 Also, a word "en" or "if" halfway a line is considered a
9180 match.
9181 Another example, to search for the matching "{" of a "}": >
9182
9183 :echo searchpair('{', '', '}', 'bW')
9184
9185< This works when the cursor is at or before the "}" for which a
9186 match is to be found. To reject matches that syntax
9187 highlighting recognized as strings: >
9188
9189 :echo searchpair('{', '', '}', 'bW',
9190 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9191<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009192 Return type: |Number|
9193
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009194 *searchpairpos()*
9195searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9196 [, {stopline} [, {timeout}]]]])
9197 Same as |searchpair()|, but returns a |List| with the line and
9198 column position of the match. The first element of the |List|
9199 is the line number and the second element is the byte index of
9200 the column position of the match. If no match is found,
9201 returns [0, 0]. >
9202
9203 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9204<
9205 See |match-parens| for a bigger and more useful example.
9206
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009207 Return type: list<number>
9208
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009209 *searchpos()*
9210searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9211 Same as |search()|, but returns a |List| with the line and
9212 column position of the match. The first element of the |List|
9213 is the line number and the second element is the byte index of
9214 the column position of the match. If no match is found,
9215 returns [0, 0].
9216 Example: >
9217 :let [lnum, col] = searchpos('mypattern', 'n')
9218
9219< When the 'p' flag is given then there is an extra item with
9220 the sub-pattern match number |search()-sub-match|. Example: >
9221 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9222< In this example "submatch" is 2 when a lowercase letter is
9223 found |/\l|, 3 when an uppercase letter is found |/\u|.
9224
9225 Can also be used as a |method|: >
9226 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009227<
9228 Return type: list<number>
9229
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009230
9231server2client({clientid}, {string}) *server2client()*
9232 Send a reply string to {clientid}. The most recent {clientid}
9233 that sent a string can be retrieved with expand("<client>").
9234 {only available when compiled with the |+clientserver| feature}
9235 Returns zero for success, -1 for failure.
9236 Note:
9237 This id has to be stored before the next command can be
9238 received. I.e. before returning from the received command and
9239 before calling any commands that waits for input.
9240 See also |clientserver|.
9241 Example: >
9242 :echo server2client(expand("<client>"), "HELLO")
9243
9244< Can also be used as a |method|: >
9245 GetClientId()->server2client(string)
9246<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009247 Return type: |Number|
9248
9249
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009250serverlist() *serverlist()*
9251 Return a list of available server names, one per line.
9252 When there are no servers or the information is not available
9253 an empty string is returned. See also |clientserver|.
9254 {only available when compiled with the |+clientserver| feature}
9255 Example: >
9256 :echo serverlist()
9257<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009258 Return type: |String|
9259
9260
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009261setbufline({buf}, {lnum}, {text}) *setbufline()*
9262 Set line {lnum} to {text} in buffer {buf}. This works like
9263 |setline()| for the specified buffer.
9264
9265 This function works only for loaded buffers. First call
9266 |bufload()| if needed.
9267
9268 To insert lines use |appendbufline()|.
9269 Any text properties in {lnum} are cleared.
9270
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009271 {text} can be a string to set one line, or a List of strings
9272 to set multiple lines. If the List extends below the last
9273 line then those lines are added. If the List is empty then
9274 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009275
9276 For the use of {buf}, see |bufname()| above.
9277
9278 {lnum} is used like with |setline()|.
9279 Use "$" to refer to the last line in buffer {buf}.
9280 When {lnum} is just below the last line the {text} will be
9281 added below the last line.
9282
9283 When {buf} is not a valid buffer, the buffer is not loaded or
9284 {lnum} is not valid then 1 is returned. In |Vim9| script an
9285 error is given.
9286 On success 0 is returned.
9287
9288 Can also be used as a |method|, the base is passed as the
9289 third argument: >
9290 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009291<
9292 Return type: |Number|
9293
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009294
9295setbufvar({buf}, {varname}, {val}) *setbufvar()*
9296 Set option or local variable {varname} in buffer {buf} to
9297 {val}.
9298 This also works for a global or local window option, but it
9299 doesn't work for a global or local window variable.
9300 For a local window option the global value is unchanged.
9301 For the use of {buf}, see |bufname()| above.
9302 The {varname} argument is a string.
9303 Note that the variable name without "b:" must be used.
9304 Examples: >
9305 :call setbufvar(1, "&mod", 1)
9306 :call setbufvar("todo", "myvar", "foobar")
9307< This function is not available in the |sandbox|.
9308
9309 Can also be used as a |method|, the base is passed as the
9310 third argument: >
9311 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009312<
9313 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009314
9315
9316setcellwidths({list}) *setcellwidths()*
9317 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009318 tells Vim how wide characters are when displayed in the
9319 terminal, counted in screen cells. The values override
9320 'ambiwidth'. Example: >
9321 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009322 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009323 \ [0x2194, 0x2199, 2],
9324 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009325
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009326< The {list} argument is a List of Lists with each three
9327 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9328 {low} and {high} can be the same, in which case this refers to
9329 one character. Otherwise it is the range of characters from
9330 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009331 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009332
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009333 {width} must be either 1 or 2, indicating the character width
9334 in screen cells. *E1112*
9335 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009336 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009337
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009338 If the new value causes 'fillchars' or 'listchars' to become
9339 invalid it is rejected and an error is given.
9340
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009341 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009342 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009343
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009344< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009345 the effect for known emoji characters. Move the cursor
9346 through the text to check if the cell widths of your terminal
9347 match with what Vim knows about each emoji. If it doesn't
9348 look right you need to adjust the {list} argument.
9349
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009350 Return type: |Number|
9351
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009352
9353setcharpos({expr}, {list}) *setcharpos()*
9354 Same as |setpos()| but uses the specified column number as the
9355 character index instead of the byte index in the line.
9356
9357 Example:
9358 With the text "여보세요" in line 8: >
9359 call setcharpos('.', [0, 8, 4, 0])
9360< positions the cursor on the fourth character '요'. >
9361 call setpos('.', [0, 8, 4, 0])
9362< positions the cursor on the second character '보'.
9363
9364 Can also be used as a |method|: >
9365 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009366<
9367 Return type: |Number|
9368
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009369
9370setcharsearch({dict}) *setcharsearch()*
9371 Set the current character search information to {dict},
9372 which contains one or more of the following entries:
9373
9374 char character which will be used for a subsequent
9375 |,| or |;| command; an empty string clears the
9376 character search
9377 forward direction of character search; 1 for forward,
9378 0 for backward
9379 until type of character search; 1 for a |t| or |T|
9380 character search, 0 for an |f| or |F|
9381 character search
9382
9383 This can be useful to save/restore a user's character search
9384 from a script: >
9385 :let prevsearch = getcharsearch()
9386 :" Perform a command which clobbers user's search
9387 :call setcharsearch(prevsearch)
9388< Also see |getcharsearch()|.
9389
9390 Can also be used as a |method|: >
9391 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009392<
9393 Return type: dict<any>
9394
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009395
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009396setcmdline({str} [, {pos}]) *setcmdline()*
9397 Set the command line to {str} and set the cursor position to
9398 {pos}.
9399 If {pos} is omitted, the cursor is positioned after the text.
9400 Returns 0 when successful, 1 when not editing the command
9401 line.
9402
9403 Can also be used as a |method|: >
9404 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009405<
9406 Return type: |Number|
9407
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009408
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009409setcmdpos({pos}) *setcmdpos()*
9410 Set the cursor position in the command line to byte position
9411 {pos}. The first position is 1.
9412 Use |getcmdpos()| to obtain the current position.
9413 Only works while editing the command line, thus you must use
9414 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9415 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9416 set after the command line is set to the expression. For
9417 |c_CTRL-R_=| it is set after evaluating the expression but
9418 before inserting the resulting text.
9419 When the number is too big the cursor is put at the end of the
9420 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009421 Returns 0 when successful, 1 when not editing the command
9422 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009423
9424 Can also be used as a |method|: >
9425 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009426<
9427 Return type: |Number|
9428
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009429
9430setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9431setcursorcharpos({list})
9432 Same as |cursor()| but uses the specified column number as the
9433 character index instead of the byte index in the line.
9434
9435 Example:
9436 With the text "여보세요" in line 4: >
9437 call setcursorcharpos(4, 3)
9438< positions the cursor on the third character '세'. >
9439 call cursor(4, 3)
9440< positions the cursor on the first character '여'.
9441
9442 Can also be used as a |method|: >
9443 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009444<
9445 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009446
9447
9448setenv({name}, {val}) *setenv()*
9449 Set environment variable {name} to {val}. Example: >
9450 call setenv('HOME', '/home/myhome')
9451
9452< When {val} is |v:null| the environment variable is deleted.
9453 See also |expr-env|.
9454
9455 Can also be used as a |method|, the base is passed as the
9456 second argument: >
9457 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009458<
9459 Return type: |Number|
9460
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009461
9462setfperm({fname}, {mode}) *setfperm()* *chmod*
9463 Set the file permissions for {fname} to {mode}.
9464 {mode} must be a string with 9 characters. It is of the form
9465 "rwxrwxrwx", where each group of "rwx" flags represent, in
9466 turn, the permissions of the owner of the file, the group the
9467 file belongs to, and other users. A '-' character means the
9468 permission is off, any other character means on. Multi-byte
9469 characters are not supported.
9470
9471 For example "rw-r-----" means read-write for the user,
9472 readable by the group, not accessible by others. "xx-x-----"
9473 would do the same thing.
9474
9475 Returns non-zero for success, zero for failure.
9476
9477 Can also be used as a |method|: >
9478 GetFilename()->setfperm(mode)
9479<
9480 To read permissions see |getfperm()|.
9481
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009482 Return type: |Number|
9483
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009484
9485setline({lnum}, {text}) *setline()*
9486 Set line {lnum} of the current buffer to {text}. To insert
9487 lines use |append()|. To set lines in another buffer use
9488 |setbufline()|. Any text properties in {lnum} are cleared.
9489
9490 {lnum} is used like with |getline()|.
9491 When {lnum} is just below the last line the {text} will be
9492 added below the last line.
9493 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009494 converted to a String. When {text} is an empty List then
9495 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009496
9497 If this succeeds, FALSE is returned. If this fails (most likely
9498 because {lnum} is invalid) TRUE is returned.
9499 In |Vim9| script an error is given if {lnum} is invalid.
9500
9501 Example: >
9502 :call setline(5, strftime("%c"))
9503
9504< When {text} is a |List| then line {lnum} and following lines
9505 will be set to the items in the list. Example: >
9506 :call setline(5, ['aaa', 'bbb', 'ccc'])
9507< This is equivalent to: >
9508 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9509 : call setline(n, l)
9510 :endfor
9511
9512< Note: The '[ and '] marks are not set.
9513
9514 Can also be used as a |method|, the base is passed as the
9515 second argument: >
9516 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009517<
9518 Return type: |Number|
9519
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009520
9521setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9522 Create or replace or add to the location list for window {nr}.
9523 {nr} can be the window number or the |window-ID|.
9524 When {nr} is zero the current window is used.
9525
9526 For a location list window, the displayed location list is
9527 modified. For an invalid window number {nr}, -1 is returned.
9528 Otherwise, same as |setqflist()|.
9529 Also see |location-list|.
9530
9531 For {action} see |setqflist-action|.
9532
9533 If the optional {what} dictionary argument is supplied, then
9534 only the items listed in {what} are set. Refer to |setqflist()|
9535 for the list of supported keys in {what}.
9536
9537 Can also be used as a |method|, the base is passed as the
9538 second argument: >
9539 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009540<
9541 Return type: |Number|
9542
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009543
9544setmatches({list} [, {win}]) *setmatches()*
9545 Restores a list of matches saved by |getmatches()| for the
9546 current window. Returns 0 if successful, otherwise -1. All
9547 current matches are cleared before the list is restored. See
9548 example for |getmatches()|.
9549 If {win} is specified, use the window with this number or
9550 window ID instead of the current window.
9551
9552 Can also be used as a |method|: >
9553 GetMatches()->setmatches()
9554<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009555 Return type: |Number|
9556
9557
9558setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009559 Set the position for String {expr}. Possible values:
9560 . the cursor
9561 'x mark x
9562
9563 {list} must be a |List| with four or five numbers:
9564 [bufnum, lnum, col, off]
9565 [bufnum, lnum, col, off, curswant]
9566
9567 "bufnum" is the buffer number. Zero can be used for the
9568 current buffer. When setting an uppercase mark "bufnum" is
9569 used for the mark position. For other marks it specifies the
9570 buffer to set the mark in. You can use the |bufnr()| function
9571 to turn a file name into a buffer number.
9572 For setting the cursor and the ' mark "bufnum" is ignored,
9573 since these are associated with a window, not a buffer.
9574 Does not change the jumplist.
9575
9576 "lnum" and "col" are the position in the buffer. The first
9577 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9578 smaller than 1 then 1 is used. To use the character count
9579 instead of the byte count, use |setcharpos()|.
9580
9581 The "off" number is only used when 'virtualedit' is set. Then
9582 it is the offset in screen columns from the start of the
9583 character. E.g., a position within a <Tab> or after the last
9584 character.
9585
9586 The "curswant" number is only used when setting the cursor
9587 position. It sets the preferred column for when moving the
9588 cursor vertically. When the "curswant" number is missing the
9589 preferred column is not set. When it is present and setting a
9590 mark position it is not used.
9591
9592 Note that for '< and '> changing the line number may result in
9593 the marks to be effectively be swapped, so that '< is always
9594 before '>.
9595
9596 Returns 0 when the position could be set, -1 otherwise.
9597 An error message is given if {expr} is invalid.
9598
9599 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9600
9601 This does not restore the preferred column for moving
9602 vertically; if you set the cursor position with this, |j| and
9603 |k| motions will jump to previous columns! Use |cursor()| to
9604 also set the preferred column. Also see the "curswant" key in
9605 |winrestview()|.
9606
9607 Can also be used as a |method|: >
9608 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009609<
9610 Return type: |Number|
9611
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009612
9613setqflist({list} [, {action} [, {what}]]) *setqflist()*
9614 Create or replace or add to the quickfix list.
9615
9616 If the optional {what} dictionary argument is supplied, then
9617 only the items listed in {what} are set. The first {list}
9618 argument is ignored. See below for the supported items in
9619 {what}.
9620 *setqflist-what*
9621 When {what} is not present, the items in {list} are used. Each
9622 item must be a dictionary. Non-dictionary items in {list} are
9623 ignored. Each dictionary item can contain the following
9624 entries:
9625
9626 bufnr buffer number; must be the number of a valid
9627 buffer
9628 filename name of a file; only used when "bufnr" is not
9629 present or it is invalid.
9630 module name of a module; if given it will be used in
9631 quickfix error window instead of the filename.
9632 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00009633 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009634 pattern search pattern used to locate the error
9635 col column number
9636 vcol when non-zero: "col" is visual column
9637 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00009638 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009639 nr error number
9640 text description of the error
9641 type single-character error type, 'E', 'W', etc.
9642 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +02009643 user_data custom data associated with the item, can be
9644 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009645
9646 The "col", "vcol", "nr", "type" and "text" entries are
9647 optional. Either "lnum" or "pattern" entry can be used to
9648 locate a matching error line.
9649 If the "filename" and "bufnr" entries are not present or
9650 neither the "lnum" or "pattern" entries are present, then the
9651 item will not be handled as an error line.
9652 If both "pattern" and "lnum" are present then "pattern" will
9653 be used.
9654 If the "valid" entry is not supplied, then the valid flag is
9655 set when "bufnr" is a valid buffer or "filename" exists.
9656 If you supply an empty {list}, the quickfix list will be
9657 cleared.
9658 Note that the list is not exactly the same as what
9659 |getqflist()| returns.
9660
9661 {action} values: *setqflist-action* *E927*
9662 'a' The items from {list} are added to the existing
9663 quickfix list. If there is no existing list, then a
9664 new list is created.
9665
9666 'r' The items from the current quickfix list are replaced
9667 with the items from {list}. This can also be used to
9668 clear the list: >
9669 :call setqflist([], 'r')
9670<
9671 'f' All the quickfix lists in the quickfix stack are
9672 freed.
9673
9674 If {action} is not present or is set to ' ', then a new list
9675 is created. The new quickfix list is added after the current
9676 quickfix list in the stack and all the following lists are
9677 freed. To add a new quickfix list at the end of the stack,
9678 set "nr" in {what} to "$".
9679
9680 The following items can be specified in dictionary {what}:
9681 context quickfix list context. See |quickfix-context|
9682 efm errorformat to use when parsing text from
9683 "lines". If this is not present, then the
9684 'errorformat' option value is used.
9685 See |quickfix-parse|
9686 id quickfix list identifier |quickfix-ID|
9687 idx index of the current entry in the quickfix
9688 list specified by 'id' or 'nr'. If set to '$',
9689 then the last entry in the list is set as the
9690 current entry. See |quickfix-index|
9691 items list of quickfix entries. Same as the {list}
9692 argument.
9693 lines use 'errorformat' to parse a list of lines and
9694 add the resulting entries to the quickfix list
9695 {nr} or {id}. Only a |List| value is supported.
9696 See |quickfix-parse|
9697 nr list number in the quickfix stack; zero
9698 means the current quickfix list and "$" means
9699 the last quickfix list.
9700 quickfixtextfunc
9701 function to get the text to display in the
9702 quickfix window. The value can be the name of
9703 a function or a funcref or a lambda. Refer to
9704 |quickfix-window-function| for an explanation
9705 of how to write the function and an example.
9706 title quickfix list title text. See |quickfix-title|
9707 Unsupported keys in {what} are ignored.
9708 If the "nr" item is not present, then the current quickfix list
9709 is modified. When creating a new quickfix list, "nr" can be
9710 set to a value one greater than the quickfix stack size.
9711 When modifying a quickfix list, to guarantee that the correct
9712 list is modified, "id" should be used instead of "nr" to
9713 specify the list.
9714
9715 Examples (See also |setqflist-examples|): >
9716 :call setqflist([], 'r', {'title': 'My search'})
9717 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
9718 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
9719<
9720 Returns zero for success, -1 for failure.
9721
9722 This function can be used to create a quickfix list
9723 independent of the 'errorformat' setting. Use a command like
9724 `:cc 1` to jump to the first position.
9725
9726 Can also be used as a |method|, the base is passed as the
9727 second argument: >
9728 GetErrorlist()->setqflist()
9729<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009730 Return type: |Number|
9731
9732
9733setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009734 Set the register {regname} to {value}.
9735 If {regname} is "" or "@", the unnamed register '"' is used.
9736 The {regname} argument is a string. In |Vim9-script|
9737 {regname} must be one character.
9738
9739 {value} may be any value returned by |getreg()| or
9740 |getreginfo()|, including a |List| or |Dict|.
9741 If {options} contains "a" or {regname} is upper case,
9742 then the value is appended.
9743
9744 {options} can also contain a register type specification:
9745 "c" or "v" |characterwise| mode
9746 "l" or "V" |linewise| mode
9747 "b" or "<CTRL-V>" |blockwise-visual| mode
9748 If a number immediately follows "b" or "<CTRL-V>" then this is
9749 used as the width of the selection - if it is not specified
9750 then the width of the block is set to the number of characters
9751 in the longest line (counting a <Tab> as 1 character).
9752
9753 If {options} contains no register settings, then the default
9754 is to use character mode unless {value} ends in a <NL> for
9755 string {value} and linewise mode for list {value}. Blockwise
9756 mode is never selected automatically.
9757 Returns zero for success, non-zero for failure.
9758
9759 *E883*
9760 Note: you may not use |List| containing more than one item to
9761 set search and expression registers. Lists containing no
9762 items act like empty strings.
9763
9764 Examples: >
9765 :call setreg(v:register, @*)
9766 :call setreg('*', @%, 'ac')
9767 :call setreg('a', "1\n2\n3", 'b5')
9768 :call setreg('"', { 'points_to': 'a'})
9769
9770< This example shows using the functions to save and restore a
9771 register: >
9772 :let var_a = getreginfo()
9773 :call setreg('a', var_a)
9774< or: >
9775 :let var_a = getreg('a', 1, 1)
9776 :let var_amode = getregtype('a')
9777 ....
9778 :call setreg('a', var_a, var_amode)
9779< Note: you may not reliably restore register value
9780 without using the third argument to |getreg()| as without it
9781 newlines are represented as newlines AND Nul bytes are
9782 represented as newlines as well, see |NL-used-for-Nul|.
9783
9784 You can also change the type of a register by appending
9785 nothing: >
9786 :call setreg('a', '', 'al')
9787
9788< Can also be used as a |method|, the base is passed as the
9789 second argument: >
9790 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009791<
9792 Return type: |Number|
9793
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009794
9795settabvar({tabnr}, {varname}, {val}) *settabvar()*
9796 Set tab-local variable {varname} to {val} in tab page {tabnr}.
9797 |t:var|
9798 The {varname} argument is a string.
9799 Note that autocommands are blocked, side effects may not be
9800 triggered, e.g. when setting 'filetype'.
9801 Note that the variable name without "t:" must be used.
9802 Tabs are numbered starting with one.
9803 This function is not available in the |sandbox|.
9804
9805 Can also be used as a |method|, the base is passed as the
9806 third argument: >
9807 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009808<
9809 Return type: |Number|
9810
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009811
9812settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
9813 Set option or local variable {varname} in window {winnr} to
9814 {val}.
9815 Tabs are numbered starting with one. For the current tabpage
9816 use |setwinvar()|.
9817 {winnr} can be the window number or the |window-ID|.
9818 When {winnr} is zero the current window is used.
9819 Note that autocommands are blocked, side effects may not be
9820 triggered, e.g. when setting 'filetype' or 'syntax'.
9821 This also works for a global or local buffer option, but it
9822 doesn't work for a global or local buffer variable.
9823 For a local buffer option the global value is unchanged.
9824 Note that the variable name without "w:" must be used.
9825 Examples: >
9826 :call settabwinvar(1, 1, "&list", 0)
9827 :call settabwinvar(3, 2, "myvar", "foobar")
9828< This function is not available in the |sandbox|.
9829
9830 Can also be used as a |method|, the base is passed as the
9831 fourth argument: >
9832 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009833<
9834 Return type: |Number|
9835
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009836
9837settagstack({nr}, {dict} [, {action}]) *settagstack()*
9838 Modify the tag stack of the window {nr} using {dict}.
9839 {nr} can be the window number or the |window-ID|.
9840
9841 For a list of supported items in {dict}, refer to
9842 |gettagstack()|. "curidx" takes effect before changing the tag
9843 stack.
9844 *E962*
9845 How the tag stack is modified depends on the {action}
9846 argument:
9847 - If {action} is not present or is set to 'r', then the tag
9848 stack is replaced.
9849 - If {action} is set to 'a', then new entries from {dict} are
9850 pushed (added) onto the tag stack.
9851 - If {action} is set to 't', then all the entries from the
9852 current entry in the tag stack or "curidx" in {dict} are
9853 removed and then new entries are pushed to the stack.
9854
9855 The current index is set to one after the length of the tag
9856 stack after the modification.
9857
9858 Returns zero for success, -1 for failure.
9859
9860 Examples (for more examples see |tagstack-examples|):
9861 Empty the tag stack of window 3: >
9862 call settagstack(3, {'items' : []})
9863
9864< Save and restore the tag stack: >
9865 let stack = gettagstack(1003)
9866 " do something else
9867 call settagstack(1003, stack)
9868 unlet stack
9869<
9870 Can also be used as a |method|, the base is passed as the
9871 second argument: >
9872 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009873<
9874 Return type: |Number|
9875
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009876
9877setwinvar({winnr}, {varname}, {val}) *setwinvar()*
9878 Like |settabwinvar()| for the current tab page.
9879 Examples: >
9880 :call setwinvar(1, "&list", 0)
9881 :call setwinvar(2, "myvar", "foobar")
9882
9883< Can also be used as a |method|, the base is passed as the
9884 third argument: >
9885 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009886<
9887 Return type: |Number|
9888
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009889
9890sha256({string}) *sha256()*
9891 Returns a String with 64 hex characters, which is the SHA256
9892 checksum of {string}.
9893
9894 Can also be used as a |method|: >
9895 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009896<
9897 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009898
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009899 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009900
9901shellescape({string} [, {special}]) *shellescape()*
9902 Escape {string} for use as a shell command argument.
9903 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +00009904 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009905 in single quotes and will double up all internal single
9906 quotes.
9907 On MS-Windows, when 'shellslash' is not set, it will enclose
9908 {string} in double quotes and double all double quotes within
9909 {string}.
9910 Otherwise it will enclose {string} in single quotes and
9911 replace all "'" with "'\''".
9912
Enno5faeb602024-05-15 21:54:19 +02009913 The {special} argument adds additional escaping of keywords
9914 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +09009915 number or a non-empty String (|non-zero-arg|), then special
9916 items such as "!", "%", "#" and "<cword>" (as listed in
9917 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +02009918 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009919
9920 The "!" character will be escaped (again with a |non-zero-arg|
9921 {special}) when 'shell' contains "csh" in the tail. That is
9922 because for csh and tcsh "!" is used for history replacement
9923 even when inside single quotes.
9924
9925 With a |non-zero-arg| {special} the <NL> character is also
9926 escaped. When 'shell' containing "csh" in the tail it's
9927 escaped a second time.
9928
9929 The "\" character will be escaped when 'shell' contains "fish"
9930 in the tail. That is because for fish "\" is used as an escape
9931 character inside single quotes.
9932
9933 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009934 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009935< This results in a directory listing for the file under the
9936 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009937 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009938< See also |::S|.
9939
9940 Can also be used as a |method|: >
9941 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009942<
9943 Return type: |String|
9944
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009945
9946shiftwidth([{col}]) *shiftwidth()*
9947 Returns the effective value of 'shiftwidth'. This is the
9948 'shiftwidth' value unless it is zero, in which case it is the
9949 'tabstop' value. This function was introduced with patch
9950 7.3.694 in 2012, everybody should have it by now (however it
9951 did not allow for the optional {col} argument until 8.1.542).
9952
9953 When there is one argument {col} this is used as column number
9954 for which to return the 'shiftwidth' value. This matters for the
9955 'vartabstop' feature. If the 'vartabstop' setting is enabled and
9956 no {col} argument is given, column 1 will be assumed.
9957
9958 Can also be used as a |method|: >
9959 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009960<
9961 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009962
9963sign_ functions are documented here: |sign-functions-details|
9964
9965
9966simplify({filename}) *simplify()*
9967 Simplify the file name as much as possible without changing
9968 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
9969 Unix) are not resolved. If the first path component in
9970 {filename} designates the current directory, this will be
9971 valid for the result as well. A trailing path separator is
9972 not removed either. On Unix "//path" is unchanged, but
9973 "///path" is simplified to "/path" (this follows the Posix
9974 standard).
9975 Example: >
9976 simplify("./dir/.././/file/") == "./file/"
9977< Note: The combination "dir/.." is only removed if "dir" is
9978 a searchable directory or does not exist. On Unix, it is also
9979 removed when "dir" is a symbolic link within the same
9980 directory. In order to resolve all the involved symbolic
9981 links before simplifying the path name, use |resolve()|.
9982
9983 Can also be used as a |method|: >
9984 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009985<
9986 Return type: |String|
9987
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009988
9989sin({expr}) *sin()*
9990 Return the sine of {expr}, measured in radians, as a |Float|.
9991 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009992 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009993 Examples: >
9994 :echo sin(100)
9995< -0.506366 >
9996 :echo sin(-4.01)
9997< 0.763301
9998
9999 Can also be used as a |method|: >
10000 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010001<
10002 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010003
10004
10005sinh({expr}) *sinh()*
10006 Return the hyperbolic sine of {expr} as a |Float| in the range
10007 [-inf, inf].
10008 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010009 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010010 Examples: >
10011 :echo sinh(0.5)
10012< 0.521095 >
10013 :echo sinh(-0.9)
10014< -1.026517
10015
10016 Can also be used as a |method|: >
10017 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010018<
10019 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010020
10021
10022slice({expr}, {start} [, {end}]) *slice()*
10023 Similar to using a |slice| "expr[start : end]", but "end" is
10024 used exclusive. And for a string the indexes are used as
10025 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010026 |vim9script|. Also, composing characters are treated as a
10027 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010028 When {end} is omitted the slice continues to the last item.
10029 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010030 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010031
10032 Can also be used as a |method|: >
10033 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010034<
10035 Return type: list<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010036
10037
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010038sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010039 Sort the items in {list} in-place. Returns {list}.
10040
10041 If you want a list to remain unmodified make a copy first: >
10042 :let sortedlist = sort(copy(mylist))
10043
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010044< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010045 string representation of each item to sort on. Numbers sort
10046 after Strings, |Lists| after Numbers. For sorting text in the
10047 current buffer use |:sort|.
10048
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010049 When {how} is given and it is 'i' then case is ignored.
10050 In legacy script, for backwards compatibility, the value one
10051 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010052
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010053 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010054 locale is used for ordering. Implementation details: strcoll()
10055 is used to compare strings. See |:language| check or set the
10056 collation locale. |v:collate| can also be used to check the
10057 current locale. Sorting using the locale typically ignores
10058 case. Example: >
10059 " ö is sorted similarly to o with English locale.
10060 :language collate en_US.UTF8
10061 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10062< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10063>
10064 " ö is sorted after z with Swedish locale.
10065 :language collate sv_SE.UTF8
10066 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10067< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10068 This does not work properly on Mac.
10069
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010070 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010071 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010072 strtod() function to parse numbers. Strings, Lists, Dicts and
10073 Funcrefs will be considered as being 0). Note that this won't
10074 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010075
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010076 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010077 sorted numerical. This is like 'n' but a string containing
10078 digits will be used as the number they represent.
10079
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010080 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010081 sorted numerical. All values must be a Number or a Float.
10082
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010083 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010084 is called to compare items. The function is invoked with two
10085 items as argument and must return zero if they are equal, 1 or
10086 bigger if the first one sorts after the second one, -1 or
10087 smaller if the first one sorts before the second one.
10088
10089 {dict} is for functions with the "dict" attribute. It will be
10090 used to set the local variable "self". |Dictionary-function|
10091
10092 The sort is stable, items which compare equal (as number or as
10093 string) will keep their relative position. E.g., when sorting
10094 on numbers, text strings will sort next to each other, in the
10095 same order as they were originally.
10096
10097 Can also be used as a |method|: >
10098 mylist->sort()
10099
10100< Also see |uniq()|.
10101
10102 Example: >
10103 func MyCompare(i1, i2)
10104 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10105 endfunc
10106 eval mylist->sort("MyCompare")
10107< A shorter compare version for this specific simple case, which
10108 ignores overflow: >
10109 func MyCompare(i1, i2)
10110 return a:i1 - a:i2
10111 endfunc
10112< For a simple expression you can use a lambda: >
10113 eval mylist->sort({i1, i2 -> i1 - i2})
10114<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010115 Return type: list<{type}>
10116
10117
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010118sound_clear() *sound_clear()*
10119 Stop playing all sounds.
10120
10121 On some Linux systems you may need the libcanberra-pulse
10122 package, otherwise sound may not stop.
10123
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010124 Return type: |Number|
10125
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010126 {only available when compiled with the |+sound| feature}
10127
10128 *sound_playevent()*
10129sound_playevent({name} [, {callback}])
10130 Play a sound identified by {name}. Which event names are
10131 supported depends on the system. Often the XDG sound names
10132 are used. On Ubuntu they may be found in
10133 /usr/share/sounds/freedesktop/stereo. Example: >
10134 call sound_playevent('bell')
10135< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10136 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10137 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010138 On macOS, {name} refers to files located in
10139 /System/Library/Sounds (e.g. "Tink"). It will also work for
10140 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010141
10142 When {callback} is specified it is invoked when the sound is
10143 finished. The first argument is the sound ID, the second
10144 argument is the status:
10145 0 sound was played to the end
10146 1 sound was interrupted
10147 2 error occurred after sound started
10148 Example: >
10149 func Callback(id, status)
10150 echomsg "sound " .. a:id .. " finished with " .. a:status
10151 endfunc
10152 call sound_playevent('bell', 'Callback')
10153
10154< MS-Windows: {callback} doesn't work for this function.
10155
10156 Returns the sound ID, which can be passed to `sound_stop()`.
10157 Returns zero if the sound could not be played.
10158
10159 Can also be used as a |method|: >
10160 GetSoundName()->sound_playevent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010161<
10162 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010163
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010164 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010165
10166 *sound_playfile()*
10167sound_playfile({path} [, {callback}])
10168 Like `sound_playevent()` but play sound file {path}. {path}
10169 must be a full path. On Ubuntu you may find files to play
10170 with this command: >
10171 :!find /usr/share/sounds -type f | grep -v index.theme
10172
10173< Can also be used as a |method|: >
10174 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010175<
10176 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010177
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010178 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010179
10180
10181sound_stop({id}) *sound_stop()*
10182 Stop playing sound {id}. {id} must be previously returned by
10183 `sound_playevent()` or `sound_playfile()`.
10184
10185 On some Linux systems you may need the libcanberra-pulse
10186 package, otherwise sound may not stop.
10187
10188 On MS-Windows, this does not work for event sound started by
10189 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10190
10191 Can also be used as a |method|: >
10192 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010193<
10194 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010195
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010196 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010197
10198 *soundfold()*
10199soundfold({word})
10200 Return the sound-folded equivalent of {word}. Uses the first
10201 language in 'spelllang' for the current window that supports
10202 soundfolding. 'spell' must be set. When no sound folding is
10203 possible the {word} is returned unmodified.
10204 This can be used for making spelling suggestions. Note that
10205 the method can be quite slow.
10206
10207 Can also be used as a |method|: >
10208 GetWord()->soundfold()
10209<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010210 Return type: |String|
10211
10212
10213spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010214 Without argument: The result is the badly spelled word under
10215 or after the cursor. The cursor is moved to the start of the
10216 bad word. When no bad word is found in the cursor line the
10217 result is an empty string and the cursor doesn't move.
10218
10219 With argument: The result is the first word in {sentence} that
10220 is badly spelled. If there are no spelling mistakes the
10221 result is an empty string.
10222
10223 The return value is a list with two items:
10224 - The badly spelled word or an empty string.
10225 - The type of the spelling error:
10226 "bad" spelling mistake
10227 "rare" rare word
10228 "local" word only valid in another region
10229 "caps" word should start with Capital
10230 Example: >
10231 echo spellbadword("the quik brown fox")
10232< ['quik', 'bad'] ~
10233
10234 The spelling information for the current window and the value
10235 of 'spelllang' are used.
10236
10237 Can also be used as a |method|: >
10238 GetText()->spellbadword()
10239<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010240 Return type: list<string>
10241
10242
10243spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010244 Return a |List| with spelling suggestions to replace {word}.
10245 When {max} is given up to this number of suggestions are
10246 returned. Otherwise up to 25 suggestions are returned.
10247
10248 When the {capital} argument is given and it's non-zero only
10249 suggestions with a leading capital will be given. Use this
10250 after a match with 'spellcapcheck'.
10251
10252 {word} can be a badly spelled word followed by other text.
10253 This allows for joining two words that were split. The
10254 suggestions also include the following text, thus you can
10255 replace a line.
10256
10257 {word} may also be a good word. Similar words will then be
10258 returned. {word} itself is not included in the suggestions,
10259 although it may appear capitalized.
10260
10261 The spelling information for the current window is used. The
10262 values of 'spelllang' and 'spellsuggest' are used.
10263
10264 Can also be used as a |method|: >
10265 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010266<
10267 Return type: list<string> or list<any>
10268
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010269
10270split({string} [, {pattern} [, {keepempty}]]) *split()*
10271 Make a |List| out of {string}. When {pattern} is omitted or
10272 empty each white-separated sequence of characters becomes an
10273 item.
10274 Otherwise the string is split where {pattern} matches,
10275 removing the matched characters. 'ignorecase' is not used
10276 here, add \c to ignore case. |/\c|
10277 When the first or last item is empty it is omitted, unless the
10278 {keepempty} argument is given and it's non-zero.
10279 Other empty items are kept when {pattern} matches at least one
10280 character or when {keepempty} is non-zero.
10281 Example: >
10282 :let words = split(getline('.'), '\W\+')
10283< To split a string in individual characters: >
10284 :for c in split(mystring, '\zs')
10285< If you want to keep the separator you can also use '\zs' at
10286 the end of the pattern: >
10287 :echo split('abc:def:ghi', ':\zs')
10288< ['abc:', 'def:', 'ghi'] ~
10289 Splitting a table where the first element can be empty: >
10290 :let items = split(line, ':', 1)
10291< The opposite function is |join()|.
10292
10293 Can also be used as a |method|: >
10294 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010295<
10296 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010297
10298sqrt({expr}) *sqrt()*
10299 Return the non-negative square root of Float {expr} as a
10300 |Float|.
10301 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010302 is negative the result is NaN (Not a Number). Returns 0.0 if
10303 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010304 Examples: >
10305 :echo sqrt(100)
10306< 10.0 >
10307 :echo sqrt(-4.01)
10308< nan
10309 "nan" may be different, it depends on system libraries.
10310
10311 Can also be used as a |method|: >
10312 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010313<
10314 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010315
10316
10317srand([{expr}]) *srand()*
10318 Initialize seed used by |rand()|:
10319 - If {expr} is not given, seed values are initialized by
10320 reading from /dev/urandom, if possible, or using time(NULL)
10321 a.k.a. epoch time otherwise; this only has second accuracy.
10322 - If {expr} is given it must be a Number. It is used to
10323 initialize the seed values. This is useful for testing or
10324 when a predictable sequence is intended.
10325
10326 Examples: >
10327 :let seed = srand()
10328 :let seed = srand(userinput)
10329 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010330<
10331 Return type: list<number>
10332
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010333
10334state([{what}]) *state()*
10335 Return a string which contains characters indicating the
10336 current state. Mostly useful in callbacks that want to do
10337 work that may not always be safe. Roughly this works like:
10338 - callback uses state() to check if work is safe to do.
10339 Yes: then do it right away.
10340 No: add to work queue and add a |SafeState| and/or
10341 |SafeStateAgain| autocommand (|SafeState| triggers at
10342 toplevel, |SafeStateAgain| triggers after handling
10343 messages and callbacks).
10344 - When SafeState or SafeStateAgain is triggered and executes
10345 your autocommand, check with `state()` if the work can be
10346 done now, and if yes remove it from the queue and execute.
10347 Remove the autocommand if the queue is now empty.
10348 Also see |mode()|.
10349
10350 When {what} is given only characters in this string will be
10351 added. E.g, this checks if the screen has scrolled: >
10352 if state('s') == ''
10353 " screen has not scrolled
10354<
10355 These characters indicate the state, generally indicating that
10356 something is busy:
10357 m halfway a mapping, :normal command, feedkeys() or
10358 stuffed command
10359 o operator pending, e.g. after |d|
10360 a Insert mode autocomplete active
10361 x executing an autocommand
10362 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10363 ch_readraw() when reading json
10364 S not triggering SafeState or SafeStateAgain, e.g. after
10365 |f| or a count
10366 c callback invoked, including timer (repeats for
10367 recursiveness up to "ccc")
10368 s screen has scrolled for messages
10369
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010370 Return type: |String|
10371
10372
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010373str2float({string} [, {quoted}]) *str2float()*
10374 Convert String {string} to a Float. This mostly works the
10375 same as when using a floating point number in an expression,
10376 see |floating-point-format|. But it's a bit more permissive.
10377 E.g., "1e40" is accepted, while in an expression you need to
10378 write "1.0e40". The hexadecimal form "0x123" is also
10379 accepted, but not others, like binary or octal.
10380 When {quoted} is present and non-zero then embedded single
10381 quotes before the dot are ignored, thus "1'000.0" is a
10382 thousand.
10383 Text after the number is silently ignored.
10384 The decimal point is always '.', no matter what the locale is
10385 set to. A comma ends the number: "12,345.67" is converted to
10386 12.0. You can strip out thousands separators with
10387 |substitute()|: >
10388 let f = str2float(substitute(text, ',', '', 'g'))
10389<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010390 Returns 0.0 if the conversion fails.
10391
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010392 Can also be used as a |method|: >
10393 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010394<
10395 Return type: |Float|
10396
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010397
10398str2list({string} [, {utf8}]) *str2list()*
10399 Return a list containing the number values which represent
10400 each character in String {string}. Examples: >
10401 str2list(" ") returns [32]
10402 str2list("ABC") returns [65, 66, 67]
10403< |list2str()| does the opposite.
10404
10405 When {utf8} is omitted or zero, the current 'encoding' is used.
10406 When {utf8} is TRUE, always treat the String as UTF-8
10407 characters. With UTF-8 composing characters are handled
10408 properly: >
10409 str2list("á") returns [97, 769]
10410
10411< Can also be used as a |method|: >
10412 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010413<
10414 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010415
10416
10417str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10418 Convert string {string} to a number.
10419 {base} is the conversion base, it can be 2, 8, 10 or 16.
10420 When {quoted} is present and non-zero then embedded single
10421 quotes are ignored, thus "1'000'000" is a million.
10422
10423 When {base} is omitted base 10 is used. This also means that
10424 a leading zero doesn't cause octal conversion to be used, as
10425 with the default String to Number conversion. Example: >
10426 let nr = str2nr('0123')
10427<
10428 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10429 different base the result will be zero. Similarly, when
10430 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10431 {base} is 2 a leading "0b" or "0B" is ignored.
10432 Text after the number is silently ignored.
10433
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010434 Returns 0 if {string} is empty or on error.
10435
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010436 Can also be used as a |method|: >
10437 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010438<
10439 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010440
10441
10442strcharlen({string}) *strcharlen()*
10443 The result is a Number, which is the number of characters
10444 in String {string}. Composing characters are ignored.
10445 |strchars()| can count the number of characters, counting
10446 composing characters separately.
10447
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010448 Returns 0 if {string} is empty or on error.
10449
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010450 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10451
10452 Can also be used as a |method|: >
10453 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010454<
10455 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010456
10457
10458strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10459 Like |strpart()| but using character index and length instead
10460 of byte index and length.
10461 When {skipcc} is omitted or zero, composing characters are
10462 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010463 When {skipcc} set to 1, composing characters are treated as a
10464 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010465 When a character index is used where a character does not
10466 exist it is omitted and counted as one character. For
10467 example: >
10468 strcharpart('abc', -1, 2)
10469< results in 'a'.
10470
Bram Moolenaard592deb2022-06-17 15:42:40 +010010471 Returns an empty string on error.
10472
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010473 Can also be used as a |method|: >
10474 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010475<
10476 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010477
10478
10479strchars({string} [, {skipcc}]) *strchars()*
10480 The result is a Number, which is the number of characters
10481 in String {string}.
10482 When {skipcc} is omitted or zero, composing characters are
10483 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010484 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010485 |strcharlen()| always does this.
10486
Bram Moolenaard592deb2022-06-17 15:42:40 +010010487 Returns zero on error.
10488
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010489 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10490
10491 {skipcc} is only available after 7.4.755. For backward
10492 compatibility, you can define a wrapper function: >
10493 if has("patch-7.4.755")
10494 function s:strchars(str, skipcc)
10495 return strchars(a:str, a:skipcc)
10496 endfunction
10497 else
10498 function s:strchars(str, skipcc)
10499 if a:skipcc
10500 return strlen(substitute(a:str, ".", "x", "g"))
10501 else
10502 return strchars(a:str)
10503 endif
10504 endfunction
10505 endif
10506<
10507 Can also be used as a |method|: >
10508 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010509<
10510 Return type: |Number|
10511
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010512
10513strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10514 The result is a Number, which is the number of display cells
10515 String {string} occupies on the screen when it starts at {col}
10516 (first column is zero). When {col} is omitted zero is used.
10517 Otherwise it is the screen column where to start. This
10518 matters for Tab characters.
10519 The option settings of the current window are used. This
10520 matters for anything that's displayed differently, such as
10521 'tabstop' and 'display'.
10522 When {string} contains characters with East Asian Width Class
10523 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010524 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010525 Also see |strlen()|, |strwidth()| and |strchars()|.
10526
10527 Can also be used as a |method|: >
10528 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010529<
10530 Return type: |Number|
10531
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010532
10533strftime({format} [, {time}]) *strftime()*
10534 The result is a String, which is a formatted date and time, as
10535 specified by the {format} string. The given {time} is used,
10536 or the current time if no time is given. The accepted
10537 {format} depends on your system, thus this is not portable!
10538 See the manual page of the C function strftime() for the
10539 format. The maximum length of the result is 80 characters.
10540 See also |localtime()|, |getftime()| and |strptime()|.
10541 The language can be changed with the |:language| command.
10542 Examples: >
10543 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10544 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10545 :echo strftime("%y%m%d %T") 970427 11:53:55
10546 :echo strftime("%H:%M") 11:55
10547 :echo strftime("%c", getftime("file.c"))
10548 Show mod time of file.c.
10549< Not available on all systems. To check use: >
10550 :if exists("*strftime")
10551
10552< Can also be used as a |method|: >
10553 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010554<
10555 Return type: |String|
10556
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010557
10558strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010559 Get a Number corresponding to the character at {index} in
10560 {str}. This uses a zero-based character index, not a byte
10561 index. Composing characters are considered separate
10562 characters here. Use |nr2char()| to convert the Number to a
10563 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010564 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010565 Also see |strcharpart()| and |strchars()|.
10566
10567 Can also be used as a |method|: >
10568 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010569<
10570 Return type: |Number|
10571
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010572
10573stridx({haystack}, {needle} [, {start}]) *stridx()*
10574 The result is a Number, which gives the byte index in
10575 {haystack} of the first occurrence of the String {needle}.
10576 If {start} is specified, the search starts at index {start}.
10577 This can be used to find a second match: >
10578 :let colon1 = stridx(line, ":")
10579 :let colon2 = stridx(line, ":", colon1 + 1)
10580< The search is done case-sensitive.
10581 For pattern searches use |match()|.
10582 -1 is returned if the {needle} does not occur in {haystack}.
10583 See also |strridx()|.
10584 Examples: >
10585 :echo stridx("An Example", "Example") 3
10586 :echo stridx("Starting point", "Start") 0
10587 :echo stridx("Starting point", "start") -1
10588< *strstr()* *strchr()*
10589 stridx() works similar to the C function strstr(). When used
10590 with a single character it works similar to strchr().
10591
10592 Can also be used as a |method|: >
10593 GetHaystack()->stridx(needle)
10594<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010595 Return type: |Number|
10596
10597
10598string({expr}) *string()*
10599 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010600 Float, String, Blob or a composition of them, then the result
10601 can be parsed back with |eval()|.
10602 {expr} type result ~
10603 String 'string' (single quotes are doubled)
10604 Number 123
10605 Float 123.123456 or 1.123456e8
10606 Funcref function('name')
10607 Blob 0z00112233.44556677.8899
10608 List [item, item]
10609 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000010610 Class class SomeName
10611 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010010612 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020010613 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010614
10615 When a |List| or |Dictionary| has a recursive reference it is
10616 replaced by "[...]" or "{...}". Using eval() on the result
10617 will then fail.
10618
mityu7f0bba22024-03-29 10:14:41 +010010619 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010620 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010010621 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010622
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010623 Can also be used as a |method|: >
10624 mylist->string()
10625
10626< Also see |strtrans()|.
10627
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010628 Return type: |String|
10629
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010630
10631strlen({string}) *strlen()*
10632 The result is a Number, which is the length of the String
10633 {string} in bytes.
10634 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010635 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010636 If you want to count the number of multibyte characters use
10637 |strchars()|.
10638 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
10639
10640 Can also be used as a |method|: >
10641 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010642<
10643 Return type: |Number|
10644
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010645
10646strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
10647 The result is a String, which is part of {src}, starting from
10648 byte {start}, with the byte length {len}.
10649 When {chars} is present and TRUE then {len} is the number of
10650 characters positions (composing characters are not counted
10651 separately, thus "1" means one base character and any
10652 following composing characters).
10653 To count {start} as characters instead of bytes use
10654 |strcharpart()|.
10655
10656 When bytes are selected which do not exist, this doesn't
10657 result in an error, the bytes are simply omitted.
10658 If {len} is missing, the copy continues from {start} till the
10659 end of the {src}. >
10660 strpart("abcdefg", 3, 2) == "de"
10661 strpart("abcdefg", -2, 4) == "ab"
10662 strpart("abcdefg", 5, 4) == "fg"
10663 strpart("abcdefg", 3) == "defg"
10664
10665< Note: To get the first character, {start} must be 0. For
10666 example, to get the character under the cursor: >
10667 strpart(getline("."), col(".") - 1, 1, v:true)
10668<
Bram Moolenaard592deb2022-06-17 15:42:40 +010010669 Returns an empty string on error.
10670
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010671 Can also be used as a |method|: >
10672 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010673<
10674 Return type: |String|
10675
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010676
10677strptime({format}, {timestring}) *strptime()*
10678 The result is a Number, which is a unix timestamp representing
10679 the date and time in {timestring}, which is expected to match
10680 the format specified in {format}.
10681
10682 The accepted {format} depends on your system, thus this is not
10683 portable! See the manual page of the C function strptime()
10684 for the format. Especially avoid "%c". The value of $TZ also
10685 matters.
10686
10687 If the {timestring} cannot be parsed with {format} zero is
10688 returned. If you do not know the format of {timestring} you
10689 can try different {format} values until you get a non-zero
10690 result.
10691
10692 See also |strftime()|.
10693 Examples: >
10694 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
10695< 862156163 >
10696 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
10697< Sun Apr 27 11:53:55 1997 >
10698 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
10699< Sun Apr 27 12:53:55 1997
10700
10701 Can also be used as a |method|: >
10702 GetFormat()->strptime(timestring)
10703<
10704 Not available on all systems. To check use: >
10705 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010706<
10707 Return type: |Number|
10708
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010709
10710strridx({haystack}, {needle} [, {start}]) *strridx()*
10711 The result is a Number, which gives the byte index in
10712 {haystack} of the last occurrence of the String {needle}.
10713 When {start} is specified, matches beyond this index are
10714 ignored. This can be used to find a match before a previous
10715 match: >
10716 :let lastcomma = strridx(line, ",")
10717 :let comma2 = strridx(line, ",", lastcomma - 1)
10718< The search is done case-sensitive.
10719 For pattern searches use |match()|.
10720 -1 is returned if the {needle} does not occur in {haystack}.
10721 If the {needle} is empty the length of {haystack} is returned.
10722 See also |stridx()|. Examples: >
10723 :echo strridx("an angry armadillo", "an") 3
10724< *strrchr()*
10725 When used with a single character it works similar to the C
10726 function strrchr().
10727
10728 Can also be used as a |method|: >
10729 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010730<
10731 Return type: |Number|
10732
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010733
10734strtrans({string}) *strtrans()*
10735 The result is a String, which is {string} with all unprintable
10736 characters translated into printable characters |'isprint'|.
10737 Like they are shown in a window. Example: >
10738 echo strtrans(@a)
10739< This displays a newline in register a as "^@" instead of
10740 starting a new line.
10741
Bram Moolenaard592deb2022-06-17 15:42:40 +010010742 Returns an empty string on error.
10743
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010744 Can also be used as a |method|: >
10745 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010746<
10747 Return type: |String|
10748
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010749
Christian Brabandt67672ef2023-04-24 21:09:54 +010010750strutf16len({string} [, {countcc}]) *strutf16len()*
10751 The result is a Number, which is the number of UTF-16 code
10752 units in String {string} (after converting it to UTF-16).
10753
10754 When {countcc} is TRUE, composing characters are counted
10755 separately.
10756 When {countcc} is omitted or FALSE, composing characters are
10757 ignored.
10758
10759 Returns zero on error.
10760
10761 Also see |strlen()| and |strcharlen()|.
10762 Examples: >
10763 echo strutf16len('a') returns 1
10764 echo strutf16len('©') returns 1
10765 echo strutf16len('😊') returns 2
10766 echo strutf16len('ą́') returns 1
10767 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090010768<
Christian Brabandt67672ef2023-04-24 21:09:54 +010010769 Can also be used as a |method|: >
10770 GetText()->strutf16len()
10771<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010772 Return type: |Number|
10773
10774
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010775strwidth({string}) *strwidth()*
10776 The result is a Number, which is the number of display cells
10777 String {string} occupies. A Tab character is counted as one
10778 cell, alternatively use |strdisplaywidth()|.
10779 When {string} contains characters with East Asian Width Class
10780 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010781 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010782 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
10783
10784 Can also be used as a |method|: >
10785 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010786<
10787 Return type: |Number|
10788
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010789
10790submatch({nr} [, {list}]) *submatch()* *E935*
10791 Only for an expression in a |:substitute| command or
10792 substitute() function.
10793 Returns the {nr}'th submatch of the matched text. When {nr}
10794 is 0 the whole matched text is returned.
10795 Note that a NL in the string can stand for a line break of a
10796 multi-line match or a NUL character in the text.
10797 Also see |sub-replace-expression|.
10798
10799 If {list} is present and non-zero then submatch() returns
10800 a list of strings, similar to |getline()| with two arguments.
10801 NL characters in the text represent NUL characters in the
10802 text.
10803 Only returns more than one item for |:substitute|, inside
10804 |substitute()| this list will always contain one or zero
10805 items, since there are no real line breaks.
10806
10807 When substitute() is used recursively only the submatches in
10808 the current (deepest) call can be obtained.
10809
Bram Moolenaard592deb2022-06-17 15:42:40 +010010810 Returns an empty string or list on error.
10811
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010812 Examples: >
10813 :s/\d\+/\=submatch(0) + 1/
10814 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
10815< This finds the first number in the line and adds one to it.
10816 A line break is included as a newline character.
10817
10818 Can also be used as a |method|: >
10819 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010820<
10821 Return type: |String| or list<string> depending on {list}
10822
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010823
10824substitute({string}, {pat}, {sub}, {flags}) *substitute()*
10825 The result is a String, which is a copy of {string}, in which
10826 the first match of {pat} is replaced with {sub}.
10827 When {flags} is "g", all matches of {pat} in {string} are
10828 replaced. Otherwise {flags} should be "".
10829
10830 This works like the ":substitute" command (without any flags).
10831 But the matching with {pat} is always done like the 'magic'
10832 option is set and 'cpoptions' is empty (to make scripts
10833 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
10834 if you want to ignore or match case and ignore 'ignorecase'.
10835 'smartcase' is not used. See |string-match| for how {pat} is
10836 used.
10837
10838 A "~" in {sub} is not replaced with the previous {sub}.
10839 Note that some codes in {sub} have a special meaning
10840 |sub-replace-special|. For example, to replace something with
10841 "\n" (two characters), use "\\\\n" or '\\n'.
10842
10843 When {pat} does not match in {string}, {string} is returned
10844 unmodified.
10845
10846 Example: >
10847 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
10848< This removes the last component of the 'path' option. >
10849 :echo substitute("testing", ".*", "\\U\\0", "")
10850< results in "TESTING".
10851
10852 When {sub} starts with "\=", the remainder is interpreted as
10853 an expression. See |sub-replace-expression|. Example: >
10854 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010855 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010856
10857< When {sub} is a Funcref that function is called, with one
10858 optional argument. Example: >
10859 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
10860< The optional argument is a list which contains the whole
10861 matched string and up to nine submatches, like what
10862 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010863 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010864
Bram Moolenaard592deb2022-06-17 15:42:40 +010010865< Returns an empty string on error.
10866
10867 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010868 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010869<
10870 Return type: |String|
10871
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010872
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000010873swapfilelist() *swapfilelist()*
10874 Returns a list of swap file names, like what "vim -r" shows.
10875 See the |-r| command argument. The 'directory' option is used
10876 for the directories to inspect. If you only want to get a
10877 list of swap files in the current directory then temporarily
10878 set 'directory' to a dot: >
10879 let save_dir = &directory
10880 let &directory = '.'
10881 let swapfiles = swapfilelist()
10882 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010883<
10884 Return type: list<string>
10885
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000010886
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010887swapinfo({fname}) *swapinfo()*
10888 The result is a dictionary, which holds information about the
10889 swapfile {fname}. The available fields are:
10890 version Vim version
10891 user user name
10892 host host name
10893 fname original file name
10894 pid PID of the Vim process that created the swap
10895 file
10896 mtime last modification time in seconds
10897 inode Optional: INODE number of the file
10898 dirty 1 if file was modified, 0 if not
10899 Note that "user" and "host" are truncated to at most 39 bytes.
10900 In case of failure an "error" item is added with the reason:
10901 Cannot open file: file not found or in accessible
10902 Cannot read file: cannot read first block
10903 Not a swap file: does not contain correct block ID
10904 Magic number mismatch: Info in first block is invalid
10905
10906 Can also be used as a |method|: >
10907 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010908<
10909 Return type: dict<any> or dict<string>
10910
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010911
10912swapname({buf}) *swapname()*
10913 The result is the swap file path of the buffer {expr}.
10914 For the use of {buf}, see |bufname()| above.
10915 If buffer {buf} is the current buffer, the result is equal to
10916 |:swapname| (unless there is no swap file).
10917 If buffer {buf} has no swap file, returns an empty string.
10918
10919 Can also be used as a |method|: >
10920 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010921<
10922 Return type: |String|
10923
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010924
10925synID({lnum}, {col}, {trans}) *synID()*
10926 The result is a Number, which is the syntax ID at the position
10927 {lnum} and {col} in the current window.
10928 The syntax ID can be used with |synIDattr()| and
10929 |synIDtrans()| to obtain syntax information about text.
10930
10931 {col} is 1 for the leftmost column, {lnum} is 1 for the first
10932 line. 'synmaxcol' applies, in a longer line zero is returned.
10933 Note that when the position is after the last character,
10934 that's where the cursor can be in Insert mode, synID() returns
10935 zero. {lnum} is used like with |getline()|.
10936
10937 When {trans} is |TRUE|, transparent items are reduced to the
10938 item that they reveal. This is useful when wanting to know
10939 the effective color. When {trans} is |FALSE|, the transparent
10940 item is returned. This is useful when wanting to know which
10941 syntax item is effective (e.g. inside parens).
10942 Warning: This function can be very slow. Best speed is
10943 obtained by going through the file in forward direction.
10944
Bram Moolenaard592deb2022-06-17 15:42:40 +010010945 Returns zero on error.
10946
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010947 Example (echoes the name of the syntax item under the cursor): >
10948 :echo synIDattr(synID(line("."), col("."), 1), "name")
10949<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010950 Return type: |Number|
10951
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010952
10953synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
10954 The result is a String, which is the {what} attribute of
10955 syntax ID {synID}. This can be used to obtain information
10956 about a syntax item.
10957 {mode} can be "gui", "cterm" or "term", to get the attributes
10958 for that mode. When {mode} is omitted, or an invalid value is
10959 used, the attributes for the currently active highlighting are
10960 used (GUI, cterm or term).
10961 Use synIDtrans() to follow linked highlight groups.
10962 {what} result
10963 "name" the name of the syntax item
10964 "fg" foreground color (GUI: color name used to set
10965 the color, cterm: color number as a string,
10966 term: empty string)
10967 "bg" background color (as with "fg")
10968 "font" font name (only available in the GUI)
10969 |highlight-font|
10970 "sp" special color for the GUI (as with "fg")
10971 |highlight-guisp|
10972 "ul" underline color for cterm: number as a string
10973 "fg#" like "fg", but for the GUI and the GUI is
10974 running the name in "#RRGGBB" form
10975 "bg#" like "fg#" for "bg"
10976 "sp#" like "fg#" for "sp"
10977 "bold" "1" if bold
10978 "italic" "1" if italic
10979 "reverse" "1" if reverse
10980 "inverse" "1" if inverse (= reverse)
10981 "standout" "1" if standout
10982 "underline" "1" if underlined
10983 "undercurl" "1" if undercurled
10984 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010010985 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010986
Bram Moolenaard592deb2022-06-17 15:42:40 +010010987 Returns an empty string on error.
10988
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010989 Example (echoes the color of the syntax item under the
10990 cursor): >
10991 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
10992<
10993 Can also be used as a |method|: >
10994 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010995<
10996 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010997
10998
10999synIDtrans({synID}) *synIDtrans()*
11000 The result is a Number, which is the translated syntax ID of
11001 {synID}. This is the syntax group ID of what is being used to
11002 highlight the character. Highlight links given with
11003 ":highlight link" are followed.
11004
Bram Moolenaard592deb2022-06-17 15:42:40 +010011005 Returns zero on error.
11006
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011007 Can also be used as a |method|: >
11008 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011009<
11010 Return type: |Number|
11011
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011012
11013synconcealed({lnum}, {col}) *synconcealed()*
11014 The result is a |List| with currently three items:
11015 1. The first item in the list is 0 if the character at the
11016 position {lnum} and {col} is not part of a concealable
11017 region, 1 if it is. {lnum} is used like with |getline()|.
11018 2. The second item in the list is a string. If the first item
11019 is 1, the second item contains the text which will be
11020 displayed in place of the concealed text, depending on the
11021 current setting of 'conceallevel' and 'listchars'.
11022 3. The third and final item in the list is a number
11023 representing the specific syntax region matched in the
11024 line. When the character is not concealed the value is
11025 zero. This allows detection of the beginning of a new
11026 concealable region if there are two consecutive regions
11027 with the same replacement character. For an example, if
11028 the text is "123456" and both "23" and "45" are concealed
11029 and replaced by the character "X", then:
11030 call returns ~
11031 synconcealed(lnum, 1) [0, '', 0]
11032 synconcealed(lnum, 2) [1, 'X', 1]
11033 synconcealed(lnum, 3) [1, 'X', 1]
11034 synconcealed(lnum, 4) [1, 'X', 2]
11035 synconcealed(lnum, 5) [1, 'X', 2]
11036 synconcealed(lnum, 6) [0, '', 0]
11037
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011038 Note: Doesn't consider |matchadd()| highlighting items,
11039 since syntax and matching highlighting are two different
11040 mechanisms |syntax-vs-match|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011041<
11042 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011043
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011044
11045synstack({lnum}, {col}) *synstack()*
11046 Return a |List|, which is the stack of syntax items at the
11047 position {lnum} and {col} in the current window. {lnum} is
11048 used like with |getline()|. Each item in the List is an ID
11049 like what |synID()| returns.
11050 The first item in the List is the outer region, following are
11051 items contained in that one. The last one is what |synID()|
11052 returns, unless not the whole item is highlighted or it is a
11053 transparent item.
11054 This function is useful for debugging a syntax file.
11055 Example that shows the syntax stack under the cursor: >
11056 for id in synstack(line("."), col("."))
11057 echo synIDattr(id, "name")
11058 endfor
11059< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011060 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011061 character in a line and the first column in an empty line are
11062 valid positions.
11063
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011064 Return type: list<number> or list<any>
11065
11066
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011067system({expr} [, {input}]) *system()* *E677*
11068 Get the output of the shell command {expr} as a |String|. See
11069 |systemlist()| to get the output as a |List|.
11070
11071 When {input} is given and is a |String| this string is written
11072 to a file and passed as stdin to the command. The string is
11073 written as-is, you need to take care of using the correct line
11074 separators yourself.
11075 If {input} is given and is a |List| it is written to the file
11076 in a way |writefile()| does with {binary} set to "b" (i.e.
11077 with a newline between each list item with newlines inside
11078 list items converted to NULs).
11079 When {input} is given and is a number that is a valid id for
11080 an existing buffer then the content of the buffer is written
11081 to the file line by line, each line terminated by a NL and
11082 NULs characters where the text has a NL.
11083
11084 Pipes are not used, the 'shelltemp' option is not used.
11085
11086 When prepended by |:silent| the terminal will not be set to
11087 cooked mode. This is meant to be used for commands that do
11088 not need the user to type. It avoids stray characters showing
11089 up on the screen which require |CTRL-L| to remove. >
11090 :silent let f = system('ls *.vim')
11091<
11092 Note: Use |shellescape()| or |::S| with |expand()| or
11093 |fnamemodify()| to escape special characters in a command
11094 argument. Newlines in {expr} may cause the command to fail.
11095 The characters in 'shellquote' and 'shellxquote' may also
11096 cause trouble.
11097 This is not to be used for interactive commands.
11098
11099 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011100 :let files = system('ls ' .. shellescape(expand('%:h')))
11101 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011102
11103< To make the result more system-independent, the shell output
11104 is filtered to replace <CR> with <NL> for Macintosh, and
11105 <CR><NL> with <NL> for DOS-like systems.
11106 To avoid the string being truncated at a NUL, all NUL
11107 characters are replaced with SOH (0x01).
11108
11109 The command executed is constructed using several options:
11110 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11111 ({tmp} is an automatically generated file name).
11112 For Unix, braces are put around {expr} to allow for
11113 concatenated commands.
11114
11115 The command will be executed in "cooked" mode, so that a
11116 CTRL-C will interrupt the command (on Unix at least).
11117
11118 The resulting error code can be found in |v:shell_error|.
11119 This function will fail in |restricted-mode|.
11120
11121 Note that any wrong value in the options mentioned above may
11122 make the function fail. It has also been reported to fail
11123 when using a security agent application.
11124 Unlike ":!cmd" there is no automatic check for changed files.
11125 Use |:checktime| to force a check.
11126
11127 Can also be used as a |method|: >
11128 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011129<
11130 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011131
11132
11133systemlist({expr} [, {input}]) *systemlist()*
11134 Same as |system()|, but returns a |List| with lines (parts of
11135 output separated by NL) with NULs transformed into NLs. Output
11136 is the same as |readfile()| will output with {binary} argument
11137 set to "b", except that there is no extra empty item when the
11138 result ends in a NL.
11139 Note that on MS-Windows you may get trailing CR characters.
11140
11141 To see the difference between "echo hello" and "echo -n hello"
11142 use |system()| and |split()|: >
11143 echo system('echo hello')->split('\n', 1)
11144<
11145 Returns an empty string on error.
11146
11147 Can also be used as a |method|: >
11148 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011149<
11150 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011151
11152
11153tabpagebuflist([{arg}]) *tabpagebuflist()*
11154 The result is a |List|, where each item is the number of the
11155 buffer associated with each window in the current tab page.
11156 {arg} specifies the number of the tab page to be used. When
11157 omitted the current tab page is used.
11158 When {arg} is invalid the number zero is returned.
11159 To get a list of all buffers in all tabs use this: >
11160 let buflist = []
11161 for i in range(tabpagenr('$'))
11162 call extend(buflist, tabpagebuflist(i + 1))
11163 endfor
11164< Note that a buffer may appear in more than one window.
11165
11166 Can also be used as a |method|: >
11167 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011168<
11169 Return type: list<number>
11170
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011171
11172tabpagenr([{arg}]) *tabpagenr()*
11173 The result is a Number, which is the number of the current
11174 tab page. The first tab page has number 1.
11175
11176 The optional argument {arg} supports the following values:
11177 $ the number of the last tab page (the tab page
11178 count).
11179 # the number of the last accessed tab page
11180 (where |g<Tab>| goes to). if there is no
11181 previous tab page 0 is returned.
11182 The number can be used with the |:tab| command.
11183
Bram Moolenaard592deb2022-06-17 15:42:40 +010011184 Returns zero on error.
11185
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011186 Return type: |Number|
11187
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011188
11189tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11190 Like |winnr()| but for tab page {tabarg}.
11191 {tabarg} specifies the number of tab page to be used.
11192 {arg} is used like with |winnr()|:
11193 - When omitted the current window number is returned. This is
11194 the window which will be used when going to this tab page.
11195 - When "$" the number of windows is returned.
11196 - When "#" the previous window nr is returned.
11197 Useful examples: >
11198 tabpagewinnr(1) " current window of tab page 1
11199 tabpagewinnr(4, '$') " number of windows in tab page 4
11200< When {tabarg} is invalid zero is returned.
11201
11202 Can also be used as a |method|: >
11203 GetTabpage()->tabpagewinnr()
11204<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011205 Return type: |Number|
11206
11207
11208tagfiles() *tagfiles()*
11209 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011210 for the current buffer. This is the 'tags' option expanded.
11211
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011212 Return type: list<string> or list<any>
11213
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011214
11215taglist({expr} [, {filename}]) *taglist()*
11216 Returns a |List| of tags matching the regular expression {expr}.
11217
11218 If {filename} is passed it is used to prioritize the results
11219 in the same way that |:tselect| does. See |tag-priority|.
11220 {filename} should be the full path of the file.
11221
11222 Each list item is a dictionary with at least the following
11223 entries:
11224 name Name of the tag.
11225 filename Name of the file where the tag is
11226 defined. It is either relative to the
11227 current directory or a full path.
11228 cmd Ex command used to locate the tag in
11229 the file.
11230 kind Type of the tag. The value for this
11231 entry depends on the language specific
11232 kind values. Only available when
11233 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011234 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011235 static A file specific tag. Refer to
11236 |static-tag| for more information.
11237 More entries may be present, depending on the content of the
11238 tags file: access, implementation, inherits and signature.
11239 Refer to the ctags documentation for information about these
11240 fields. For C code the fields "struct", "class" and "enum"
11241 may appear, they give the name of the entity the tag is
11242 contained in.
11243
11244 The ex-command "cmd" can be either an ex search pattern, a
11245 line number or a line number followed by a byte number.
11246
11247 If there are no matching tags, then an empty list is returned.
11248
11249 To get an exact tag match, the anchors '^' and '$' should be
11250 used in {expr}. This also make the function work faster.
11251 Refer to |tag-regexp| for more information about the tag
11252 search regular expression pattern.
11253
11254 Refer to |'tags'| for information about how the tags file is
11255 located by Vim. Refer to |tags-file-format| for the format of
11256 the tags file generated by the different ctags tools.
11257
11258 Can also be used as a |method|: >
11259 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011260<
11261 Return type: list<dict<any>> or list<any>
11262
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011263
11264tan({expr}) *tan()*
11265 Return the tangent of {expr}, measured in radians, as a |Float|
11266 in the range [-inf, inf].
11267 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011268 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011269 Examples: >
11270 :echo tan(10)
11271< 0.648361 >
11272 :echo tan(-4.01)
11273< -1.181502
11274
11275 Can also be used as a |method|: >
11276 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011277<
11278 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011279
11280
11281tanh({expr}) *tanh()*
11282 Return the hyperbolic tangent of {expr} as a |Float| in the
11283 range [-1, 1].
11284 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011285 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011286 Examples: >
11287 :echo tanh(0.5)
11288< 0.462117 >
11289 :echo tanh(-1)
11290< -0.761594
11291
11292 Can also be used as a |method|: >
11293 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011294<
11295 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011296
11297
11298tempname() *tempname()* *temp-file-name*
11299 The result is a String, which is the name of a file that
11300 doesn't exist. It can be used for a temporary file. The name
11301 is different for at least 26 consecutive calls. Example: >
11302 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011303 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011304< For Unix, the file will be in a private directory |tempfile|
11305 that is recursively deleted when Vim exits, on other systems
11306 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011307 For MS-Windows forward slashes are used when the 'shellslash'
11308 option is set, or when 'shellcmdflag' starts with '-' and
11309 'shell' does not contain powershell or pwsh.
11310
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011311 Return type: |String|
11312
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011313
11314term_ functions are documented here: |terminal-function-details|
11315
11316
11317terminalprops() *terminalprops()*
11318 Returns a |Dictionary| with properties of the terminal that Vim
11319 detected from the response to |t_RV| request. See
11320 |v:termresponse| for the response itself. If |v:termresponse|
11321 is empty most values here will be 'u' for unknown.
11322 cursor_style whether sending |t_RS| works **
11323 cursor_blink_mode whether sending |t_RC| works **
11324 underline_rgb whether |t_8u| works **
11325 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011326 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011327
11328 ** value 'u' for unknown, 'y' for yes, 'n' for no
11329
11330 If the |+termresponse| feature is missing then the result is
11331 an empty dictionary.
11332
11333 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11334 current cursor style.
11335 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11336 request the cursor blink status.
11337 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11338 is not empty, Vim will detect the working of sending |t_RS|
11339 and |t_RC| on startup.
11340
11341 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11342 This avoids sending it to xterm, which would clear the colors.
11343
11344 For "mouse" the value 'u' is unknown
11345
11346 Also see:
11347 - 'ambiwidth' - detected by using |t_u7|.
11348 - |v:termstyleresp| and |v:termblinkresp| for the response to
11349 |t_RS| and |t_RC|.
11350
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011351 Return type: dict<string>
11352
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011353
11354test_ functions are documented here: |test-functions-details|
11355
11356
11357 *timer_info()*
11358timer_info([{id}])
11359 Return a list with information about timers.
11360 When {id} is given only information about this timer is
11361 returned. When timer {id} does not exist an empty list is
11362 returned.
11363 When {id} is omitted information about all timers is returned.
11364
11365 For each timer the information is stored in a |Dictionary| with
11366 these items:
11367 "id" the timer ID
11368 "time" time the timer was started with
11369 "remaining" time until the timer fires
11370 "repeat" number of times the timer will still fire;
11371 -1 means forever
11372 "callback" the callback
11373 "paused" 1 if the timer is paused, 0 otherwise
11374
11375 Can also be used as a |method|: >
11376 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011377<
11378 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011379
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011380 {only available when compiled with the |+timers| feature}
11381
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011382
11383timer_pause({timer}, {paused}) *timer_pause()*
11384 Pause or unpause a timer. A paused timer does not invoke its
11385 callback when its time expires. Unpausing a timer may cause
11386 the callback to be invoked almost immediately if enough time
11387 has passed.
11388
11389 Pausing a timer is useful to avoid the callback to be called
11390 for a short time.
11391
11392 If {paused} evaluates to a non-zero Number or a non-empty
11393 String, then the timer is paused, otherwise it is unpaused.
11394 See |non-zero-arg|.
11395
11396 Can also be used as a |method|: >
11397 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011398<
11399 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011400
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011401 {only available when compiled with the |+timers| feature}
11402
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011403
11404 *timer_start()* *timer* *timers*
11405timer_start({time}, {callback} [, {options}])
11406 Create a timer and return the timer ID.
11407
11408 {time} is the waiting time in milliseconds. This is the
11409 minimum time before invoking the callback. When the system is
11410 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011411 Zero can be used to execute the callback when Vim is back in
11412 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011413
11414 {callback} is the function to call. It can be the name of a
11415 function or a |Funcref|. It is called with one argument, which
11416 is the timer ID. The callback is only invoked when Vim is
11417 waiting for input.
11418 If you want to show a message look at |popup_notification()|
11419 to avoid interfering with what the user is doing.
11420
11421 {options} is a dictionary. Supported entries:
11422 "repeat" Number of times to repeat calling the
11423 callback. -1 means forever. When not present
11424 the callback will be called once.
11425 If the timer causes an error three times in a
11426 row the repeat is cancelled. This avoids that
11427 Vim becomes unusable because of all the error
11428 messages.
11429
Bram Moolenaard592deb2022-06-17 15:42:40 +010011430 Returns -1 on error.
11431
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011432 Example: >
11433 func MyHandler(timer)
11434 echo 'Handler called'
11435 endfunc
11436 let timer = timer_start(500, 'MyHandler',
11437 \ {'repeat': 3})
11438< This will invoke MyHandler() three times at 500 msec
11439 intervals.
11440
11441 Can also be used as a |method|: >
11442 GetMsec()->timer_start(callback)
11443
11444< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011445
11446 Return type: |Number|
11447
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011448 {only available when compiled with the |+timers| feature}
11449
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011450
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011451timer_stop({timer}) *timer_stop()*
11452 Stop a timer. The timer callback will no longer be invoked.
11453 {timer} is an ID returned by timer_start(), thus it must be a
11454 Number. If {timer} does not exist there is no error.
11455
11456 Can also be used as a |method|: >
11457 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011458<
11459 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011460
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011461 {only available when compiled with the |+timers| feature}
11462
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011463
11464timer_stopall() *timer_stopall()*
11465 Stop all timers. The timer callbacks will no longer be
11466 invoked. Useful if a timer is misbehaving. If there are no
11467 timers there is no error.
11468
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011469 Return type: |Number|
11470
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011471 {only available when compiled with the |+timers| feature}
11472
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011473
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011474tolower({expr}) *tolower()*
11475 The result is a copy of the String given, with all uppercase
11476 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011477 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011478
11479 Can also be used as a |method|: >
11480 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011481<
11482 Return type: |String|
11483
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011484
11485toupper({expr}) *toupper()*
11486 The result is a copy of the String given, with all lowercase
11487 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011488 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011489
11490 Can also be used as a |method|: >
11491 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011492<
11493 Return type: |String|
11494
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011495
11496tr({src}, {fromstr}, {tostr}) *tr()*
11497 The result is a copy of the {src} string with all characters
11498 which appear in {fromstr} replaced by the character in that
11499 position in the {tostr} string. Thus the first character in
11500 {fromstr} is translated into the first character in {tostr}
11501 and so on. Exactly like the unix "tr" command.
11502 This code also deals with multibyte characters properly.
11503
Bram Moolenaard592deb2022-06-17 15:42:40 +010011504 Returns an empty string on error.
11505
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011506 Examples: >
11507 echo tr("hello there", "ht", "HT")
11508< returns "Hello THere" >
11509 echo tr("<blob>", "<>", "{}")
11510< returns "{blob}"
11511
11512 Can also be used as a |method|: >
11513 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011514<
11515 Return type: |String|
11516
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011517
11518trim({text} [, {mask} [, {dir}]]) *trim()*
11519 Return {text} as a String where any character in {mask} is
11520 removed from the beginning and/or end of {text}.
11521
Illia Bobyr80799172023-10-17 18:00:50 +020011522 If {mask} is not given, or is an empty string, {mask} is all
11523 characters up to 0x20, which includes Tab, space, NL and CR,
11524 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011525
11526 The optional {dir} argument specifies where to remove the
11527 characters:
11528 0 remove from the beginning and end of {text}
11529 1 remove only at the beginning of {text}
11530 2 remove only at the end of {text}
11531 When omitted both ends are trimmed.
11532
11533 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011534 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011535
11536 Examples: >
11537 echo trim(" some text ")
11538< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011539 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011540< returns "RESERVE_TAIL" >
11541 echo trim("rm<Xrm<>X>rrm", "rm<>")
11542< returns "Xrm<>X" (characters in the middle are not removed) >
11543 echo trim(" vim ", " ", 2)
11544< returns " vim"
11545
11546 Can also be used as a |method|: >
11547 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011548<
11549 Return type: |String|
11550
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011551
11552trunc({expr}) *trunc()*
11553 Return the largest integral value with magnitude less than or
11554 equal to {expr} as a |Float| (truncate towards zero).
11555 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011556 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011557 Examples: >
11558 echo trunc(1.456)
11559< 1.0 >
11560 echo trunc(-5.456)
11561< -5.0 >
11562 echo trunc(4.0)
11563< 4.0
11564
11565 Can also be used as a |method|: >
11566 Compute()->trunc()
11567<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011568 Return type: |Float|
11569
11570
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011571 *type()*
11572type({expr}) The result is a Number representing the type of {expr}.
11573 Instead of using the number directly, it is better to use the
11574 v:t_ variable that has the value:
11575 Number: 0 |v:t_number|
11576 String: 1 |v:t_string|
11577 Funcref: 2 |v:t_func|
11578 List: 3 |v:t_list|
11579 Dictionary: 4 |v:t_dict|
11580 Float: 5 |v:t_float|
11581 Boolean: 6 |v:t_bool| (v:false and v:true)
11582 None: 7 |v:t_none| (v:null and v:none)
11583 Job: 8 |v:t_job|
11584 Channel: 9 |v:t_channel|
11585 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090011586 Class: 12 |v:t_class|
11587 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010011588 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011589 Enum: 15 |v:t_enum|
11590 EnumValue: 16 |v:t_enumvalue|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011591 For backward compatibility, this method can be used: >
11592 :if type(myvar) == type(0)
11593 :if type(myvar) == type("")
11594 :if type(myvar) == type(function("tr"))
11595 :if type(myvar) == type([])
11596 :if type(myvar) == type({})
11597 :if type(myvar) == type(0.0)
11598 :if type(myvar) == type(v:false)
11599 :if type(myvar) == type(v:none)
11600< To check if the v:t_ variables exist use this: >
11601 :if exists('v:t_number')
11602
11603< Can also be used as a |method|: >
11604 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011605<
11606 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011607
11608
11609typename({expr}) *typename()*
11610 Return a string representation of the type of {expr}.
11611 Example: >
11612 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000011613< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011614
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011615 Return type: |String|
11616
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011617
11618undofile({name}) *undofile()*
11619 Return the name of the undo file that would be used for a file
11620 with name {name} when writing. This uses the 'undodir'
11621 option, finding directories that exist. It does not check if
11622 the undo file exists.
11623 {name} is always expanded to the full path, since that is what
11624 is used internally.
11625 If {name} is empty undofile() returns an empty string, since a
11626 buffer without a file name will not write an undo file.
11627 Useful in combination with |:wundo| and |:rundo|.
11628 When compiled without the |+persistent_undo| option this always
11629 returns an empty string.
11630
11631 Can also be used as a |method|: >
11632 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011633<
11634 Return type: |String|
11635
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011636
Devin J. Pohly5fee1112023-04-23 20:26:59 -050011637undotree([{buf}]) *undotree()*
11638 Return the current state of the undo tree for the current
11639 buffer, or for a specific buffer if {buf} is given. The
11640 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011641 "seq_last" The highest undo sequence number used.
11642 "seq_cur" The sequence number of the current position in
11643 the undo tree. This differs from "seq_last"
11644 when some changes were undone.
11645 "time_cur" Time last used for |:earlier| and related
11646 commands. Use |strftime()| to convert to
11647 something readable.
11648 "save_last" Number of the last file write. Zero when no
11649 write yet.
11650 "save_cur" Number of the current position in the undo
11651 tree.
11652 "synced" Non-zero when the last undo block was synced.
11653 This happens when waiting from input from the
11654 user. See |undo-blocks|.
11655 "entries" A list of dictionaries with information about
11656 undo blocks.
11657
11658 The first item in the "entries" list is the oldest undo item.
11659 Each List item is a |Dictionary| with these items:
11660 "seq" Undo sequence number. Same as what appears in
11661 |:undolist|.
11662 "time" Timestamp when the change happened. Use
11663 |strftime()| to convert to something readable.
11664 "newhead" Only appears in the item that is the last one
11665 that was added. This marks the last change
11666 and where further changes will be added.
11667 "curhead" Only appears in the item that is the last one
11668 that was undone. This marks the current
11669 position in the undo tree, the block that will
11670 be used by a redo command. When nothing was
11671 undone after the last change this item will
11672 not appear anywhere.
11673 "save" Only appears on the last block before a file
11674 write. The number is the write count. The
11675 first write has number 1, the last one the
11676 "save_last" mentioned above.
11677 "alt" Alternate entry. This is again a List of undo
11678 blocks. Each item may again have an "alt"
11679 item.
11680
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011681 Return type: dict<any>
11682
11683
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011684uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
11685 Remove second and succeeding copies of repeated adjacent
11686 {list} items in-place. Returns {list}. If you want a list
11687 to remain unmodified make a copy first: >
11688 :let newlist = uniq(copy(mylist))
11689< The default compare function uses the string representation of
11690 each item. For the use of {func} and {dict} see |sort()|.
11691
Bram Moolenaard592deb2022-06-17 15:42:40 +010011692 Returns zero if {list} is not a |List|.
11693
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011694 Can also be used as a |method|: >
11695 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010011696<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011697 Return type: list<{type}>
11698
11699
Christian Brabandt67672ef2023-04-24 21:09:54 +010011700 *utf16idx()*
11701utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011702 Same as |charidx()| but returns the UTF-16 code unit index of
11703 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010011704
11705 When {charidx} is present and TRUE, {idx} is used as the
11706 character index in the String {string} instead of as the byte
11707 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010011708 An {idx} in the middle of a UTF-8 sequence is rounded
11709 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010011710
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011711 Returns -1 if the arguments are invalid or if there are less
11712 than {idx} bytes in {string}. If there are exactly {idx} bytes
11713 the length of the string in UTF-16 code units is returned.
11714
Christian Brabandt67672ef2023-04-24 21:09:54 +010011715 See |byteidx()| and |byteidxcomp()| for getting the byte index
11716 from the UTF-16 index and |charidx()| for getting the
11717 character index from the UTF-16 index.
11718 Refer to |string-offset-encoding| for more information.
11719 Examples: >
11720 echo utf16idx('a😊😊', 3) returns 2
11721 echo utf16idx('a😊😊', 7) returns 4
11722 echo utf16idx('a😊😊', 1, 0, 1) returns 2
11723 echo utf16idx('a😊😊', 2, 0, 1) returns 4
11724 echo utf16idx('aą́c', 6) returns 2
11725 echo utf16idx('aą́c', 6, 1) returns 4
11726 echo utf16idx('a😊😊', 9) returns -1
11727<
11728 Can also be used as a |method|: >
11729 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011730<
11731 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010011732
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011733
11734values({dict}) *values()*
11735 Return a |List| with all the values of {dict}. The |List| is
11736 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011737 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011738
11739 Can also be used as a |method|: >
11740 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011741<
11742 Return type: list<any>
11743
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011744
zeertzjq825cf812023-08-17 22:55:25 +020011745virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011746 The result is a Number, which is the screen column of the file
11747 position given with {expr}. That is, the last screen position
11748 occupied by the character at that position, when the screen
11749 would be of unlimited width. When there is a <Tab> at the
11750 position, the returned Number will be the column at the end of
11751 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
11752 set to 8, it returns 8. |conceal| is ignored.
11753 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011754
zeertzjq02f3eba2024-06-12 20:45:24 +020011755 For the use of {expr} see |getpos()| and |col()|.
zeertzjqd353d272024-06-13 23:00:25 +080011756 When {expr} is "$", it means the end of the cursor line, so
11757 the result is the number of cells in the cursor line plus one.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011758
11759 When 'virtualedit' is used {expr} can be [lnum, col, off],
11760 where "off" is the offset in screen columns from the start of
11761 the character. E.g., a position within a <Tab> or after the
11762 last character. When "off" is omitted zero is used. When
11763 Virtual editing is active in the current mode, a position
11764 beyond the end of the line can be returned. Also see
11765 |'virtualedit'|
11766
zeertzjq825cf812023-08-17 22:55:25 +020011767 If {list} is present and non-zero then virtcol() returns a
11768 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010011769 character.
11770
zeertzjq825cf812023-08-17 22:55:25 +020011771 With the optional {winid} argument the values are obtained for
11772 that window instead of the current window.
11773
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011774 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +020011775
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011776 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010011777 " With text "foo^Lbar" and cursor on the "^L":
11778
11779 virtcol(".") " returns 5
11780 virtcol(".", 1) " returns [4, 5]
11781 virtcol("$") " returns 9
11782
11783 " With text " there", with 't at 'h':
11784
11785 virtcol("'t") " returns 6
zeertzjq02f3eba2024-06-12 20:45:24 +020011786<
11787 The first column is 1. 0 or [0, 0] is returned for an error.
11788
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011789 A more advanced example that echoes the maximum length of
11790 all lines: >
11791 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
11792
11793< Can also be used as a |method|: >
11794 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011795<
11796 Return type: |Number|
11797
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011798
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011799virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
11800 The result is a Number, which is the byte index of the
11801 character in window {winid} at buffer line {lnum} and virtual
11802 column {col}.
11803
zeertzjqb583eda2023-10-14 11:32:28 +020011804 If buffer line {lnum} is an empty line, 0 is returned.
11805
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011806 If {col} is greater than the last virtual column in line
11807 {lnum}, then the byte index of the character at the last
11808 virtual column is returned.
11809
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020011810 For a multi-byte character, the column number of the first
11811 byte in the character is returned.
11812
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011813 The {winid} argument can be the window number or the
11814 |window-ID|. If this is zero, then the current window is used.
11815
11816 Returns -1 if the window {winid} doesn't exist or the buffer
11817 line {lnum} or virtual column {col} is invalid.
11818
11819 See also |screenpos()|, |virtcol()| and |col()|.
11820
11821 Can also be used as a |method|: >
11822 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011823<
11824 Return type: |Number|
11825
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011826
11827visualmode([{expr}]) *visualmode()*
11828 The result is a String, which describes the last Visual mode
11829 used in the current buffer. Initially it returns an empty
11830 string, but once Visual mode has been used, it returns "v",
11831 "V", or "<CTRL-V>" (a single CTRL-V character) for
11832 character-wise, line-wise, or block-wise Visual mode
11833 respectively.
11834 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011835 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011836< This enters the same Visual mode as before. It is also useful
11837 in scripts if you wish to act differently depending on the
11838 Visual mode that was used.
11839 If Visual mode is active, use |mode()| to get the Visual mode
11840 (e.g., in a |:vmap|).
11841 If {expr} is supplied and it evaluates to a non-zero Number or
11842 a non-empty String, then the Visual mode will be cleared and
11843 the old value is returned. See |non-zero-arg|.
11844
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011845 Return type: |String|
11846
11847
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011848wildmenumode() *wildmenumode()*
11849 Returns |TRUE| when the wildmenu is active and |FALSE|
11850 otherwise. See 'wildmenu' and 'wildmode'.
11851 This can be used in mappings to handle the 'wildcharm' option
11852 gracefully. (Makes only sense with |mapmode-c| mappings).
11853
11854 For example to make <c-j> work like <down> in wildmode, use: >
11855 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
11856<
11857 (Note, this needs the 'wildcharm' option set appropriately).
11858
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011859 Return type: |Number|
11860
11861
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011862win_execute({id}, {command} [, {silent}]) *win_execute()*
11863 Like `execute()` but in the context of window {id}.
11864 The window will temporarily be made the current window,
11865 without triggering autocommands or changing directory. When
11866 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010011867 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011868 Example: >
11869 call win_execute(winid, 'set syntax=python')
11870< Doing the same with `setwinvar()` would not trigger
11871 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011872 *E994*
11873 Not all commands are allowed in popup windows.
11874 When window {id} does not exist then no error is given and
11875 an empty string is returned.
11876
11877 Can also be used as a |method|, the base is passed as the
11878 second argument: >
11879 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011880<
11881 Return type: |String|
11882
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011883
11884win_findbuf({bufnr}) *win_findbuf()*
11885 Returns a |List| with |window-ID|s for windows that contain
11886 buffer {bufnr}. When there is none the list is empty.
11887
11888 Can also be used as a |method|: >
11889 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011890<
11891 Return type: list<number> or list<any>
11892
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011893
11894win_getid([{win} [, {tab}]]) *win_getid()*
11895 Get the |window-ID| for the specified window.
11896 When {win} is missing use the current window.
11897 With {win} this is the window number. The top window has
11898 number 1.
11899 Without {tab} use the current tab, otherwise the tab with
11900 number {tab}. The first tab has number one.
11901 Return zero if the window cannot be found.
11902
11903 Can also be used as a |method|: >
11904 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011905<
11906 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011907
11908
11909win_gettype([{nr}]) *win_gettype()*
11910 Return the type of the window:
11911 "autocmd" autocommand window. Temporary window
11912 used to execute autocommands.
11913 "command" command-line window |cmdwin|
11914 (empty) normal window
11915 "loclist" |location-list-window|
11916 "popup" popup window |popup|
11917 "preview" preview window |preview-window|
11918 "quickfix" |quickfix-window|
11919 "unknown" window {nr} not found
11920
11921 When {nr} is omitted return the type of the current window.
11922 When {nr} is given return the type of this window by number or
11923 |window-ID|.
11924
11925 Also see the 'buftype' option. When running a terminal in a
11926 popup window then 'buftype' is "terminal" and win_gettype()
11927 returns "popup".
11928
11929 Can also be used as a |method|: >
11930 GetWinid()->win_gettype()
11931<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011932 Return type: |String|
11933
11934
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011935win_gotoid({expr}) *win_gotoid()*
11936 Go to window with ID {expr}. This may also change the current
11937 tabpage.
11938 Return TRUE if successful, FALSE if the window cannot be found.
11939
11940 Can also be used as a |method|: >
11941 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011942<
11943 Return type: |Number|
11944
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011945
11946win_id2tabwin({expr}) *win_id2tabwin()*
11947 Return a list with the tab number and window number of window
11948 with ID {expr}: [tabnr, winnr].
11949 Return [0, 0] if the window cannot be found.
11950
11951 Can also be used as a |method|: >
11952 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011953<
11954 Return type: list<number>
11955
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011956
11957win_id2win({expr}) *win_id2win()*
11958 Return the window number of window with ID {expr}.
11959 Return 0 if the window cannot be found in the current tabpage.
11960
11961 Can also be used as a |method|: >
11962 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011963<
11964 Return type: |Number|
11965
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011966
Daniel Steinbergee630312022-01-10 13:36:34 +000011967win_move_separator({nr}, {offset}) *win_move_separator()*
11968 Move window {nr}'s vertical separator (i.e., the right border)
11969 by {offset} columns, as if being dragged by the mouse. {nr}
11970 can be a window number or |window-ID|. A positive {offset}
11971 moves right and a negative {offset} moves left. Moving a
11972 window's vertical separator will change the width of the
11973 window and the width of other windows adjacent to the vertical
11974 separator. The magnitude of movement may be smaller than
11975 specified (e.g., as a consequence of maintaining
11976 'winminwidth'). Returns TRUE if the window can be found and
11977 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011978 This will fail for the rightmost window and a full-width
11979 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000011980 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000011981
11982 Can also be used as a |method|: >
11983 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011984<
11985 Return type: |Number|
11986
Daniel Steinbergee630312022-01-10 13:36:34 +000011987
11988win_move_statusline({nr}, {offset}) *win_move_statusline()*
11989 Move window {nr}'s status line (i.e., the bottom border) by
11990 {offset} rows, as if being dragged by the mouse. {nr} can be a
11991 window number or |window-ID|. A positive {offset} moves down
11992 and a negative {offset} moves up. Moving a window's status
11993 line will change the height of the window and the height of
11994 other windows adjacent to the status line. The magnitude of
11995 movement may be smaller than specified (e.g., as a consequence
11996 of maintaining 'winminheight'). Returns TRUE if the window can
11997 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000011998 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000011999
12000 Can also be used as a |method|: >
12001 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012002<
12003 Return type: |Number|
12004
Daniel Steinbergee630312022-01-10 13:36:34 +000012005
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012006win_screenpos({nr}) *win_screenpos()*
12007 Return the screen position of window {nr} as a list with two
12008 numbers: [row, col]. The first window always has position
12009 [1, 1], unless there is a tabline, then it is [2, 1].
12010 {nr} can be the window number or the |window-ID|. Use zero
12011 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012012 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012013
12014 Can also be used as a |method|: >
12015 GetWinid()->win_screenpos()
12016<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012017 Return type: list<number>
12018
12019
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012020win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012021 Temporarily switch to window {target}, then move window {nr}
12022 to a new split adjacent to {target}.
12023 Unlike commands such as |:split|, no new windows are created
12024 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012025
12026 Both {nr} and {target} can be window numbers or |window-ID|s.
12027 Both must be in the current tab page.
12028
12029 Returns zero for success, non-zero for failure.
12030
12031 {options} is a |Dictionary| with the following optional entries:
12032 "vertical" When TRUE, the split is created vertically,
12033 like with |:vsplit|.
12034 "rightbelow" When TRUE, the split is made below or to the
12035 right (if vertical). When FALSE, it is done
12036 above or to the left (if vertical). When not
12037 present, the values of 'splitbelow' and
12038 'splitright' are used.
12039
12040 Can also be used as a |method|: >
12041 GetWinid()->win_splitmove(target)
12042<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012043 Return type: |Number|
12044
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012045
12046 *winbufnr()*
12047winbufnr({nr}) The result is a Number, which is the number of the buffer
12048 associated with window {nr}. {nr} can be the window number or
12049 the |window-ID|.
12050 When {nr} is zero, the number of the buffer in the current
12051 window is returned.
12052 When window {nr} doesn't exist, -1 is returned.
12053 Example: >
12054 :echo "The file in the current window is " . bufname(winbufnr(0))
12055<
12056 Can also be used as a |method|: >
12057 FindWindow()->winbufnr()->bufname()
12058<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012059 Return type: |Number|
12060
12061
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012062 *wincol()*
12063wincol() The result is a Number, which is the virtual column of the
12064 cursor in the window. This is counting screen cells from the
12065 left side of the window. The leftmost column is one.
12066
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012067 Return type: |Number|
12068
12069
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012070 *windowsversion()*
12071windowsversion()
12072 The result is a String. For MS-Windows it indicates the OS
12073 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12074 Windows XP is "5.1". For non-MS-Windows systems the result is
12075 an empty string.
12076
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012077 Return type: |String|
12078
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012079winheight({nr}) *winheight()*
12080 The result is a Number, which is the height of window {nr}.
12081 {nr} can be the window number or the |window-ID|.
12082 When {nr} is zero, the height of the current window is
12083 returned. When window {nr} doesn't exist, -1 is returned.
12084 An existing window always has a height of zero or more.
12085 This excludes any window toolbar line.
12086 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012087 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012088
12089< Can also be used as a |method|: >
12090 GetWinid()->winheight()
12091<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012092 Return type: |Number|
12093
12094
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012095winlayout([{tabnr}]) *winlayout()*
12096 The result is a nested List containing the layout of windows
12097 in a tabpage.
12098
12099 Without {tabnr} use the current tabpage, otherwise the tabpage
12100 with number {tabnr}. If the tabpage {tabnr} is not found,
12101 returns an empty list.
12102
12103 For a leaf window, it returns:
12104 ['leaf', {winid}]
12105 For horizontally split windows, which form a column, it
12106 returns:
12107 ['col', [{nested list of windows}]]
12108 For vertically split windows, which form a row, it returns:
12109 ['row', [{nested list of windows}]]
12110
12111 Example: >
12112 " Only one window in the tab page
12113 :echo winlayout()
12114 ['leaf', 1000]
12115 " Two horizontally split windows
12116 :echo winlayout()
12117 ['col', [['leaf', 1000], ['leaf', 1001]]]
12118 " The second tab page, with three horizontally split
12119 " windows, with two vertically split windows in the
12120 " middle window
12121 :echo winlayout(2)
12122 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12123 ['leaf', 1001]]], ['leaf', 1000]]]
12124<
12125 Can also be used as a |method|: >
12126 GetTabnr()->winlayout()
12127<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012128 Return type: list<any>
12129
12130
12131winline() *winline()*
12132 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012133 in the window. This is counting screen lines from the top of
12134 the window. The first line is one.
12135 If the cursor was moved the view on the file will be updated
12136 first, this may cause a scroll.
12137
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012138 Return type: |Number|
12139
12140
12141winnr([{arg}]) *winnr()*
12142 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012143 window. The top window has number 1.
12144 Returns zero for a popup window.
12145
12146 The optional argument {arg} supports the following values:
12147 $ the number of the last window (the window
12148 count).
12149 # the number of the last accessed window (where
12150 |CTRL-W_p| goes to). If there is no previous
12151 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012152 returned. May refer to the current window in
12153 some cases (e.g. when evaluating 'statusline'
12154 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012155 {N}j the number of the Nth window below the
12156 current window (where |CTRL-W_j| goes to).
12157 {N}k the number of the Nth window above the current
12158 window (where |CTRL-W_k| goes to).
12159 {N}h the number of the Nth window left of the
12160 current window (where |CTRL-W_h| goes to).
12161 {N}l the number of the Nth window right of the
12162 current window (where |CTRL-W_l| goes to).
12163 The number can be used with |CTRL-W_w| and ":wincmd w"
12164 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012165 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012166 Also see |tabpagewinnr()| and |win_getid()|.
12167 Examples: >
12168 let window_count = winnr('$')
12169 let prev_window = winnr('#')
12170 let wnum = winnr('3k')
12171
12172< Can also be used as a |method|: >
12173 GetWinval()->winnr()
12174<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012175 Return type: |Number|
12176
12177
12178winrestcmd() *winrestcmd()*
12179 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012180 the current window sizes. Only works properly when no windows
12181 are opened or closed and the current window and tab page is
12182 unchanged.
12183 Example: >
12184 :let cmd = winrestcmd()
12185 :call MessWithWindowSizes()
12186 :exe cmd
12187<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012188 Return type: |String|
12189
12190
12191winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012192 Uses the |Dictionary| returned by |winsaveview()| to restore
12193 the view of the current window.
12194 Note: The {dict} does not have to contain all values, that are
12195 returned by |winsaveview()|. If values are missing, those
12196 settings won't be restored. So you can use: >
12197 :call winrestview({'curswant': 4})
12198<
12199 This will only set the curswant value (the column the cursor
12200 wants to move on vertical movements) of the cursor to column 5
12201 (yes, that is 5), while all other settings will remain the
12202 same. This is useful, if you set the cursor position manually.
12203
12204 If you have changed the values the result is unpredictable.
12205 If the window size changed the result won't be the same.
12206
12207 Can also be used as a |method|: >
12208 GetView()->winrestview()
12209<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012210 Return type: |Number|
12211
12212
12213winsaveview() *winsaveview()*
12214 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012215 the view of the current window. Use |winrestview()| to
12216 restore the view.
12217 This is useful if you have a mapping that jumps around in the
12218 buffer and you want to go back to the original view.
12219 This does not save fold information. Use the 'foldenable'
12220 option to temporarily switch off folding, so that folds are
12221 not opened when moving around. This may have side effects.
12222 The return value includes:
12223 lnum cursor line number
12224 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012225 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012226 returns)
12227 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012228 curswant column for vertical movement (Note:
12229 the first column is zero, as opposed
12230 to what |getcurpos()| returns). After
12231 |$| command it will be a very large
12232 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012233 topline first line in the window
12234 topfill filler lines, only in diff mode
12235 leftcol first column displayed; only used when
12236 'wrap' is off
12237 skipcol columns skipped
12238 Note that no option values are saved.
12239
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012240 Return type: dict<number>
12241
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012242
12243winwidth({nr}) *winwidth()*
12244 The result is a Number, which is the width of window {nr}.
12245 {nr} can be the window number or the |window-ID|.
12246 When {nr} is zero, the width of the current window is
12247 returned. When window {nr} doesn't exist, -1 is returned.
12248 An existing window always has a width of zero or more.
12249 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012250 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012251 :if winwidth(0) <= 50
12252 : 50 wincmd |
12253 :endif
12254< For getting the terminal or screen size, see the 'columns'
12255 option.
12256
12257 Can also be used as a |method|: >
12258 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012259<
12260 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012261
12262
12263wordcount() *wordcount()*
12264 The result is a dictionary of byte/chars/word statistics for
12265 the current buffer. This is the same info as provided by
12266 |g_CTRL-G|
12267 The return value includes:
12268 bytes Number of bytes in the buffer
12269 chars Number of chars in the buffer
12270 words Number of words in the buffer
12271 cursor_bytes Number of bytes before cursor position
12272 (not in Visual mode)
12273 cursor_chars Number of chars before cursor position
12274 (not in Visual mode)
12275 cursor_words Number of words before cursor position
12276 (not in Visual mode)
12277 visual_bytes Number of bytes visually selected
12278 (only in Visual mode)
12279 visual_chars Number of chars visually selected
12280 (only in Visual mode)
12281 visual_words Number of words visually selected
12282 (only in Visual mode)
12283
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012284 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012285
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012286
12287writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012288 When {object} is a |List| write it to file {fname}. Each list
12289 item is separated with a NL. Each list item must be a String
12290 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012291 All NL characters are replaced with a NUL character.
12292 Inserting CR characters needs to be done before passing {list}
12293 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012294
12295 When {object} is a |Blob| write the bytes to file {fname}
12296 unmodified, also when binary mode is not specified.
12297
12298 {flags} must be a String. These characters are recognized:
12299
12300 'b' Binary mode is used: There will not be a NL after the
12301 last list item. An empty item at the end does cause the
12302 last line in the file to end in a NL.
12303
12304 'a' Append mode is used, lines are appended to the file: >
12305 :call writefile(["foo"], "event.log", "a")
12306 :call writefile(["bar"], "event.log", "a")
12307<
12308 'D' Delete the file when the current function ends. This
12309 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012310 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012311< Fails when not in a function. Also see |:defer|.
12312
12313 's' fsync() is called after writing the file. This flushes
12314 the file to disk, if possible. This takes more time but
12315 avoids losing the file if the system crashes.
12316
12317 'S' fsync() is not called, even when 'fsync' is set.
12318
12319 When {flags} does not contain "S" or "s" then fsync() is
12320 called if the 'fsync' option is set.
12321
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012322 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012323
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012324 When the write fails -1 is returned, otherwise 0. There is an
12325 error message if the file can't be created or when writing
12326 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012327
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012328 Also see |readfile()|.
12329 To copy a file byte for byte: >
12330 :let fl = readfile("foo", "b")
12331 :call writefile(fl, "foocopy", "b")
12332
12333< Can also be used as a |method|: >
12334 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012335<
12336 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012337
12338
12339xor({expr}, {expr}) *xor()*
12340 Bitwise XOR on the two arguments. The arguments are converted
12341 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012342 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012343 Example: >
12344 :let bits = xor(bits, 0x80)
12345<
12346 Can also be used as a |method|: >
12347 :let bits = bits->xor(0x80)
12348<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012349 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012350
12351==============================================================================
123523. Feature list *feature-list*
12353
12354There are three types of features:
123551. Features that are only supported when they have been enabled when Vim
12356 was compiled |+feature-list|. Example: >
12357 :if has("cindent")
12358< *gui_running*
123592. Features that are only supported when certain conditions have been met.
12360 Example: >
12361 :if has("gui_running")
12362< *has-patch*
123633. Beyond a certain version or at a certain version and including a specific
12364 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12365 later, or it is version 7.4 and patch 248 was included. Example: >
12366 :if has("patch-7.4.248")
12367< Note that it's possible for patch 248 to be omitted even though 249 is
12368 included. Only happens when cherry-picking patches.
12369 Note that this form only works for patch 7.4.237 and later, before that
12370 you need to check for the patch and the v:version. Example (checking
12371 version 6.2.148 or later): >
12372 :if v:version > 602 || (v:version == 602 && has("patch148"))
12373
12374Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12375use: `if exists('+shellslash')`
12376
12377
12378acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012379all_builtin_terms Compiled with all builtin terminals enabled. (always
12380 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012381amiga Amiga version of Vim.
12382arabic Compiled with Arabic support |Arabic|.
12383arp Compiled with ARP support (Amiga).
12384autocmd Compiled with autocommand support. (always true)
12385autochdir Compiled with support for 'autochdir'
12386autoservername Automatically enable |clientserver|
12387balloon_eval Compiled with |balloon-eval| support.
12388balloon_multiline GUI supports multiline balloons.
12389beos BeOS version of Vim.
12390browse Compiled with |:browse| support, and browse() will
12391 work.
12392browsefilter Compiled with support for |browsefilter|.
12393bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012394builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012395byte_offset Compiled with support for 'o' in 'statusline'
12396channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012397cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012398clientserver Compiled with remote invocation support |clientserver|.
12399clipboard Compiled with 'clipboard' support.
12400clipboard_working Compiled with 'clipboard' support and it can be used.
12401cmdline_compl Compiled with |cmdline-completion| support.
12402cmdline_hist Compiled with |cmdline-history| support.
12403cmdline_info Compiled with 'showcmd' and 'ruler' support.
12404comments Compiled with |'comments'| support.
12405compatible Compiled to be very Vi compatible.
12406conpty Platform where |ConPTY| can be used.
12407cryptv Compiled with encryption support |encryption|.
12408cscope Compiled with |cscope| support.
12409cursorbind Compiled with |'cursorbind'| (always true)
12410debug Compiled with "DEBUG" defined.
12411dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012412dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012413dialog_gui Compiled with GUI dialog support.
12414diff Compiled with |vimdiff| and 'diff' support.
12415digraphs Compiled with support for digraphs.
12416directx Compiled with support for DirectX and 'renderoptions'.
12417dnd Compiled with support for the "~ register |quote_~|.
12418drop_file Compiled with |drop_file| support.
12419ebcdic Compiled on a machine with ebcdic character set.
12420emacs_tags Compiled with support for Emacs tags.
12421eval Compiled with expression evaluation support. Always
12422 true, of course!
12423ex_extra |+ex_extra| (always true)
12424extra_search Compiled with support for |'incsearch'| and
12425 |'hlsearch'|
12426farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012427file_in_path Compiled with support for |gf| and |<cfile>| (always
12428 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012429filterpipe When 'shelltemp' is off pipes are used for shell
12430 read/write/filter commands
12431find_in_path Compiled with support for include file searches
12432 |+find_in_path|.
12433float Compiled with support for |Float|.
12434fname_case Case in file names matters (for Amiga and MS-Windows
12435 this is not present).
12436folding Compiled with |folding| support.
12437footer Compiled with GUI footer support. |gui-footer|
12438fork Compiled to use fork()/exec() instead of system().
12439gettext Compiled with message translation |multi-lang|
12440gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012441gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012442gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12443gui_gtk Compiled with GTK+ GUI (any version).
12444gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12445gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12446gui_haiku Compiled with Haiku GUI.
12447gui_mac Compiled with Macintosh GUI.
12448gui_motif Compiled with Motif GUI.
12449gui_photon Compiled with Photon GUI.
12450gui_running Vim is running in the GUI, or it will start soon.
12451gui_win32 Compiled with MS-Windows Win32 GUI.
12452gui_win32s idem, and Win32s system being used (Windows 3.1)
12453haiku Haiku version of Vim.
12454hangul_input Compiled with Hangul input support. |hangul|
12455hpux HP-UX version of Vim.
12456iconv Can use iconv() for conversion.
12457insert_expand Compiled with support for CTRL-X expansion commands in
12458 Insert mode. (always true)
12459job Compiled with support for |channel| and |job|
12460ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012461jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012462keymap Compiled with 'keymap' support.
12463lambda Compiled with |lambda| support.
12464langmap Compiled with 'langmap' support.
12465libcall Compiled with |libcall()| support.
12466linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12467 'breakindent' support.
12468linux Linux version of Vim.
12469lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012470 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012471listcmds Compiled with commands for the buffer list |:files|
12472 and the argument list |arglist|.
12473localmap Compiled with local mappings and abbr. |:map-local|
12474lua Compiled with Lua interface |Lua|.
12475mac Any Macintosh version of Vim cf. osx
12476macunix Synonym for osxdarwin
12477menu Compiled with support for |:menu|.
12478mksession Compiled with support for |:mksession|.
12479modify_fname Compiled with file name modifiers. |filename-modifiers|
12480 (always true)
12481mouse Compiled with support for mouse.
12482mouse_dec Compiled with support for Dec terminal mouse.
12483mouse_gpm Compiled with support for gpm (Linux console mouse)
12484mouse_gpm_enabled GPM mouse is working
12485mouse_netterm Compiled with support for netterm mouse.
12486mouse_pterm Compiled with support for qnx pterm mouse.
12487mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12488mouse_sgr Compiled with support for sgr mouse.
12489mouse_urxvt Compiled with support for urxvt mouse.
12490mouse_xterm Compiled with support for xterm mouse.
12491mouseshape Compiled with support for 'mouseshape'.
12492multi_byte Compiled with support for 'encoding' (always true)
12493multi_byte_encoding 'encoding' is set to a multibyte encoding.
12494multi_byte_ime Compiled with support for IME input method.
12495multi_lang Compiled with support for multiple languages.
12496mzscheme Compiled with MzScheme interface |mzscheme|.
12497nanotime Compiled with sub-second time stamp checks.
12498netbeans_enabled Compiled with support for |netbeans| and connected.
12499netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012500num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012501ole Compiled with OLE automation support for Win32.
12502osx Compiled for macOS cf. mac
12503osxdarwin Compiled for macOS, with |mac-darwin-feature|
12504packages Compiled with |packages| support.
12505path_extra Compiled with up/downwards search in 'path' and 'tags'
12506perl Compiled with Perl interface.
12507persistent_undo Compiled with support for persistent undo history.
12508postscript Compiled with PostScript file printing.
12509printer Compiled with |:hardcopy| support.
12510profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012511prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012512python Python 2.x interface available. |has-python|
12513python_compiled Compiled with Python 2.x interface. |has-python|
12514python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12515python3 Python 3.x interface available. |has-python|
12516python3_compiled Compiled with Python 3.x interface. |has-python|
12517python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012518python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012519pythonx Python 2.x and/or 3.x interface available. |python_x|
12520qnx QNX version of Vim.
12521quickfix Compiled with |quickfix| support.
12522reltime Compiled with |reltime()| support.
12523rightleft Compiled with 'rightleft' support.
12524ruby Compiled with Ruby interface |ruby|.
12525scrollbind Compiled with 'scrollbind' support. (always true)
12526showcmd Compiled with 'showcmd' support.
12527signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012528smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012529sodium Compiled with libsodium for better crypt support
12530sound Compiled with sound support, e.g. `sound_playevent()`
12531spell Compiled with spell checking support |spell|.
12532startuptime Compiled with |--startuptime| support.
12533statusline Compiled with support for 'statusline', 'rulerformat'
12534 and special formats of 'titlestring' and 'iconstring'.
12535sun SunOS version of Vim.
12536sun_workshop Support for Sun |workshop| has been removed.
12537syntax Compiled with syntax highlighting support |syntax|.
12538syntax_items There are active syntax highlighting items for the
12539 current buffer.
12540system Compiled to use system() instead of fork()/exec().
12541tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012542 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012543tag_old_static Support for old static tags was removed, see
12544 |tag-old-static|.
12545tcl Compiled with Tcl interface.
12546termguicolors Compiled with true color in terminal support.
12547terminal Compiled with |terminal| support.
12548terminfo Compiled with terminfo instead of termcap.
12549termresponse Compiled with support for |t_RV| and |v:termresponse|.
12550textobjects Compiled with support for |text-objects|.
12551textprop Compiled with support for |text-properties|.
12552tgetent Compiled with tgetent support, able to use a termcap
12553 or terminfo file.
12554timers Compiled with |timer_start()| support.
12555title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012556 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012557toolbar Compiled with support for |gui-toolbar|.
12558ttyin input is a terminal (tty)
12559ttyout output is a terminal (tty)
12560unix Unix version of Vim. *+unix*
12561unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
12562user_commands User-defined commands. (always true)
12563vartabs Compiled with variable tabstop support |'vartabstop'|.
12564vcon Win32: Virtual console support is working, can use
12565 'termguicolors'. Also see |+vtp|.
12566vertsplit Compiled with vertically split windows |:vsplit|.
12567 (always true)
12568vim_starting True while initial source'ing takes place. |startup|
12569 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000012570vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012571viminfo Compiled with viminfo support.
12572vimscript-1 Compiled Vim script version 1 support
12573vimscript-2 Compiled Vim script version 2 support
12574vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010012575vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012576virtualedit Compiled with 'virtualedit' option. (always true)
12577visual Compiled with Visual mode. (always true)
12578visualextra Compiled with extra Visual mode commands. (always
12579 true) |blockwise-operators|.
12580vms VMS version of Vim.
12581vreplace Compiled with |gR| and |gr| commands. (always true)
12582vtp Compiled for vcon support |+vtp| (check vcon to find
12583 out if it works in the current console).
12584wildignore Compiled with 'wildignore' option.
12585wildmenu Compiled with 'wildmenu' option.
12586win16 old version for MS-Windows 3.1 (always false)
12587win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
12588 64 bits)
12589win32unix Win32 version of Vim, using Unix files (Cygwin)
12590win64 Win64 version of Vim (MS-Windows 64 bit).
12591win95 Win32 version for MS-Windows 95/98/ME (always false)
12592winaltkeys Compiled with 'winaltkeys' option.
12593windows Compiled with support for more than one window.
12594 (always true)
12595writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020012596xattr Compiled with extended attributes support |xattr|
12597 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012598xfontset Compiled with X fontset support |xfontset|.
12599xim Compiled with X input method support |xim|.
12600xpm Compiled with pixmap support.
12601xpm_w32 Compiled with pixmap support for Win32. (Only for
12602 backward compatibility. Use "xpm" instead.)
12603xsmp Compiled with X session management support.
12604xsmp_interact Compiled with interactive X session management support.
12605xterm_clipboard Compiled with support for xterm clipboard.
12606xterm_save Compiled with support for saving and restoring the
12607 xterm screen.
12608x11 Compiled with X11 support.
12609
12610
12611==============================================================================
126124. Matching a pattern in a String *string-match*
12613
12614This is common between several functions. A regexp pattern as explained at
12615|pattern| is normally used to find a match in the buffer lines. When a
12616pattern is used to find a match in a String, almost everything works in the
12617same way. The difference is that a String is handled like it is one line.
12618When it contains a "\n" character, this is not seen as a line break for the
12619pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
12620>
12621 :let a = "aaaa\nxxxx"
12622 :echo matchstr(a, "..\n..")
12623 aa
12624 xx
12625 :echo matchstr(a, "a.x")
12626 a
12627 x
12628
12629Don't forget that "^" will only match at the first character of the String and
12630"$" at the last character of the string. They don't match after or before a
12631"\n".
12632
12633 vim:tw=78:ts=8:noet:ft=help:norl: